Martin, > > according to the author of Guice 4.0 there are 2 COMPLETELY DIFFERENT > CONFIGURATIONS for WebServlet and WebSocket configurations
WebServlet is used for configuring the routes/ scope from guice module. Where as extending ServerEndpointConfig.Configurator is not something Guice provided it is provided by JSR(356). I can explain over call as well. Skype:bhuvangupta89 On Wed, May 31, 2017 at 5:39 PM, Martin Gainty <mgai...@hotmail.com> wrote: > according to the author of Guice 4.0 there are 2 COMPLETELY DIFFERENT > CONFIGURATIONS for WebServlet and > > WebSocket configurations > > > Custom Guice servlet context listener: > > public class CustomServletContextListener extends GuiceServletContextListener > { > public static Injector injector; > > @Override > protected Injector getInjector() { > injector = Guice.createInjector(...); > return injector; > }} > > Websockets custom configurator: > > public class CustomConfigurator extends Configurator { > @Override > public <T> T getEndpointInstance(Class<T> clazz) > throws InstantiationException { > return CustomServletContextListener.injector.getInstance(clazz); > }} > > And then in the Websocket endpoint: > > @ServerEndpoint(value = "/ws/sample_endpoint", configurator = > CustomConfigurator.class)public class SampleEndpoint { > private final SomeService service; > > @Inject > public SampleEndpoint(SomeService service) { > this.service = service; > } > ...} > > in ServerEndpoint you need to change your configurator to WebSocket > Configurator class that extends ServerEndpointConfig.Configurator > > > https://stackoverflow.com/questions/27499800/tomcat8- > websockets-jsr-356-with-guice-3-0 > > <https://stackoverflow.com/questions/27499800/tomcat8-websockets-jsr-356-with-guice-3-0> > Tomcat8 WebSockets (JSR-356) with Guice 3.0 > <https://stackoverflow.com/questions/27499800/tomcat8-websockets-jsr-356-with-guice-3-0> > stackoverflow.com > I am trying to @Inject a Guice service into a @ServerEndpoint. I am using > Tomcat 8.0.15 as the JSR-356 implementation. However, the dependency > injection isn't working. Is there any additional > > > > BTW: if your claim that Guice is NOT JSR-356 conformant is valid you need > to take this up with Guice Authors > > i use Guice occasionally opting instead to use Spring Framework 4.x for > the majority of my work > > > Good Luck! > Martin > ______________________________________________ > > > ------------------------------ > *From:* Bhuvan Gupta <bhuva...@gmail.com> > *Sent:* Tuesday, May 30, 2017 11:33 PM > *To:* Martin Gainty; Tomcat Users List > *Subject:* Re: Considering @serverEndPoint url for routing the request , > if the request is of ws:// type > > >>>at what point does your websocket class extend org.apache.tomcat.webso > cket.server.WsFilter > > I am not extending the o.a.t.w.s.WsFilter at any point , i am using the > JSR(356) where i only need to define the @ServerEndPoint. > > If you look at the 6th observation in https://stackoverflow.com/ > questions/44216801/tomcat-using-servlet-and-websocket- > jsr356-in-same-web-app > > <https://stackoverflow.com/questions/44216801/tomcat-using-servlet-and-websocket-jsr356-in-same-web-app> > Tomcat: using servlet and websocket (jsr356) in same web app > <https://stackoverflow.com/questions/44216801/tomcat-using-servlet-and-websocket-jsr356-in-same-web-app> > stackoverflow.com > I create a sample webapp using Guice-servlets and websocket in tomcat, now > once guice filter is used websocket stop working Basic information: In my > web.xml, i initialized the Guiceservlet using > > > > > > On Wed, May 31, 2017 at 12:00 AM, Martin Gainty <mgai...@hotmail.com> > wrote: > >> possibly mixing up asking guice to inject HttpServlets with asking >> guice injecting webSocket classes >> >> >> at what point does your websocket class extend org.apache.tomcat.webso >> cket.server.WsFilter >> >> >> ? >> M >> ______________________________________________ >> >> >> >> >> ------------------------------ >> *From:* Bhuvan Gupta <bhuva...@gmail.com> >> *Sent:* Tuesday, May 30, 2017 11:12 AM >> *To:* Tomcat Users List >> *Subject:* Re: Considering @serverEndPoint url for routing the request , >> if the request is of ws:// type >> >> I have added some observation for the issue and observation 5 is >> interesting >> Basically it shows that web.xml filter are registered before WsFilter can >> register, which creates a problem >> >> Please clarify: >> >> https://stackoverflow.com/questions/44216801/tomcat-using- >> servlet-and-websocket-jsr356-in-same-web-app >> >> <https://stackoverflow.com/questions/44216801/tomcat-using-servlet-and-websocket-jsr356-in-same-web-app> >> Tomcat: using servlet and websocket (jsr356) in same web app >> <https://stackoverflow.com/questions/44216801/tomcat-using-servlet-and-websocket-jsr356-in-same-web-app> >> stackoverflow.com >> I create a sample webapp using Guice-servlets and websocket in tomcat, >> now once guice filter is used websocket stop working Basic information: In >> my web.xml, i initialized the Guiceservlet using >> >> >> >> On Tue, May 30, 2017 at 12:15 PM, Mark Thomas <ma...@apache.org> wrote: >> >> > This time to the list... >> > >> > On 29/05/17 16:49, Bhuvan Gupta wrote: >> > > Mark, >> > > >> > >>> Explicitly declare Tomcat's WebSocket filter and ensure it is the >> first >> > > filter in the processing chain. >> > > Can you please give a sample , how to create such filter. >> > > >> > > I looked into the documentation , but cant find it >> > >> > You don't need to create a filter. You just need to configure Tomcat's >> > WebSocket filter in your web.xml before the GuiceFilter. Like the >> > GuiceFilter, it needs to be mapped to "/*". It also needs to be >> > configured to handle DispatcherType.REQUEST and DispatcherType.FORWARD >> > >> > Mark >> > >> > >> > > >> > > On Sun, May 28, 2017 at 3:44 PM, Mark Thomas <ma...@apache.org> >> wrote: >> > > >> > >> On 28 May 2017 10:09:03 BST, Bhuvan Gupta <bhuva...@gmail.com> >> wrote: >> > >>> Hello, >> > >>> >> > >>> >> > >>> >> > >>> I create a sample webapp using servlets and http, which work fine >> and >> > >>> the >> > >>> web.xml looks like >> > >>> >> > >>> <filter> >> > >>> <filter-name>guiceFilter</filter-name> >> > >>> <filter-class>com.google.inject.servlet.GuiceFilter</ >> > >> filter-class></filter> >> > >>> <filter-mapping> >> > >>> <filter-name>guiceFilter</filter-name> >> > >>> <url-pattern>/*</url-pattern></filter-mapping> >> > >>> >> > >>> Now i want to add few @ServerEndPoint class to use websocket. So i >> > >>> added a >> > >>> class and added @ServerEndpoint(value = "/websocket/chat) on that >> > >>> class. >> > >>> >> > >>> Now i expected that when i use websocket client and use >> > >>> ws://localhost:8080/app/websocket/chatto connect it should work >> but it >> > >>> does >> > >>> not as i already have a /* filter which redirect request to >> > >>> guiceFilter. >> > >>> >> > >>> *If i comment the filter it works fine.* >> > >>> ------------------------------ >> > >>> >> > >>> *Question:* >> > >>> >> > >>> How can i tell tomcat to first consider serverEndPoint url for >> routing >> > >>> the >> > >>> request before matching the filter url patterns ? >> > >> >> > >> Explicitly declare Tomcat's WebSocket filter and ensure it is the >> first >> > >> filter in the processing chain. >> > >> >> > >> Mark >> > >> >> > >> >> > >> ------------------------------------------------------------ >> --------- >> > >> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org >> > >> For additional commands, e-mail: users-h...@tomcat.apache.org >> > >> >> > >> >> > > >> > >> > >> > --------------------------------------------------------------------- >> > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org >> > For additional commands, e-mail: users-h...@tomcat.apache.org >> > >> > >> > >