Coder Social home page Coder Social logo

guice-cxf's Introduction

A simple EDSL (Embedded Domain-Specific Language) for configuring the Apache CXF implementation of JSR-311.

Provides a configured JAXRSServerFactoryBean instance that you can use to start a Server in any particular way you need.

Resources and providers will be created with Guice, then they will have the normal CXF/JAX-RS injections performed on them.

Example:

protected void configure() {		 
 serve().atAddress("/rest");
  
 publish(LibraryResource.class);
  
 readAndWriteBody(JAXBElementProvider.class);
 readAndWriteBody(JSONProvider.class);
 
 mapExceptions(ApplicationExceptionMapper.class);
}

guice-cxf supports injecting Jax-Rs resource with dependencies bound in Guice.

@Path("foo");
public class LibraryResource {

   @Inject private BookService service;

   @GET
   public Books search(@QueryParam("q") String q){
      return service.findBooks(q);
   }
   
   // [...]
   
}

You can also enable injecting sub-resources instead of creating them manually;

protected void configure(){
 bind(BookResource.class).in(REQUEST);
}
@Path("foo");
public class LibraryResource {
   // [...]
   
   @Injected
   @Path("{id}")
   public BookResource getBook(@PathParam("id") String id){
      throw new UnsupportedOperationException("will be implemented by Guice");
   }

}

Finally you can inject @Context dependencies (HttpHeaders, Request, UriInfo etc.), provided you are in appropriate scope (there is a special REQUEST scope provided for Jax-Rs requets).

public class BookTitleResolver {
   @Inject
   private HttpHeaders headers;

   public String resolveTitleFor(String id){
     return getBook(id).getTitleForLanguage(headers.getLanguage());
   }

   // [...]
  
}

To create a server do:

  injector.getInstance(JAXRSServerFactoryBean.class).create();

The current version is well tested and working, although not all CXF features can be configured yet (you can always set them on the provided JAXRSServerFactoryBean instance).

See the Features page for a more complete list.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.