include agfa in author + fix test in case port is shorter + inject services into eample conformance provider + set moxy in scope test
This commit is contained in:
parent
5a7d2b40e8
commit
26a801edcb
|
@ -93,6 +93,7 @@
|
|||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-moxy</artifactId>
|
||||
<version>${jersey_version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
|
|
@ -42,7 +42,8 @@ import ca.uhn.fhir.util.ReflectionUtil;
|
|||
/**
|
||||
* This is the conformance provider for the jax rs servers. It requires all providers to be registered
|
||||
* during startup because the conformance profile is generated during the postconstruct phase.
|
||||
* @author Peter Van Houte
|
||||
*
|
||||
* @author Peter Van Houte | peter.vanhoute@agfa.com | Agfa Healthcare
|
||||
*/
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
public abstract class AbstractJaxRsConformanceProvider extends AbstractJaxRsProvider implements IResourceProvider {
|
||||
|
|
|
@ -25,7 +25,8 @@ import ca.uhn.fhir.rest.server.IServerAddressStrategy;
|
|||
/**
|
||||
* This is the abstract superclass for all jaxrs providers. It contains some defaults implementing
|
||||
* the IRestfulServerDefaults interface and exposes the uri and headers.
|
||||
* @author Peter Van Houte
|
||||
*
|
||||
* @author Peter Van Houte | peter.vanhoute@agfa.com | Agfa Healthcare
|
||||
*/
|
||||
public abstract class AbstractJaxRsProvider implements IRestfulServerDefaults {
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
|||
/**
|
||||
* This server is the abstract superclass for all resource providers. It exposes
|
||||
* a large amount of the fhir api functionality using JAXRS
|
||||
* @author Peter Van Houte
|
||||
* @author Peter Van Houte | peter.vanhoute@agfa.com | Agfa Healthcare
|
||||
*/
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN })
|
||||
@Consumes({ MediaType.APPLICATION_FORM_URLENCODED, MediaType.APPLICATION_JSON, Constants.CT_FHIR_JSON,
|
||||
|
@ -93,7 +93,7 @@ public abstract class AbstractJaxRsResourceProvider<R extends IResource> extends
|
|||
* @see <a href="https://www.hl7.org/fhir/http.html#create">https://www.hl7. org/fhir/http.html#create</a>
|
||||
*/
|
||||
@POST
|
||||
public Response create(final String resource) throws Exception {
|
||||
public Response create(final String resource) throws IOException {
|
||||
return execute(getRequest(RequestTypeEnum.POST, RestOperationTypeEnum.CREATE).resource(resource));
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ public abstract class AbstractJaxRsResourceProvider<R extends IResource> extends
|
|||
*/
|
||||
@POST
|
||||
@Path("/_search")
|
||||
public Response searchWithPost() throws Exception {
|
||||
public Response searchWithPost() throws IOException {
|
||||
return execute(getRequest(RequestTypeEnum.POST, RestOperationTypeEnum.SEARCH_TYPE));
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ public abstract class AbstractJaxRsResourceProvider<R extends IResource> extends
|
|||
* @see <a href="https://www.hl7.org/fhir/http.html#search">https://www.hl7.org/fhir/http.html#search</a>
|
||||
*/
|
||||
@GET
|
||||
public Response search() throws Exception {
|
||||
public Response search() throws IOException {
|
||||
return execute(getRequest(RequestTypeEnum.GET, RestOperationTypeEnum.SEARCH_TYPE));
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,7 @@ public abstract class AbstractJaxRsResourceProvider<R extends IResource> extends
|
|||
*/
|
||||
@PUT
|
||||
@Path("/{id}")
|
||||
public Response update(@PathParam("id") final String id, final String resource) throws Exception {
|
||||
public Response update(@PathParam("id") final String id, final String resource) throws IOException {
|
||||
return execute(getRequest(RequestTypeEnum.PUT, RestOperationTypeEnum.UPDATE).id(id).resource(resource));
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ public abstract class AbstractJaxRsResourceProvider<R extends IResource> extends
|
|||
*/
|
||||
@DELETE
|
||||
@Path("/{id}")
|
||||
public Response delete(@PathParam("id") final String id) throws Exception {
|
||||
public Response delete(@PathParam("id") final String id) throws IOException {
|
||||
return execute(getRequest(RequestTypeEnum.DELETE, RestOperationTypeEnum.DELETE).id(id));
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ public abstract class AbstractJaxRsResourceProvider<R extends IResource> extends
|
|||
*/
|
||||
@GET
|
||||
@Path("/{id}")
|
||||
public Response find(@PathParam("id") final String id) throws Exception {
|
||||
public Response find(@PathParam("id") final String id) throws IOException {
|
||||
return execute(getRequest(RequestTypeEnum.GET, RestOperationTypeEnum.READ).id(id));
|
||||
}
|
||||
|
||||
|
@ -172,7 +172,7 @@ public abstract class AbstractJaxRsResourceProvider<R extends IResource> extends
|
|||
* @see <a href="https://www.hl7.org/fhir/operations.html">https://www.hl7.org/fhir/operations.html</a>
|
||||
*/
|
||||
protected Response customOperation(final String resource, RequestTypeEnum requestType, String id,
|
||||
String operationName, RestOperationTypeEnum operationType) throws Exception {
|
||||
String operationName, RestOperationTypeEnum operationType) throws IOException {
|
||||
Builder request = getRequest(requestType, operationType).resource(resource).id(id);
|
||||
return execute(request, operationName);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,8 @@ import ca.uhn.fhir.rest.server.interceptor.ExceptionHandlingInterceptor;
|
|||
|
||||
/**
|
||||
* An interceptor that catches the jax-rs exceptions
|
||||
* @author Peter Van Houte
|
||||
*
|
||||
* @author Peter Van Houte | peter.vanhoute@agfa.com | Agfa Healthcare
|
||||
*/
|
||||
public class JaxRsExceptionInterceptor {
|
||||
|
||||
|
@ -64,6 +65,7 @@ public class JaxRsExceptionInterceptor {
|
|||
* @param theRequest the request
|
||||
* @param theException the thrown exception
|
||||
* @return the response describing the error
|
||||
* @throws IOException
|
||||
*/
|
||||
public Response convertExceptionIntoResponse(JaxRsRequest theRequest, JaxRsResponseException theException)
|
||||
throws IOException {
|
||||
|
|
|
@ -6,7 +6,8 @@ import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
|
|||
|
||||
/**
|
||||
* A JEE wrapper exception that will not force a rollback.
|
||||
* @author Peter Van Houte
|
||||
*
|
||||
* @author Peter Van Houte | peter.vanhoute@agfa.com | Agfa Healthcare
|
||||
*/
|
||||
@ApplicationException(rollback=false)
|
||||
public class JaxRsResponseException extends BaseServerResponseException {
|
||||
|
|
|
@ -16,7 +16,8 @@ import ca.uhn.fhir.util.ReflectionUtil;
|
|||
|
||||
/**
|
||||
* Class that contains the method bindings defined by a ResourceProvider
|
||||
* @author Peter Van Houte
|
||||
*
|
||||
* @author Peter Van Houte | peter.vanhoute@agfa.com | Agfa Healthcare
|
||||
*/
|
||||
public class JaxRsMethodBindings {
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ import ca.uhn.fhir.util.UrlUtil;
|
|||
/**
|
||||
* The JaxRsRequest is a jax-rs specific implementation of the RequestDetails.
|
||||
*
|
||||
* @author Peter Van Houte
|
||||
* @author Peter Van Houte | peter.vanhoute@agfa.com | Agfa Healthcare
|
||||
*/
|
||||
public class JaxRsRequest extends RequestDetails {
|
||||
|
||||
|
@ -40,6 +40,12 @@ public class JaxRsRequest extends RequestDetails {
|
|||
private String theVersion;
|
||||
private String theCompartment;
|
||||
|
||||
/**
|
||||
* Utility Constructor
|
||||
* @param theServer the server
|
||||
* @param theRequestType the request type
|
||||
* @param theRestOperation the rest operation
|
||||
*/
|
||||
public Builder(AbstractJaxRsProvider theServer, RequestTypeEnum theRequestType,
|
||||
RestOperationTypeEnum theRestOperation) {
|
||||
this.theServer = theServer;
|
||||
|
@ -123,6 +129,13 @@ public class JaxRsRequest extends RequestDetails {
|
|||
private HttpHeaders headers;
|
||||
private AbstractJaxRsProvider myServer;
|
||||
|
||||
/**
|
||||
* Utility Constructor
|
||||
* @param server the server
|
||||
* @param resourceString the resource body
|
||||
* @param requestType the request type
|
||||
* @param restOperation the operation type
|
||||
*/
|
||||
public JaxRsRequest(AbstractJaxRsProvider server, String resourceString, RequestTypeEnum requestType,
|
||||
RestOperationTypeEnum restOperation) {
|
||||
this.headers = server.getHeaders();
|
||||
|
@ -139,6 +152,10 @@ public class JaxRsRequest extends RequestDetails {
|
|||
return myServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the server
|
||||
* @param theServer the server to set
|
||||
*/
|
||||
public void setServer(AbstractJaxRsProvider theServer) {
|
||||
this.myServer = theServer;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import ca.uhn.fhir.rest.server.RestfulServerUtils;
|
|||
/**
|
||||
* The JaxRsResponse is a jax-rs specific implementation of the RestfulResponse.
|
||||
*
|
||||
* @author Peter Van Houte
|
||||
* @author Peter Van Houte | peter.vanhoute@agfa.com | Agfa Healthcare
|
||||
*/
|
||||
public class JaxRsResponse extends RestfulResponse<JaxRsRequest> {
|
||||
|
||||
|
|
|
@ -75,6 +75,7 @@ public class AbstractJaxRsResourceProviderTest {
|
|||
private static final FhirContext ourCtx = FhirContext.forDstu2();
|
||||
private static final String PATIENT_NAME = "Van Houte";
|
||||
private static int ourPort;
|
||||
private static String serverBase;
|
||||
private static Server jettyServer;
|
||||
|
||||
@BeforeClass
|
||||
|
@ -93,10 +94,10 @@ public class AbstractJaxRsResourceProviderTest {
|
|||
TestJaxRsConformanceRestProvider.class.getCanonicalName()), ";"));
|
||||
jettyServer.start();
|
||||
|
||||
final FhirContext ctx = FhirContext.forDstu2();
|
||||
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000);
|
||||
client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/");
|
||||
serverBase = "http://localhost:" + ourPort + "/";
|
||||
client = ourCtx.newRestfulGenericClient(serverBase);
|
||||
client.setEncoding(EncodingEnum.JSON);
|
||||
client.registerInterceptor(new LoggingInterceptor(true));
|
||||
}
|
||||
|
@ -392,7 +393,7 @@ public class AbstractJaxRsResourceProviderTest {
|
|||
}
|
||||
|
||||
private void compareResultUrl(String url, IResource resource) {
|
||||
assertEquals(url, resource.getId().getValueAsString().substring("http://localhost:55844".length()));
|
||||
assertEquals(url, resource.getId().getValueAsString().substring(serverBase.length() - 1));
|
||||
}
|
||||
|
||||
private <T> T withId(final T id) {
|
||||
|
|
|
@ -6,9 +6,10 @@ import javax.ws.rs.core.Application;
|
|||
/**
|
||||
* Fhir Patient Demo Application
|
||||
*
|
||||
* @author Peter Van Houte
|
||||
* @author Peter Van Houte | peter.vanhoute@agfa.com | Agfa Healthcare
|
||||
*/
|
||||
@ApplicationPath(value=FhirPatientDemoApplication.PATH)
|
||||
public class FhirPatientDemoApplication extends Application {
|
||||
/** The demo application path */
|
||||
public final static String PATH = "/jaxrs-demo";
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package ca.uhn.fhir.jaxrs.server.example;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
@ -14,7 +15,7 @@ import ca.uhn.fhir.rest.server.IResourceProvider;
|
|||
/**
|
||||
* Conformance Rest Service
|
||||
*
|
||||
* @author Peter Van Houte
|
||||
* @author Peter Van Houte | peter.vanhoute@agfa.com | Agfa Healthcare
|
||||
*/
|
||||
@Path("")
|
||||
@Stateless
|
||||
|
@ -23,7 +24,13 @@ public class JaxRsConformanceProvider extends AbstractJaxRsConformanceProvider {
|
|||
private static final String SERVER_VERSION = "1.0.0";
|
||||
private static final String SERVER_DESCRIPTION = "Jax-Rs Test Example Description";
|
||||
private static final String SERVER_NAME = "Jax-Rs Test Example";
|
||||
|
||||
@Inject
|
||||
private JaxRsPatientRestProvider patientProvider;
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
*/
|
||||
public JaxRsConformanceProvider() {
|
||||
super(SERVER_VERSION, SERVER_DESCRIPTION, SERVER_NAME);
|
||||
}
|
||||
|
@ -31,8 +38,8 @@ public class JaxRsConformanceProvider extends AbstractJaxRsConformanceProvider {
|
|||
@Override
|
||||
protected ConcurrentHashMap<Class<? extends IResourceProvider>, IResourceProvider> getProviders() {
|
||||
ConcurrentHashMap<Class<? extends IResourceProvider>, IResourceProvider> map = new ConcurrentHashMap<Class<? extends IResourceProvider>, IResourceProvider>();
|
||||
map.put(JaxRsConformanceProvider.class, new JaxRsConformanceProvider());
|
||||
map.put(JaxRsPatientRestProvider.class, new JaxRsPatientRestProvider());
|
||||
map.put(JaxRsConformanceProvider.class, this);
|
||||
map.put(JaxRsPatientRestProvider.class, patientProvider);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,6 +50,8 @@ import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
|||
|
||||
/**
|
||||
* A demo JaxRs Patient Rest Provider
|
||||
*
|
||||
* @author Peter Van Houte | peter.vanhoute@agfa.com | Agfa Healthcare
|
||||
*/
|
||||
@Local
|
||||
@Path(JaxRsPatientRestProvider.PATH)
|
||||
|
|
Loading…
Reference in New Issue