Hi, the idea is to start with the minimal working version. So if the simple use case works already for you we can track it down to maybe a bug in the HttpContext handling with websockets.
regards, Achim 2017-05-08 21:21 GMT+02:00 Csákány Róbert <[email protected]>: > Hi Achim, > > Thanks for the response. > > When I deploy as a WAR it works fine - so I don't think there is a general > problem. I've tried with debugging, but I don't know the details of > Pax-Web. The HTTPContext was an idea to be able to emulate the isolation > like in a WAR deployment - before I've tried without context with no luck. > The log messages shows everything okay, because the Websocket tracker > catches the service, find the annotation and find the HTTPContext. So it > seems OK, but the URL is not mapped. I have the feeling something with the > URL mapping goes wrong. I haven't tried that the very same HTTPContext > initializing a Servlet - so I will try it. So all the two scenario > mentioned earlier works same way - the websocket is catched and Jetty > registration is called, but the URL is unavailable, I've got 404. - that > was that point where I call for help, because my knowledge ended here :) > > > I've checked the integraton test - WebSocketWhiteBoardIntegrationTest > > I see there is no any property on service, only the naked instance of > service is registered. It is not fit for me, because I need managed > instance of service (because I would like to reference other services). > > Regards, > > Robert > > On Monday, May 8, 2017 at 9:03:21 PM UTC+2, Achim Nierbeck wrote: >> >> Hi, >> >> this is actually a tricky one. Over the weekend I tried to work on some >> integration tests for it, but failed. >> Is it not working in general? Or just in combination with the >> HttpContext? >> For the second one we might find an easier solution :) >> >> regards, Achim >> >> >> 2017-05-08 20:19 GMT+02:00 Csákány Róbert <[email protected]>: >> >>> I'm not sure my problems related to this issue, or it is a different one. >>> >>> I have a problem with the PAX-Web. I've tried to register a Websocket >>> service as declrarative, but it is unaccessible from web. I've tried the >>> given websocket-jsr356-6.0.3.war and it works fine. As I see the WAR file >>> handles differently the org.osgi.service.http.HttpContext. I've tried >>> the following scenarios: >>> >>> >>> **Scenario 1 - OSGi R6 Whiteboard HTTP method** >>> >>> >>> Creating a ServletContextHelper: >>> >>> >>> package hu.blackbelt.judo.common.rest.regular; >>> >>> import org.apache.felix.scr.annotations.Component; >>> import org.apache.felix.scr.annotations.Properties; >>> import org.apache.felix.scr.annotations.Property; >>> import org.apache.felix.scr.annotations.Service; >>> import org.osgi.service.http.context.ServletContextHelper; >>> import org.osgi.service.http.whiteboard.HttpWhiteboardConstants; >>> >>> @Component(immediate = true) >>> @Service(ServletContextHelper.class) >>> @Properties(value = { >>> @Property(name = >>> HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, value = "chat"), >>> @Property(name = >>> HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, value = "/test") >>> }) >>> public class ChatServletContext extends ServletContextHelper { >>> } >>> >>> >>> And adding the Websocket Endpoint: >>> >>> >>> package hu.blackbelt.judo.common.rest.regular; >>> >>> >>> import lombok.extern.slf4j.Slf4j; >>> import org.apache.felix.scr.annotations.Component; >>> import org.apache.felix.scr.annotations.Properties; >>> import org.apache.felix.scr.annotations.Property; >>> import org.apache.felix.scr.annotations.Service; >>> >>> import javax.websocket.EncodeException; >>> import javax.websocket.OnMessage; >>> import javax.websocket.OnOpen; >>> import javax.websocket.Session; >>> import javax.websocket.server.PathParam; >>> import javax.websocket.server.ServerEndpoint; >>> import java.io.IOException; >>> >>> @Component(immediate = true) >>> @Service(Object.class) >>> @Properties(value = { >>> @Property(name = >>> HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT, >>> value = "=(" + >>> HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=chat)") >>> }) >>> @Slf4j >>> public class ChatEndpoint { >>> >>> public static final String ROOM = "room"; >>> >>> @OnOpen >>> public void onOpen(final Session session, @PathParam(ROOM) final >>> String room) { >>> LOGGER.info("session openend and bound to room: " + room); >>> session.getUserProperties().put(ROOM, room); >>> } >>> >>> @OnMessage >>> public void onMessage(final Session session, final ChatMessage >>> chatMessage) { >>> String room = (String) session.getUserProperties().get(ROOM); >>> try { >>> for (Session s : session.getOpenSessions()) { >>> if (s.isOpen() >>> && >>> room.equals(s.getUserProperties().get(ROOM))) { >>> s.getBasicRemote().sendObject(chatMessage); >>> } >>> } >>> } catch (IOException | EncodeException e) { >>> LOGGER.warn("onMessage failed", e); >>> } >>> } >>> } >>> >>> The logs show me that the Endpoint is catched. I've debugged and Pax-Web >>> is registering it. >>> >>> >>> The log shows the following line: >>> >>> 2017-05-04 02:36:02,698 | INFO | Thread-70 | WebSocketTracker | 330 - >>> org.ops4j.pax.web.pax-web-extender-whiteboard - 6.0.3 | found websocket >>> endpoint!! >>> >>> >>> But the websocket is unaccessible with the following URL: >>> ws://localost:8181/test/chat/testroom >>> >>> >>> >>> **Scenario 2 - Pax-Web properties on registered HttpContext (with >>> JAX-RS it works)** >>> >>> >>> Creating HttpContext instance: (Utilizing the OSGi given Helper abstract >>> class): >>> >>> package hu.blackbelt.judo.common.rest.regular; >>> >>> import org.apache.felix.scr.annotations.Component; >>> import org.apache.felix.scr.annotations.Properties; >>> import org.apache.felix.scr.annotations.Property; >>> import org.apache.felix.scr.annotations.Service; >>> import org.osgi.service.http.HttpContext; >>> import org.osgi.service.http.context.ServletContextHelper; >>> >>> @Component(immediate = true) >>> @Service(HttpContext.class) >>> @Properties(value = { >>> @Property(name = "httpContext.id", value = "chat"), >>> @Property(name = "httpContext.path", value = "test") >>> }) >>> public class ChatHttpContext extends ServletContextHelper implements >>> HttpContext { >>> } >>> >>> >>> And the Websocket Endpoint: >>> >>> >>> package hu.blackbelt.judo.common.rest.regular; >>> >>> import lombok.extern.slf4j.Slf4j; >>> import org.apache.felix.scr.annotations.Component; >>> import org.apache.felix.scr.annotations.Properties; >>> import org.apache.felix.scr.annotations.Property; >>> import org.apache.felix.scr.annotations.Service; >>> import org.osgi.service.http.whiteboard.HttpWhiteboardConstants; >>> >>> import javax.websocket.EncodeException; >>> import javax.websocket.OnMessage; >>> import javax.websocket.OnOpen; >>> import javax.websocket.Session; >>> import javax.websocket.server.PathParam; >>> import javax.websocket.server.ServerEndpoint; >>> import java.io.IOException; >>> >>> @SuppressWarnings({"checkstyle:missingctor", "checkstyle:illegaltoken"}) >>> >>> @Component(immediate = true) >>> @Service(Object.class) >>> @Properties(value = { >>> @Property(name = "httpContext.id", value = "chat") >>> }) >>> @ServerEndpoint(value = "/chat/{room}", encoders = >>> ChatMessageEncoder.class, decoders = ChatMessageDecoder.class) >>> @Slf4j >>> public class ChatEndpoint { >>> >>> public static final String ROOM = "room"; >>> >>> @OnOpen >>> public void onOpen(final Session session, @PathParam(ROOM) final >>> String room) { >>> LOGGER.info("session openend and bound to room: " + room); >>> session.getUserProperties().put(ROOM, room); >>> } >>> >>> @OnMessage >>> public void onMessage(final Session session, final ChatMessage >>> chatMessage) { >>> String room = (String) session.getUserProperties().get(ROOM); >>> try { >>> for (Session s : session.getOpenSessions()) { >>> if (s.isOpen() >>> && >>> room.equals(s.getUserProperties().get(ROOM))) { >>> s.getBasicRemote().sendObject(chatMessage); >>> } >>> } >>> } catch (IOException | EncodeException e) { >>> LOGGER.warn("onMessage failed", e); >>> } >>> } >>> } >>> >>> But the websocket is unaccessible with the following URL: >>> ws://localost:8181/test/chat/testroom >>> >>> >>> >>> How can I achive that webcsocket be available? I do not want to >>> repackage my bundle as WAB. Is there any way? >>> >>> -- >>> -- >>> ------------------ >>> OPS4J - http://www.ops4j.org - [email protected] >>> >>> --- >>> You received this message because you are subscribed to the Google >>> Groups "OPS4J" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> >> -- >> >> Apache Member >> Apache Karaf <http://karaf.apache.org/> Committer & PMC >> OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer >> & Project Lead >> blog <http://notizblog.nierbeck.de/> >> Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS> >> >> Software Architect / Project Manager / Scrum Master >> >> -- > -- > ------------------ > OPS4J - http://www.ops4j.org - [email protected] > > --- > You received this message because you are subscribed to the Google Groups > "OPS4J" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- Apache Member Apache Karaf <http://karaf.apache.org/> Committer & PMC OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer & Project Lead blog <http://notizblog.nierbeck.de/> Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS> Software Architect / Project Manager / Scrum Master -- -- ------------------ OPS4J - http://www.ops4j.org - [email protected] --- You received this message because you are subscribed to the Google Groups "OPS4J" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
