Hi

I don't understand what are you trying to do. It does look too complex.

What exactly are you trying to achieve besides registering a CXF servlet as a Jetty handler ?

What do you need to initialize, the service implementation, the providers, both ?

Sergey



On 19/01/15 07:24, Maarten Boekhold wrote:
Hi again,

Studied the CXF source code a bit more, and I've got something that
works, by overriding getResourceProviders() and providing my own
ResourceProvider implementation as follows. Bit complex however, I would
not mind some simpler standard API around this!

    public class TheApp {
    private static final Logger LOG =
LoggerFactory.getLogger(TheApp.class);

    TheResource resource;

    public static class BeanResourceProvider implements ResourceProvider {
    private final Object theBean;

    public BeanResourceProvider(Object theBean) {
    this.theBean = theBean;
    }

    @Override
    public Object getInstance(Message m) {
    return theBean;
    }

    @Override
    public void releaseInstance(Message m, Object o) {
    }

    @Override
    public Class<?> getResourceClass() {
    return theBean.getClass();
    }

    @Override
    public boolean isSingleton() {
    return true;
    }

         };

    public TheApp(int port) throws Exception {
    resource = new TheResource();

    CXFNonSpringJaxrsServlet context = new CXFNonSpringJaxrsServlet() {
    public void configureSingleton(Object o) {
    LOG.info("configureSingleton() called");
    }

    public Map<Class<?>, ResourceProvider>
    getResourceProviders(ServletConfig servletConfig,
    Map<Class<?>, Map<String, List<String>>> resourceClasses) throws
    ServletException {
    LOG.info("getResourceProviders called");

    Map<Class<?>, ResourceProvider> map = new HashMap<Class<?>,
    ResourceProvider>();
    for (Map.Entry<Class<?>, Map<String, List<String>>> entry :
    resourceClasses.entrySet()) {
    Class<?> c = entry.getKey();
    LOG.info("getting provider for {}", c.getName());
    map.put(c, new BeanResourceProvider(resource));
    }
    return map;
    }
    };

    ServletHolder holder = new ServletHolder(context);
    holder.setInitParameter("jaxrs.serviceClasses",
    "com.misys.tools.integration.cxfjetty.TheResource");

    ServletContextHandler handler = new ServletContextHandler();
    handler.addServlet(holder, "/*");
    handler.setContextPath("/theroot");

    Server server = new Server(port);
    server.setHandler(handler);
    server.start();
    server.join();
         }

    public static void main(String[] args) throws Exception {
    TheApp app = new TheApp(8122);
         }
    }

Maarten

On 2015-01-19 11:07, Maarten Boekhold wrote:
Hi,

I've managed to override configureSingleton(), but at the moment my
implementation just logs something and then delegates to
super.configureSingleton() (which is empty itself btw). I'm not
exactly sure what code I would need to include in my implementation.
Any suggestions?

Another suggestions I got on Stack Overflow was to extend
CXFNonSpringJaxrsServlet.getResourceProviders(). Same thing here, I
can't figure out what my implementation would need to do :).

Does anybody have any further pointers/suggestions? Btw. Haven't
figured out how/where to register a custom application yet, so no
progress in that direction yet.

Maarten

On 2015-01-18 21:27, Sergey Beryozkin wrote:
Hi


Right now it is not possible to pass an initialized instance directly
to the servlet, though I can see it can be handy in some cases.
In many cases one can still achieve the same with the current
approach, example, you can have Catalog properties passed too,
Catalog(a=1 b=2), see the example at the wiki. List properties can be
passed too.

if you do need to pass some ready instance then you can either go
with working directlu with JAXRSServerFactoryBean (I'd prefer it
instead of dealing directly with Jetty handlers), use jaxrs:server
with an absolute HTTP address, or in this case, extend
CxfNonSpringJaxrsServlet and override its configureSingleton class or
it it is more involved, register a custom Application.

I'll add a constructor CxfNonSpringJaxrsServlet(Application) to make
things simpler too

Cheers, Sergey



Reply via email to