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

Jersey2-Chat sample with Embedded Jetty results in 404 #1586

Closed
kirevse opened this issue May 8, 2014 · 2 comments
Closed

Jersey2-Chat sample with Embedded Jetty results in 404 #1586

kirevse opened this issue May 8, 2014 · 2 comments

Comments

@kirevse
Copy link

kirevse commented May 8, 2014

Since the system I am trying to integrate Atmosphere into uses embedded Jetty, I was trying to convert Jersey2-Chat sample to the same logic.

However, when I ran my server and entered a value into the input field, I got "org.atmosphere.websocket.WebSocket - 404 Not Found" on the server.

Here is the code for my server:

public class ChatServer {
    private Server server = null;

    public ChatServer() {
        ServletHolder atmosphereServletHolder = new ServletHolder(AtmosphereServlet.class);
        atmosphereServletHolder.setInitParameter("jersey.config.server.provider.packages", "org.atmosphere.samples.chat.jersey");
        atmosphereServletHolder.setInitParameter("org.atmosphere.websocket.messageContentType", "application/json");
        atmosphereServletHolder.setAsyncSupported(true);

        ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
        servletContextHandler.addServlet(atmosphereServletHolder, "/chat/*");   

        this.server = new Server(8084);
        this.server.setHandler(servletContextHandler);
    }

    public void start() throws Exception {
        this.server.start();
    }

    public void stop() throws Exception {
        this.server.stop();
    }

    public static void main(String[] args) throws Exception {
        ChatServer chatServer = new ChatServer();
        try {
            chatServer.start();
        } catch (Exception e) {
            e.printStackTrace();
            chatServer.stop();
        }
    }
}

My test was using Atmosphere 2.2.0-SNAPSHOT and jersey-container-servlet 2.8.
The only change made to the application.js was to hardcode the URL:

url: 'http://localhost:8084/chat'

so that the index.html can be ran from the file system.

The solution was to change the following line:

        servletContextHandler.addServlet(atmosphereServletHolder, "/chat/*");    

to:

        servletContextHandler.addServlet(atmosphereServletHolder, "/*");

At the same time a regular Jersey servlet works with the following line:

        servletContextHandler.addServlet(jerseyServletHolder, "/test/*");

Please, make this consistent.
Thank you!

@bogdanbrindusan
Copy link

From what I know, Jetty "cuts" from URI the part defined in web.xml, that is, in your case "/chat".
If the request is: /chat/whatever, and servlet is mapped to "/chat/*", Jetty will cut out "/chat" leaving only "/whatever" to match into Jersey resources.

Tomcat, for example, does not have this behaviour.

@jfarcand
Copy link
Member

@bogdanbrindusan Yes fixing this issue won't be easy because of specific container behavior...but contribution welcomed if you have the cycle.

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

No branches or pull requests

3 participants