• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Websocket java 404 response

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, im creating a websocket in java 7, im using servelet, maven for dependencies, glassfish as server.

i create the server endpoint



and in the client side i add this code



when i open my aplication in mozilla firefox i call the url  ws://localhost:8888/nsjp/mensaje  and i get the next message Firefox was unable to establish a connection to the server, checking the network resources in the firefox console i get a 404 code

i dont know if the problem is maybe, im wrong with the call to the server endpoint class inside my project or the url is wrong

 
Saloon Keeper
Posts: 24557
168
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That sounds like 2 different - and mutually exclusive - problems.

"Unable to contact server" typically means that a network connection to the webapp server could not be made. The network was down, DNS did not resolve, a firewall blocked the request, or the URL was sent to the wrong server and/or wrong port.

A "404" on the other hand comes from a web server. It means "resource not found". So something did contact a server. Hopefully even the correct server. You get a "404" when the server cannot find a webapp to send the URL request to , or that webapp doesn't know what to do with that URL.

The server determines which webapp to send a request to by resolving its servlet context component. That's the "nsjp" in your URL. So there should be a context named "nsjp" deployed in your Glassfish server and typically a WAR named "nsjp" in yout Glassfish webapps directory. If there is, then something didn't provide the routing to endpoint "/mensaje". Possibly your aren't properly configured to scan that part of the webapp for @ServerEndpoint annotations.
 
mike salazar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:That sounds like 2 different - and mutually exclusive - problems.

"Unable to contact server" typically means that a network connection to the webapp server could not be made. The network was down, DNS did not resolve, a firewall blocked the request, or the URL was sent to the wrong server and/or wrong port.

A "404" on the other hand comes from a web server. It means "resource not found". So something did contact a server. Hopefully even the correct server. You get a "404" when the server cannot find a webapp to send the URL request to , or that webapp doesn't know what to do with that URL.

The server determines which webapp to send a request to by resolving its servlet context component. That's the "nsjp" in your URL. So there should be a context named "nsjp" deployed in your Glassfish server and typically a WAR named "nsjp" in yout Glassfish webapps directory. If there is, then something didn't provide the routing to endpoint "/mensaje". Possibly your aren't properly configured to scan that part of the webapp for @ServerEndpoint annotations.



I check again the nsjp in the url was wrong, i change the url i now i get error 405
 
Tim Holloway
Saloon Keeper
Posts: 24557
168
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HTTP 405 is "Method not allowed". It means that your URL requests a method type that is not permitted for that application URL. For example, a POST when only a GET would be permitted.

From your code, I can't tell if you're doing a GET, a POST, or even a DELETE though.
 
mike salazar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:HTTP 405 is "Method not allowed". It means that your URL requests a method type that is not permitted for that application URL. For example, a POST when only a GET would be permitted.

From your code, I can't tell if you're doing a GET, a POST, or even a DELETE though.



the console throw, that is get method, im using the next code




 
mike salazar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i update my code, i delete the client class and i only lef the server side class with call by javascript in my html, now i get a 200 code when i try to connect ws://localhost:8888/nsjp-web-pg/ but when i put ws://localhost:8888/nsjp-web-pg/mensaje, including the ServerEndPoint i get 404 error code and firefox say cant stablish connection
 
Tim Holloway
Saloon Keeper
Posts: 24557
168
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
200 means "OK". The first URL would be a request for your webapp's welcome page. If the second URL gives a 404, then it means that the URL isn't mapped properly to your service. May be upper/lower case conflict, spelling problem, or failure to process the annotation properly.

Tomcat does not process web service annotations, so make sure that you're setting the webapp up correctly. Especially the part that handles the service annotations.
 
mike salazar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:200 means "OK". The first URL would be a request for your webapp's welcome page. If the second URL gives a 404, then it means that the URL isn't mapped properly to your service. May be upper/lower case conflict, spelling problem, or failure to process the annotation properly.

Tomcat does not process web service annotations, so make sure that you're setting the webapp up correctly. Especially the part that handles the service annotations.



im using glassfish 3.1 the first map nsjp-web-pg is the app name mensaje is the ServerEndPoint

 
Tim Holloway
Saloon Keeper
Posts: 24557
168
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry. I'm not in the forum I thought I was in. I don't know if Glassfish needs help in processing @ServerEndPoint annotations or not. It's a full-stack server, unlike Tomcat.
 
mike salazar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:Sorry. I'm not in the forum I thought I was in. I don't know if Glassfish needs help in processing @ServerEndPoint annotations or not. It's a full-stack server, unlike Tomcat.



i think, maybe my serverEndpoint is call mensaje, but my class is call websocket and the code doesnt know this class and inside my code i doesnt call this class

the project is nsjp-web-pg and the url call this that is the app, but after that it cant reach the mensaje ServerEndpoint inside the Websocket class, that is my problem i dont know how to reach this class, i think only calling the serverendpoint, the code will be executed
 
mike salazar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

mike salazar wrote:

Tim Holloway wrote:200 means "OK". The first URL would be a request for your webapp's welcome page. If the second URL gives a 404, then it means that the URL isn't mapped properly to your service. May be upper/lower case conflict, spelling problem, or failure to process the annotation properly.

Tomcat does not process web service annotations, so make sure that you're setting the webapp up correctly. Especially the part that handles the service annotations.



im using glassfish 3.1 the first map nsjp-web-pg is the app name mensaje is the ServerEndPoint



im not sure, how my app can access the serverendpoint class.
 
Tim Holloway
Saloon Keeper
Posts: 24557
168
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I never really got into websockets myself. But I think your main problem is that you're annotating a Servlet when you should be creating a disting websocket handler class. See https://docs.oracle.com/javaee/7/api/javax/websocket/server/ServerEndpoint.html

Note also that although they said that such a class MUST have a no-argument (default) constructor, their example doesn't include one. Grrr.

I THINK that part of the overall websocket implementation includes a general-purpose websocket dispatcher servlet that's what actually gets called when you define an endpoint and then that dispatcher calls the endpoint code itself. But that's just based on how similar systems work. As I said, I never really played with websockets myself.
 
mike salazar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good morning i made some changes in the code, i am getting Error during WebSocket handshake: Unexpected response code: 404, im using glassfish i run this command to enable websocket



i try to access but still get 404
 
mike salazar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i was reading and i check, that simply i can reach the serverendpoint, firefox says it cant establish a connection and edge says error 404 handshaking.

I am sure the serverendpoint is fine, the path is fine, but simply i cant reach the serverendpoint, cant establish the connection.

Im using dependencies by maven, this is the one i am using:




and i made more simple the serverendpoint class, just for test




and the javascript


and url

i really dont have an idea, is the first time i use websockets, im using java 7, glassfish 3.1

 
mike salazar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I made big changes in my project, i made a change and i add in my web.xml file a servlet for my serverEndPoint and the error changes to 405

this is my web.xml code where i add the servlet to the websocket




And says the get method is not supported by the url, i really dont know what means

this the serverEndPointClass





i dont know, if i made a mistake calling the class or what is the error, because is not error of websocket


 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic