users@jersey.java.net

Re: [Jersey] LW HTTP Server and injectable providers

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 10 Jun 2008 18:56:59 +0200

Bertold Kolics wrote:
> My case maybe special, because I have a constructor in my injectable
> provider that takes some parameters. The simplest way I can find to
> setup an LW HTTP Server was something like this (hacked together from
> the ContainerFactory and HttpServerFactory classes). Is there a better way?
>

We need to create a better way. What if there was a specific resource
config property that contains a list of injectable provider instances to
add to the web application?

I can modify the ContainerFactory to check for this property.

Paul.

> Bertold
>
> String classPath = System.getProperty("java.class.path");
> String[] paths = classPath.split(File.pathSeparator);
> ClasspathResourceConfig config = new ClasspathResourceConfig(paths);
> WebApplication wa = WebApplicationFactory.createWebApplication();
> wa.addInjectable(new MyInjectableProvider(myParams));
>
> // Revese the order so that applications may override
> LinkedList<ContainerProvider> cps = new
> LinkedList<ContainerProvider>();
> for (ContainerProvider cp :
> ServiceFinder.find(ContainerProvider.class, true))
> cps.addFirst(cp);
>
> HttpHandler handler = null;
> for (ContainerProvider<HttpHandler> cp : cps) {
> handler = cp.createContainer(HttpHandler.class, config, wa);
> if (handler != null) {
> Object o = config.getProperties().get(
> ResourceConfig.PROPERTY_CONTAINER_NOTIFIER);
> if (o instanceof ContainerNotifier &&
> handler instanceof ContainerListener) {
> ContainerNotifier crf = (ContainerNotifier)o;
> crf.addListener((ContainerListener)handler);
> }
> }
> }
>
> HttpServer server =
> HttpServerFactory.create("http://localhost:9998/", handler);
>
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net For
> additional commands, e-mail: users-help_at_jersey.dev.java.net

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109