-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add site-documentation for jaxrs base
- set example for operation on instance level - remove not thrown exceptions
- Loading branch information
1 parent
26a801e
commit 94f3091
Showing
9 changed files
with
241 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
examples/src/main/java/example/JaxRsConformanceProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package example; | ||
|
||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import javax.ejb.EJB; | ||
import javax.ejb.Stateless; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import ca.uhn.fhir.jaxrs.server.AbstractJaxRsConformanceProvider; | ||
import ca.uhn.fhir.rest.server.Constants; | ||
import ca.uhn.fhir.rest.server.IResourceProvider; | ||
|
||
/** | ||
* Conformance Rest Service | ||
* | ||
* @author Peter Van Houte | ||
*/ | ||
// START SNIPPET: jax-rs-conformance | ||
@Path("") | ||
@Stateless | ||
@Produces({ MediaType.APPLICATION_JSON, Constants.CT_FHIR_JSON, Constants.CT_FHIR_XML }) | ||
public class JaxRsConformanceProvider extends AbstractJaxRsConformanceProvider { | ||
|
||
@EJB | ||
private JaxRsPatientRestProvider provider; | ||
|
||
public JaxRsConformanceProvider() { | ||
super("My Server Version", "My Server Description", "My Server Name"); | ||
} | ||
|
||
@Override | ||
protected ConcurrentHashMap<Class<? extends IResourceProvider>, IResourceProvider> getProviders() { | ||
ConcurrentHashMap<Class<? extends IResourceProvider>, IResourceProvider> map = new ConcurrentHashMap<Class<? extends IResourceProvider>, IResourceProvider>(); | ||
map.put(JaxRsConformanceProvider.class, this); | ||
map.put(JaxRsPatientRestProvider.class, provider); | ||
return map; | ||
} | ||
} | ||
// END SNIPPET: jax-rs-conformance |
82 changes: 82 additions & 0 deletions
82
examples/src/main/java/example/JaxRsPatientRestProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package example; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
|
||
import javax.ejb.Local; | ||
import javax.ejb.Stateless; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import ca.uhn.fhir.jaxrs.server.AbstractJaxRsResourceProvider; | ||
import ca.uhn.fhir.model.dstu2.resource.Parameters; | ||
import ca.uhn.fhir.model.dstu2.resource.Patient; | ||
import ca.uhn.fhir.model.primitive.IdDt; | ||
import ca.uhn.fhir.model.primitive.StringDt; | ||
import ca.uhn.fhir.rest.annotation.ConditionalUrlParam; | ||
import ca.uhn.fhir.rest.annotation.Create; | ||
import ca.uhn.fhir.rest.annotation.IdParam; | ||
import ca.uhn.fhir.rest.annotation.Operation; | ||
import ca.uhn.fhir.rest.annotation.OperationParam; | ||
import ca.uhn.fhir.rest.annotation.ResourceParam; | ||
import ca.uhn.fhir.rest.api.MethodOutcome; | ||
import ca.uhn.fhir.rest.api.RequestTypeEnum; | ||
import ca.uhn.fhir.rest.api.RestOperationTypeEnum; | ||
import ca.uhn.fhir.rest.server.Constants; | ||
|
||
/** | ||
* A demo JaxRs Patient Rest Provider | ||
*/ | ||
@Local | ||
@Stateless | ||
// START SNIPPET: jax-rs-provider-construction | ||
@Path("/Patient") | ||
@Produces({ MediaType.APPLICATION_JSON, Constants.CT_FHIR_JSON, Constants.CT_FHIR_XML }) | ||
public class JaxRsPatientRestProvider extends AbstractJaxRsResourceProvider<Patient> { | ||
|
||
public JaxRsPatientRestProvider() { | ||
super(JaxRsPatientRestProvider.class); | ||
} | ||
// END SNIPPET: jax-rs-provider-construction | ||
|
||
@Override | ||
public Class<Patient> getResourceType() { | ||
return Patient.class; | ||
} | ||
|
||
|
||
@Create | ||
public MethodOutcome create(@ResourceParam final Patient patient, @ConditionalUrlParam String theConditional) { | ||
// create the patient ... | ||
return new MethodOutcome(new IdDt(1L)).setCreated(true); | ||
} | ||
|
||
// START SNIPPET: jax-rs-provider-operation | ||
@GET | ||
@Path("/{id}/$someCustomOperation") | ||
public Response someCustomOperationUsingGet(@PathParam("id") String id, String resource) throws Exception { | ||
return customOperation(resource, RequestTypeEnum.GET, id, "$someCustomOperation", | ||
RestOperationTypeEnum.EXTENDED_OPERATION_INSTANCE); | ||
} | ||
|
||
@Operation(name = "someCustomOperation", idempotent = true, returnParameters = { | ||
@OperationParam(name = "return", type = StringDt.class) }) | ||
public Parameters someCustomOperation(@IdParam IdDt myId, @OperationParam(name = "dummy") StringDt dummyInput) { | ||
Parameters parameters = new Parameters(); | ||
parameters.addParameter().setName("return").setValue(new StringDt("My Dummy Result")); | ||
return parameters; | ||
} | ||
// END SNIPPET: jax-rs-provider-operation | ||
|
||
@POST | ||
@Path("/{id}/$someCustomOperation") | ||
public Response someCustomOperationUsingPost(@PathParam("id") String id, String resource) throws Exception { | ||
return customOperation(resource, RequestTypeEnum.POST, id, "$someCustomOperation", | ||
RestOperationTypeEnum.EXTENDED_OPERATION_INSTANCE); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters