Starting a simple WebSocket Server with Spring integration
<p>I am trying to start a simple websocket server in a spring integration application.</p>

<p>I build my application thanks to the following dependancies : </p>

<pre><code>dependencies {
    compile("org.springframework.boot:spring-boot-starter-integration")
    compile("org.springframework:spring-websocket")
    compile("org.springframework.integration:spring-integration-ip")
    compile("org.springframework.integration:spring-integration-websocket")
    compile('com.fasterxml.jackson.core:jackson-databind')
    compile("org.springframework.integration:spring-integration-feed")   
}
</code></pre>

<p>I launch my application thanks to the following Java file : </p>

<pre><code>import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
org.springframework.integration.annotation.IntegrationComponentScan;

@Configuration
@EnableAutoConfiguration
@IntegrationComponentScan
public class Application {
    public static void main(String[] args) throws Exception {
        ConfigurableApplicationContext ctx = new SpringApplication("/integration.xml").run(args);
        System.out.println("Hit Enter to terminate");
        System.in.read();
        ctx.close();
    }

}
</code></pre>

<p>Here is my "integartion.xml" : </p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:file="http://www.springframework.org/schema/integration/file"
    xmlns:feed="http://www.springframework.org/schema/integration/feed"
        xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
        xmlns:ws="http://www.springframework.org/schema/integration/websocket"
    xsi:schemaLocation="http://www.springframework.org/schema/integration/feed http://www.springframework.org/schema/integration/feed/spring-integration-feed.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
                http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd
                http://www.springframework.org/schema/integration/websocket http://www.springframework.org/schema/integration/websocket/spring-integration-websocket.xsd"&gt;

    &lt;int-ip:udp-inbound-channel-adapter id="udpReceiver"
        channel="udpOutChannel"
        port="11111"
        receive-buffer-size="500"
        multicast="true"
        multicast-address="225.6.7.8"/&gt;
    &lt;int:object-to-string-transformer input-channel="udpOutChannel" output-channel="stringified"/&gt;
    &lt;bean id="nmeaParser" class="transformers.NMEAParser"/&gt;   
    &lt;int:transformer input-channel="stringified" ref="nmeaParser" output-channel="parsedData"/&gt;   
    &lt;int:channel id="jsondata"/&gt;
    &lt;int:object-to-json-transformer input-channel="parsedData" output-channel="jsondata"/&gt;
    &lt;ws:server-container id="server" path="/position"/&gt;        
    &lt;ws:outbound-channel-adapter container="server" channel="jsondata"/&gt;
&lt;/beans&gt;
</code></pre>

<p>As you can see, I create an UDP inbound channel. This channels works like a charm. I am able to see that data are sucessfully passed to my "NMEAParser" bean.</p>

<p>I think that my Websocket server doesn't work because : </p>

<p><em>I can't connect to it with wscat</em>... When I try to do :</p>

<pre><code>wscat -c ws://127.0.0.1:8080/position
</code></pre>

<p>I receive a "CONNECTION REFUSED", the same message I receive when nothing is launched.</p>

<p><em>In the Spring log's I can read this</em> : </p>

<pre><code>Starting beans in phase 0    
Adding {object-to-string-transformer} as a subscriber to the 'udpOutChannel' channel    
Channel 'application:8080.udpOutChannel' has 1 subscriber(s).   
started org.springframework.integration.config.ConsumerEndpointFactoryBean#0    
Adding {transformer} as a subscriber to the 'stringified' channel    
Channel 'application:8080.stringified' has 1 subscriber(s).    
started org.springframework.integration.config.ConsumerEndpointFactoryBean#1    
Adding {object-to-json-transformer} as a subscriber to the 'parsedData' channel    
Channel 'application:8080.parsedData' has 1 subscriber(s).    
started org.springframework.integration.config.ConsumerEndpointFactoryBean#2    
Adding {websocket:outbound-channel-adapter} as a subscriber to the 'jsondata' channel    
Channel 'application:8080.jsondata' has 1 subscriber(s).    
started org.springframework.integration.config.ConsumerEndpointFactoryBean#3    
Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel    
Channel 'application:8080.errorChannel' has 1 subscriber(s).    
started _org.springframework.integration.errorLogger    
Starting beans in phase 1073741823    
started udpReceiver    
Started Application in 0.792 seconds (JVM running for 1.121)
</code></pre>

<p>We can see here that all my beans are launched, except the bean "server" which is my server container. There is no trace of this bean in this log message.</p>

<p>To write my application I read carrefully <a href="https://github.com/spring-projects/spring-integration-samples/blob/master/applications/stomp-chat/src/main/resources/org/springframework/integration/samples/chat/stomp/server/stomp-server.xml" rel="nofollow">this sampe</a> and <a href="http://docs.spring.io/spring-integration/reference/html/web-sockets.html" rel="nofollow">this doc</a>.</p>

<p><strong>What am I doing wrong, or what I forgot ?</strong></p>