Skip to content

Commit

Permalink
resteasy support javax injection instead of static delegate factory (#…
Browse files Browse the repository at this point in the history
…5272)

* resteasy support javax injection instead of static delegate factory

* fixed resteasy joda example
  • Loading branch information
chameleon82 authored and wing328 committed Dec 11, 2017
1 parent d881cb3 commit 643ef64
Show file tree
Hide file tree
Showing 61 changed files with 207 additions and 214 deletions.
Expand Up @@ -23,7 +23,6 @@ public JavaResteasyServerCodegen() {
outputFolder = "generated-code/JavaJaxRS-Resteasy";
apiTemplateFiles.put("apiService.mustache", ".java");
apiTemplateFiles.put("apiServiceImpl.mustache", ".java");
apiTemplateFiles.put("apiServiceFactory.mustache", ".java");
apiTestTemplateFiles.clear(); // TODO: add test template

// clear model and api doc template as AbstractJavaJAXRSServerCodegen
Expand Down
Expand Up @@ -2,7 +2,6 @@ package {{package}};

import {{modelPackage}}.*;
import {{package}}.{{classname}}Service;
import {{package}}.factories.{{classname}}ServiceFactory;

import io.swagger.annotations.ApiParam;
import io.swagger.jaxrs.*;
Expand All @@ -20,6 +19,8 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.*;
import javax.inject.Inject;

{{#useBeanValidation}}
import javax.validation.constraints.*;
{{/useBeanValidation}}
Expand All @@ -32,7 +33,8 @@ import javax.validation.constraints.*;
{{>generatedAnnotation}}
{{#operations}}
public class {{classname}} {
private final {{classname}}Service delegate = {{classname}}ServiceFactory.get{{classname}}();
@Inject {{classname}}Service service;

{{#operation}}
@{{httpMethod}}
Expand All @@ -51,7 +53,7 @@ public class {{classname}} {
{{/hasMore}}{{/responses}} })
public Response {{nickname}}({{#isMultipart}}MultipartFormDataInput input,{{/isMultipart}}{{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{^isMultipart}}{{>formParams}},{{/isMultipart}}{{#isMultipart}}{{^isFormParam}},{{/isFormParam}}{{/isMultipart}}{{/allParams}}@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.{{nickname}}({{#isMultipart}}input,{{/isMultipart}}{{#allParams}}{{^isMultipart}}{{paramName}},{{/isMultipart}}{{#isMultipart}}{{^isFormParam}}{{paramName}},{{/isFormParam}}{{/isMultipart}}{{/allParams}}securityContext);
return service.{{nickname}}({{#isMultipart}}input,{{/isMultipart}}{{#allParams}}{{^isMultipart}}{{paramName}},{{/isMultipart}}{{#isMultipart}}{{^isFormParam}}{{paramName}},{{/isFormParam}}{{/isMultipart}}{{/allParams}}securityContext);
}
{{/operation}}
}
Expand Down
Expand Up @@ -18,9 +18,9 @@ import javax.ws.rs.core.SecurityContext;

{{>generatedAnnotation}}
{{#operations}}
public abstract class {{classname}}Service {
public interface {{classname}}Service {
{{#operation}}
public abstract Response {{nickname}}({{#isMultipart}}MultipartFormDataInput input,{{/isMultipart}}{{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{^isMultipart}}{{>serviceFormParams}},{{/isMultipart}}{{#isMultipart}}{{^isFormParam}},{{/isFormParam}}{{/isMultipart}}{{/allParams}}SecurityContext securityContext)
Response {{nickname}}({{#isMultipart}}MultipartFormDataInput input,{{/isMultipart}}{{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{^isMultipart}}{{>serviceFormParams}},{{/isMultipart}}{{#isMultipart}}{{^isFormParam}},{{/isFormParam}}{{/isMultipart}}{{/allParams}}SecurityContext securityContext)
throws NotFoundException;
{{/operation}}
}
Expand Down

This file was deleted.

Expand Up @@ -13,14 +13,15 @@ import {{package}}.NotFoundException;

import java.io.InputStream;

import javax.enterprise.context.RequestScoped;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;

@RequestScoped
{{>generatedAnnotation}}
{{#operations}}
public class {{classname}}ServiceImpl extends {{classname}}Service {
public class {{classname}}ServiceImpl implements {{classname}}Service {
{{#operation}}
@Override
public Response {{nickname}}({{#isMultipart}}MultipartFormDataInput input,{{/isMultipart}}{{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{^isMultipart}}{{>serviceFormParams}},{{/isMultipart}}{{#isMultipart}}{{^isFormParam}},{{/isFormParam}}{{/isMultipart}}{{/allParams}}SecurityContext securityContext)
throws NotFoundException {
// do some magic!
Expand Down
Expand Up @@ -13,13 +13,18 @@ dependencies {
providedCompile 'org.jboss.resteasy:resteasy-validator-provider-11:3.0.11.Final'
providedCompile 'org.jboss.resteasy:resteasy-multipart-provider:3.0.11.Final'
providedCompile 'javax.annotation:javax.annotation-api:1.2'
providedCompile 'javax:javaee-api:7.0'
providedCompile 'org.jboss.spec.javax.servlet:jboss-servlet-api_3.0_spec:1.0.0.Final'
compile 'io.swagger:swagger-annotations:1.5.10'
compile 'org.jboss.resteasy:resteasy-jackson2-provider:3.0.11.Final'
{{#joda}}
{{#useBeanValidation}}
providedCompile 'javax.validation:validation-api:1.1.0.Final'
{{/useBeanValidation}}
compile 'com.fasterxml.jackson.datatype:jackson-datatype-joda:2.4.1'
compile 'joda-time:joda-time:2.7'
{{/joda}}
//TODO: swaggerFeature
compile 'io.swagger:swagger-jaxrs:1.5.12'

testCompile 'junit:junit:4.12',
'org.hamcrest:hamcrest-core:1.3'
}
Expand Down
Expand Up @@ -58,6 +58,14 @@
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/javax/javaee-api -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
Expand Down Expand Up @@ -103,6 +111,7 @@
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>${resteasy-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
Expand Down
7 changes: 7 additions & 0 deletions samples/server/petstore/jaxrs-resteasy/default/build.gradle
Expand Up @@ -13,9 +13,16 @@ dependencies {
providedCompile 'org.jboss.resteasy:resteasy-validator-provider-11:3.0.11.Final'
providedCompile 'org.jboss.resteasy:resteasy-multipart-provider:3.0.11.Final'
providedCompile 'javax.annotation:javax.annotation-api:1.2'
providedCompile 'javax:javaee-api:7.0'
providedCompile 'org.jboss.spec.javax.servlet:jboss-servlet-api_3.0_spec:1.0.0.Final'
compile 'io.swagger:swagger-annotations:1.5.10'
compile 'org.jboss.resteasy:resteasy-jackson2-provider:3.0.11.Final'
providedCompile 'javax.validation:validation-api:1.1.0.Final'
compile 'com.fasterxml.jackson.datatype:jackson-datatype-joda:2.4.1'
compile 'joda-time:joda-time:2.7'
//TODO: swaggerFeature
compile 'io.swagger:swagger-jaxrs:1.5.12'

testCompile 'junit:junit:4.12',
'org.hamcrest:hamcrest-core:1.3'
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,2 @@
Manifest-Version: 1.0

18 changes: 18 additions & 0 deletions samples/server/petstore/jaxrs-resteasy/default/pom.xml
Expand Up @@ -9,6 +9,15 @@
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
Expand Down Expand Up @@ -49,6 +58,14 @@
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/javax/javaee-api -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
Expand Down Expand Up @@ -94,6 +111,7 @@
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>${resteasy-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
Expand Down
Expand Up @@ -2,7 +2,6 @@

import io.swagger.model.*;
import io.swagger.api.PetApiService;
import io.swagger.api.factories.PetApiServiceFactory;

import io.swagger.annotations.ApiParam;
import io.swagger.jaxrs.*;
Expand All @@ -21,6 +20,8 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.*;
import javax.inject.Inject;

import javax.validation.constraints.*;
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;

Expand All @@ -30,7 +31,8 @@
@io.swagger.annotations.Api(description = "the pet API")

public class PetApi {
private final PetApiService delegate = PetApiServiceFactory.getPetApi();

@Inject PetApiService service;

@POST

Expand All @@ -46,7 +48,7 @@ public class PetApi {
@io.swagger.annotations.ApiResponse(code = 405, message = "Invalid input", response = Void.class) })
public Response addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true) Pet body,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.addPet(body,securityContext);
return service.addPet(body,securityContext);
}
@DELETE
@Path("/{petId}")
Expand All @@ -62,7 +64,7 @@ public Response addPet(@ApiParam(value = "Pet object that needs to be added to t
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid pet value", response = Void.class) })
public Response deletePet( @PathParam("petId") Long petId,@ApiParam(value = "" )@HeaderParam("api_key") String apiKey,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.deletePet(petId,apiKey,securityContext);
return service.deletePet(petId,apiKey,securityContext);
}
@GET
@Path("/findByStatus")
Expand All @@ -80,7 +82,7 @@ public Response deletePet( @PathParam("petId") Long petId,@ApiParam(value = "" )
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid status value", response = Void.class) })
public Response findPetsByStatus( @NotNull @QueryParam("status") List<String> status,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.findPetsByStatus(status,securityContext);
return service.findPetsByStatus(status,securityContext);
}
@GET
@Path("/findByTags")
Expand All @@ -98,7 +100,7 @@ public Response findPetsByStatus( @NotNull @QueryParam("status") List<String> s
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid tag value", response = Void.class) })
public Response findPetsByTags( @NotNull @QueryParam("tags") List<String> tags,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.findPetsByTags(tags,securityContext);
return service.findPetsByTags(tags,securityContext);
}
@GET
@Path("/{petId}")
Expand All @@ -115,7 +117,7 @@ public Response findPetsByTags( @NotNull @QueryParam("tags") List<String> tags,
@io.swagger.annotations.ApiResponse(code = 404, message = "Pet not found", response = Void.class) })
public Response getPetById( @PathParam("petId") Long petId,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.getPetById(petId,securityContext);
return service.getPetById(petId,securityContext);
}
@PUT

Expand All @@ -135,7 +137,7 @@ public Response getPetById( @PathParam("petId") Long petId,@Context SecurityCont
@io.swagger.annotations.ApiResponse(code = 405, message = "Validation exception", response = Void.class) })
public Response updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true) Pet body,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.updatePet(body,securityContext);
return service.updatePet(body,securityContext);
}
@POST
@Path("/{petId}")
Expand All @@ -151,7 +153,7 @@ public Response updatePet(@ApiParam(value = "Pet object that needs to be added t
@io.swagger.annotations.ApiResponse(code = 405, message = "Invalid input", response = Void.class) })
public Response updatePetWithForm( @PathParam("petId") Long petId,@ApiParam(value = "Updated name of the pet")@FormParam("name") String name,@ApiParam(value = "Updated status of the pet")@FormParam("status") String status,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.updatePetWithForm(petId,name,status,securityContext);
return service.updatePetWithForm(petId,name,status,securityContext);
}
@POST
@Path("/{petId}/uploadImage")
Expand All @@ -167,6 +169,6 @@ public Response updatePetWithForm( @PathParam("petId") Long petId,@ApiParam(valu
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse.class) })
public Response uploadFile(MultipartFormDataInput input, @PathParam("petId") Long petId,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.uploadFile(input,petId,securityContext);
return service.uploadFile(input,petId,securityContext);
}
}
Expand Up @@ -18,21 +18,21 @@
import javax.ws.rs.core.SecurityContext;


public abstract class PetApiService {
public abstract Response addPet(Pet body,SecurityContext securityContext)
public interface PetApiService {
Response addPet(Pet body,SecurityContext securityContext)
throws NotFoundException;
public abstract Response deletePet(Long petId,String apiKey,SecurityContext securityContext)
Response deletePet(Long petId,String apiKey,SecurityContext securityContext)
throws NotFoundException;
public abstract Response findPetsByStatus(List<String> status,SecurityContext securityContext)
Response findPetsByStatus(List<String> status,SecurityContext securityContext)
throws NotFoundException;
public abstract Response findPetsByTags(List<String> tags,SecurityContext securityContext)
Response findPetsByTags(List<String> tags,SecurityContext securityContext)
throws NotFoundException;
public abstract Response getPetById(Long petId,SecurityContext securityContext)
Response getPetById(Long petId,SecurityContext securityContext)
throws NotFoundException;
public abstract Response updatePet(Pet body,SecurityContext securityContext)
Response updatePet(Pet body,SecurityContext securityContext)
throws NotFoundException;
public abstract Response updatePetWithForm(Long petId,String name,String status,SecurityContext securityContext)
Response updatePetWithForm(Long petId,String name,String status,SecurityContext securityContext)
throws NotFoundException;
public abstract Response uploadFile(MultipartFormDataInput input,Long petId,SecurityContext securityContext)
Response uploadFile(MultipartFormDataInput input,Long petId,SecurityContext securityContext)
throws NotFoundException;
}
Expand Up @@ -2,7 +2,6 @@

import io.swagger.model.*;
import io.swagger.api.StoreApiService;
import io.swagger.api.factories.StoreApiServiceFactory;

import io.swagger.annotations.ApiParam;
import io.swagger.jaxrs.*;
Expand All @@ -20,6 +19,8 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.*;
import javax.inject.Inject;

import javax.validation.constraints.*;

@Path("/store")
Expand All @@ -28,7 +29,8 @@
@io.swagger.annotations.Api(description = "the store API")

public class StoreApi {
private final StoreApiService delegate = StoreApiServiceFactory.getStoreApi();

@Inject StoreApiService service;

@DELETE
@Path("/order/{orderId}")
Expand All @@ -41,7 +43,7 @@ public class StoreApi {
@io.swagger.annotations.ApiResponse(code = 404, message = "Order not found", response = Void.class) })
public Response deleteOrder( @PathParam("orderId") String orderId,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.deleteOrder(orderId,securityContext);
return service.deleteOrder(orderId,securityContext);
}
@GET
@Path("/inventory")
Expand All @@ -54,7 +56,7 @@ public Response deleteOrder( @PathParam("orderId") String orderId,@Context Secur
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Map.class, responseContainer = "Map") })
public Response getInventory(@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.getInventory(securityContext);
return service.getInventory(securityContext);
}
@GET
@Path("/order/{orderId}")
Expand All @@ -69,7 +71,7 @@ public Response getInventory(@Context SecurityContext securityContext)
@io.swagger.annotations.ApiResponse(code = 404, message = "Order not found", response = Void.class) })
public Response getOrderById( @Min(1) @Max(5) @PathParam("orderId") Long orderId,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.getOrderById(orderId,securityContext);
return service.getOrderById(orderId,securityContext);
}
@POST
@Path("/order")
Expand All @@ -82,6 +84,6 @@ public Response getOrderById( @Min(1) @Max(5) @PathParam("orderId") Long orderId
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid Order", response = Void.class) })
public Response placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true) Order body,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.placeOrder(body,securityContext);
return service.placeOrder(body,securityContext);
}
}

0 comments on commit 643ef64

Please sign in to comment.