• 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:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Tomcat 7 is not creating connection for web socket.

 
Ranch Hand
Posts: 51
Eclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have trouble while building my web Socket connection while using tomcat 7.0.53 server. I have spent hours in finding solution of this and attempted different combination of mentioned solution, unfortunately it didn't work for me. I need help in this regards as i got following error.

Firefox can't establish a connection to the server at ws://localhost:8080/socket/webSocket.

Below is my client side code :



Server Side Code :



I am using ecllispe and javax.websocket-api-1.0.jar is in my project dependency list.

Much needed help to resolve this issue. Thanks
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this JAR file deployed with your web application? If so, make sure it doesn't. Tomcat 7.0.53 comes with its own JAR file in the lib folder (websocket-api.jar).
 
sohaib yasir
Ranch Hand
Posts: 51
Eclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:Is this JAR file deployed with your web application? If so, make sure it doesn't. Tomcat 7.0.53 comes with its own JAR file in the lib folder (websocket-api.jar).



I have removed it from tomcat lib folder and result is same . Any other suggestion ?
 
sohaib yasir
Ranch Hand
Posts: 51
Eclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
help help help ......
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you really think that this kind of post makes people want to help you? You can use the "Edit" button to give it a more reasonable shape. Also tell us what you have tried since yesterday.
 
sohaib yasir
Ranch Hand
Posts: 51
Eclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My bad if it seems annoying. People don't see posts after suggesting something. Suggestion from "Rob" didn't solve my problem which make me to do this but surely i will edit it.
I have tried to remove Tomcat websocket-api.jar and tried to change tomcat version like 7.0.29 but same issue. Faced same issue at every try with following message
can't establish a connection to the server at ws://localhost:8080/socket/webSocket.
 
sohaib yasir
Ranch Hand
Posts: 51
Eclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have also tried to make connection with following line :

In this case my connection is successful and i see the alert on screen as written in my code pasted above. Obviously it just a test to verify that issue is with my web socket server. In my case my socket end point is "SocketEndPoint " deployed on tomcat 7.0.53.
This is what i had done since yesterday. Now i am blocked on this completely.
My web.xml is as follows which was missed in first code snippet.


 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make sure that the jar file you're using is not named in a way so it will be skipped when processing annotations. See http://tomcat.apache.org/migration-7.html#Annotation_scanning for what that means, and crosscheck with the jarsToSkip property in conf/catalina.properties.
 
sohaib yasir
Ranch Hand
Posts: 51
Eclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dittmer,

Nothing worked. I have ensured that JAR files in tomcat lib for web socket should properly skipped and my connection could established.
 
sohaib yasir
Ranch Hand
Posts: 51
Eclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My Web.xml for this attempt :




My dependency jar file. Now suggest what else i can do to solve this ?
Untitled.png
[Thumbnail for Untitled.png]
apache.png
[Thumbnail for apache.png]
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there anything in the Tomcat logs that show logs related to the application deployment? Can you post that part?
 
sohaib yasir
Ranch Hand
Posts: 51
Eclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of following lines which logs on server up nothing getting log in tomcat log files.

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have ensured that JAR files in tomcat lib for web socket should properly skipped and my connection could established.


This sounds as if you have misunderstood the meaning of what I posted. The files in Tomcat's lib folder are irrelevant. What's important is the jar file your class is in (assuming that it is in a jar file). If it is, then it must not be skipped. That means you have to match its name against all the jar files names that will be skipped, and ensure that the name of yours does not match any of those.

When I implemented such an endpoint I had exactly the same problem - and it turned out that my jar file was matching one of the file names being skipped for annotation scans. As soon as I changed the name of the jar file, everything worked. So I think this is something to look at closely: a) are your classes in a jar file (or several)?, and b) if they are, what are the names of those jar files?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, and you need to remove metadata-complete="true" from your web.xml, as well as the servlet mapping for WsChatServlet (what is that doing there, this isn't a servlet) and the "absolute-ordering" element.

Why is the class extending HttpServlet instead of Endpoint?
 
sohaib yasir
Ranch Hand
Posts: 51
Eclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Why is the class extending HttpServlet instead of Endpoint?




Sorry, you are right i miss understood it. There is no particular reason that i am extending my class with HttpServlet and mapping in web.xml. I was just to try different combinations of solution so that my EndPoint annotation could be read. That was just a test. I will surely remove it. Let me try it again and share the results.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to be clear: this is unlikely to fix the underlying problem. You need to investigate the issue about jar file scanning. Why don't you start by giving us some information so we can help you:


So I think this is something to look at closely: a) are your classes in a jar file (or several)?, and b) if they are, what are the names of those jar files?

 
sohaib yasir
Ranch Hand
Posts: 51
Eclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:You need to investigate the issue about jar file scanning. Why don't you start by giving us some information so we can help you:



Apology if i could miss understood it again. My classes are not under any jar file. They just exist under WEB-INF directory in classes folder. Let me show you my class file structure.
Source-and-class-file.png
[Thumbnail for Source-and-class-file.png]
 
sohaib yasir
Ranch Hand
Posts: 51
Eclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My error message changes suddenly. Let me explain what i have done so far.
I have removed servlet entry from my web.xml file and removed extends HttpServlet from my webSocket end point java class.
I had created a jar file of my webSocket end point as suggested and add in my lib folder. I think i am very close to resolve the issue. Now error message is :



Please suggest it.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A URLs starts with the protocol.
 
sohaib yasir
Ranch Hand
Posts: 51
Eclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After trying all the mentioned stuff i am standing on first step of ladder.
Same error same issue. Noting is printing in logs. Interestingly i have a network error now along with connection not established.

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure what's happening. Here's a small demo I cobbled together that works fine if I drop it into my Tomcat webapps folder. Source is included.
Filename: websocket.war
Description: WebSocket API demo web app
File size: 8 Kbytes
 
sohaib yasir
Ranch Hand
Posts: 51
Eclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ulf Dittmer. I highly appreciate your interest in resolving my problem. I think it will give my life to resolve the issue and now i got the same problem while running your war file.We have very long thread on the implementation of web socket and i have changed the code as per suggestions. I really thinking that we should should consider Server and environment in it. I have reviewed implementation in war file which is almost same as mine and result is same "Connection failed" . WAR is running in your environment but i am not being able to run that. Ultimately its server responsibility to create web socket. Put some light on server version and your environment where this WAR file is running. Thanks.

Finally the error while running on chrome :


Error on Firefox :

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In that case I'm out of ideas - that war file deploys and runs fine on my local machine. Your Tomcat log file should show something like "INFO: Deploying web application archive ...../webapps/websocket.war" (and no error message, obviously). Do you see that?
 
sohaib yasir
Ranch Hand
Posts: 51
Eclipse IDE MySQL Database Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Ulf Dittmer. Your war file is running fine now. I just reinstall my Tomcat server 7.0.53. Now it will be easy to find issue in my implementation. Once again Thanks for helping me "Ulf Dittmer".
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad to hear you got it to run. Just keep in mind the issue I mentioned earlier about the name of the jar file - because you really should deploy your classes in a jar file, and not as loose class files.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm only just noticing that the "examples" web app that comes with Tomcat 7 contains 4 complete examples of how to use WebSocket, including client and server source code. Too late :-(
 
sohaib yasir
Ranch Hand
Posts: 51
Eclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:noticing that the "examples" web app that comes with Tomcat 7 contains 4 complete. Too late :-(



I had noticed and tried it before posting my question. I got the same connection error while running those examples. That's why i thought about to take experts opinion. Luckily example war given by you is running successfully and unfortunately i am still unable to run mine . But i am hopeful that after getting a running war file i will surely run my implementation .
 
Here. Have a potato. I grew it in my armpit. And from my other armpit, this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic