This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 233973

Summary: websocket context path not correct
Product: javaee Reporter: keith_cambron
Component: Web ProjectAssignee: David Konecny <dkonecny>
Status: RESOLVED FIXED    
Severity: normal Keywords: TOMCAT
Priority: P3    
Version: 7.2.1   
Hardware: PC   
OS: Windows 7   
Issue Type: DEFECT Exception Reporter:
Attachments: IDE log

Description keith_cambron 2013-08-05 21:00:28 UTC
Product Version = NetBeans IDE 7.2.1 (Build 201210100934)
Operating System = Windows 7 version 6.1 running on amd64
Java; VM; Vendor = 1.7.0
Runtime = Java HotSpot(TM) 64-Bit Server VM 21.0-b17
Tomcat = apache-tomcat-7.0.42.0

I'm building a JSP/Javascript web application that uses websockets, and couldn't get the Javascript command ws = new WebSocket(URL) to properly open a connection. To make sure I was using the command correctly I loaded the apache-tomcat example 'websocket' from my tomcat release, listed above, as a project in NetBeans. As expected,  NetBeans deployed my project in place at NetBeansProjects/proj_name/build/web . When I ran the application from the IDE, the application was found using a context path that identical to the deployment in build and the application loads and ran fine. However, when my Javascipt code tries to open a connection with new WebSocket(URL), the javascript uses CATALINA_BASE as the context path, so it does not find the WebSocketServlet class in build/web/WEB-INF/classes, which was loaded at startup. It ends up instantiating a new WebSocketServlet from CATALINA_BASE, not the one in the build/web path. Any work around appears tedious, either requiring me to manually deploy my project to CATALINA_BASE, or to declare the build/web directory to be CATALINA_BASE.
Comment 1 keith_cambron 2013-08-05 21:00:33 UTC
Created attachment 138318 [details]
IDE log
Comment 2 Vladimir Riha 2013-08-06 05:38:00 UTC
Probably JavaEE area?
Comment 3 David Konecny 2013-08-06 20:01:25 UTC
A test project demonstrating this problem would make it easier for me to reproduce the problem and provide help. Having said that this does not sound like a NetBeans problem but rather an issue in how project is setup or deployed.

Could you give an example of URL you expect and URL which NetBeans uses? I'd think that you deploy an app to Tomcat, eg. "http://localhost:8080/myapp/" and from your HTML page you do new WebSocket("ws://localhost:8080/myapp/mywebsocket").
Comment 4 keith_cambron 2013-08-08 15:14:59 UTC
The problem was resolved by creating a separate WebSocketServlet, rather than extending the existing HttpServlet, and by declaring both servlets with unique URL patterns in web.xml .