Skip to content
Browse files

Improve documentation, clean up. No functional changes

  • Loading branch information...
1 parent ee04f6d commit 64a36aa84ca0d45f19557bf2a51ec790def1a924 @jfarcand jfarcand committed
View
62 README.md
@@ -152,9 +152,6 @@ You can also generate ServiceDefinition on the fly from any POJO object. Let's s
private static int idx = 4;
public AddressBook() {
- peoplea.put("1", new Person("1", "jason@maven.org", "Jason", "van Zyl"));
- peoplea.put("2", new Person("2", "bob@maven.org", "Bob", "McWhirter"));
- peoplea.put("3", new Person("3", "james@maven.org", "James", "Strachan"));
}
public Person createPerson(Person person) {
@@ -252,9 +249,9 @@ Existing JAXRS or Sitebricks resource can be used as it with RestSimple. All you
@Override
protected Injector getInjector() {
- JaxrsConfig config = new JaxrsConfig();
+ RestSimpleJaxrsModule module = new RestSimpleJaxrsModule();
config.scan( Extension.class.getPackage() );
- return Guice.createInjector(config);
+ return Guice.createInjector(module);
}
@Path("/lolipet/{myPet}")
@@ -302,7 +299,54 @@ There is many ways to deploy a ServiceDefinition. First, you need to decide whic
}
}
-All you need to do is to extends the appropriate ServiceDefinitionConfig: JaxrsConfig or SitebricksConfig. The abstract method defineServices is where you define one or many ServiceDefinition. That's it: the framework will take care of deploying your ServiceDefinition.
+All you need to do is to extends the appropriate Guice Module: RestSimpleJaxrsModule or RestSimpleSitebricksModule. The abstract method defineServices is where you define one or many ServiceDefinition. That's it: the framework will take care of deploying your ServiceDefinition.
+
+You can also let scan for classes annotated with the @Service annotation that contains a method returning a ServiceDefinition like:
+
+ @Service
+ public class Foo {
+
+ @Inject
+ ServiceDefinition serviceDefinition;
+
+ public ServiceDefinition create() {
+ serviceDefinition
+ .consuming(JSON)
+ .producing(JSON);
+ .get("/getPet/{pet}", action)
+ .delete("/deletePet/{pet}", action)
+ .post("/addPet/{pet}", action);
+
+ return serviceDefinition
+ }
+ }
+
+and then just do:
+
+ public class ScanServiceDefinition extends GuiceServletContextListener {
+
+ @Override
+ protected Injector getInjector() {
+ RestSimpleJaxrsModule module = new RestSimpleJaxrsModule();
+ config.scan( Foo.class.getPackage() );
+ return Guice.createInjector(module);
+ }
+ }
+
+You can also add ServiceDefinition classes or instance directly by doing:
+
+ public class ManuallyServiceDefinition extends GuiceServletContextListener {
+
+ @Override
+ protected Injector getInjector() {
+ RestSimpleJaxrsModule module = new RestSimpleJaxrsModule();
+
+ module.addClass( Foo.class ); // Guice will take care of creating the class.
+ module.addInstance ( new Foo() );
+
+ return Guice.createInjector(module);
+ }
+ }
Building the client side of a RestSimple application.
@@ -343,17 +387,17 @@ Finally, you can also generate a client implementation using the WebProxy class.
@Get
@Path("getPet")
- @Produces(PetstoreAction.APPLICATION + "/" + PetstoreAction.JSON)
+ @Produces("application/json)
public Pet get(@PathParam("myPet") String path);
@Post
@Path("addPet")
- @Produces(PetstoreAction.APPLICATION + "/" + PetstoreAction.JSON)
+ @Produces("application/json)
public Pet post(@PathParam("myPet") String myPet, String body);
@Delete
@Path("deletePet")
- @Produces(PetstoreAction.APPLICATION + "/" + PetstoreAction.JSON)
+ @Produces("application/json)
public Pet delete(@PathParam("myPet") String path);
}
View
8 ...stsimple/spi/ServiceDefinitionConfig.java → ...stsimple/spi/ServiceDefinitionModule.java
@@ -20,7 +20,7 @@
* A simple interface allowing applications to define a list of {@link ServiceDefinition} to deploy, and configure
* the server side functionality.
*/
-public interface ServiceDefinitionConfig {
+public interface ServiceDefinitionModule {
/**
* Return the a list of ServiceDefinition to generate. By default this method scan the classpath in search
@@ -48,20 +48,20 @@
*
* @param packageName the package name
*/
- ServiceDefinitionConfig scan(Package packageName);
+ ServiceDefinitionModule scan(Package packageName);
/**
* Add a Rest resource.
*
* @param className the class name
*/
- ServiceDefinitionConfig addClass(Class<?> className);
+ ServiceDefinitionModule addClass(Class<?> className);
/**
* Add a Rest resource.
*
* @param instance the class name
*/
- ServiceDefinitionConfig addInstance(ServiceDefinition instance);
+ ServiceDefinitionModule addInstance(ServiceDefinition instance);
}
View
12 ...simple-jaxrs/src/main/java/org/sonatype/restsimple/jaxrs/guice/RestSimpleJaxrsModule.java
@@ -26,7 +26,7 @@
import org.sonatype.restsimple.spi.NegotiationTokenGenerator;
import org.sonatype.restsimple.spi.RFC2295NegotiationTokenGenerator;
import org.sonatype.restsimple.spi.ResourceModuleConfig;
-import org.sonatype.restsimple.spi.ServiceDefinitionConfig;
+import org.sonatype.restsimple.spi.ServiceDefinitionModule;
import org.sonatype.restsimple.spi.ServiceDefinitionGenerator;
import org.sonatype.restsimple.spi.ServiceHandlerMapper;
import org.sonatype.restsimple.spi.scan.Classes;
@@ -48,7 +48,7 @@
* Base class for deploying {@link ServiceDefinition} to a JAXRS implementation.
*/
public class RestSimpleJaxrsModule
- extends ServletModule implements ServiceDefinitionConfig {
+ extends ServletModule implements ServiceDefinitionModule {
private final Logger logger = LoggerFactory.getLogger(RestSimpleJaxrsModule.class);
private Injector parent;
@@ -99,7 +99,7 @@ protected final void configureServlets() {
NegotiationTokenGenerator token = injector.getInstance( NegotiationTokenGenerator.class );
bind(NegotiationTokenGenerator.class).toInstance( token );
- ServiceHandlerMapper mapper = injector().getInstance( ServiceHandlerMapper.class );
+ ServiceHandlerMapper mapper = injector().getInstance(ServiceHandlerMapper.class);
bind( ServiceHandlerMapper.class ).toInstance( mapper );
sdSet.addAll( defineServices( injector ) );
@@ -107,17 +107,17 @@ protected final void configureServlets() {
@Override
public <A> void bindToInstance(Class<A> clazz, A instance) {
- binder().withSource( "[generated]" ).bind( clazz ).toInstance(instance);
+ binder().bind( clazz ).toInstance(instance);
}
@Override
public <A> void bindTo(Class<A> clazz, Class<? extends A> clazz2) {
- binder().withSource( "[generated]" ).bind( clazz ).to(clazz2);
+ binder().bind( clazz ).to(clazz2);
}
@Override
public void bind(Class<?> clazz) {
- binder().withSource( "[generated]" ).bind( clazz ).asEagerSingleton();
+ binder().bind( clazz ).asEagerSingleton();
}
@Override
View
6 ...ks/src/main/java/org/sonatype/restsimple/sitebricks/guice/RestSimpleSitebricksModule.java
@@ -28,7 +28,7 @@
import org.sonatype.restsimple.spi.NegotiationTokenGenerator;
import org.sonatype.restsimple.spi.RFC2295NegotiationTokenGenerator;
import org.sonatype.restsimple.spi.ResourceModuleConfig;
-import org.sonatype.restsimple.spi.ServiceDefinitionConfig;
+import org.sonatype.restsimple.spi.ServiceDefinitionModule;
import org.sonatype.restsimple.spi.ServiceDefinitionGenerator;
import org.sonatype.restsimple.spi.ServiceHandlerMapper;
import org.sonatype.restsimple.spi.scan.Classes;
@@ -46,7 +46,7 @@
* Base class for deploying {@link org.sonatype.restsimple.api.ServiceDefinition} to a Sitebricks.
*/
public class RestSimpleSitebricksModule
- extends ServletModule implements ServiceDefinitionConfig {
+ extends ServletModule implements ServiceDefinitionModule {
private final Logger logger = LoggerFactory.getLogger(RestSimpleSitebricksModule.class);
@@ -112,7 +112,7 @@ public void install(Module module) {
NegotiationTokenGenerator token = injector.getInstance( NegotiationTokenGenerator.class );
bind(NegotiationTokenGenerator.class).toInstance( token );
- ServiceHandlerMapper mapper = injector.getInstance( ServiceHandlerMapper.class );
+ ServiceHandlerMapper mapper = injector.getInstance(ServiceHandlerMapper.class);
bind( ServiceHandlerMapper.class ).toInstance( mapper );
if (sdSet != null && sdSet.size() > 0) {
View
4 restsimple-webdriver/src/main/java/org/sonatype/restsimple/WebDriver.java
@@ -24,7 +24,7 @@
import org.sonatype.restsimple.api.ServiceDefinition;
import org.sonatype.restsimple.jaxrs.guice.RestSimpleJaxrsModule;
import org.sonatype.restsimple.sitebricks.guice.RestSimpleSitebricksModule;
-import org.sonatype.restsimple.spi.ServiceDefinitionConfig;
+import org.sonatype.restsimple.spi.ServiceDefinitionModule;
import java.io.IOException;
import java.net.ServerSocket;
@@ -107,7 +107,7 @@ public WebDriver serviceDefinition(final ServiceDefinition serviceDefinition) th
protected Injector getInjector() {
ServletModule config = provider.equals(PROVIDER.JAXRS) ? new RestSimpleJaxrsModule() : new RestSimpleSitebricksModule();
- ((ServiceDefinitionConfig)config).addInstance( serviceDefinition );
+ ((ServiceDefinitionModule)config).addInstance( serviceDefinition );
return Guice.createInjector(config);
}
});

0 comments on commit 64a36aa

Please sign in to comment.
Something went wrong with that request. Please try again.