Reputation: 179
I am getting below error on testing WebSocket ServerEndPoint through Google Chrome.
2018-01-26 04:27:02 [http-nio-8090-exec-5] DEBUG o.a.coyote.http11.Http11Processor - Error parsing HTTP request header "java.io.EOFException: null at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1250) at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEndpoint.java:1190) at org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:717) at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:366) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:687) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)
I search it on Google and found, it happened when your URL too long but in my case it's not.
EndPoint URL: ws://localhost:8090/ExchangeService
. The version of Tomcat embed inside Spring Boot is 8.5.23
Here is ServerEndPoint
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
@Autowired
private ApplicationContext context;
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { registry.addHandler(context.getBean(ExchangeService.class), "/ExchangeService"); }
}
Upvotes: 1
Views: 3422
Reputation: 179
Finally solved it by setAllowedOrigins("*") in WebSocket config
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
registry.addHandler(context.getBean(TestWebSocket.class), "/ExchangeService").setAllowedOrigins("*");
}
Thank you!
Upvotes: 1
Reputation: 52488
Your WebSocket endpoint doesn't work. Class WebSocketConfig
should be like this
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/exchange_service");
}
}
(I am using Spring Boot 2.0.0.M7)
for end-point ws://localhost:8090/exchange_service
Upvotes: 0