Added initial lenient handling

This commit is contained in:
Jens Kristian Villadsen 2016-11-15 13:41:13 +01:00
parent fab75f1add
commit 6aba4610e6
5 changed files with 39 additions and 7 deletions

View File

@ -47,7 +47,16 @@
<artifactId>hapi-fhir-structures-dstu2</artifactId>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>1.7.21</version>
</dependency>
</dependencies>
<build>

View File

@ -7,6 +7,7 @@ import javax.servlet.DispatcherType;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.slf4j.bridge.SLF4JBridgeHandler;
import com.google.inject.servlet.GuiceFilter;
@ -14,6 +15,9 @@ public class ServerStartup {
public static void main(final String[] args) throws Exception {
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
final Server server = new Server(9090);
final ServletContextHandler sch = new ServletContextHandler(server, "/");
sch.addEventListener(new ContextListener());

View File

@ -4,6 +4,8 @@ import java.util.List;
import org.hl7.fhir.instance.model.api.IBaseResource;
import com.google.common.collect.Lists;
import ca.uhn.fhir.model.dstu2.resource.Practitioner;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.rest.annotation.RequiredParam;
@ -21,8 +23,9 @@ public class SomeResourceProvider implements IResourceProvider {
@Search()
public List<Practitioner> findPractitionersByName(
@RequiredParam(name = Practitioner.SP_NAME) final StringDt theName) {
throw new UnprocessableEntityException(
"Please provide more than 4 characters for the name");
// throw new UnprocessableEntityException(
// "Please provide more than 4 characters for the name");
return Lists.newArrayList();
}
}

View File

@ -37,7 +37,6 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.context.ConfigurationException;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.valueset.BundleTypeEnum;
@ -140,6 +139,21 @@ public class SearchMethodBinding extends BaseResourceReturningMethodBinding {
@Override
public boolean incomingServerRequestMatchesMethod(RequestDetails theRequest) {
String clientPreference = theRequest.getHeader(Constants.HEADER_PREFER);
boolean lenientHandling = false;
if(clientPreference != null)
{
String[] preferences = clientPreference.split(";");
for( String p : preferences){
if("handling:lenient".equalsIgnoreCase(p))
{
lenientHandling = true;
break;
}
}
}
if (theRequest.getId() != null && myIdParamIndex == null) {
ourLog.trace("Method {} doesn't match because ID is not null: {}", theRequest.getId());
return false;
@ -235,6 +249,9 @@ public class SearchMethodBinding extends BaseResourceReturningMethodBinding {
}
}
Set<String> keySet = theRequest.getParameters().keySet();
if(lenientHandling == true)
return true;
if (myAllowUnknownParams == false) {
for (String next : keySet) {
if (!methodParamsTemp.contains(next)) {
@ -271,7 +288,7 @@ public class SearchMethodBinding extends BaseResourceReturningMethodBinding {
}
@Override
public IBundleProvider invokeServer(IRestfulServer theServer, RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException {
public IBundleProvider invokeServer(IRestfulServer<?> theServer, RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException {
if (myIdParamIndex != null) {
theMethodParams[myIdParamIndex] = theRequest.getId();
}

View File

@ -61,7 +61,6 @@ import ca.uhn.fhir.model.valueset.BundleTypeEnum;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.api.PreferReturnEnum;
import ca.uhn.fhir.rest.api.SummaryEnum;
import ca.uhn.fhir.rest.client.apache.ApacheHttpRequest;
import ca.uhn.fhir.rest.client.api.IHttpRequest;
import ca.uhn.fhir.rest.method.ElementsParameter;
import ca.uhn.fhir.rest.method.RequestDetails;
@ -378,7 +377,7 @@ public class RestfulServerUtils {
break;
}
} catch (IllegalArgumentException e) {
ourLog.debug("Invalid {} parameger: {}", Constants.PARAM_NARRATIVE, narrative[0]);
ourLog.debug("Invalid {} parameter: {}", Constants.PARAM_NARRATIVE, narrative[0]);
}
}
}