Dan,

In the current experiment, I'm adding a handler to the server via
explicit Java code, not spring wiring.

Nothing I am adding is exactly a context, it is just a resource handler.

Perhaps it needs a 'stop', too.

I could argue that there should be some way to say, 'make me a
self-contained universe using no static variables.'


> -----Original Message-----
> From: Daniel Kulp [mailto:[EMAIL PROTECTED]
> Sent: Monday, October 01, 2007 2:07 PM
> To: cxf-user@incubator.apache.org
> Cc: Benson Margulies
> Subject: Re: Spring, bus, confusion
> 
> 
> Benson,
> 
> The Jetty servers are static, not per bus.   The main reason is if you
> two buss's in your application that have services that need to be
> deployed on the same port (like port 80), we can do that without port
in
> use issues.
> 
> When you call bus.shutdown, it will only shutdown the port if there
are 0
> contexts left (supposedly).    Thus, before you call shutdown, you
would
> need to unregister any extra contexts created in the @Before.
> 
> Hmm....   are you adding the contexts via spring?   That might get
more
> involved.   We might not have added a bean.setDestroyMethodName(...);
> type thing for the extra contexts to remove them.   Looking....
> 
> The method:
> public void shutdown()
> certainly doesn't remove the handlers.
> 
> Definitely some bugs in that area.  :-(
> 
> Dan
> 
> 
> On Monday 01 October 2007, Benson Margulies wrote:
> > The server's list of handlers still has the extra handler. Did you
> > look at the source code I sent? The @Before method inserts an extra
> > handler into the server. The @After calls bus.shutdown.
> >
> > The next time we run the @Before, we should be restarting from
> > complete zero, we are rereading the beans into a new app context.
Yet,
> > the server on the bus still somehow has the extra handler.
> >
> > > -----Original Message-----
> > > From: Willem2 [mailto:[EMAIL PROTECTED]
> > > Sent: Monday, October 01, 2007 11:32 AM
> > > To: cxf-user@incubator.apache.org
> > > Subject: RE: Spring, bus, confusion
> > >
> > >
> > > What do you mean the server's configuration is there?
> > >
> > > Do you mean the jetty server is still there ?
> > >
> > > Willem.
> > >
> > > bmargulies wrote:
> > > > I tried that. I still found my configuration changes to the
server
> > > > 'already present' when I create the next application context.
> > > >
> > > >> -----Original Message-----
> > > >> From: Willem2 [mailto:[EMAIL PROTECTED]
> > > >> Sent: Monday, October 01, 2007 9:11 AM
> > > >> To: cxf-user@incubator.apache.org
> > > >> Subject: Re: Spring, bus, confusion
> > > >>
> > > >>
> > > >> Hi Benson,
> > > >>
> > > >> You can call bus.shutdown(true) in @After to tear down the
server
> >
> > and
> >
> > > > the
> > > >
> > > >> jetty engine.
> > > >>
> > > >>
> > > >> Willem.
> > > >>
> > > >> bmargulies wrote:
> > > >> > Please forgive me for pasting a lot of code into here.
> > > >> >
> > > >> > I'm trying to set up a unit test framework where the fixture
> > > >> > sets
> >
> > up
> >
> > > >> > jetty with an endpoint and some static content. So, as you
will
> >
> > see,
> >
> > > > I
> > > >
> > > >> > have an @Before that sets everything up, and an @After that
> > > >> > tries
> >
> > to
> >
> > > >> > tear everything down.
> > > >> >
> > > >> > However, when the @Before runs the second time, things sure
> > > >> > look
> >
> > as
> >
> > > > if
> > > >
> > > >> > they have all hung around from the first time around.
> > > >> >
> > > >> > I bet that there's something simple about the bus that I'm
> >
> > missing,
> >
> > > >> > namely, that the cxf bus exists independently of my app
> > > >> > context,
> >
> > and
> >
> > > > I
> > > >
> > > >> > have to \do something/ to tear \it/ down.
> > > >> >
> > > >> >
> > > >> >
> > > >> >
> > > >> >
> > > >> > package com.basistech.ws;
> > > >> >
> > > >> > import java.io.File;
> > > >> > import java.net.URL;
> > > >> >
> > > >> > import org.apache.cxf.Bus;
> > > >> > import org.apache.cxf.endpoint.ServerImpl;
> > > >> > import org.apache.cxf.endpoint.ServerRegistry;
> > > >> > import
> > > >> > org.apache.cxf.transport.http_jetty.JettyHTTPDestination;
> > > >> > import
> > > >> > org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine;
> > > >> > import org.junit.After;
> > > >> > import org.junit.Before;
> > > >> > import org.mortbay.jetty.Handler;
> > > >> > import org.mortbay.jetty.Server;
> > > >> > import org.mortbay.jetty.handler.ContextHandlerCollection;
> > > >> > import org.mortbay.jetty.handler.HandlerList;
> > > >> > import org.mortbay.jetty.handler.ResourceHandler;
> > > >> > import org.mortbay.resource.FileResource;
> > > >> > import
> > > >
> > > > org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
> > > >
> > > >> > import
> > > >
> > > > org.springframework.context.support.GenericApplicationContext;
> > > >
> > > >> > import org.springframework.core.io.ClassPathResource;
> > > >> > import org.springframework.core.io.Resource;
> > > >> >
> > > >> > /**
> > > >> >  * Class used to launch a CXF/jetty web service using the
> >
> > embedded
> >
> > > > jetty
> > > >
> > > >> > in CXF.
> > > >> >  *
> > > >> >  */
> > > >> > public abstract class AbstractTestService {
> > > >> >
> > > >> >     protected abstract Resource getServiceDefinitionBeans();
> > > >> >     protected abstract String getStaticContentPath();
> > > >> >     protected GenericApplicationContext applicationContext;
> > > >> >     protected Bus bus;
> > > >> >
> > > >> >     private void readBeans(Resource beanResource) {
> > > >> >         XmlBeanDefinitionReader reader = new
> > > >> > XmlBeanDefinitionReader(applicationContext);
> > > >> >         reader.loadBeanDefinitions(beanResource);
> > > >> >     }
> > > >> >
> > > >> >     @Before
> > > >> >     public void launchService() throws Exception {
> > > >> >         applicationContext = new GenericApplicationContext();
> > > >> >         readBeans(new
> > > >> > ClassPathResource("META-INF/cxf/cxf.xml")); readBeans(new
> > > >> > ClassPathResource("META-INF/cxf/cxf-extension-soap.xml"));
> > > >> >         readBeans(new
> > > >> > ClassPathResource("META-INF/cxf/cxf-extension-http.xml"));
> > > >> >         readBeans(new
> > > >> >
ClassPathResource("META-INF/cxf/cxf-extension-http-jetty.xml"))
> > > >> >; readBeans(getServiceDefinitionBeans());
> > > >> >         applicationContext.refresh();
> > > >> >
> > > >> >         bus = (Bus)applicationContext.getBean("cxf");
> > > >> >         ServerRegistry sr=
> >
> > bus.getExtension(ServerRegistry.class);
> >
> > > >> >         ServerImpl si = (ServerImpl) sr.getServers().get(0);
> > > >> >         JettyHTTPDestination jhd =
> > > >> > (JettyHTTPDestination)si.getDestination();
> > > >> >         JettyHTTPServerEngine engine =
(JettyHTTPServerEngine)
> > > >> > jhd.getEngine();
> > > >> >         Server server = engine.getServer();
> > > >> >         Handler serverHandler = server.getHandler();
> > > >> >         ContextHandlerCollection contextHandlerCollection =
> > > >> > (ContextHandlerCollection)serverHandler;
> > > >> >         HandlerList handlerList = new HandlerList();
> > > >> >         ResourceHandler resourceHandler = new
> > > >> > ResourceHandler(); handlerList.addHandler(resourceHandler);
> > > >> >         handlerList.addHandler(contextHandlerCollection);
> > > >> >         server.setHandler(handlerList);
> > > >> >         handlerList.start();
> > > >> >         File staticContentFile = new
> >
> > File(getStaticContentPath());
> >
> > > >> >         URL targetURL = new URL("file://" +
> > > >> > staticContentFile.getCanonicalPath());
> > > >> >         FileResource fileResource = new
> > > >> > FileResource(targetURL);
> > > >> > resourceHandler.setBaseResource(fileResource); }
> > > >> >
> > > >> >     @After
> > > >> >     public void shutdownService() throws Exception {
> > > >> >         bus = (Bus)applicationContext.getBean("cxf");
> > > >> >         ServerRegistry sr =
> >
> > bus.getExtension(ServerRegistry.class);
> >
> > > >> >         ServerImpl si = (ServerImpl) sr.getServers().get(0);
> > > >> >         JettyHTTPDestination jhd =
> > > >> > (JettyHTTPDestination)si.getDestination();
> > > >> >         JettyHTTPServerEngine e = (JettyHTTPServerEngine)
> > > >> > jhd.getEngine();
> > > >> >         e.getServer().stop();
> > > >> >         applicationContext.destroy();
> > > >> >     }
> > > >> >
> > > >> > }
> > > >>
> > > >> --
> > > >> View this message in context:
> >
> > http://www.nabble.com/Spring%2C-bus%2C-
> >
> > > >> confusion-tf4545841.html#a12978917
> > > >> Sent from the cxf-user mailing list archive at Nabble.com.
> > >
> > > --
> > > View this message in context:
> > > http://www.nabble.com/Spring%2C-bus%2C-
> > > confusion-tf4545841.html#a12981449
> > > Sent from the cxf-user mailing list archive at Nabble.com.
> 
> 
> 
> --
> J. Daniel Kulp
> Principal Engineer
> IONA
> P: 781-902-8727    C: 508-380-7194
> [EMAIL PROTECTED]
> http://www.dankulp.com/blog

Reply via email to