Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8255109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:24:58+00:00 2026-06-08T01:24:58+00:00

I’m using Sonatype async-http-client java library to make a websocket call to a WebServer

  • 0

I’m using Sonatype async-http-client java library to make a websocket call to a WebServer using Atmosphere on Jersey on Jetty.

I’m getting exception java.lang.IllegalStateException: Invalid upgrade protocol, status should be 101 but was 200. The error is launched by the WebSocketTextListener.onError(Throwable t) method.

Any idea how to solve this?

This is the client-code using Sonatype async-http-client:

public void getMealWebSocketSubscriber(String restaurantId , String mealId, OnGetMealListener listener) throws ApiException {

    try {

        WebSocket websocket = client.prepareGet(getAbsolutePath("restaurants/" + restaurantId + "/meals/" + mealId + "/websocket/"))
                .execute(new WebSocketUpgradeHandler.Builder().build())
                .get();


        websocket.addWebSocketListener(
                new WebSocketTextListener() {

                    public void onOpen(WebSocket websocket) {
                        System.out.println("WebSocket onOpen");
                    }

                    public void onClose(WebSocket websocket) {
                        System.out.println("WebSocket onClose");
                    }

                    public void onError(Throwable t) {
                        System.out.println("WebSocket onError");
                        t.printStackTrace();
                    }

                    public void onMessage(String message) {
                        System.out.println("WebSocket onMessage: " + message);
                    }

                    public void onFragment(String fragment, boolean last) {
                        // TODO Auto-generated method stub

                    }


                });

    } catch (Exception e) {
        throw new ApiException(e.getMessage());
    }

}

These are the Jersey resource method using Atmosphere:

@Path("/websocket")
@Suspend
@GET
@Produces({MediaType.APPLICATION_JSON})
public String suspend() {
    return "";
}   

@Path("/websocket")
@Broadcast(writeEntity = false)
@POST
@Produces({MediaType.APPLICATION_JSON})
public Meal broadcast() {
    return getMealById(mealId);
}

This is the code used to launch my Atmosphere servlet:

this.webServer = new Server(8080);

    AtmosphereServlet atmosphereServlet = new AtmosphereServlet();
    ServletHolder servletHolder = new ServletHolder(atmosphereServlet);

    //Atmosphere

    servletHolder.setInitParameter("org.atmosphere.websocket.messageContentType"    , "application/json");
    servletHolder.setInitParameter("org.atmosphere.useWebSocket","true");
    servletHolder.setAsyncSupported(true);



    //Jersey resources

    //      servletHolder.setInitParameter("com.sun.jersey.config.property.packages", "com.famenu.server.resources");
    servletHolder.setInitParameter("com.sun.jersey.config.property.resourceConfigClass" ,   "com.sun.jersey.api.core.ClassNamesResourceConfig");
    servletHolder.setInitParameter("com.sun.jersey.config.property.classnames"          ,   
            "com.famenu.server.resources.ItemResource, "        +
                    "com.famenu.server.resources.MealAtmosphereResource, "  +
                    "com.famenu.server.resources.MealResource, "            +
                    "com.famenu.server.resources.MealsResource, " + MY_OTHER_JERSEY_RESOURCES);

    servletHolder.setInitParameter("com.sun.jersey.spi.container.ContainerRequestFilters"   , "com.sun.jersey.api.container.filter.LoggingFilter");
    servletHolder.setInitParameter("com.sun.jersey.spi.container.ContainerResponseFilters"  , "com.sun.jersey.api.container.filter.LoggingFilter");


    servletHolder.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature"         , "true");

    ServletContextHandler servletContextHandler = new ServletContextHandler(webServer, "/rest", true, false);
    servletContextHandler.addServlet(servletHolder, "/");

    webServer.setHandler(servletContextHandler);

    webServer.start();

Stacktrace of the exception:

java.lang.IllegalStateException: Invalid upgrade protocol, status should be 101 but was 200
at com.famenu.shared.api.AsyncApi.getMealWebSocketSubscriber(AsyncApi.java:172)
at com.famenu.shared.api.AsyncApiTest.testGetMealWebSocketSubscriber(AsyncApiTest.java:120)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

I’m using Atmosphere-jersey 0.9.7 , Jetty & jetty-websocket 7.6RC4 , sonatype/async-http-client 1.7.4 , Jersey 1.12.

There’s a post on the asyn-http-client google group but the code sample they are referring to as a possible solution to this problem is not available anymore on github. 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:24:59+00:00Added an answer on June 8, 2026 at 1:24 am

    The error is given by setting http:// protocol instead of ws:// in the url.

    WRONG:

    http://127.0.0.1:8080/JERSEY_RESOURCES

    CORRECT:

    ws://127.0.0.1:8080/JERSEY_RESOURCES
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.