Я создал простое приложение Spring Boot и клиент javascript, где связь осуществляется через соединение через веб-сокет с использованием Stomp.
Все отлично работает на локальном хосте и на локальном удаленном сервере, но когда Я загружаю приложение в облаке Azure, получаю эту ошибку:
ERROR 115 --- [p-nio-80-exec-6] o.s.b.w.servlet.support.ErrorPageFilter :
Forwarding to error page from request /gs-guide-websocket/123/...] due to exception [Uncaught failure in SockJS request, uri=..../azurewebsites.net/gs-guide-websocket/123/...;
nested exception is org.springframework.web.socket.sockjs.SockJsTransportFailureException: Failed to open session;
nested exception is java.lang.IllegalArgumentException: Async support must be enabled on a servlet and for all filters involved in async request processing.
This is done in Java code using the Servlet API or by adding "<async-supported>true</async-supported>" to servlet and filter declarations in web.xml.
Also you must use a Servlet 3.0+ container]
at org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler.handleRequest(SockJsHttpRequestHandler.java:137)
at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:53)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.microsoft.azure.appservice.filters.AppServiceFilter.doFilter(AppServiceFilter.java:35)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.microsoft.azure.appservice.EasyAuthFilter.doFilter(EasyAuthFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.myapp.MyCustomFilter.doFilter(MyCustomFilter.java:27) // -> my custom filter
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
.....
Чтобы включить asyn c, я реализовал интерфейс WebApplicationInitializer:
public class ApplicationInitializer implements WebApplicationInitializer
{
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
Dynamic servlet = servletContext.addServlet("springDispatcher", new DispatcherServlet(ctx));
servlet.addMapping("/");
servlet.setAsyncSupported(true);
servlet.setLoadOnStartup(1);
}
}
Я даже создал собственный фильтр и убедился, что он также поддерживает asyn c, и, похоже, он запускается нормально, это часть журнала при запуске приложения:
[INFO] init() method has been get invoked
[INFO] Filter name is myCustomFilter
[INFO] {"filterDef":{"filterClass":"com.myapp.MyCustomFilter","filterName":"myCustomFilter","parameters":{},"asyncSupported":"true"}}
[INFO] ServletContext name isorg.apache.catalina.core.ApplicationContextFacade@80249b0
[INFO] init() method is ended
[INFO] 2020-01-17 15:20:19.122 INFO 115 --- [MessageBroker-1] o.s.w.s.c.WebSocketMessageBrokerStats : WebSocketSession[0 current WS(0)-HttpStream(0)-HttpPoll(0), 0 total, 0 closed abnormally (0 connect failure, 0 send limit, 0 transport error)], stompSubProtocol[processed CONNECT(0)-CONNECTED(0)-DISCONNECT(0)], stompBrokerRelay[null], inboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], outboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], sockJsScheduler[pool size = 1, active threads = 1, queued tasks = 0, completed tasks = 0]
Websockets включены с платформы Azure.