(please don't add me as recipient, I'm already subscribed to the list) :-)
I'm able to deploy the app to context path "/" and accesss following link:
http://localhost:8080/index.jsp?url=ws://localhost:8080/web/test
Originally I suspected that the issue will be related to the context
path value, but it seems its not the case.
I can see that your site works when I access:
http://test.heroesofcadwick.com/?url=ws://test.heroesofcadwick.com/Websockets/web/test
So do you have any redirect in place? It seems like your app is deployed
on context path "/WebSockets", but the index.jsp is accessible directly
from
http://test.heroesofcadwick.com/ ...
Pavel
On 12/02/15 17:24, Mladen Adamović wrote:
> Hi Pavel,
>
> that project doesn't have web.xml.
>
> I've created a smallest project to reproduce the issue and deployed it
> to server test.heroesofcadwick.com <http://test.heroesofcadwick.com> -
> the issue is same and still existing.
>
> The project has two sourcefiles and I'm attaching whole Netbeans project
> with sources.
>
> If you deploy it to test.oracle.com <http://test.oracle.com> (for
> example), you can run from your browser:
> http://test.oracle.com/?url=ws://test.oracle.com/web/test
> (that one shows Websocket connection fails at my
> test.heroesofcadwick.com <http://test.heroesofcadwick.com>)
> but
> http://localhost:8080/Websockets/?url=ws://localhost:8080/Websockets/web/test
> is failing
>
> Attached Netbeans project source containing two small source files:
> *index.jsp
> *
> <%_at_page contentType="text/html" pageEncoding="UTF-8"%>
> <!DOCTYPE html>
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html;
> face="monospace, monospace"> <title>Websockets Test</title>
> </head>
> <body>
> <h1>Websockets Test</h1>
> </body>
> <script>
> function print(str) {
> console.log(str);
> var para = document.createElement("P");
> var t = document.createTextNode(str);
> para.appendChild(t);
> document.body.appendChild(para);
> }
>
> function onError(evt) {
> print('<span style="color: red;">ERROR:</span> ' + evt.data);
> }
>
> function onOpen() {
> print("Connected to " + wsUri);
> }
>
> function onClose() {
> print("Closed connection to " + wsUri);
> }
> function sendText(json) {
> console.log("sending text: " + json);
> websocket.send(json);
> }
> <%
> String url = request.getParameter("url");
> if (url == null) {
> url = "ws://test.heroesofcadwick.com/web/test
> <http://test.heroesofcadwick.com/web/test>";
> }
> %>
> var wsUri = "<%=url%>";
> var websocket = new WebSocket(wsUri);
> websocket.onerror = function(evt) { onError(evt) };
> websocket.onopen = function(evt) { onOpen(evt) };
> websocket.onclose = function(evt) { onClose(evt) };
> websocket.onmessage = function(evt) { onMessage(evt) };
> </script>
>
> </script>
> </html>
>
> </body>
> </html>
>
>
> *TestWSEndPoint.java*
> package websocketsTest;
>
> import java.io.IOException;
> import java.util.logging.Level;
> import java.util.logging.Logger;
> import javax.websocket.CloseReason;
> import javax.websocket.EndpointConfig;
> import javax.websocket.OnClose;
> import javax.websocket.OnMessage;
> import javax.websocket.OnOpen;
> import javax.websocket.Session;
> import javax.websocket.server.ServerEndpoint;
>
> /**
> *
> * @author mladen
> */
> @ServerEndpoint(value = "/web/test")
> public class TestWSEndpoint {
> @OnOpen
> public void open(Session session,
> EndpointConfig c) throws IOException {
> }
> @OnClose
> public void close(Session session,
> CloseReason reason) {
> Logger.getLogger(this.getClass().getName()).log(Level.INFO, "close
> {0} cause {1}", new Object[] { reason.toString(),
> reason.getReasonPhrase() } );
> }
> // @OnMessage
> // public String onMessage(String message, @PathParam("battle_id")
> String battle_id, @PathParam("secret") String secret, Session session) {
> //
> // }
>
> @OnMessage
> public void onMessage(String message) {
> Logger.getLogger(this.getClass().getName()).log(Level.INFO,
> "server onMessage {0}", new Object[] { message });
> }
>
> }
>
>
>
>
> On Thu, Feb 12, 2015 at 1:10 PM, Pavel Bucek <pavel.bucek_at_oracle.com
> <mailto:pavel.bucek_at_oracle.com>> wrote:
>
> Hi Mladen,
>
> can you share web.xml or ideally whole project?
>
> Thanks,
> Pavel
>
> On 12/02/15 12:29, Mladen Adamović wrote:
>
> I have difficulties getting Websockets to work for me.
>
> What to check apart that http-listener-1 has Websockets enabled
> (it is
> indeed enabled) ?
>
> this is simple example which works at localhost and doesn't work in
> production.
> Ordinary servlets do work in production (running on port 8080
> and I have
> iptables port forwarding to port 80).
> *
> *
>
> This is my testing endpoint:
> @ServerEndpoint(value = "/web/test")
> public class TestWSEndpoint {
> @OnOpen
> public void open(Session session,
> EndpointConfig c) throws IOException {
> }
> @OnClose
> public void close(Session session,
> CloseReason reason) {
>
> Logger.getLogger(this.__getClass().getName()).log(__Level.INFO, "close
> {0} cause {1}", new Object[] { reason.toString(),
> reason.getReasonPhrase() } );
> }
> @OnMessage
> public void onMessage(String message) {
>
> Logger.getLogger(this.__getClass().getName()).log(__Level.INFO,
> "server onMessage {0}", new Object[] { message });
> }
>
>
> I can access it from localhost, but trying to open it from
> ws://www.heroesofcadwick.com/__web/test
> <http://www.heroesofcadwick.com/web/test>
> <http://www.heroesofcadwick.__com/web/test
> <http://www.heroesofcadwick.com/web/test>>
> it doesn't work.
> (I'm using have a simple HTML page at:
> http://www.heroesofcadwick.__com/test_ws.jsp
> <http://www.heroesofcadwick.com/test_ws.jsp>
> ) to access websockets.
>
> That page has this content:
>
> <%_at_page import="heroes.Configuration"%__>
> <%_at_page contentType="text/html" pageEncoding="UTF-8"%>
> <!DOCTYPE html>
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html;
> style="font-family:monospace"> <title>JSP Page</title>
> </head>
> <body>
> <h1>Hello World!</h1>
> </body>
> <script>
> function onError(evt) {
> console.log('<span style="color: red;">ERROR:</span> ' +
> evt.data);
> }
>
> function onOpen() {
> console.log("Connected to " + wsUri);
> }
>
> function onClose() {
> console.log("Closed connection to " + wsUri);
> }
>
> function sendText(json) {
> console.log("sending text: " + json);
> websocket.send(json);
> }
> <%
> if (!Configuration.__isRunningLocally()) {
> %>
> var wsUri = "ws://www.heroesofcadwick.com/__web/test
> <http://www.heroesofcadwick.com/web/test>
> <http://www.heroesofcadwick.__com/web/test
> <http://www.heroesofcadwick.com/web/test>>";
> <%
> } else {
> %>
> var wsUri = "ws://localhost:8080/Heroes/__web/test";
> <%
> }
> %>
> var websocket = new WebSocket(wsUri);
> websocket.onerror = function(evt) { onError(evt) };
> websocket.onopen = function(evt) { onOpen(evt) };
> websocket.onclose = function(evt) { onClose(evt) };
> websocket.onmessage = function(evt) { onMessage(evt) };
> </script>
>
> </script>
> </html>
>
>