0

My aim: I want to broadcast a message to all clients on my page when a specific event occurs. This will probably happen all 15 seconds.

I wanted to work with Websockets and it looks pretty good at the moment. After watching different talks and read multiple project declarations and the official doc, I think I got the deal.

However, I'm stuck on this error message and I don't know what to do anymore:

JBWEB000034: Cannot upgrade from HTTP/1.1 without IO events

Setup:

  • Spring Version 4.1.1
  • JBoss EAP 6.3
  • IntelliJ
  • Maven

I'll dump out all my configurations and the current state of code:

WebsocketController

@Controller
public class WebsocketController extends TextWebSocketHandler{

    @MessageMapping
    @SendTo("/topic/nextImg")
    public Message nextImg() {
        return new Message("next");
    }
}

Message (simple DTO)

public class Message {
    private String message;

    public Message(String message) {
        this.message = message;
    }

    public String getMessage() {
        return message;
    }
}

mvc-dispatcher-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:task="http://www.springframework.org/schema/task"
       xmlns:websocket="http://www.springframework.org/schema/websocket"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd
        http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket-4.1.xsd">

    <context:component-scan base-package="global.pics"/>
    <mvc:annotation-driven/>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

    <bean id="multipartResolver"
                class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

        <!-- setting maximum upload size -->
        <property name="maxUploadSize" value="10000000" />

    </bean>

    <bean id="websocketController" class="global.pics.websocket.WebsocketController"/>

    <websocket:handlers>
        <websocket:mapping path="/next" handler="websocketController"/>
        <websocket:sockjs/>
    </websocket:handlers>


    <websocket:message-broker application-destination-prefix="/app">
        <websocket:stomp-endpoint path="/next">
            <websocket:sockjs/>
        </websocket:stomp-endpoint>
        <websocket:simple-broker prefix="/topic"/>
    </websocket:message-broker>


    <mvc:resources mapping="/resources/**" location="/resources/" />

    <task:scheduled-tasks>
        <task:scheduled ref="queueController" method="nextImg" fixed-rate="13370"/>
    </task:scheduled-tasks>

    <task:scheduled-tasks>
        <task:scheduled ref="imageCounter" method="backup" fixed-delay="60000"/>
    </task:scheduled-tasks>

</beans>

web.xml

<web-app version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>share.pics.global</display-name>

    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>



<!--update: context-param-->

<context-param>
    <param-name>websockets-enabled</param-name>
    <param-value>true</param-value>
</context-param>

</web-app>

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.springapp</groupId>
    <artifactId>picsglobal</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>picsglobal</name>

    <properties>
        <spring.version>4.1.1.RELEASE</spring.version>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.1.10.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.spec.javax.websocket</groupId>
            <artifactId>jboss-websocket-api_1.1_spec</artifactId>
            <version>1.1.1.Final</version>
        </dependency>

        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.2.1</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.4</version>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
            <version>1.2.1.RELEASE</version>
        </dependency>


        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-messaging</artifactId>
            <version>4.1.4.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.13</version>
        </dependency>
        <!--update: looks like this is nescessary for whatever reason-->

        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-spring</artifactId>
            <version>3.0.10.Final</version>
        </dependency>

    </dependencies>

    <build>
        <finalName>picsglobal</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <includes>
                        <include>**/*Tests.java</include>
                    </includes>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
        <repository>
            <id>central</id>
            <url>http://repo1.maven.org/maven/</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>

</project>

If I missed something you can find everything on my Github: https://github.com/r79/picsglobal

I hope anyone is able to help me. This thing gets pretty frustrated, even though it's sommehow my fault for not doing any of the examples and just trying to build something with it.

UPDATE:

I added context-params to my web.xml (see above). It looks like spring-web.xml is deprecated and the solution with the context-param is the updated form.

I also added the following dependency to my pom.xml.

I'm working with the newest Wildfly-Alpha at the moment (9.0.0) because it looks like the current productive version has a bug with spring: https://issues.jboss.org/browse/WFLY-3439

However, I still get error messages. I'm trying to fix those and update this thread if I find a solution. A possible quickfix for others encountering the problem might be switching to Tomcat, it seems it works there. I have to try running it with Wildfly first because I used some dependencies on JBoss.

Newer update:

Looks like the newest WildFly I tried to make this thing working (9.0.0.alpha1) has another bug with Spring: [unable to post a second link because my reputation here is to low, google for "wildfly 9 getresteasyspringvirtualfile", it was the first link there]

It looks like they pulled the Request into their development branch, but I'm not able to build it without errors. At this point, I stop trying to make it work with wildfly and switch to Tomcat.

Solution therefor is to wait out for a bug-free WildFly-environment or to just use Tomcat. I'll answer this Question as soon as I manage to get this thing running on Tomcat.

R79
  • 1
  • 3
  • Take a look here, please: http://stackoverflow.com/questions/24016996/jboss-eap-6-3-beta-with-websocket-and-stockjs-stomp-js-using-spring-framework – Artem Bilan Feb 03 '15 at 21:15
  • @ArtemBilan Allready found this. On the only answer to the question, the first link is dead and the second link refers to the documentation and only tells me that undertow 1.0 (which JBoss uses) is supported. Searches on how to use a jboss-web.xml only refered to the official documentation with no examples on how to bind it in. If anybody is able to explain what that thing is and how to bind it in it might be helpful. – R79 Feb 03 '15 at 21:48
  • I think you mean this one https://github.com/jboss-developer/jboss-eap-quickstarts/tree/6.4.x-develop/websocket-hello – Artem Bilan Feb 03 '15 at 21:57
  • @ArtemBilan Thank you very much. Now it looks like that example doesn't works correctly. Something seems to be wrong with the xml location (essential error message on startup): Message: Unexpected element '{http://www.jboss.com/xml/ns/javaee}enable-websockets' encountered"}} – R79 Feb 03 '15 at 22:15
  • could you update your question then with that jboss-web.xml file – Brian Clozel Feb 04 '15 at 21:48
  • @BrianClozel added the update below the whole submission. Looks like jboss-web.xml is deprecated. – R79 Feb 07 '15 at 21:12

1 Answers1

0

I think you're mixing three issues here.

"Cannot upgrade from HTTP/1.1 without IO events" on JBoss EAP 6.3

This usually means that you forgot to activate "websockets-enabled" in your configuration. The "jboss-web.xml" file may be deprecated now, but not for that JBoss version.

Wildfly 8.2 and WFLY-3439

This doesn't state anywhere that it's related to Spring. Could you elaborate on that? Did you run into this issue?

Wildfly 9.0.0.alpha1

Wildfly 9.0/undertow 1.2 are not officially supported with Spring at the moment (but they may work right now out of the box) - please follow SPR-12469 and report issues there if you have any.

Brian Clozel
  • 56,583
  • 15
  • 167
  • 176
  • 2
    The "jboss-web.xml" is not deprecated. Please follow this: https://github.com/burrsutter/simplechat and the latest docs: https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.3/html/Development_Guide/Create_a_Websocket_Application.html. – Jared Burrows Mar 12 '15 at 15:15