Re: can i have programatically access to the ServerContainer (websocket) in tomcat 7?

2014-02-27 Thread Mark Thomas
On 27/02/2014 17:12, Johan Compagner wrote:
> thx,
> 
> On 27 February 2014 15:25, Mark Thomas  wrote:
> 
>>
>> You haven't started the Context so the attributes won't have been
>> populated.
>>
>> Try adding a ContextListener to the context and use that to set up the
>> endpoints using the programmatic API.
>>
>> Mark
> 
> 
> I have it working for WebSocket endpoints yes. Those can be added at
> anytime it seems on the fly
> 
> Problem is that i want to do the same for servlets and filters (then onces
> that are annotated).. But the context is already initialized
> so even call ServletContext.addFilter(Filter.class)
> directly after Catalina.load(); (but before start()) will already result in:
> 
> SEVERE: A child container failed during start
> java.util.concurrent.ExecutionException: java.lang.IllegalStateException:
> Filters can not be added to context /beans as the context has been
> initialised
>  at java.util.concurrent.FutureTask.report(Unknown Source)
> 
> 
> or is it possible to do something directly on the StandardContext ?

You can do it directly (look at the unit tests for lots of examples). Or
you can do it via a ServletContextListener.

Mark



-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: can i have programatically access to the ServerContainer (websocket) in tomcat 7?

2014-02-27 Thread Johan Compagner
thx,

On 27 February 2014 15:25, Mark Thomas  wrote:

>
> You haven't started the Context so the attributes won't have been
> populated.
>
> Try adding a ContextListener to the context and use that to set up the
> endpoints using the programmatic API.
>
> Mark



I have it working for WebSocket endpoints yes. Those can be added at
anytime it seems on the fly

Problem is that i want to do the same for servlets and filters (then onces
that are annotated).. But the context is already initialized
so even call ServletContext.addFilter(Filter.class)
directly after Catalina.load(); (but before start()) will already result in:

SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: java.lang.IllegalStateException:
Filters can not be added to context /beans as the context has been
initialised
 at java.util.concurrent.FutureTask.report(Unknown Source)


or is it possible to do something directly on the StandardContext ?

johan





-- 
Johan Compagner
Servoy


Re: can i have programatically access to the ServerContainer (websocket) in tomcat 7?

2014-02-27 Thread Mark Thomas
On 27/02/2014 14:03, Johan Compagner wrote:
> Like what is described here?
> 
> http://dev.eclipse.org/mhonarc/lists/jetty-dev/msg01999.html
> 
> 
>  ServerContainer container =
> (ServerContainer)context.getAttribute("javax.websocket.server.ServerContainer"
> );
> try
> {
> container.addEndpoint(EchoSocket.class);

You can do it exactly like that.



> this is what i just tried:
> 
> Catalina catalina = new Catalina();
> catalina.setParentClassLoader(new
> OSGIWebappClassLoader(TomcatStarter.class.getClassLoader()));
> catalina.load();
>  Service[] services = catalina.getServer().findServices();
> for (Service service : services) {
> Container[] containers = service.getContainer().findChildren();
>  for (Container host : containers) {
> Container[] contexts = host.findChildren();
> for (Container container : contexts) {
>  StandardContext sc = (StandardContext) container;
> ServletContext context = sc.getServletContext();
>  ServerContainer serverContainer =
> (ServerContainer)context.getAttribute("javax.websocket.server.ServerContainer");
> System.err.println(serverContainer);
> 
> But that attribute doesn't seem to be there at least at that time
> 
> Any body an idea?

You haven't started the Context so the attributes won't have been populated.

Try adding a ContextListener to the context and use that to set up the
endpoints using the programmatic API.

Mark

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



can i have programatically access to the ServerContainer (websocket) in tomcat 7?

2014-02-27 Thread Johan Compagner
Like what is described here?

http://dev.eclipse.org/mhonarc/lists/jetty-dev/msg01999.html


 ServerContainer container =
(ServerContainer)context.getAttribute("javax.websocket.server.ServerContainer"
);
try
{
container.addEndpoint(EchoSocket.class);


i need a way to add fully programatically a Websocket endpoint to the
context/container

i also can't use the ApplicationConfig because that one also needs to be
scanned by tomcat first
the classes are not in the web app. they are coming from osgi and are
provided by the system
So i need a way to add them on the fly to a context

this is what i just tried:

Catalina catalina = new Catalina();
catalina.setParentClassLoader(new
OSGIWebappClassLoader(TomcatStarter.class.getClassLoader()));
catalina.load();
 Service[] services = catalina.getServer().findServices();
for (Service service : services) {
Container[] containers = service.getContainer().findChildren();
 for (Container host : containers) {
Container[] contexts = host.findChildren();
for (Container container : contexts) {
 StandardContext sc = (StandardContext) container;
ServletContext context = sc.getServletContext();
 ServerContainer serverContainer =
(ServerContainer)context.getAttribute("javax.websocket.server.ServerContainer");
System.err.println(serverContainer);

But that attribute doesn't seem to be there at least at that time

Any body an idea?

(it doesn't have to be a standard servlet way, i can use the tomcat api
itself if needed)

johan
-- 
Johan Compagner
Servoy