users@grizzly.java.net

Re: Atmosphere + Grizzly: No AtmosphereHandler maps request for /chat Status 500 Message Server Error

From: Oleksiy Stashok <oleksiy.stashok_at_oracle.com>
Date: Wed, 23 Apr 2014 13:31:22 -0700

Hi,

how does you request URI look like?
I tried to replace AtmosphereServlet with a simple one:

         final HttpServlet atmosphereServlet = new HttpServlet() {

             @Override
             protected void doGet(HttpServletRequest req,
HttpServletResponse resp) throws ServletException, IOException {
                 System.out.println("servletPath=" + req.getServletPath());
             }
         };

and the output I see after making "http://localhost:8181/chat/a/b/c" is
"/chat"

Thanks.

WBR,
Alexey.

On 23.04.14 05:49, Jeanfrancois Arcand wrote:
> Hi,
>
> sound like a bug in Grizzly 2.3.11 as getServletPath should never
> return null:
>
> http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getServletPath()
>
> File an issue there, I'm pretty sure they will fix it ASAP.
>
> Thanks
>
> -- Jeanfrancois
>
> On 2014-04-23, 8:20 AM, miguelnaterasolmedo_at_gmail.com wrote:
>> Hello Atmosphere team.
>>
>> I'm testing Atmosphere 2.1.3 using Grizzly 2.3.11. I've created a
>> ManagedService(path="/chat"), but I get this error: 'No
>> AtmosphereHandler maps request for /chat Status 500 Message Server
>> Error'. If I change the path to ManagedService(path="/") it works.
>> I've debugged a bit and it seems that
>> org.atmosphere.cpr.AtmosphereRequest.getServletPath() always returns
>> null, so
>> org.atmosphere.util.DefaultEndpointMapper.computePath(AtmosphereRequest
>> req) returns "/" and that's the cause that makes my test work using
>> ManagedService(path="/").
>>
>> Well, I'll appreciate any help. Thanks in advance!
>>
>>
>> PD: These are my test classes:
>>
>> package com.dweb.atmosphere.grizzly;
>>
>> import java.io.IOException;
>> import org.atmosphere.container.Grizzly2CometSupport;
>> import org.atmosphere.cpr.AtmosphereServlet;
>> import org.glassfish.grizzly.comet.CometAddOn;
>> import org.glassfish.grizzly.http.server.HttpServer;
>> import org.glassfish.grizzly.http.server.NetworkListener;
>> import org.glassfish.grizzly.http.server.StaticHttpHandler;
>> import org.glassfish.grizzly.servlet.ServletRegistration;
>> import org.glassfish.grizzly.servlet.WebappContext;
>> import org.glassfish.grizzly.websockets.WebSocketAddOn;
>>
>> public class Main {
>>
>> public static void main(String[] args) throws IOException {
>>
>> final HttpServer server = HttpServer.createSimpleServer(".",
>> 8181);
>>
>> final WebappContext ctx = new WebappContext("ctx", "/");
>>
>> // enable web socket support
>> final WebSocketAddOn addon = new WebSocketAddOn();
>>
>> for (NetworkListener listener : server.getListeners()) {
>> listener.registerAddOn(addon);
>> }
>>
>> // add atmosphere servlet support
>> final AtmosphereServlet atmosphereServlet = new
>> AtmosphereServlet();.
>>
>> final ServletRegistration atmosphereServletRegistration =
>> ctx.addServlet("AtmosphereServlet", atmosphereServlet);
>>
>> atmosphereServletRegistration.setInitParameter(
>> "org.atmosphere.websocket.messageContentType",
>> "application/json");
>> atmosphereServletRegistration.addMapping("/chat/*");
>> atmosphereServletRegistration.setLoadOnStartup(1);
>>
>> // deploy
>> ctx.deploy(server);
>>
>> try {
>> server.start();
>> System.out.println("Press enter to stop the server...");
>> System.in.read();
>> } finally {
>> server.shutdownNow();
>> }
>> }
>> }
>>
>>
>>
>> package com.dweb.atmosphere.grizzly;
>>
>> import static org.atmosphere.cpr.ApplicationConfig.MAX_INACTIVE;
>> import java.io.IOException;
>> import org.atmosphere.config.service.Disconnect;
>> import org.atmosphere.config.service.Get;
>> import org.atmosphere.config.service.ManagedService;
>> import org.atmosphere.config.service.Ready;
>> import org.atmosphere.cpr.AtmosphereResource;
>> import org.atmosphere.cpr.AtmosphereResourceEvent;
>> import org.slf4j.Logger;
>> import org.slf4j.LoggerFactory;
>>
>> /**
>> * Simple annotated class that demonstrate the power of Atmosphere.
>> This class supports all transports, support
>> * message length garantee, heart beat, message cache thanks to the
>> {_at_link ManagedService}.
>> */
>> @Config
>> @ManagedService(path = "/chat", atmosphereConfig = MAX_INACTIVE +
>> "=120000")
>> public class ChatRoom {
>> private final Logger logger =
>> LoggerFactory.getLogger(ChatRoom.class);
>>
>> // Uncomment for changing response's state
>> // @Get
>> // public void init(AtmosphereResource r) {
>> // r.getResponse().setCharacterEncoding("UTF-8");
>> // r.getResponse().write("Chat 2");
>> // }
>>
>> /**
>> * Invoked when the connection as been fully established and
>> suspended, e.g ready for receiving messages.
>> *
>> * @param r
>> */
>> @Ready
>> public void onReady(final AtmosphereResource r) {
>> logger.debug("Browser {} connected.", r.uuid());
>> }
>>
>> /**
>> * Invoked when the client disconnect or when an unexpected
>> closing of the underlying connection happens.
>> *
>> * @param event
>> */
>> @Disconnect
>> public void onDisconnect(AtmosphereResourceEvent event) {
>> if (event.isCancelled()) {
>> logger.info("Browser {} unexpectedly disconnected",
>> event.getResource().uuid());
>> } else if (event.isClosedByClient()) {
>> logger.info("Browser {} closed the connection",
>> event.getResource().uuid());
>> }
>> }
>>
>> /**
>> * Simple annotated class that demonstrate how {_at_link
>> org.atmosphere.config.managed.Encoder} and {_at_link
>> org.atmosphere.config.managed.Decoder
>> * can be used.
>> *
>> * @param message an instance of {_at_link Message}
>> * @return
>> * @throws IOException
>> */
>> @org.atmosphere.config.service.Message
>> public String onMessage(String message) throws IOException {
>> logger.info("just send() {}", message);
>> return message;
>> }
>>
>> }
>> --
>> Need support? http://async-io.org/subscription.html
>