Search code examples
jax-rsjax-wsgrizzly

Grizzly JAX-WS and JAX-RS


I created two projects using grizzly.

One is for jax-rs and one for jax-ws.

The code to get the jax-rs running looks like this:

    String BASE_URI = "http://localhost:8080/myapp/";
    ResourceConfig rc = new ResourceConfig().packages("za.co.quinn.grizzly.rest");
    HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);

The code to get the jax-ws running looks like this:

    HttpServer httpServer = new HttpServer();
    ServerConfiguration configuration = httpServer.getServerConfiguration();
    configuration.addHttpHandler(new JaxwsHandler(new AddService()), "/add");
    httpServer.addListener(new NetworkListener("jaxws-listener", "0.0.0.0", 8080));
    httpServer.start();

I want to combine the two to get jax-ws and jax-rs working in the same project.

It would have been nice to have a JaxrsHandler which I could just add like so:

configuration.addHttpHandler(new JaxrsHandler(new AddAnotherService()), "/addAnother");

But no JaxrsHandler exist.

Is there another way I can combine the two?


Solution

  • This solved my problem:

        Injector injector = Guice.createInjector(new JpaPersistModule("myJpaUnit"),
                new ServletModule() {
                    @Override
                    protected void configureServlets() {
                        bind(new TypeLiteral<ExerciseDao>() {
                        }).to(ExerciseDaoImpl.class);
                    }
                });
    
        ResourceConfig rc = new PackagesResourceConfig("za.co.quinn.ws");
        IoCComponentProviderFactory ioc = new GuiceComponentProviderFactory(rc, injector);
    
        PersistInitializer initializer = injector.getInstance(PersistInitializer.class);
        HttpServer server = GrizzlyServerFactory.createHttpServer(BASE_URI, rc, ioc);