Documentation enhancements

This commit is contained in:
jamesagnew 2014-04-17 18:13:23 -04:00
parent 1808896b28
commit e9a71d843a
12 changed files with 79 additions and 82 deletions

View File

@ -33,6 +33,10 @@
* Support "Binary" resource, which is a special resource type
* Javadocs for getters/setters of IDatatype (e.g. Observation#getApplies()) should
include a list of the types that are allowed (and maybe a check?) or maybe some custom
getters and setters or something
---------
Issues:

View File

@ -1,39 +0,0 @@
package ca.uhn.fhir.rest.client.exceptions;
public abstract class BaseServerResponseException extends RuntimeException {
private static final long serialVersionUID = 1L;
/**
* Constructor
*
* @param theMessage
* The message
*/
public BaseServerResponseException(String theMessage) {
super(theMessage);
}
/**
* Constructor
*
* @param theMessage
* The message
* @param theCause The cause
*/
public BaseServerResponseException(String theMessage, Throwable theCause) {
super(theMessage, theCause);
}
/**
* Constructor
*
* @param theCause
* The underlying cause exception
*/
public BaseServerResponseException(Throwable theCause) {
super(theCause.toString(), theCause);
}
}

View File

@ -1,5 +1,7 @@
package ca.uhn.fhir.rest.client.exceptions;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
public class InvalidResponseException extends BaseServerResponseException {
private static final long serialVersionUID = 1L;
@ -10,8 +12,8 @@ public class InvalidResponseException extends BaseServerResponseException {
* @param theMessage
* The message
*/
public InvalidResponseException(String theMessage) {
super(theMessage);
public InvalidResponseException(int theStatusCode, String theMessage) {
super(theStatusCode, theMessage);
}
/**
@ -21,8 +23,8 @@ public class InvalidResponseException extends BaseServerResponseException {
* The message
* @param theCause The cause
*/
public InvalidResponseException(String theMessage, Throwable theCause) {
super(theMessage, theCause);
public InvalidResponseException(int theStatusCode, String theMessage, Throwable theCause) {
super(theStatusCode, theMessage, theCause);
}
/**
@ -31,8 +33,8 @@ public class InvalidResponseException extends BaseServerResponseException {
* @param theCause
* The underlying cause exception
*/
public InvalidResponseException(Throwable theCause) {
super(theCause.toString(), theCause);
public InvalidResponseException(int theStatusCode, Throwable theCause) {
super(theStatusCode, theCause.toString(), theCause);
}
}

View File

@ -1,10 +1,11 @@
package ca.uhn.fhir.rest.client.exceptions;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
public class NonFhirResponseException extends BaseServerResponseException {
private static final long serialVersionUID = 1L;
private final String myContentType;
private final int myStatusCode;
private final String myResponseText;
/**
@ -12,29 +13,22 @@ public class NonFhirResponseException extends BaseServerResponseException {
*
* @param theMessage
* The message
* @param theResponseText
* @param theStatusCode
* @param theContentType
* @param theResponseText
* @param theStatusCode
* @param theContentType
*/
public NonFhirResponseException(String theMessage, String theContentType, int theStatusCode, String theResponseText) {
super(theMessage);
myContentType=theContentType;
myStatusCode=theStatusCode;
myResponseText=theResponseText;
super(theStatusCode, theMessage);
myContentType = theContentType;
myResponseText = theResponseText;
}
public String getContentType() {
return myContentType;
}
public int getStatusCode() {
return myStatusCode;
}
public String getResponseText() {
return myResponseText;
}
}

View File

@ -108,7 +108,7 @@ public abstract class BaseResourceReturningMethodBinding extends BaseMethodBindi
} else if (list.size() == 1) {
return list.get(0);
} else {
throw new InvalidResponseException("FHIR server call returned a bundle with multiple resources, but this method is only able to returns one.");
throw new InvalidResponseException(theResponseStatusCode, "FHIR server call returned a bundle with multiple resources, but this method is only able to returns one.");
}
}
break;

View File

@ -20,6 +20,7 @@ import ca.uhn.fhir.rest.client.GetClientInvocation;
import ca.uhn.fhir.rest.param.IParameter;
import ca.uhn.fhir.rest.param.IQueryParameter;
import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
@ -103,6 +104,14 @@ public class SearchMethodBinding extends BaseResourceReturningMethodBinding {
} catch (IllegalArgumentException e) {
throw new InternalErrorException(e);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause != null) {
if (cause instanceof BaseServerResponseException) {
throw (BaseServerResponseException)cause;
} else {
throw new InternalErrorException(cause);
}
}
throw new InternalErrorException(e);
}

View File

@ -43,7 +43,6 @@ public abstract class RestfulServer extends HttpServlet {
private static final long serialVersionUID = 1L;
private FhirContext myFhirContext;
private INarrativeGenerator myNarrativeGenerator;
private Map<String, ResourceBinding> myResourceNameToProvider = new HashMap<String, ResourceBinding>();
private Object myServerConformanceProvider;
private Map<Class<? extends IResource>, IResourceProvider> myTypeToProvider = new HashMap<Class<? extends IResource>, IResourceProvider>();
@ -139,9 +138,6 @@ public abstract class RestfulServer extends HttpServlet {
return myFhirContext;
}
public INarrativeGenerator getNarrativeGenerator() {
return myNarrativeGenerator;
}
public Collection<ResourceBinding> getResourceBindings() {
return myResourceNameToProvider.values();
@ -354,8 +350,6 @@ public abstract class RestfulServer extends HttpServlet {
ourLog.info("Got {} resource providers", myTypeToProvider.size());
myFhirContext.setNarrativeGenerator(myNarrativeGenerator);
for (IResourceProvider provider : myTypeToProvider.values()) {
findResourceMethods(provider);
}
@ -382,19 +376,16 @@ public abstract class RestfulServer extends HttpServlet {
return myUseBrowserFriendlyContentTypes;
}
/**
* Sets the {@link INarrativeGenerator Narrative Generator} to use when serializing responses from this server, or <code>null</code> (which is the default) to disable narrative generation.
* Note that this method can only be called before the server is initialized.
*
* @throws IllegalStateException
* Note that this method can only be called prior to {@link #init() initialization} and will throw an {@link IllegalStateException} if called after that.
*/
public void setNarrativeGenerator(INarrativeGenerator theNarrativeGenerator) {
if (myFhirContext != null) {
throw new IllegalStateException("Server has already been initialized, can not change this property");
}
myNarrativeGenerator = theNarrativeGenerator;
}
// /**
// * Sets the {@link INarrativeGenerator Narrative Generator} to use when serializing responses from this server, or <code>null</code> (which is the default) to disable narrative generation.
// * Note that this method can only be called before the server is initialized.
// *
// * @throws IllegalStateException
// * Note that this method can only be called prior to {@link #init() initialization} and will throw an {@link IllegalStateException} if called after that.
// */
// public void setNarrativeGenerator(INarrativeGenerator theNarrativeGenerator) {
// myNarrativeGenerator = theNarrativeGenerator;
// }
/**
* Returns the server conformance provider, which is the provider that

View File

@ -11,6 +11,11 @@
<div th:each="resource : ${resource.restFirstRep.resource}">
<h1 th:text="${resource.type.value}"/>
<p>
This resource type supports the following search parameters:
</p>
</div>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 45 KiB

View File

@ -48,10 +48,12 @@
</p>
</subsection>
<subsection name="The Data Model">
<subsection name="Fluent Interface">
<p>
The HAPI API makes it very easy to create FHIR resources:
The HAPI API is designed to allow interaction with
FHIR model objects using a convenient
<a href="http://en.wikipedia.org/wiki/Fluent_interface">Fluent Interface</a>.
</p>
<source><![CDATA[Patient patient = new Patient();
patient.addIdentifier().setUse(OFFICIAL).setSystem("urn:fake:mrns").setValue("7000135");
@ -60,7 +62,10 @@ patient.addIdentifier().setUse(SECONDARY).setSystem("urn:fake:otherids").setValu
patient.addName().addFamily("Smith").addGiven("John").addGiven("Q").addSuffix("Junior");
patient.setGender(AdministrativeGenderCodesEnum.M);]]></source>
</subsection>
<subsection name="Encoding Support">
<p>
Both XML and JSON encoding are suported natively using a simple API
to pick between them. XML support is built on top of the lightning-fast
@ -74,6 +79,9 @@ String xmlEncoded = ctx.newXmlParser().encodeResourceToString(patient);
String jsonEncoded = ctx.newJsonParser().encodeResourceToString(patient);
]]></source>
</subsection>
<subsection name="Easy RESTful Client and Servers">
<p>
Creating clients is simple and uses an annotation based format
that will be familiar to users of JAX-WS.

View File

@ -69,6 +69,7 @@ import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.param.CodingListParam;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.QualifiedDateParam;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.provider.ServerProfileProvider;
import ca.uhn.fhir.testutil.RandomServerPortProvider;
import ca.uhn.fhir.util.ExtensionConstants;
@ -286,6 +287,19 @@ public class ResfulServerMethodTest {
assertEquals("urn:bbb|bbb", patient.getIdentifier().get(2).getValueAsQueryToken());
}
@Test
public void test404IsPropagatedCorrectly() throws Exception {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/DiagnosticReport?throw404=true");
HttpResponse status = ourClient.execute(httpGet);
String responseContent = IOUtils.toString(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
assertEquals(404, status.getStatusLine().getStatusCode());
assertThat(responseContent, StringContains.containsString("AAAABBBB"));
}
// @Test
// public void testSearchByComplex() throws Exception {
//
@ -868,6 +882,15 @@ public class ResfulServerMethodTest {
return new MethodOutcome(true, id, version);
}
/**
* @param theValue
*/
@Search
public DiagnosticReport alwaysThrow404(@RequiredParam(name="throw404") StringDt theValue) {
throw new ResourceNotFoundException("AAAABBBB");
}
@SuppressWarnings("unused")
@Delete()
public void deleteDiagnosticReport(@IdParam IdDt theId) {