Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jersey 2, GWT 2.7, Atmosphere 3.0.0 #213

Open
cvjones17 opened this issue Nov 7, 2015 · 0 comments
Open

Jersey 2, GWT 2.7, Atmosphere 3.0.0 #213

cvjones17 opened this issue Nov 7, 2015 · 0 comments

Comments

@cvjones17
Copy link

Trying to get Atmosphere to work with GWT2.7 and Jersey 2. Using versions:

atmosphere: 3.0.0-Snapshot
atmosphere-extensions: 2.3.0-GWT27
jersey: 2.19
atmosophere-client-version: 2.2.11

Figured out that atmosphere-gwt-jersey pulls in version 1.19 of Jersey, so added exclusion to the maven dependency, e.g.,

org.atmosphere.extensions atmosphere-gwt20-jersey ${atmosphere-extensions-version} org.glassfish.jersey.core jersey-server org.glassfish.jersey.core jersey-servlet

But now I'm having an atmosphere/jersey path issue that I haven't been able to figure out. I've been trying to duplicate the code in the atmosphere jersey sample here: https://github.com/Atmosphere/atmosphere-samples/tree/master/samples/jersey2-chat

web.xml specifies the root path, e.g., which uses the same url-pattern, /chat/* as in the jersey sample.

AtmosphereServlet AtmosphereServlet org.atmosphere.cpr.AtmosphereServlet com.sun.jersey.config.property.packages com.atlanticds.server.Atmosphere;org.atmosphere.gwt20.jersey
    <init-param>
        <param-name>org.atmosphere.websocket.messageContentType</param-name>
        <param-value>application/json</param-value> 
    </init-param>

    <load-on-startup>1</load-on-startup>
    <async-supported>true</async-supported> 

</servlet>
<servlet-mapping>
    <servlet-name>AtmosphereServlet</servlet-name>
    <url-pattern>/chat/*</url-pattern>
</servlet-mapping>

I'm able to see in the javascript console that the websocket is connected, via the following log lines:

Invoking executeWebSocket
atmosphere.js:3221 Using URL: ws://127.0.0.1:8888/chat?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.2.11-javascript&X-Atmosphere-Transport=websocket&Content-Type=application/json&X-atmo-protocol=true

Sat Nov 07 2015 12:41:07 GMT-0800 (PST) Atmosphere: websocket.onopen
atmosphere.js:3221 Websocket successfully opened
atmosphere.js:3221 Sat Nov 07 2015 12:41:07 GMT-0800 (PST) Atmosphere: websocket.onmessage
atmosphere.js:3221 Sat Nov 07 2015 12:41:07 GMT-0800 (PST) Atmosphere: Firing onMessage

but then the server returns an HTTP 404 to the client. I've looked at various support pages online including:

Atmosphere/atmosphere#1586

I turned on Jersey trace debugging, and here's what I see:

Nov 07, 2015 12:41:06 PM org.glassfish.jersey.message.internal.TracingLogger$TracingLoggerImpl logImpl
[ERROR] FINE: START baseUri=[http://127.0.0.1:8888/chat/] requestUri=[http://127.0.0.1:8888/chat] method=[GET] authScheme=[n/a] accept=n/a accept-encoding=[gzip, deflate, sdch] accept-charset=n/a accept-language=[en-US,en;q=0.8] content-type=[application/json] content-length=n/a [ ---- ms]
[ERROR] Nov 07, 2015 12:41:06 PM org.glassfish.jersey.message.internal.TracingLogger$TracingLoggerImpl logImpl
[ERROR] FINE: PRE_MATCH_SUMMARY PreMatchRequest summary: 0 filters [ 0.01 ms]
[ERROR] Nov 07, 2015 12:41:06 PM org.glassfish.jersey.message.internal.TracingLogger$TracingLoggerImpl logImpl
[ERROR] FINER: MATCH_PATH_FIND Matching path [/] [ ---- ms]
[ERROR] Nov 07, 2015 12:41:06 PM org.glassfish.jersey.message.internal.TracingLogger$TracingLoggerImpl logImpl
[ERROR] FINE: MATCH_SUMMARY RequestMatching summary [ 0.21 ms]
[ERROR] Nov 07, 2015 12:41:06 PM org.glassfish.jersey.server.ServerRuntime$Responder mapException
[ERROR] FINER: Starting mapping of the exception.
[ERROR] javax.ws.rs.NotFoundException: HTTP 404 Not Found
[ERROR] at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:305)
[ERROR] at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
[ERROR] at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
[ERROR] at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
[ERROR] at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
[ERROR] at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
[ERROR] at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
[ERROR] at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:291)
[ERROR] at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1140)
[ERROR] at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:403)
[ERROR] at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:386)
[ERROR] at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:334)
[ERROR] at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221)
[ERROR] at org.atmosphere.util.AtmosphereFilterChain.doFilter(AtmosphereFilterChain.java:135)
[ERROR] at org.atmosphere.util.AtmosphereFilterChain.invokeFilterChain(AtmosphereFilterChain.java:96)
[ERROR] at org.atmosphere.handler.ReflectorServletProcessor$FilterChainServletWrapper.service(ReflectorServletProcessor.java:317)
[ERROR] at org.atmosphere.handler.ReflectorServletProcessor.onRequest(ReflectorServletProcessor.java:160)
[ERROR] at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:215)
[ERROR] at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:109)
[ERROR] at org.atmosphere.container.JettyWebSocketUtil.doService(JettyWebSocketUtil.java:73)
[ERROR] at org.atmosphere.container.JettyServlet30AsyncSupportWithWebSocket.service(JettyServlet30AsyncSupportWithWebSocket.java:52)
[ERROR] at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:2310)
[ERROR] at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:578)
[ERROR] at org.atmosphere.websocket.DefaultWebSocketProcessor.open(DefaultWebSocketProcessor.java:222)
[ERROR] at org.atmosphere.container.JettyWebSocketHandler.onOpen(JettyWebSocketHandler.java:104)
[ERROR] at org.eclipse.jetty.websocket.WebSocketConnectionRFC6455.onWebSocketOpen(WebSocketConnectionRFC6455.java:425)
[ERROR] at org.eclipse.jetty.websocket.WebSocketServletConnectionRFC6455.handshake(WebSocketServletConnectionRFC6455.java:60)
[ERROR] at org.eclipse.jetty.websocket.WebSocketFactory.upgrade(WebSocketFactory.java:323)
[ERROR] at org.eclipse.jetty.websocket.WebSocketFactory.acceptWebSocket(WebSocketFactory.java:396)
[ERROR] at org.atmosphere.container.JettyWebSocketUtil.doService(JettyWebSocketUtil.java:63)
[ERROR] at org.atmosphere.container.JettyServlet30AsyncSupportWithWebSocket.service(JettyServlet30AsyncSupportWithWebSocket.java:52)
[ERROR] at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:2310)
[ERROR] at org.atmosphere.cpr.AtmosphereServlet.doPost(AtmosphereServlet.java:190)
[ERROR] at org.atmosphere.cpr.AtmosphereServlet.doGet(AtmosphereServlet.java:176)
[ERROR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:735)
[ERROR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
[ERROR] at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:686)
[ERROR] at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1494)
[ERROR] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:368)
[ERROR] at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
[ERROR] at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
[ERROR] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
[ERROR] at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
[ERROR] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
[ERROR] at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
[ERROR] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
[ERROR] at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
[ERROR] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
[ERROR] at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
[ERROR] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
[ERROR] at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
[ERROR] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
[ERROR] at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
[ERROR] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
[ERROR] at com.atlanticds.server.Authentication.AtlanticConcurrentSessionFilter.doFilter(AtlanticConcurrentSessionFilter.java:61)
[ERROR] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
[ERROR] at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:169)
[ERROR] at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
[ERROR] at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
[ERROR] at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1474)
[ERROR] at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:499)
[ERROR] at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
[ERROR] at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
[ERROR] at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
[ERROR] at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
[ERROR] at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:428)
[ERROR] at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
[ERROR] at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
[ERROR] at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
[ERROR] at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
[ERROR] at org.eclipse.jetty.server.handler.RequestLogHandler.handle(RequestLogHandler.java:68)
[ERROR] at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
[ERROR] at org.eclipse.jetty.server.Server.handle(Server.java:370)
[ERROR] at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
[ERROR] at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:949)
[ERROR] at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1011)
[ERROR] at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644)
[ERROR] at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
[ERROR] at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
[ERROR] at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:668)
[ERROR] at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
[ERROR] at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
[ERROR] at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
[ERROR] at java.lang.Thread.run(Thread.java:745)

Here's the server side code:

@path("/")
@AtmosphereService(
dispatch = true,
interceptors = { AtmosphereResourceLifecycleInterceptor.class,TrackMessageSizeInterceptor.class},
path = "/chat",
servlet = "org.glassfish.jersey.servlet.ServletContainer")
public class ScheduleUpdateBroadcaster {
private final static Logger logger = Logger.getLogger(ScheduleUpdateBroadcaster.class.getName());
/*
public ScheduleUpdateBroadcaster() {
logger.info("Initializing ScheduleUpdateBroadcaster");
packages("com.atlanticds.server.Atmosphere");

        // Enable LoggingFilter & output entity.     
     registerInstances(new LoggingFilter(java.util.logging.Logger.getLogger(ScheduleUpdateBroadcaster.class.getName()), true));
 }*/

 @Context
 private HttpServletRequest request;

 @GET
 public String configureAtmosphereResource() {
     logger.info("ScheduleUpdateBroadcaster configuring atmosphere");

     AtmosphereResource r = (AtmosphereResource) request.getAttribute(ApplicationConfig.ATMOSPHERE_RESOURCE);

     if (r != null) {
         r.addEventListener(new AtmosphereResourceEventListenerAdapter.OnDisconnect() {
             @Override
             public void onDisconnect(AtmosphereResourceEvent event) {
                 if (event.isCancelled()) {
                     logger.info("ScheduleUpdateBroadcaster atmosphere  Browser "+event.getResource().uuid()+" unexpectedly disconnected" );
                 } else if (event.isClosedByClient()) {
                     logger.info("ScheduleUpdateBroadcaster atmosphere Browser"+event.getResource().uuid()+" closed the connection" );
                 }
             }
         });

         r.addEventListener(new AtmosphereResourceEventListenerAdapter.OnBroadcast() {

            @Override
            public void onBroadcast(AtmosphereResourceEvent event) {
                logger.info("ScheduleUpdateBroadcaster atmosphere: got broadcast event from "+event.getResource().uuid()+" message "+event.getMessage()+" broadcaster "+event.broadcaster().getID());

            }
        });
     } else {
         throw new IllegalStateException();
     }
     return "{result:\"hello from configureAtmosphereResource\"}";
 }

 @POST
 @Consumes(MediaType.APPLICATION_JSON)
 public void broadcast(ScheduleUpdateEvent event) {
     logger.info("ScheduleUpdateBroadcaster atmosphere Received ScheduleUpdateEvent on Jersey: " + event.getPath());
     AtmosphereResource r = (AtmosphereResource) request.getAttribute(ApplicationConfig.ATMOSPHERE_RESOURCE);

     if (r != null) {
         r.getBroadcaster().broadcast(event);
     } else {
         throw new IllegalStateException();
     }
 }

 @POST 
 public void broadcast(String message) {
     logger.info("atmosphere : received broadcast message "+message);
     AtmosphereResource r = (AtmosphereResource) request.getAttribute(ApplicationConfig.ATMOSPHERE_RESOURCE);

     if (r != null) {
         r.getBroadcaster().broadcast(message);
     } else {
         throw new IllegalStateException();
     }
 }

}

And here's a piece of client side code:

public void initializeScheduleUpdates(final VLayout mainWidget) {
Log.info("atmosphere: initializeScheduleUpdates started");
ScheduleUpdateEventSerializer scheduleUpdateEventSerializer = GWT.create(ScheduleUpdateEventSerializer.class);

    AtmosphereRequestConfig scheduleUpdateEventRequestConfig = AtmosphereRequestConfig.create(scheduleUpdateEventSerializer);
    scheduleUpdateEventRequestConfig.setUrl(GWT.getHostPageBaseURL() + "chat");//AtmosphereConstants.BROADCAST_UNROOTED_SCHEDULE_PATH);
    scheduleUpdateEventRequestConfig.setTransport(AtmosphereRequestConfig.Transport.WEBSOCKET);
    scheduleUpdateEventRequestConfig.setFallbackTransport(AtmosphereRequestConfig.Transport.LONG_POLLING);
    scheduleUpdateEventRequestConfig.setLogLevel("debug");
    scheduleUpdateEventRequestConfig.setContentType(MediaType.APPLICATION_JSON);
    scheduleUpdateEventRequestConfig.setOpenHandler(new AtmosphereOpenHandler() {
        @Override
        public void onOpen(AtmosphereResponse response) {
            Log.info("ScheduleUpdateListener.onOpen, atmosphere: Jersey RPC Connection opened");
        }
    });

    scheduleUpdateEventRequestConfig.setCloseHandler(new AtmosphereCloseHandler() {
        @Override
        public void onClose(AtmosphereResponse response) {
            Log.info("ScheduleUpdateListener.onClose atmosphere: ScheduleUpdateListener closed");
        }

    });

    scheduleUpdateEventRequestConfig.setMessageHandler(new AtmosphereMessageHandler() {
        @Override
        public void onMessage(AtmosphereResponse response) {
            Log.info("ScheduleUpdateListener.onMessage. Got atmosphere message response "+response.getResponseBody());
            List<ScheduleUpdateEvent> scheduleUpdateEvents = response.getMessages();
            for (ScheduleUpdateEvent scheduleUpdateEvent : scheduleUpdateEvents) {
                Log.info("ScheduleUpdateListener.onMessage.  atmosphere: received scheduleUpdateMessage through Jersey RPC: " + scheduleUpdateEvent.getPath());
                ClientEventBus.publish(ClientEventBus.REFRESH_SCHEDULE_VIEWS_EVENT, new RefreshScheduleViewsEvent(scheduleUpdateEvent.getPath()));
            }
        }
    });

    scheduleUpdateEventRequestConfig.setErrorHandler(new AtmosphereErrorHandler() {

        @Override
        public void onError(AtmosphereResponse response) {
            Log.info("ScheduleUpdateListener.onError. Got atmosphere error "+response.getResponseBody());

        }

    });

    scheduleUpdateEventRequestConfig.clearFlags(Flags.dropAtmosphereHeaders);
    Atmosphere atmosphere = Atmosphere.create();
    Log.info("ScheduleUpdateListener. about to subscribe. atmosphere is "+atmosphere);

    final AtmosphereRequest scheduleUpdateRequest = atmosphere.subscribe(scheduleUpdateEventRequestConfig);     

    Log.info("ScheduleUpdateListener. atmosphere: subscription to schedule updates. request UUID is "+scheduleUpdateRequest.getUUID());   

    HorizontalPanel buttons = new HorizontalPanel();
    final TextBox messageInput = new TextBox();
    buttons.add(messageInput);

    Button sendRPC = new Button("send (GWT-RPC)");
    buttons.add(sendRPC);

    mainWidget.addMember(buttons);

    sendRPC.addClickHandler(new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              Log.info("ScheduleUpdateListener.onClick Trying to send a message");
            if (messageInput.getText().trim().length() > 0) {
              try {
                //              service.sendEvent(new Event(messageInput.getText()), callback);
                  ScheduleUpdateEvent scheduleUpdateEvent = new ScheduleUpdateEvent();
                  scheduleUpdateEvent.setPath(messageInput.getValue());                  
                  Log.info("ScheduleUpdateListener.onClick Sending event "+scheduleUpdateEvent);
                  scheduleUpdateRequest.push(scheduleUpdateEvent);
              } catch (SerializationException ex) {
                Log.error("ScheduleUpdateListener.onClick. Failed to serialize message", ex);
              }
            }
          }
        });
}

From what I can tell AtmosphereService causes the AtmosphereServlet to delegate the request processing to org.glassfish.jersey.servlet.ServletContainer, and that servlet does not like the path it was given. I've tried many variations of the path parameters (in the server code, in web.xml and in the client code), but can never seem to get the Jersey code to not return a 404.

Thanks for the help,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant