You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Bob DeRemer <bo...@thingworx.com> on 2013/09/03 22:35:41 UTC
RE: is it possible to dynamically add servlets and websocket
endpoints during startup based on our own configuration settings?
> -----Original Message-----
> From: Mark Thomas [mailto:markt@apache.org]
> Sent: Friday, August 23, 2013 8:40 AM
> To: Tomcat Users List
> Subject: Re: is it possible to dynamically add servlets and websocket endpoints
> during startup based on our own configuration settings?
>
> On 23/08/2013 13:28, Bob DeRemer wrote:
> >
> >
> >> -----Original Message-----
> >> From: Mark Thomas [mailto:markt@apache.org]
> >> Sent: Friday, August 23, 2013 8:14 AM
> >> To: Tomcat Users List
> >> Subject: Re: is it possible to dynamically add servlets and websocket
> >> endpoints during startup based on our own configuration settings?
> >>
> >> On 22/08/2013 19:32, Bob DeRemer wrote:
> >>> I'm in the process of developing a configurable server application
> >>> which must handle various protocols, but the respective endpoints
> >>> must be configurable. Specifically, I would like to
> >>> programmatically add both HTTP servlet(s) as well as WebSocket
> >>> Servlets/Endpoints during the contextInitialized call [based on our
> >>> own configuration settings], as opposed to having all servlets in
> >>> web.xml or annotated classes loaded automatically.
> >>>
> >>> Is this possible in Tomcat 7; and, if yes, are there any examples?
> >>> I know the Endpoint aspect of the question depends on JSR-356 being
> >>> back-ported.
> >>
> >> Yes, it is possible.
> >>
> >> There are some examples in the unit tests:
> >>
> >> http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/co
> >> re/Test
> >> StandardContext.java?view=annotate
> >>
> >> Look for calls to addServlet(...)
> >
> > Great! So, how do I tell Tomcat NOT to load anything in the first place?
>
> Exclude the JARs containing the Servlets with an absolute-ordering in web.xml
>
> > Can I still use Annotation on my servlets, or will I have to use an interface-
> based approach?
>
> I don't believe @WebServlet has any effect when adding Servlets via
> addServlet()
>
> > Also, how about for the JSR-356 Endpoints? Is there an addEndpoint(...) call?
>
> Yes on ServerContainer, as long as you do it before any of them are used.
>
Just getting around to trying this - maybe a stupid question, but how do I get access to the WsServerContainer instance?
> Mark
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: is it possible to dynamically add servlets and websocket endpoints
during startup based on our own configuration settings?
Posted by Mark Thomas <ma...@apache.org>.
On 03/09/2013 22:14, Bob DeRemer wrote:
>
>
>> -----Original Message----- From: Mark Thomas
>> [mailto:markt@apache.org] Sent: Tuesday, September 03, 2013 4:46
>> PM To: Tomcat Users List Subject: Re: is it possible to dynamically
>> add servlets and websocket endpoints during startup based on our
>> own configuration settings?
>>
>> On 03/09/2013 21:35, Bob DeRemer wrote:
>>
>>> Just getting around to trying this - maybe a stupid question, but
>>> how do I get
>> access to the WsServerContainer instance?
>>
>> From the ServletContext. You want the attribute called
>> "javax.websocket.server.ServerContainer"
>
> Thanks, I got the ServerContainer and can now call addEndpoint, but
> it expects the class I pass in to have the @ServerEndpoint
> annotation. I removed the annotation because Tomcat was ALWAYS
> adding any pojo with that annotation, and my goal is to only add
> ServerEndpoints that I read in from my own configuration. Is there a
> way to do this?
You want the other addEndpoint method - the one that takes a
ServerEndpointConfig instance. If you look at the source for the
addEndpoint method you are currently using, you'll see an example of how
to build a ServerEndpointConfig instance.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: is it possible to dynamically add servlets and websocket
endpoints during startup based on our own configuration settings?
Posted by Bob DeRemer <bo...@thingworx.com>.
> -----Original Message-----
> From: Mark Thomas [mailto:markt@apache.org]
> Sent: Tuesday, September 03, 2013 4:46 PM
> To: Tomcat Users List
> Subject: Re: is it possible to dynamically add servlets and websocket endpoints
> during startup based on our own configuration settings?
>
> On 03/09/2013 21:35, Bob DeRemer wrote:
>
> > Just getting around to trying this - maybe a stupid question, but how do I get
> access to the WsServerContainer instance?
>
> From the ServletContext. You want the attribute called
> "javax.websocket.server.ServerContainer"
Thanks, I got the ServerContainer and can now call addEndpoint, but it expects the class I pass in to have the @ServerEndpoint annotation. I removed the annotation because Tomcat was ALWAYS adding any pojo with that annotation, and my goal is to only add ServerEndpoints that I read in from my own configuration. Is there a way to do this?
>
> Mark
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: is it possible to dynamically add servlets and websocket endpoints
during startup based on our own configuration settings?
Posted by Mark Thomas <ma...@apache.org>.
On 03/09/2013 21:35, Bob DeRemer wrote:
> Just getting around to trying this - maybe a stupid question, but how do I get access to the WsServerContainer instance?
>From the ServletContext. You want the attribute called
"javax.websocket.server.ServerContainer"
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org