diff --git a/hapi-fhir-base/pom.xml b/hapi-fhir-base/pom.xml index 207b14ac276..a5d135cec62 100644 --- a/hapi-fhir-base/pom.xml +++ b/hapi-fhir-base/pom.xml @@ -92,34 +92,6 @@ true - - org.springframework - spring-beans - true - - - commons-logging - commons-logging - - - - - org.springframework - spring-web - true - - - commons-logging - commons-logging - - - - - org.springframework - spring-test - test - - diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ParameterUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ParameterUtil.java index 26a65eeb896..8049e75ff41 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ParameterUtil.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ParameterUtil.java @@ -1,5 +1,7 @@ package ca.uhn.fhir.rest.param; +import static org.apache.commons.lang3.StringUtils.isBlank; + import java.lang.annotation.Annotation; import java.lang.reflect.Method; /* @@ -27,14 +29,22 @@ import org.hl7.fhir.instance.model.api.IIdType; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.api.*; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.IntegerDt; import ca.uhn.fhir.rest.annotation.*; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.QualifiedParamList; +import ca.uhn.fhir.util.ReflectionUtil; import ca.uhn.fhir.util.UrlUtil; public class ParameterUtil { private static final Set> BINDABLE_INTEGER_TYPES; + private static final String LABEL = "label=\""; + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ParameterUtil.class); + + private static final String SCHEME = "scheme=\""; static { HashSet> intTypes = new HashSet>(); @@ -44,9 +54,15 @@ public class ParameterUtil { } - // public static Integer findSinceParameterIndex(Method theMethod) { - // return findParamIndex(theMethod, Since.class); - // } + @SuppressWarnings("unchecked") + public static T convertIdToType(IIdType value, Class theIdParamType) { + if (value != null && !theIdParamType.isAssignableFrom(value.getClass())) { + IIdType newValue = ReflectionUtil.newInstance(theIdParamType); + newValue.setValue(value.getValue()); + value = newValue; + } + return (T) value; + } /** * Escapes a string according to the rules for parameter escaping specified in the FHIR Specification Escaping @@ -61,14 +77,14 @@ public class ParameterUtil { for (int i = 0; i < theValue.length(); i++) { char next = theValue.charAt(i); switch (next) { - case '$': - case ',': - case '|': - case '\\': - b.append('\\'); - break; - default: - break; + case '$': + case ',': + case '|': + case '\\': + b.append('\\'); + break; + default: + break; } b.append(next); } @@ -116,6 +132,10 @@ public class ParameterUtil { return index; } + // public static Integer findSinceParameterIndex(Method theMethod) { + // return findParamIndex(theMethod, Since.class); + // } + public static Integer findParamAnnotationIndex(Method theMethod, Class toFind) { int paramIndex = 0; for (Annotation[] annotations : theMethod.getParameterAnnotations()) { @@ -170,6 +190,134 @@ public class ParameterUtil { return -1; } + public static String parseETagValue(String value) { + String eTagVersion; + value = value.trim(); + if (value.length() > 1) { + if (value.charAt(value.length() - 1) == '"') { + if (value.charAt(0) == '"') { + eTagVersion = value.substring(1, value.length() - 1); + } else if (value.length() > 3 && value.charAt(0) == 'W' && value.charAt(1) == '/' + && value.charAt(2) == '"') { + eTagVersion = value.substring(3, value.length() - 1); + } else { + eTagVersion = value; + } + } else { + eTagVersion = value; + } + } else { + eTagVersion = value; + } + return eTagVersion; + } + + @Deprecated + public static void parseTagValue(TagList tagList, String nextTagComplete) { + StringBuilder next = new StringBuilder(nextTagComplete); + parseTagValue(tagList, nextTagComplete, next); + } + + @Deprecated + private static void parseTagValue(TagList theTagList, String theCompleteHeaderValue, StringBuilder theBuffer) { + int firstSemicolon = theBuffer.indexOf(";"); + int deleteTo; + if (firstSemicolon == -1) { + firstSemicolon = theBuffer.indexOf(","); + if (firstSemicolon == -1) { + firstSemicolon = theBuffer.length(); + deleteTo = theBuffer.length(); + } else { + deleteTo = firstSemicolon; + } + } else { + deleteTo = firstSemicolon + 1; + } + + String term = theBuffer.substring(0, firstSemicolon); + String scheme = null; + String label = null; + if (isBlank(term)) { + return; + } + + theBuffer.delete(0, deleteTo); + while (theBuffer.length() > 0 && theBuffer.charAt(0) == ' ') { + theBuffer.deleteCharAt(0); + } + + while (theBuffer.length() > 0) { + boolean foundSomething = false; + if (theBuffer.length() > SCHEME.length() && theBuffer.substring(0, SCHEME.length()).equals(SCHEME)) { + int closeIdx = theBuffer.indexOf("\"", SCHEME.length()); + scheme = theBuffer.substring(SCHEME.length(), closeIdx); + theBuffer.delete(0, closeIdx + 1); + foundSomething = true; + } + if (theBuffer.length() > LABEL.length() && theBuffer.substring(0, LABEL.length()).equals(LABEL)) { + int closeIdx = theBuffer.indexOf("\"", LABEL.length()); + label = theBuffer.substring(LABEL.length(), closeIdx); + theBuffer.delete(0, closeIdx + 1); + foundSomething = true; + } + // TODO: support enc2231-string as described in + // http://tools.ietf.org/html/draft-johnston-http-category-header-02 + // TODO: support multiple tags in one header as described in + // http://hl7.org/implement/standards/fhir/http.html#tags + + while (theBuffer.length() > 0 && (theBuffer.charAt(0) == ' ' || theBuffer.charAt(0) == ';')) { + theBuffer.deleteCharAt(0); + } + + if (!foundSomething) { + break; + } + } + + if (theBuffer.length() > 0 && theBuffer.charAt(0) == ',') { + theBuffer.deleteCharAt(0); + while (theBuffer.length() > 0 && theBuffer.charAt(0) == ' ') { + theBuffer.deleteCharAt(0); + } + theTagList.add(new Tag(scheme, term, label)); + parseTagValue(theTagList, theCompleteHeaderValue, theBuffer); + } else { + theTagList.add(new Tag(scheme, term, label)); + } + + if (theBuffer.length() > 0) { + ourLog.warn("Ignoring extra text at the end of " + Constants.HEADER_CATEGORY + " tag '" + + theBuffer.toString() + "' - Complete tag value was: " + theCompleteHeaderValue); + } + + } + + public static IQueryParameterOr singleton(final IQueryParameterType theParam, final String theParamName) { + return new IQueryParameterOr() { + + private static final long serialVersionUID = 1L; + + @Override + public List getValuesAsQueryTokens() { + return Collections.singletonList(theParam); + } + + @Override + public void setValuesAsQueryTokens(FhirContext theContext, String theParamName, + QualifiedParamList theParameters) { + if (theParameters.isEmpty()) { + return; + } + if (theParameters.size() > 1) { + throw new IllegalArgumentException( + "Type " + theParam.getClass().getCanonicalName() + " does not support multiple values"); + } + theParam.setValueAsQueryToken(theContext, theParamName, theParameters.getQualifier(), + theParameters.get(0)); + } + }; + } + static List splitParameterString(String theInput, boolean theUnescapeComponents) { return splitParameterString(theInput, ',', theUnescapeComponents); } @@ -245,13 +393,13 @@ public class ParameterUtil { b.append(next); } else { switch (theValue.charAt(i + 1)) { - case '$': - case ',': - case '|': - case '\\': - continue; - default: - b.append(next); + case '$': + case ',': + case '|': + case '\\': + continue; + default: + b.append(next); } } } else { diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseAddOrDeleteTagsMethodBinding.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseAddOrDeleteTagsMethodBinding.java index 43a9ef94fd5..ebd1a713e6c 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseAddOrDeleteTagsMethodBinding.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseAddOrDeleteTagsMethodBinding.java @@ -17,7 +17,10 @@ import ca.uhn.fhir.rest.annotation.TagListParam; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; -import ca.uhn.fhir.rest.server.exceptions.*; +import ca.uhn.fhir.rest.param.ParameterUtil; +import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; +import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; +import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; abstract class BaseAddOrDeleteTagsMethodBinding extends BaseMethodBinding { @@ -38,9 +41,9 @@ abstract class BaseAddOrDeleteTagsMethodBinding extends BaseMethodBinding myResourceName = theContext.getResourceDefinition(myType).getName(); - myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); - myVersionIdParamIndex = MethodUtil.findVersionIdParameterIndex(theMethod); - myTagListParamIndex = MethodUtil.findTagListParameterIndex(theMethod); + myIdParamIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext()); + myVersionIdParamIndex = ParameterUtil.findVersionIdParameterIndex(theMethod); + myTagListParamIndex = ParameterUtil.findTagListParameterIndex(theMethod); if (myIdParamIndex == null) { throw new ConfigurationException("Method '" + theMethod.getName() + "' does not have an @" + IdParam.class.getSimpleName() + " parameter."); diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseJavaPrimitiveBinder.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseJavaPrimitiveBinder.java index 4ae5e0e0d5d..80e516b450e 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseJavaPrimitiveBinder.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseJavaPrimitiveBinder.java @@ -28,6 +28,7 @@ import java.util.List; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IQueryParameterOr; import ca.uhn.fhir.rest.api.QualifiedParamList; +import ca.uhn.fhir.rest.param.ParameterUtil; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; @@ -49,7 +50,7 @@ abstract class BaseJavaPrimitiveBinderimplements IParamBinder { if (isBlank(retVal)) { return Collections.emptyList(); } - List retValList = Collections.singletonList(MethodUtil.singleton(new StringParam(retVal), null)); + List retValList = Collections.singletonList(ParameterUtil.singleton(new StringParam(retVal), null)); return (List>) retValList; } diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseOutcomeReturningMethodBindingWithResourceIdButNoResourceBody.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseOutcomeReturningMethodBindingWithResourceIdButNoResourceBody.java index cb140f83d4d..baeae0d8b1a 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseOutcomeReturningMethodBindingWithResourceIdButNoResourceBody.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/BaseOutcomeReturningMethodBindingWithResourceIdButNoResourceBody.java @@ -24,9 +24,14 @@ import java.lang.reflect.Method; import org.hl7.fhir.instance.model.api.IBaseResource; -import ca.uhn.fhir.context.*; +import ca.uhn.fhir.context.ConfigurationException; +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.RuntimeResourceDefinition; //TODO Use of a deprecated method should be resolved -import ca.uhn.fhir.rest.annotation.*; +import ca.uhn.fhir.rest.annotation.Delete; +import ca.uhn.fhir.rest.annotation.IdParam; +import ca.uhn.fhir.rest.annotation.VersionIdParam; +import ca.uhn.fhir.rest.param.ParameterUtil; public abstract class BaseOutcomeReturningMethodBindingWithResourceIdButNoResourceBody extends BaseOutcomeReturningMethodBinding { @@ -45,12 +50,12 @@ public abstract class BaseOutcomeReturningMethodBindingWithResourceIdButNoResour "Can not determine resource type for method '" + theMethod.getName() + "' on type " + theMethod.getDeclaringClass().getCanonicalName() + " - Did you forget to include the resourceType() value on the @" + Delete.class.getSimpleName() + " method annotation?"); } - myIdParameterIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); + myIdParameterIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext()); if (myIdParameterIndex == null) { throw new ConfigurationException("Method '" + theMethod.getName() + "' on type '" + theMethod.getDeclaringClass().getCanonicalName() + "' has no parameter annotated with the @" + IdParam.class.getSimpleName() + " annotation"); } - Integer versionIdParameterIndex = MethodUtil.findVersionIdParameterIndex(theMethod); + Integer versionIdParameterIndex = ParameterUtil.findVersionIdParameterIndex(theMethod); if (versionIdParameterIndex != null) { //TODO Use of a deprecated method should be resolved throw new ConfigurationException("Method '" + theMethod.getName() + "' on type '" + theMethod.getDeclaringClass().getCanonicalName() + "' has a parameter annotated with the @" + VersionIdParam.class.getSimpleName() + " annotation but delete methods may not have this annotation"); diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/GetTagsMethodBinding.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/GetTagsMethodBinding.java index 15b1ebd6453..6d31fa09dcd 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/GetTagsMethodBinding.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/GetTagsMethodBinding.java @@ -19,6 +19,7 @@ import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; +import ca.uhn.fhir.rest.param.ParameterUtil; import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; @@ -38,8 +39,8 @@ public class GetTagsMethodBinding extends BaseMethodBinding { myResourceName = theContext.getResourceDefinition(myType).getName(); } - myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); - myVersionIdParamIndex = MethodUtil.findVersionIdParameterIndex(theMethod); + myIdParamIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext()); + myVersionIdParamIndex = ParameterUtil.findVersionIdParameterIndex(theMethod); if (myIdParamIndex != null && myType.equals(IResource.class)) { throw new ConfigurationException("Method '" + theMethod.getName() + "' does not specify a resource type, but has an @" + IdParam.class.getSimpleName() diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/HistoryMethodBinding.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/HistoryMethodBinding.java index 08e5d2b5315..0886db3a5cf 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/HistoryMethodBinding.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/HistoryMethodBinding.java @@ -37,6 +37,7 @@ import ca.uhn.fhir.rest.annotation.History; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; +import ca.uhn.fhir.rest.param.ParameterUtil; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; public class HistoryMethodBinding extends BaseResourceReturningMethodBinding { @@ -48,7 +49,7 @@ public class HistoryMethodBinding extends BaseResourceReturningMethodBinding { public HistoryMethodBinding(Method theMethod, FhirContext theContext, Object theProvider) { super(toReturnType(theMethod, theProvider), theMethod, theContext, theProvider); - myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); + myIdParamIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext()); History historyAnnotation = theMethod.getAnnotation(History.class); Class type = historyAnnotation.type(); diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/MethodUtil.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/MethodUtil.java index 5678a7e5586..4d4f996852f 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/MethodUtil.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/MethodUtil.java @@ -1,6 +1,5 @@ package ca.uhn.fhir.rest.client.method; -import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.io.*; @@ -49,12 +48,10 @@ import ca.uhn.fhir.util.*; @SuppressWarnings("deprecation") public class MethodUtil { - private static final String LABEL = "label=\""; - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(MethodUtil.class); private static final Set ourServletRequestTypes = new HashSet(); private static final Set ourServletResponseTypes = new HashSet(); - private static final String SCHEME = "scheme=\""; + static { ourServletRequestTypes.add("javax.servlet.ServletRequest"); ourServletResponseTypes.add("javax.servlet.ServletResponse"); @@ -80,16 +77,6 @@ public class MethodUtil { } } - @SuppressWarnings("unchecked") - public static T convertIdToType(IIdType value, Class theIdParamType) { - if (value != null && !theIdParamType.isAssignableFrom(value.getClass())) { - IIdType newValue = ReflectionUtil.newInstance(theIdParamType); - newValue.setValue(value.getValue()); - value = newValue; - } - return (T) value; - } - public static HttpGetClientInvocation createConformanceInvocation(FhirContext theContext) { return new HttpGetClientInvocation(theContext, "metadata"); } @@ -98,7 +85,8 @@ public class MethodUtil { return createCreateInvocation(theResource, null, null, theContext); } - public static HttpPostClientInvocation createCreateInvocation(IBaseResource theResource, String theResourceBody, String theId, FhirContext theContext) { + public static HttpPostClientInvocation createCreateInvocation(IBaseResource theResource, String theResourceBody, + String theId, FhirContext theContext) { RuntimeResourceDefinition def = theContext.getResourceDefinition(theResource); String resourceName = def.getName(); @@ -132,32 +120,38 @@ public class MethodUtil { return retVal; } - public static HttpPostClientInvocation createCreateInvocation(IBaseResource theResource, String theResourceBody, String theId, FhirContext theContext, - Map> theIfNoneExistParams) { + public static HttpPostClientInvocation createCreateInvocation(IBaseResource theResource, String theResourceBody, + String theId, FhirContext theContext, Map> theIfNoneExistParams) { HttpPostClientInvocation retVal = createCreateInvocation(theResource, theResourceBody, theId, theContext); retVal.setIfNoneExistParams(theIfNoneExistParams); return retVal; } - public static HttpPostClientInvocation createCreateInvocation(IBaseResource theResource, String theResourceBody, String theId, FhirContext theContext, String theIfNoneExistUrl) { + public static HttpPostClientInvocation createCreateInvocation(IBaseResource theResource, String theResourceBody, + String theId, FhirContext theContext, String theIfNoneExistUrl) { HttpPostClientInvocation retVal = createCreateInvocation(theResource, theResourceBody, theId, theContext); retVal.setIfNoneExistString(theIfNoneExistUrl); return retVal; } - public static HttpPatchClientInvocation createPatchInvocation(FhirContext theContext, IIdType theId, PatchTypeEnum thePatchType, String theBody) { + public static HttpPatchClientInvocation createPatchInvocation(FhirContext theContext, IIdType theId, + PatchTypeEnum thePatchType, String theBody) { return PatchMethodBinding.createPatchInvocation(theContext, theId, thePatchType, theBody); } - public static HttpPatchClientInvocation createPatchInvocation(FhirContext theContext, String theUrl, PatchTypeEnum thePatchType, String theBody) { + public static HttpPatchClientInvocation createPatchInvocation(FhirContext theContext, String theUrl, + PatchTypeEnum thePatchType, String theBody) { return PatchMethodBinding.createPatchInvocation(theContext, theUrl, thePatchType, theBody); } - public static HttpPatchClientInvocation createPatchInvocation(FhirContext theContext, PatchTypeEnum thePatchType, String theBody, String theResourceType, Map> theMatchParams) { - return PatchMethodBinding.createPatchInvocation(theContext, thePatchType, theBody, theResourceType, theMatchParams); + public static HttpPatchClientInvocation createPatchInvocation(FhirContext theContext, PatchTypeEnum thePatchType, + String theBody, String theResourceType, Map> theMatchParams) { + return PatchMethodBinding.createPatchInvocation(theContext, thePatchType, theBody, theResourceType, + theMatchParams); } - public static HttpPutClientInvocation createUpdateInvocation(FhirContext theContext, IBaseResource theResource, String theResourceBody, Map> theMatchParams) { + public static HttpPutClientInvocation createUpdateInvocation(FhirContext theContext, IBaseResource theResource, + String theResourceBody, Map> theMatchParams) { String resourceType = theContext.getResourceDefinition(theResource).getName(); StringBuilder b = createUrl(resourceType, theMatchParams); @@ -192,7 +186,8 @@ public class MethodUtil { return b; } - public static HttpPutClientInvocation createUpdateInvocation(FhirContext theContext, IBaseResource theResource, String theResourceBody, String theMatchUrl) { + public static HttpPutClientInvocation createUpdateInvocation(FhirContext theContext, IBaseResource theResource, + String theResourceBody, String theMatchUrl) { HttpPutClientInvocation retVal; if (StringUtils.isBlank(theResourceBody)) { retVal = new HttpPutClientInvocation(theContext, theResource, theMatchUrl); @@ -205,7 +200,8 @@ public class MethodUtil { return retVal; } - public static HttpPutClientInvocation createUpdateInvocation(IBaseResource theResource, String theResourceBody, IIdType theId, FhirContext theContext) { + public static HttpPutClientInvocation createUpdateInvocation(IBaseResource theResource, String theResourceBody, + IIdType theId, FhirContext theContext) { String resourceName = theContext.getResourceDefinition(theResource).getName(); StringBuilder urlBuilder = new StringBuilder(); urlBuilder.append(resourceName); @@ -257,7 +253,8 @@ public class MethodUtil { } @SuppressWarnings("unchecked") - public static List getResourceParameters(final FhirContext theContext, Method theMethod, Object theProvider, RestOperationTypeEnum theRestfulOperationTypeEnum) { + public static List getResourceParameters(final FhirContext theContext, Method theMethod, + Object theProvider, RestOperationTypeEnum theRestfulOperationTypeEnum) { List parameters = new ArrayList(); Class[] parameterTypes = theMethod.getParameterTypes(); @@ -282,7 +279,8 @@ public class MethodUtil { parameterType = ReflectionUtil.getGenericCollectionTypeOfMethodParameter(theMethod, paramIndex); } if (Collection.class.isAssignableFrom(parameterType)) { - throw new ConfigurationException("Argument #" + paramIndex + " of Method '" + theMethod.getName() + "' in type '" + theMethod.getDeclaringClass().getCanonicalName() + throw new ConfigurationException("Argument #" + paramIndex + " of Method '" + theMethod.getName() + + "' in type '" + theMethod.getDeclaringClass().getCanonicalName() + "' is of an invalid generic type (can not be a collection of a collection of a collection)"); } } @@ -301,7 +299,8 @@ public class MethodUtil { parameter.setRequired(true); parameter.setDeclaredTypes(((RequiredParam) nextAnnotation).targetTypes()); parameter.setCompositeTypes(((RequiredParam) nextAnnotation).compositeTypes()); - parameter.setChainlists(((RequiredParam) nextAnnotation).chainWhitelist(), ((RequiredParam) nextAnnotation).chainBlacklist()); + parameter.setChainlists(((RequiredParam) nextAnnotation).chainWhitelist(), + ((RequiredParam) nextAnnotation).chainBlacklist()); parameter.setType(theContext, parameterType, innerCollectionType, outerCollectionType); MethodUtil.extractDescription(parameter, annotations); param = parameter; @@ -311,7 +310,8 @@ public class MethodUtil { parameter.setRequired(false); parameter.setDeclaredTypes(((OptionalParam) nextAnnotation).targetTypes()); parameter.setCompositeTypes(((OptionalParam) nextAnnotation).compositeTypes()); - parameter.setChainlists(((OptionalParam) nextAnnotation).chainWhitelist(), ((OptionalParam) nextAnnotation).chainBlacklist()); + parameter.setChainlists(((OptionalParam) nextAnnotation).chainWhitelist(), + ((OptionalParam) nextAnnotation).chainBlacklist()); parameter.setType(theContext, parameterType, innerCollectionType, outerCollectionType); MethodUtil.extractDescription(parameter, annotations); param = parameter; @@ -324,15 +324,20 @@ public class MethodUtil { if (parameterType == String.class) { instantiableCollectionType = null; specType = String.class; - } else if ((parameterType != Include.class) || innerCollectionType == null || outerCollectionType != null) { - throw new ConfigurationException("Method '" + theMethod.getName() + "' is annotated with @" + IncludeParam.class.getSimpleName() + " but has a type other than Collection<" + } else if ((parameterType != Include.class) || innerCollectionType == null + || outerCollectionType != null) { + throw new ConfigurationException("Method '" + theMethod.getName() + "' is annotated with @" + + IncludeParam.class.getSimpleName() + " but has a type other than Collection<" + Include.class.getSimpleName() + ">"); } else { - instantiableCollectionType = (Class>) CollectionBinder.getInstantiableCollectionType(innerCollectionType, "Method '" + theMethod.getName() + "'"); + instantiableCollectionType = (Class>) CollectionBinder + .getInstantiableCollectionType(innerCollectionType, + "Method '" + theMethod.getName() + "'"); specType = parameterType; } - param = new IncludeParameter((IncludeParam) nextAnnotation, instantiableCollectionType, specType); + param = new IncludeParameter((IncludeParam) nextAnnotation, instantiableCollectionType, + specType); } else if (nextAnnotation instanceof ResourceParam) { if (IBaseResource.class.isAssignableFrom(parameterType)) { // good @@ -362,10 +367,12 @@ public class MethodUtil { param = new ElementsParameter(); } else if (nextAnnotation instanceof Since) { param = new SinceParameter(); - ((SinceParameter) param).setType(theContext, parameterType, innerCollectionType, outerCollectionType); + ((SinceParameter) param).setType(theContext, parameterType, innerCollectionType, + outerCollectionType); } else if (nextAnnotation instanceof At) { param = new AtParameter(); - ((AtParameter) param).setType(theContext, parameterType, innerCollectionType, outerCollectionType); + ((AtParameter) param).setType(theContext, parameterType, innerCollectionType, + outerCollectionType); } else if (nextAnnotation instanceof Count) { param = new CountParameter(); } else if (nextAnnotation instanceof Sort) { @@ -373,49 +380,56 @@ public class MethodUtil { } else if (nextAnnotation instanceof TransactionParam) { param = new TransactionParameter(theContext); } else if (nextAnnotation instanceof ConditionalUrlParam) { - param = new ConditionalParamBinder(theRestfulOperationTypeEnum, ((ConditionalUrlParam) nextAnnotation).supportsMultiple()); + param = new ConditionalParamBinder(theRestfulOperationTypeEnum, + ((ConditionalUrlParam) nextAnnotation).supportsMultiple()); } else if (nextAnnotation instanceof OperationParam) { Operation op = theMethod.getAnnotation(Operation.class); param = new OperationParameter(theContext, op.name(), ((OperationParam) nextAnnotation)); } else if (nextAnnotation instanceof Validate.Mode) { if (parameterType.equals(ValidationModeEnum.class) == false) { - throw new ConfigurationException( - "Parameter annotated with @" + Validate.class.getSimpleName() + "." + Validate.Mode.class.getSimpleName() + " must be of type " + ValidationModeEnum.class.getName()); + throw new ConfigurationException("Parameter annotated with @" + + Validate.class.getSimpleName() + "." + Validate.Mode.class.getSimpleName() + + " must be of type " + ValidationModeEnum.class.getName()); } - param = new OperationParameter(theContext, Constants.EXTOP_VALIDATE, Constants.EXTOP_VALIDATE_MODE, 0, 1).setConverter(new IOperationParamConverter() { - @Override - public Object incomingServer(Object theObject) { - if (isNotBlank(theObject.toString())) { - ValidationModeEnum retVal = ValidationModeEnum.forCode(theObject.toString()); - if (retVal == null) { - OperationParameter.throwInvalidMode(theObject.toString()); + param = new OperationParameter(theContext, Constants.EXTOP_VALIDATE, + Constants.EXTOP_VALIDATE_MODE, 0, 1).setConverter(new IOperationParamConverter() { + @Override + public Object incomingServer(Object theObject) { + if (isNotBlank(theObject.toString())) { + ValidationModeEnum retVal = ValidationModeEnum + .forCode(theObject.toString()); + if (retVal == null) { + OperationParameter.throwInvalidMode(theObject.toString()); + } + return retVal; + } + return null; } - return retVal; - } - return null; - } - @Override - public Object outgoingClient(Object theObject) { - return ParametersUtil.createString(theContext, ((ValidationModeEnum) theObject).getCode()); - } - }); + @Override + public Object outgoingClient(Object theObject) { + return ParametersUtil.createString(theContext, + ((ValidationModeEnum) theObject).getCode()); + } + }); } else if (nextAnnotation instanceof Validate.Profile) { if (parameterType.equals(String.class) == false) { - throw new ConfigurationException( - "Parameter annotated with @" + Validate.class.getSimpleName() + "." + Validate.Profile.class.getSimpleName() + " must be of type " + String.class.getName()); + throw new ConfigurationException("Parameter annotated with @" + + Validate.class.getSimpleName() + "." + Validate.Profile.class.getSimpleName() + + " must be of type " + String.class.getName()); } - param = new OperationParameter(theContext, Constants.EXTOP_VALIDATE, Constants.EXTOP_VALIDATE_PROFILE, 0, 1).setConverter(new IOperationParamConverter() { - @Override - public Object incomingServer(Object theObject) { - return theObject.toString(); - } + param = new OperationParameter(theContext, Constants.EXTOP_VALIDATE, + Constants.EXTOP_VALIDATE_PROFILE, 0, 1).setConverter(new IOperationParamConverter() { + @Override + public Object incomingServer(Object theObject) { + return theObject.toString(); + } - @Override - public Object outgoingClient(Object theObject) { - return ParametersUtil.createString(theContext, theObject.toString()); - } - }); + @Override + public Object outgoingClient(Object theObject) { + return ParametersUtil.createString(theContext, theObject.toString()); + } + }); } else { continue; } @@ -425,9 +439,10 @@ public class MethodUtil { } if (param == null) { - throw new ConfigurationException( - "Parameter #" + ((paramIndex + 1)) + "/" + (parameterTypes.length) + " of method '" + theMethod.getName() + "' on type '" + theMethod.getDeclaringClass().getCanonicalName() - + "' has no recognized FHIR interface parameter annotations. Don't know how to handle this parameter"); + throw new ConfigurationException("Parameter #" + ((paramIndex + 1)) + "/" + (parameterTypes.length) + + " of method '" + theMethod.getName() + "' on type '" + + theMethod.getDeclaringClass().getCanonicalName() + + "' has no recognized FHIR interface parameter annotations. Don't know how to handle this parameter"); } param.initializeTypes(theMethod, outerCollectionType, innerCollectionType, parameterType); @@ -438,7 +453,8 @@ public class MethodUtil { return parameters; } - public static void parseClientRequestResourceHeaders(IIdType theRequestedId, Map> theHeaders, IBaseResource resource) { + public static void parseClientRequestResourceHeaders(IIdType theRequestedId, Map> theHeaders, + IBaseResource resource) { List lmHeaders = theHeaders.get(Constants.HEADER_LAST_MODIFIED_LOWERCASE); if (lmHeaders != null && lmHeaders.size() > 0 && StringUtils.isNotBlank(lmHeaders.get(0))) { String headerValue = lmHeaders.get(0); @@ -484,7 +500,7 @@ public class MethodUtil { List eTagHeaders = theHeaders.get(Constants.HEADER_ETAG_LC); String eTagVersion = null; if (eTagHeaders != null && eTagHeaders.size() > 0) { - eTagVersion = parseETagValue(eTagHeaders.get(0)); + eTagVersion = ParameterUtil.parseETagValue(eTagHeaders.get(0)); } if (isNotBlank(eTagVersion)) { if (existing == null || existing.isEmpty()) { @@ -504,7 +520,7 @@ public class MethodUtil { if (categoryHeaders != null && categoryHeaders.size() > 0 && StringUtils.isNotBlank(categoryHeaders.get(0))) { TagList tagList = new TagList(); for (String header : categoryHeaders) { - parseTagValue(tagList, header); + ParameterUtil.parseTagValue(tagList, header); } if (resource instanceof IResource) { ResourceMetadataKeyEnum.TAG_LIST.put((IResource) resource, tagList); @@ -517,31 +533,11 @@ public class MethodUtil { } } - public static String parseETagValue(String value) { - String eTagVersion; - value = value.trim(); - if (value.length() > 1) { - if (value.charAt(value.length() - 1) == '"') { - if (value.charAt(0) == '"') { - eTagVersion = value.substring(1, value.length() - 1); - } else if (value.length() > 3 && value.charAt(0) == 'W' && value.charAt(1) == '/' && value.charAt(2) == '"') { - eTagVersion = value.substring(3, value.length() - 1); - } else { - eTagVersion = value; - } - } else { - eTagVersion = value; - } - } else { - eTagVersion = value; - } - return eTagVersion; - } - /** * This is a utility method intended provided to help the JPA module. */ - public static IQueryParameterAnd parseQueryParams(FhirContext theContext, RuntimeSearchParam theParamDef, String theUnqualifiedParamName, List theParameters) { + public static IQueryParameterAnd parseQueryParams(FhirContext theContext, RuntimeSearchParam theParamDef, + String theUnqualifiedParamName, List theParameters) { RestSearchParameterTypeEnum paramType = theParamDef.getParamType(); return parseQueryParams(theContext, paramType, theUnqualifiedParamName, theParameters); } @@ -549,119 +545,52 @@ public class MethodUtil { /** * This is a utility method intended provided to help the JPA module. */ - public static IQueryParameterAnd parseQueryParams(FhirContext theContext, RestSearchParameterTypeEnum paramType, String theUnqualifiedParamName, List theParameters) { + public static IQueryParameterAnd parseQueryParams(FhirContext theContext, RestSearchParameterTypeEnum paramType, + String theUnqualifiedParamName, List theParameters) { QueryParameterAndBinder binder = null; switch (paramType) { - case COMPOSITE: - throw new UnsupportedOperationException(); - case DATE: - binder = new QueryParameterAndBinder(DateAndListParam.class, Collections.> emptyList()); - break; - case NUMBER: - binder = new QueryParameterAndBinder(NumberAndListParam.class, Collections.> emptyList()); - break; - case QUANTITY: - binder = new QueryParameterAndBinder(QuantityAndListParam.class, Collections.> emptyList()); - break; - case REFERENCE: - binder = new QueryParameterAndBinder(ReferenceAndListParam.class, Collections.> emptyList()); - break; - case STRING: - binder = new QueryParameterAndBinder(StringAndListParam.class, Collections.> emptyList()); - break; - case TOKEN: - binder = new QueryParameterAndBinder(TokenAndListParam.class, Collections.> emptyList()); - break; - case URI: - binder = new QueryParameterAndBinder(UriAndListParam.class, Collections.> emptyList()); - break; - case HAS: - binder = new QueryParameterAndBinder(HasAndListParam.class, Collections.> emptyList()); - break; + case COMPOSITE: + throw new UnsupportedOperationException(); + case DATE: + binder = new QueryParameterAndBinder(DateAndListParam.class, + Collections.> emptyList()); + break; + case NUMBER: + binder = new QueryParameterAndBinder(NumberAndListParam.class, + Collections.> emptyList()); + break; + case QUANTITY: + binder = new QueryParameterAndBinder(QuantityAndListParam.class, + Collections.> emptyList()); + break; + case REFERENCE: + binder = new QueryParameterAndBinder(ReferenceAndListParam.class, + Collections.> emptyList()); + break; + case STRING: + binder = new QueryParameterAndBinder(StringAndListParam.class, + Collections.> emptyList()); + break; + case TOKEN: + binder = new QueryParameterAndBinder(TokenAndListParam.class, + Collections.> emptyList()); + break; + case URI: + binder = new QueryParameterAndBinder(UriAndListParam.class, + Collections.> emptyList()); + break; + case HAS: + binder = new QueryParameterAndBinder(HasAndListParam.class, + Collections.> emptyList()); + break; } // FIXME null access return binder.parse(theContext, theUnqualifiedParamName, theParameters); } - public static void parseTagValue(TagList tagList, String nextTagComplete) { - StringBuilder next = new StringBuilder(nextTagComplete); - parseTagValue(tagList, nextTagComplete, next); - } - - private static void parseTagValue(TagList theTagList, String theCompleteHeaderValue, StringBuilder theBuffer) { - int firstSemicolon = theBuffer.indexOf(";"); - int deleteTo; - if (firstSemicolon == -1) { - firstSemicolon = theBuffer.indexOf(","); - if (firstSemicolon == -1) { - firstSemicolon = theBuffer.length(); - deleteTo = theBuffer.length(); - } else { - deleteTo = firstSemicolon; - } - } else { - deleteTo = firstSemicolon + 1; - } - - String term = theBuffer.substring(0, firstSemicolon); - String scheme = null; - String label = null; - if (isBlank(term)) { - return; - } - - theBuffer.delete(0, deleteTo); - while (theBuffer.length() > 0 && theBuffer.charAt(0) == ' ') { - theBuffer.deleteCharAt(0); - } - - while (theBuffer.length() > 0) { - boolean foundSomething = false; - if (theBuffer.length() > SCHEME.length() && theBuffer.substring(0, SCHEME.length()).equals(SCHEME)) { - int closeIdx = theBuffer.indexOf("\"", SCHEME.length()); - scheme = theBuffer.substring(SCHEME.length(), closeIdx); - theBuffer.delete(0, closeIdx + 1); - foundSomething = true; - } - if (theBuffer.length() > LABEL.length() && theBuffer.substring(0, LABEL.length()).equals(LABEL)) { - int closeIdx = theBuffer.indexOf("\"", LABEL.length()); - label = theBuffer.substring(LABEL.length(), closeIdx); - theBuffer.delete(0, closeIdx + 1); - foundSomething = true; - } - // TODO: support enc2231-string as described in - // http://tools.ietf.org/html/draft-johnston-http-category-header-02 - // TODO: support multiple tags in one header as described in - // http://hl7.org/implement/standards/fhir/http.html#tags - - while (theBuffer.length() > 0 && (theBuffer.charAt(0) == ' ' || theBuffer.charAt(0) == ';')) { - theBuffer.deleteCharAt(0); - } - - if (!foundSomething) { - break; - } - } - - if (theBuffer.length() > 0 && theBuffer.charAt(0) == ',') { - theBuffer.deleteCharAt(0); - while (theBuffer.length() > 0 && theBuffer.charAt(0) == ' ') { - theBuffer.deleteCharAt(0); - } - theTagList.add(new Tag(scheme, term, label)); - parseTagValue(theTagList, theCompleteHeaderValue, theBuffer); - } else { - theTagList.add(new Tag(scheme, term, label)); - } - - if (theBuffer.length() > 0) { - ourLog.warn("Ignoring extra text at the end of " + Constants.HEADER_CATEGORY + " tag '" + theBuffer.toString() + "' - Complete tag value was: " + theCompleteHeaderValue); - } - - } - - public static MethodOutcome process2xxResponse(FhirContext theContext, int theResponseStatusCode, String theResponseMimeType, Reader theResponseReader, Map> theHeaders) { + public static MethodOutcome process2xxResponse(FhirContext theContext, int theResponseStatusCode, + String theResponseMimeType, Reader theResponseReader, Map> theHeaders) { List locationHeaders = new ArrayList(); List lh = theHeaders.get(Constants.HEADER_LOCATION_LC); if (lh != null) { @@ -706,34 +635,16 @@ public class MethodUtil { } } else { - BaseOutcomeReturningMethodBinding.ourLog.debug("Ignoring response content of type: {}", theResponseMimeType); + BaseOutcomeReturningMethodBinding.ourLog.debug("Ignoring response content of type: {}", + theResponseMimeType); } } return retVal; } - public static IQueryParameterOr singleton(final IQueryParameterType theParam, final String theParamName) { - return new IQueryParameterOr() { - @Override - public List getValuesAsQueryTokens() { - return Collections.singletonList(theParam); - } - - @Override - public void setValuesAsQueryTokens(FhirContext theContext, String theParamName, QualifiedParamList theParameters) { - if (theParameters.isEmpty()) { - return; - } - if (theParameters.size() > 1) { - throw new IllegalArgumentException("Type " + theParam.getClass().getCanonicalName() + " does not support multiple values"); - } - theParam.setValueAsQueryToken(theContext, theParamName, theParameters.getQualifier(), theParameters.get(0)); - } - }; - } - - public static void addAcceptHeaderToRequest(EncodingEnum theEncoding, IHttpRequest theHttpRequest, FhirContext theContext) { + public static void addAcceptHeaderToRequest(EncodingEnum theEncoding, IHttpRequest theHttpRequest, + FhirContext theContext) { if (theEncoding == null) { if (theContext.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU2_1) == false) { theHttpRequest.addHeader(Constants.HEADER_ACCEPT, Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_LEGACY); diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/OperationMethodBinding.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/OperationMethodBinding.java index 493678eeebe..99fba7898da 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/OperationMethodBinding.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/OperationMethodBinding.java @@ -50,6 +50,7 @@ import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; +import ca.uhn.fhir.rest.param.ParameterUtil; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.util.FhirTerser; @@ -75,7 +76,7 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { myBundleType = theBundleType; myIdempotent = theIdempotent; - myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); + myIdParamIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext()); if (myIdParamIndex != null) { for (Annotation next : theMethod.getParameterAnnotations()[myIdParamIndex]) { if (next instanceof IdParam) { diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/QueryParameterTypeBinder.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/QueryParameterTypeBinder.java index 4565aec2d13..861dfd972c2 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/QueryParameterTypeBinder.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/QueryParameterTypeBinder.java @@ -29,6 +29,7 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IQueryParameterOr; import ca.uhn.fhir.model.api.IQueryParameterType; import ca.uhn.fhir.rest.api.QualifiedParamList; +import ca.uhn.fhir.rest.param.ParameterUtil; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; @@ -42,7 +43,7 @@ final class QueryParameterTypeBinder extends BaseBinder imp @Override public List> encode(FhirContext theContext, IQueryParameterType theValue) throws InternalErrorException { IQueryParameterType param = theValue; - List retVal = Collections.singletonList(MethodUtil.singleton(param, null)); + List retVal = Collections.singletonList(ParameterUtil.singleton(param, null)); return (List>) retVal; } diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/ReadMethodBinding.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/ReadMethodBinding.java index f30d0428a0f..68c9d9c2193 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/ReadMethodBinding.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/ReadMethodBinding.java @@ -23,11 +23,16 @@ package ca.uhn.fhir.rest.client.method; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Method; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.Validate; -import org.hl7.fhir.instance.model.api.*; +import org.hl7.fhir.instance.model.api.IBaseBinary; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.instance.model.api.IIdType; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; @@ -35,8 +40,11 @@ import ca.uhn.fhir.model.api.Bundle; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.valueset.BundleTypeEnum; -import ca.uhn.fhir.rest.annotation.*; +import ca.uhn.fhir.rest.annotation.Elements; +import ca.uhn.fhir.rest.annotation.IdParam; +import ca.uhn.fhir.rest.annotation.Read; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import ca.uhn.fhir.rest.param.ParameterUtil; import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; public class ReadMethodBinding extends BaseResourceReturningMethodBinding implements IClientResponseHandlerHandlesBinary { @@ -51,8 +59,8 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding implem Validate.notNull(theMethod, "Method must not be null"); - Integer idIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); - Integer versionIdIndex = MethodUtil.findVersionIdParameterIndex(theMethod); + Integer idIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext()); + Integer versionIdIndex = ParameterUtil.findVersionIdParameterIndex(theMethod); Class[] parameterTypes = theMethod.getParameterTypes(); diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/SearchMethodBinding.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/SearchMethodBinding.java index e7f27da265d..fc80ad04f8a 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/SearchMethodBinding.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/SearchMethodBinding.java @@ -23,7 +23,10 @@ import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.lang.reflect.Method; -import java.util.*; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; import org.apache.commons.lang3.StringUtils; @@ -35,8 +38,11 @@ import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.annotation.Search; -import ca.uhn.fhir.rest.api.*; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import ca.uhn.fhir.rest.api.SearchStyleEnum; import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; +import ca.uhn.fhir.rest.param.ParameterUtil; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; @@ -51,7 +57,7 @@ public class SearchMethodBinding extends BaseResourceReturningMethodBinding { Search search = theMethod.getAnnotation(Search.class); this.myQueryName = StringUtils.defaultIfBlank(search.queryName(), null); this.myCompartmentName = StringUtils.defaultIfBlank(search.compartmentName(), null); - this.myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); + this.myIdParamIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext()); Description desc = theMethod.getAnnotation(Description.class); if (desc != null) { diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/UpdateMethodBinding.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/UpdateMethodBinding.java index 81d8da5709e..0d27fe6ad7c 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/UpdateMethodBinding.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/UpdateMethodBinding.java @@ -16,6 +16,7 @@ import ca.uhn.fhir.rest.annotation.Update; import ca.uhn.fhir.rest.api.RequestTypeEnum; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; +import ca.uhn.fhir.rest.param.ParameterUtil; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; public class UpdateMethodBinding extends BaseOutcomeReturningMethodBindingWithResourceParam { @@ -25,7 +26,7 @@ public class UpdateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe public UpdateMethodBinding(Method theMethod, FhirContext theContext, Object theProvider) { super(theMethod, theContext, Update.class, theProvider); - myIdParameterIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); + myIdParameterIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext()); } diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/ValidateMethodBindingDstu1.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/ValidateMethodBindingDstu1.java index 969fcf85fe0..68628771160 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/ValidateMethodBindingDstu1.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/method/ValidateMethodBindingDstu1.java @@ -30,8 +30,11 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.annotation.Validate; -import ca.uhn.fhir.rest.api.*; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.RequestTypeEnum; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; +import ca.uhn.fhir.rest.param.ParameterUtil; public class ValidateMethodBindingDstu1 extends BaseOutcomeReturningMethodBindingWithResourceParam { @@ -40,7 +43,7 @@ public class ValidateMethodBindingDstu1 extends BaseOutcomeReturningMethodBindin public ValidateMethodBindingDstu1(Method theMethod, FhirContext theContext, Object theProvider) { super(theMethod, theContext, Validate.class, theProvider); - myIdParameterIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); + myIdParameterIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext()); } @Override diff --git a/hapi-fhir-server/pom.xml b/hapi-fhir-server/pom.xml index ee3f8c67e2d..a706a2f1bcb 100644 --- a/hapi-fhir-server/pom.xml +++ b/hapi-fhir-server/pom.xml @@ -27,6 +27,39 @@ provided + + + org.springframework + spring-beans + true + + + commons-logging + commons-logging + + + + + org.springframework + spring-web + true + + + commons-logging + commons-logging + + + + + org.springframework + spring-test + test + + + diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/api/server/IRestfulServer.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/api/server/IRestfulServer.java index 2a201e0d30b..751ec25bc02 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/api/server/IRestfulServer.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/api/server/IRestfulServer.java @@ -3,7 +3,6 @@ package ca.uhn.fhir.rest.api.server; import ca.uhn.fhir.context.api.BundleInclusionRule; import ca.uhn.fhir.rest.server.IPagingProvider; import ca.uhn.fhir.rest.server.IRestfulServerDefaults; -import ca.uhn.fhir.rest.server.method.RequestDetails; /* * #%L @@ -26,6 +25,7 @@ import ca.uhn.fhir.rest.server.method.RequestDetails; */ public interface IRestfulServer extends IRestfulServerDefaults { + @Override IPagingProvider getPagingProvider(); BundleInclusionRule getBundleInclusionRule(); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/api/server/RequestDetails.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/api/server/RequestDetails.java index 237728a5f6a..a4f55b2126c 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/api/server/RequestDetails.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/api/server/RequestDetails.java @@ -2,9 +2,11 @@ package ca.uhn.fhir.rest.api.server; import static org.apache.commons.lang3.StringUtils.isBlank; -import java.io.*; +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; - /* * #%L * HAPI FHIR - Core Library @@ -24,18 +26,101 @@ import java.nio.charset.Charset; * limitations under the License. * #L% */ -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; -import ca.uhn.fhir.rest.api.*; +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.RequestTypeEnum; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.server.IRestfulServerDefaults; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; import ca.uhn.fhir.rest.server.interceptor.IServerOperationInterceptor; -public abstract class RequestDetails implements IRequestDetails { +public abstract class RequestDetails { + private class RequestOperationCallback implements IRequestOperationCallback { + + private List getInterceptors() { + if (getServer() == null) { + return Collections.emptyList(); + } + return getServer().getInterceptors(); + } + + @Override + public void resourceCreated(IBaseResource theResource) { + for (IServerInterceptor next : getInterceptors()) { + if (next instanceof IServerOperationInterceptor) { + ((IServerOperationInterceptor) next).resourceCreated(RequestDetails.this, theResource); + } + } + } + + @Override + public void resourceDeleted(IBaseResource theResource) { + for (IServerInterceptor next : getInterceptors()) { + if (next instanceof IServerOperationInterceptor) { + ((IServerOperationInterceptor) next).resourceDeleted(RequestDetails.this, theResource); + } + } + } + + @Override + public void resourcesCreated(Collection theResource) { + for (IBaseResource next : theResource) { + resourceCreated(next); + } + } + + @Override + public void resourcesDeleted(Collection theResource) { + for (IBaseResource next : theResource) { + resourceDeleted(next); + } + } + + /** + * @deprecated Deprecated in HAPI FHIR 2.6 - Use {@link IRequestOperationCallback#resourceUpdated(IBaseResource, IBaseResource)} instead + */ + @Deprecated + public void resourcesUpdated(Collection theResource) { + for (IBaseResource next : theResource) { + resourceUpdated(next); + } + } + + + /** + * @deprecated Deprecated in HAPI FHIR 2.6 - Use {@link IRequestOperationCallback#resourceUpdated(IBaseResource, IBaseResource)} instead + */ + @Deprecated + @Override + public void resourceUpdated(IBaseResource theResource) { + for (IServerInterceptor next : getInterceptors()) { + if (next instanceof IServerOperationInterceptor) { + ((IServerOperationInterceptor) next).resourceUpdated(RequestDetails.this, theResource); + } + } + } + + @Override + public void resourceUpdated(IBaseResource theOldResource, IBaseResource theNewResource) { + for (IServerInterceptor next : getInterceptors()) { + if (next instanceof IServerOperationInterceptor) { + ((IServerOperationInterceptor) next).resourceUpdated(RequestDetails.this, theOldResource, theNewResource); + } + } + } + + } private String myCompartmentName; private String myCompleteUrl; private String myFhirServerBase; @@ -54,8 +139,9 @@ public abstract class RequestDetails implements IRequestDetails { private boolean mySubRequest; private Map> myUnqualifiedToQualifiedNames; private Map myUserData; - protected abstract byte[] getByteStreamRequestContents(); + protected abstract byte[] getByteStreamRequestContents(); + /** * Return the charset as defined by the header contenttype. Return null if it is not set. */ @@ -64,10 +150,10 @@ public abstract class RequestDetails implements IRequestDetails { public String getCompartmentName() { return myCompartmentName; } - public String getCompleteUrl() { return myCompleteUrl; } + /** * Returns the conditional URL if this request has one, or null otherwise. For an * update or delete method, this is the part of the URL after the ?. For a create, this @@ -102,6 +188,11 @@ public abstract class RequestDetails implements IRequestDetails { return this.getResourceName() + this.getCompleteUrl().substring(questionMarkIndex); } + /** + * Returns the HAPI FHIR Context associated with this request + */ + public abstract FhirContext getFhirContext(); + /** * The fhir server base url, independant of the query being executed * @@ -325,7 +416,7 @@ public abstract class RequestDetails implements IRequestDetails { public void setResponse(IRestfulResponse theResponse) { this.myResponse = theResponse; } - + public void setRestOperationType(RestOperationTypeEnum theRestOperationType) { myRestOperationType = theRestOperationType; } @@ -333,7 +424,7 @@ public abstract class RequestDetails implements IRequestDetails { public void setSecondaryOperation(String theSecondaryOperation) { mySecondaryOperation = theSecondaryOperation; } - + /** * Is this request a sub-request (i.e. a request within a batch or transaction)? This * flag is used internally by hapi-fhir-jpaserver-base, but not used in the plain server @@ -347,80 +438,4 @@ public abstract class RequestDetails implements IRequestDetails { mySubRequest = theSubRequest; } - private class RequestOperationCallback implements IRequestOperationCallback { - - private List getInterceptors() { - if (getServer() == null) { - return Collections.emptyList(); - } - return getServer().getInterceptors(); - } - - @Override - public void resourceCreated(IBaseResource theResource) { - for (IServerInterceptor next : getInterceptors()) { - if (next instanceof IServerOperationInterceptor) { - ((IServerOperationInterceptor) next).resourceCreated(RequestDetails.this, theResource); - } - } - } - - @Override - public void resourceDeleted(IBaseResource theResource) { - for (IServerInterceptor next : getInterceptors()) { - if (next instanceof IServerOperationInterceptor) { - ((IServerOperationInterceptor) next).resourceDeleted(RequestDetails.this, theResource); - } - } - } - - @Override - public void resourcesCreated(Collection theResource) { - for (IBaseResource next : theResource) { - resourceCreated(next); - } - } - - @Override - public void resourcesDeleted(Collection theResource) { - for (IBaseResource next : theResource) { - resourceDeleted(next); - } - } - - /** - * @deprecated Deprecated in HAPI FHIR 2.6 - Use {@link IRequestOperationCallback#resourceUpdated(IBaseResource, IBaseResource)} instead - */ - @Deprecated - public void resourcesUpdated(Collection theResource) { - for (IBaseResource next : theResource) { - resourceUpdated(next); - } - } - - - /** - * @deprecated Deprecated in HAPI FHIR 2.6 - Use {@link IRequestOperationCallback#resourceUpdated(IBaseResource, IBaseResource)} instead - */ - @Deprecated - @Override - public void resourceUpdated(IBaseResource theResource) { - for (IServerInterceptor next : getInterceptors()) { - if (next instanceof IServerOperationInterceptor) { - ((IServerOperationInterceptor) next).resourceUpdated(RequestDetails.this, theResource); - } - } - } - - @Override - public void resourceUpdated(IBaseResource theOldResource, IBaseResource theNewResource) { - for (IServerInterceptor next : getInterceptors()) { - if (next instanceof IServerOperationInterceptor) { - ((IServerOperationInterceptor) next).resourceUpdated(RequestDetails.this, theOldResource, theNewResource); - } - } - } - - } - } diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java index 0810ce8a454..21d730d4b26 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java @@ -22,24 +22,47 @@ package ca.uhn.fhir.rest.server; import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank; -import java.io.*; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.io.Writer; import java.net.URLEncoder; -import java.util.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.StringTokenizer; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang3.StringUtils; -import org.hl7.fhir.instance.model.api.*; +import org.hl7.fhir.instance.model.api.IAnyResource; +import org.hl7.fhir.instance.model.api.IBaseBinary; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.instance.model.api.IIdType; +import org.hl7.fhir.instance.model.api.IPrimitiveType; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirVersionEnum; -import ca.uhn.fhir.model.api.*; +import ca.uhn.fhir.model.api.Bundle; +import ca.uhn.fhir.model.api.IResource; +import ca.uhn.fhir.model.api.Include; +import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; +import ca.uhn.fhir.model.api.Tag; +import ca.uhn.fhir.model.api.TagList; import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.parser.IParser; -import ca.uhn.fhir.rest.api.*; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.api.PreferReturnEnum; +import ca.uhn.fhir.rest.api.SummaryEnum; import ca.uhn.fhir.rest.api.server.IRestfulResponse; import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseMethodBinding.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseMethodBinding.java index fabe1f0220c..96f9405329d 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseMethodBinding.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseMethodBinding.java @@ -46,13 +46,32 @@ import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.TagList; import ca.uhn.fhir.model.base.resource.BaseOperationOutcome; import ca.uhn.fhir.parser.IParser; -import ca.uhn.fhir.rest.annotation.*; -import ca.uhn.fhir.rest.api.*; -import ca.uhn.fhir.rest.api.server.*; +import ca.uhn.fhir.rest.annotation.AddTags; +import ca.uhn.fhir.rest.annotation.Create; +import ca.uhn.fhir.rest.annotation.Delete; +import ca.uhn.fhir.rest.annotation.DeleteTags; +import ca.uhn.fhir.rest.annotation.GetPage; +import ca.uhn.fhir.rest.annotation.GetTags; +import ca.uhn.fhir.rest.annotation.History; +import ca.uhn.fhir.rest.annotation.Metadata; +import ca.uhn.fhir.rest.annotation.Operation; +import ca.uhn.fhir.rest.annotation.Patch; +import ca.uhn.fhir.rest.annotation.Read; +import ca.uhn.fhir.rest.annotation.Search; +import ca.uhn.fhir.rest.annotation.Transaction; +import ca.uhn.fhir.rest.annotation.Update; +import ca.uhn.fhir.rest.annotation.Validate; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import ca.uhn.fhir.rest.api.server.IBundleProvider; +import ca.uhn.fhir.rest.api.server.IRestfulServer; +import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.client.exceptions.NonFhirResponseException; -import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; -import ca.uhn.fhir.rest.param.IParameter; -import ca.uhn.fhir.rest.server.*; +import ca.uhn.fhir.rest.server.BundleProviders; +import ca.uhn.fhir.rest.server.IDynamicSearchResourceProvider; +import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; @@ -67,7 +86,7 @@ import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetai import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.util.ReflectionUtil; -public abstract class BaseMethodBinding implements IClientResponseHandler, IServerMethodBinding { +public abstract class BaseMethodBinding { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseMethodBinding.class); private FhirContext myContext; @@ -232,8 +251,6 @@ public abstract class BaseMethodBinding implements IClientResponseHandler, public abstract boolean incomingServerRequestMatchesMethod(RequestDetails theRequest); - public abstract BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException; - public abstract Object invokeServer(IRestfulServer theServer, RequestDetails theRequest) throws BaseServerResponseException, IOException; protected final Object invokeServerMethod(IRestfulServer theServer, RequestDetails theRequest, Object[] theMethodParams) { diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseOutcomeReturningMethodBinding.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseOutcomeReturningMethodBinding.java index dea6ad675af..b0b4e4c0699 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseOutcomeReturningMethodBinding.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseOutcomeReturningMethodBinding.java @@ -21,13 +21,10 @@ package ca.uhn.fhir.rest.server.method; */ import java.io.IOException; -import java.io.Reader; import java.io.Writer; import java.lang.reflect.Method; import java.util.Collections; import java.util.EnumSet; -import java.util.List; -import java.util.Map; import java.util.Set; import javax.servlet.http.HttpServletResponse; @@ -39,12 +36,19 @@ import org.hl7.fhir.instance.model.api.IIdType; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.parser.IParser; -import ca.uhn.fhir.rest.api.*; -import ca.uhn.fhir.rest.api.server.*; -import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; -import ca.uhn.fhir.rest.server.*; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.api.PreferReturnEnum; +import ca.uhn.fhir.rest.api.RequestTypeEnum; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import ca.uhn.fhir.rest.api.SummaryEnum; +import ca.uhn.fhir.rest.api.server.IRestfulResponse; +import ca.uhn.fhir.rest.api.server.IRestfulServer; +import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.server.RestfulServer; +import ca.uhn.fhir.rest.server.RestfulServerUtils; import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; @@ -77,8 +81,6 @@ abstract class BaseOutcomeReturningMethodBinding extends BaseMethodBinding> theHeaders) throws BaseServerResponseException { - if (theResponseStatusCode >= 200 && theResponseStatusCode < 300) { - if (myReturnVoid) { - return null; - } - MethodOutcome retVal = MethodUtil.process2xxResponse(getContext(), theResponseStatusCode, theResponseMimeType, theResponseReader, theHeaders); - return retVal; - } - throw processNon2xxResponseAndReturnExceptionToThrow(theResponseStatusCode, theResponseMimeType, theResponseReader); - } - @Override public Object invokeServer(IRestfulServer theServer, RequestDetails theRequest) throws BaseServerResponseException, IOException { diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseOutcomeReturningMethodBindingWithResourceIdButNoResourceBody.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseOutcomeReturningMethodBindingWithResourceIdButNoResourceBody.java index 45176b3309b..a7652751d7d 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseOutcomeReturningMethodBindingWithResourceIdButNoResourceBody.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseOutcomeReturningMethodBindingWithResourceIdButNoResourceBody.java @@ -24,13 +24,10 @@ import java.lang.reflect.Method; 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.RuntimeResourceDefinition; -import ca.uhn.fhir.rest.annotation.Delete; -import ca.uhn.fhir.rest.annotation.IdParam; +import ca.uhn.fhir.context.*; //TODO Use of a deprecated method should be resolved -import ca.uhn.fhir.rest.annotation.VersionIdParam; +import ca.uhn.fhir.rest.annotation.*; +import ca.uhn.fhir.rest.param.ParameterUtil; import ca.uhn.fhir.rest.server.IResourceProvider; public abstract class BaseOutcomeReturningMethodBindingWithResourceIdButNoResourceBody extends BaseOutcomeReturningMethodBinding { @@ -55,12 +52,12 @@ public abstract class BaseOutcomeReturningMethodBindingWithResourceIdButNoResour } } - myIdParameterIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); + myIdParameterIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext()); if (myIdParameterIndex == null) { throw new ConfigurationException("Method '" + theMethod.getName() + "' on type '" + theMethod.getDeclaringClass().getCanonicalName() + "' has no parameter annotated with the @" + IdParam.class.getSimpleName() + " annotation"); } - Integer versionIdParameterIndex = MethodUtil.findVersionIdParameterIndex(theMethod); + Integer versionIdParameterIndex = ParameterUtil.findVersionIdParameterIndex(theMethod); if (versionIdParameterIndex != null) { //TODO Use of a deprecated method should be resolved throw new ConfigurationException("Method '" + theMethod.getName() + "' on type '" + theMethod.getDeclaringClass().getCanonicalName() + "' has a parameter annotated with the @" + VersionIdParam.class.getSimpleName() + " annotation but delete methods may not have this annotation"); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseOutcomeReturningMethodBindingWithResourceParam.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseOutcomeReturningMethodBindingWithResourceParam.java index f38b604ed93..0342f11e483 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseOutcomeReturningMethodBindingWithResourceParam.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseOutcomeReturningMethodBindingWithResourceParam.java @@ -31,13 +31,10 @@ import org.hl7.fhir.instance.model.api.IIdType; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirVersionEnum; -import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.rest.annotation.ResourceParam; import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; -import ca.uhn.fhir.rest.param.IParameter; +import ca.uhn.fhir.rest.param.ParameterUtil; import ca.uhn.fhir.rest.server.IResourceProvider; -import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; abstract class BaseOutcomeReturningMethodBindingWithResourceParam extends BaseOutcomeReturningMethodBinding { @@ -82,7 +79,7 @@ abstract class BaseOutcomeReturningMethodBindingWithResourceParam extends BaseOu } myResourceName = theContext.getResourceDefinition(myResourceType).getName(); - myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); + myIdParamIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext()); if (myIdParamIndex != null) { myIdParamType = (Class) theMethod.getParameterTypes()[myIdParamIndex]; } @@ -96,7 +93,7 @@ abstract class BaseOutcomeReturningMethodBindingWithResourceParam extends BaseOu @Override protected void addParametersForServerRequest(RequestDetails theRequest, Object[] theParams) { if (myIdParamIndex != null) { - theParams[myIdParamIndex] = MethodUtil.convertIdToType(theRequest.getId(), myIdParamType); + theParams[myIdParamIndex] = ParameterUtil.convertIdToType(theRequest.getId(), myIdParamType); } if (myResourceParameterIndex != -1) { IBaseResource resource = ((IBaseResource) theParams[myResourceParameterIndex]); @@ -124,17 +121,6 @@ abstract class BaseOutcomeReturningMethodBindingWithResourceParam extends BaseOu return myResourceName; } - @Override - public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException { - IResource resource = (IResource) theArgs[myResourceParameterIndex]; // TODO: use IBaseResource - if (resource == null) { - throw new NullPointerException("Resource can not be null"); - } - - BaseHttpClientInvocation retVal = createClientInvocation(theArgs, resource); - return retVal; - } - @Override protected void populateActionRequestDetailsForInterceptor(RequestDetails theRequestDetails, ActionRequestDetails theDetails, Object[] theMethodParams) { super.populateActionRequestDetailsForInterceptor(theRequestDetails, theDetails, theMethodParams); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseQueryParameter.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseQueryParameter.java index a0b3162cc59..c1f055c0e34 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseQueryParameter.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseQueryParameter.java @@ -1,7 +1,5 @@ package ca.uhn.fhir.rest.server.method; -import static org.apache.commons.lang3.StringUtils.isNotBlank; - /* * #%L * HAPI FHIR - Core Library @@ -23,15 +21,17 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; */ import java.lang.reflect.Method; -import java.util.*; - -import org.hl7.fhir.instance.model.api.IBaseResource; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Set; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.api.QualifiedParamList; import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum; import ca.uhn.fhir.rest.api.server.IRequestDetails; -import ca.uhn.fhir.rest.api.server.IServerMethodBinding; +import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.param.QualifierDetails; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; @@ -74,7 +74,7 @@ public abstract class BaseQueryParameter implements IParameter { public abstract Object parse(FhirContext theContext, List theString) throws InternalErrorException, InvalidRequestException; - private void parseParams(IRequestDetails theRequest, List paramList, String theQualifiedParamName, String theQualifier) { + private void parseParams(RequestDetails theRequest, List paramList, String theQualifiedParamName, String theQualifier) { QualifierDetails qualifiers = QualifierDetails.extractQualifiersFromParameterName(theQualifier); if (!qualifiers.passes(getQualifierWhitelist(), getQualifierBlacklist())) { return; @@ -92,40 +92,9 @@ public abstract class BaseQueryParameter implements IParameter { } } - @Override - public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map> theTargetQueryArguments, IBaseResource theTargetResource) throws InternalErrorException { - if (theSourceClientArgument == null) { - if (isRequired()) { - throw new NullPointerException("SearchParameter '" + getName() + "' is required and may not be null"); - } - } else { - List value = encode(theContext, theSourceClientArgument); - - for (QualifiedParamList nextParamEntry : value) { - StringBuilder b = new StringBuilder(); - for (String str : nextParamEntry) { - if (b.length() > 0) { - b.append(","); - } - b.append(str); - } - - String qualifier = nextParamEntry.getQualifier(); - String paramName = isNotBlank(qualifier) ? getName() + qualifier : getName(); - List paramValues = theTargetQueryArguments.get(paramName); - if (paramValues == null) { - paramValues = new ArrayList(value.size()); - theTargetQueryArguments.put(paramName, paramValues); - } - - paramValues.add(b.toString()); - } - - } - } @Override - public Object translateQueryParametersIntoServerArgument(IRequestDetails theRequest, IServerMethodBinding theMethodBinding) throws InternalErrorException, InvalidRequestException { + public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding theMethodBinding) throws InternalErrorException, InvalidRequestException { List paramList = new ArrayList(); String name = getName(); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseResourceReturningMethodBinding.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseResourceReturningMethodBinding.java index 95f52c99088..9fa0e4668fb 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseResourceReturningMethodBinding.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/BaseResourceReturningMethodBinding.java @@ -22,37 +22,24 @@ package ca.uhn.fhir.rest.server.method; import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.io.IOException; -import java.io.Reader; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.*; -import org.hl7.fhir.instance.model.api.IBaseBundle; -import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IPrimitiveType; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.context.FhirVersionEnum; -import ca.uhn.fhir.model.api.Bundle; -import ca.uhn.fhir.model.api.IResource; -import ca.uhn.fhir.model.api.Include; +import ca.uhn.fhir.model.api.*; import ca.uhn.fhir.model.valueset.BundleTypeEnum; -import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.rest.api.*; import ca.uhn.fhir.rest.api.server.*; -import ca.uhn.fhir.rest.client.exceptions.InvalidResponseException; -import ca.uhn.fhir.rest.param.IParameter; -import ca.uhn.fhir.rest.server.*; +import ca.uhn.fhir.rest.server.RestfulServerUtils; import ca.uhn.fhir.rest.server.RestfulServerUtils.ResponseEncoding; -import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; -import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; -import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; -import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; +import ca.uhn.fhir.rest.server.exceptions.*; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor; -import ca.uhn.fhir.util.BundleUtil; import ca.uhn.fhir.util.ReflectionUtil; import ca.uhn.fhir.util.UrlUtil; @@ -76,10 +63,8 @@ public abstract class BaseResourceReturningMethodBinding extends BaseMethodBindi } private MethodReturnTypeEnum myMethodReturnType; - private Class myResourceListCollectionType; private String myResourceName; private Class myResourceType; - private List> myPreferTypesList; @SuppressWarnings("unchecked") public BaseResourceReturningMethodBinding(Class theReturnResourceType, Method theMethod, FhirContext theContext, Object theProvider) { @@ -96,7 +81,6 @@ public abstract class BaseResourceReturningMethodBinding extends BaseMethodBindi "Method " + theMethod.getDeclaringClass().getSimpleName() + "#" + theMethod.getName() + " returns an invalid collection generic type: " + collectionType); } } - myResourceListCollectionType = collectionType; } else if (IBaseResource.class.isAssignableFrom(methodReturnType)) { if (Modifier.isAbstract(methodReturnType.getModifiers()) == false && theContext.getResourceDefinition((Class) methodReturnType).isBundle()) { @@ -126,7 +110,6 @@ public abstract class BaseResourceReturningMethodBinding extends BaseMethodBindi } } - myPreferTypesList = createPreferTypesList(); } public MethodReturnTypeEnum getMethodReturnType() { @@ -145,19 +128,6 @@ public abstract class BaseResourceReturningMethodBinding extends BaseMethodBindi public abstract ReturnTypeEnum getReturnType(); - @SuppressWarnings("unchecked") - private List> createPreferTypesList() { - List> preferTypes = null; - if (myResourceListCollectionType != null && IBaseResource.class.isAssignableFrom(myResourceListCollectionType)) { - preferTypes = new ArrayList>(1); - preferTypes.add((Class) myResourceListCollectionType); - // } else if (myResourceType != null) { - // preferTypes = new ArrayList>(1); - // preferTypes.add((Class) myResourceListCollectionType); - } - return preferTypes; - } - @Override public Object invokeServer(IRestfulServer theServer, RequestDetails theRequest) throws BaseServerResponseException, IOException { diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ConditionalParamBinder.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ConditionalParamBinder.java index 8ed1066f7ad..c302e1e646e 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ConditionalParamBinder.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ConditionalParamBinder.java @@ -10,7 +10,7 @@ package ca.uhn.fhir.rest.server.method; * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,18 +22,13 @@ package ca.uhn.fhir.rest.server.method; import java.lang.reflect.Method; import java.util.Collection; -import java.util.List; -import java.util.Map; import org.apache.commons.lang3.Validate; -import org.hl7.fhir.instance.model.api.IBaseResource; import ca.uhn.fhir.context.ConfigurationException; -import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.annotation.ConditionalUrlParam; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.param.IParameter; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; @@ -51,7 +46,8 @@ class ConditionalParamBinder implements IParameter { @Override public void initializeTypes(Method theMethod, Class> theOuterCollectionType, Class> theInnerCollectionType, Class theParameterType) { if (theOuterCollectionType != null || theInnerCollectionType != null || theParameterType.equals(String.class) == false) { - throw new ConfigurationException("Parameters annotated with @" + ConditionalUrlParam.class.getSimpleName() + " must be of type String, found incorrect parameteter in method \"" + theMethod + "\""); + throw new ConfigurationException( + "Parameters annotated with @" + ConditionalUrlParam.class.getSimpleName() + " must be of type String, found incorrect parameteter in method \"" + theMethod + "\""); } } @@ -59,11 +55,6 @@ class ConditionalParamBinder implements IParameter { return mySupportsMultiple; } - @Override - public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map> theTargetQueryArguments, IBaseResource theTargetResource) throws InternalErrorException { - throw new UnsupportedOperationException("Can not use @" + getClass().getName() + " annotated parameters in client"); - } - @Override public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding theMethodBinding) throws InternalErrorException, InvalidRequestException { return theRequest.getConditionalUrl(myOperationType); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ConformanceMethodBinding.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ConformanceMethodBinding.java index cbee78be5d7..4976e3cf06a 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ConformanceMethodBinding.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ConformanceMethodBinding.java @@ -10,7 +10,7 @@ package ca.uhn.fhir.rest.server.method; * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -28,12 +28,13 @@ import org.hl7.fhir.instance.model.api.IBaseResource; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.valueset.BundleTypeEnum; -import ca.uhn.fhir.rest.api.*; -import ca.uhn.fhir.rest.api.server.*; -import ca.uhn.fhir.rest.param.IParameter; +import ca.uhn.fhir.rest.api.RequestTypeEnum; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import ca.uhn.fhir.rest.api.server.IBundleProvider; +import ca.uhn.fhir.rest.api.server.IRestfulServer; +import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.server.SimpleBundleProvider; import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; -import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException; public class ConformanceMethodBinding extends BaseResourceReturningMethodBinding { @@ -41,9 +42,9 @@ public class ConformanceMethodBinding extends BaseResourceReturningMethodBinding public ConformanceMethodBinding(Method theMethod, FhirContext theContext, Object theProvider) { super(theMethod.getReturnType(), theMethod, theContext, theProvider); -// if (Modifier.isAbstract(theMethod.getReturnType().getModifiers())) { -// throw new ConfigurationException("Conformance resource provider method '" + theMethod.getName() + "' must not be abstract"); -// } + // if (Modifier.isAbstract(theMethod.getReturnType().getModifiers())) { + // throw new ConfigurationException("Conformance resource provider method '" + theMethod.getName() + "' must not be abstract"); + // } MethodReturnTypeEnum methodReturnType = getMethodReturnType(); Class genericReturnType = (Class) theMethod.getGenericReturnType(); if (methodReturnType != MethodReturnTypeEnum.RESOURCE || !IBaseConformance.class.isAssignableFrom(genericReturnType)) { @@ -57,20 +58,6 @@ public class ConformanceMethodBinding extends BaseResourceReturningMethodBinding return ReturnTypeEnum.RESOURCE; } - @Override - public HttpGetClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException { - HttpGetClientInvocation retVal = MethodUtil.createConformanceInvocation(getContext()); - - if (theArgs != null) { - for (int idx = 0; idx < theArgs.length; idx++) { - IParameter nextParam = getParameters().get(idx); - nextParam.translateClientArgumentIntoQueryArgument(getContext(), theArgs[idx], null, null); - } - } - - return retVal; - } - @Override public IBundleProvider invokeServer(IRestfulServer theServer, RequestDetails theRequest, Object[] theMethodParams) throws BaseServerResponseException { IBaseResource conf = (IBaseResource) invokeServerMethod(theServer, theRequest, theMethodParams); @@ -88,7 +75,7 @@ public class ConformanceMethodBinding extends BaseResourceReturningMethodBinding if (theRequest.getResourceName() != null) { return false; } - + if ("metadata".equals(theRequest.getOperation())) { if (theRequest.getRequestType() == RequestTypeEnum.GET) { return true; diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/CountParameter.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/CountParameter.java index 6ac59f8f113..d7bb4e5f644 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/CountParameter.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/CountParameter.java @@ -22,21 +22,15 @@ package ca.uhn.fhir.rest.server.method; import java.lang.reflect.Method; import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; import org.apache.commons.lang3.StringUtils; -import org.hl7.fhir.instance.model.api.IBaseResource; import ca.uhn.fhir.context.ConfigurationException; -import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.primitive.IntegerDt; import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.rest.annotation.Since; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.param.IParameter; import ca.uhn.fhir.rest.param.ParameterUtil; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; @@ -45,16 +39,6 @@ public class CountParameter implements IParameter { private Class myType; - @Override - public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map> theTargetQueryArguments, IBaseResource theTargetResource) throws InternalErrorException { - if (theSourceClientArgument != null) { - IntegerDt since = ParameterUtil.toInteger(theSourceClientArgument); - if (since.isEmpty() == false) { - theTargetQueryArguments.put(Constants.PARAM_COUNT, Collections.singletonList(since.getValueAsString())); - } - } - } - @Override public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding theMethodBinding) throws InternalErrorException, InvalidRequestException { String[] sinceParams = theRequest.getParameters().get(Constants.PARAM_COUNT); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/CreateMethodBinding.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/CreateMethodBinding.java index 9c1890ae4ad..3999744ca29 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/CreateMethodBinding.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/CreateMethodBinding.java @@ -31,12 +31,9 @@ import org.hl7.fhir.instance.model.api.IIdType; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirVersionEnum; -import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.rest.annotation.Create; import ca.uhn.fhir.rest.api.RequestTypeEnum; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; -import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; -import ca.uhn.fhir.rest.param.IParameter; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; public class CreateMethodBinding extends BaseOutcomeReturningMethodBindingWithResourceParam { @@ -45,22 +42,6 @@ public class CreateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe super(theMethod, theContext, Create.class, theProvider); } - @Override - protected BaseHttpClientInvocation createClientInvocation(Object[] theArgs, IResource theResource) { - FhirContext context = getContext(); - - BaseHttpClientInvocation retVal = MethodUtil.createCreateInvocation(theResource, context); - - if (theArgs != null) { - for (int idx = 0; idx < theArgs.length; idx++) { - IParameter nextParam = getParameters().get(idx); - nextParam.translateClientArgumentIntoQueryArgument(getContext(), theArgs[idx], null, null); - } - } - - return retVal; - } - @Override protected String getMatchingOperation() { return null; @@ -77,18 +58,21 @@ public class CreateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe } @Override - protected void validateResourceIdAndUrlIdForNonConditionalOperation(IBaseResource theResource, String theResourceId, String theUrlId, String theMatchUrl) { + protected void validateResourceIdAndUrlIdForNonConditionalOperation(IBaseResource theResource, String theResourceId, + String theUrlId, String theMatchUrl) { if (isNotBlank(theUrlId)) { - String msg = getContext().getLocalizer().getMessage(BaseOutcomeReturningMethodBindingWithResourceParam.class, "idInUrlForCreate", theUrlId); + String msg = getContext().getLocalizer() + .getMessage(BaseOutcomeReturningMethodBindingWithResourceParam.class, "idInUrlForCreate", theUrlId); throw new InvalidRequestException(msg); } if (getContext().getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3)) { if (isNotBlank(theResourceId)) { - String msg = getContext().getLocalizer().getMessage(BaseOutcomeReturningMethodBindingWithResourceParam.class, "idInBodyForCreate", theResourceId); + String msg = getContext().getLocalizer().getMessage( + BaseOutcomeReturningMethodBindingWithResourceParam.class, "idInBodyForCreate", theResourceId); throw new InvalidRequestException(msg); } } else { - theResource.setId((IIdType)null); + theResource.setId((IIdType) null); } } diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/DeleteMethodBinding.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/DeleteMethodBinding.java index ce497de4e54..7bb37f9c92e 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/DeleteMethodBinding.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/DeleteMethodBinding.java @@ -22,21 +22,13 @@ package ca.uhn.fhir.rest.server.method; import java.lang.reflect.Method; import java.util.Collections; -import java.util.List; -import java.util.Map; import java.util.Set; -import org.hl7.fhir.instance.model.api.IIdType; - import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.rest.annotation.Delete; -import ca.uhn.fhir.rest.api.*; +import ca.uhn.fhir.rest.api.RequestTypeEnum; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; -import ca.uhn.fhir.rest.param.IParameter; -import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; -import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; public class DeleteMethodBinding extends BaseOutcomeReturningMethodBindingWithResourceIdButNoResourceBody { @@ -54,47 +46,11 @@ public class DeleteMethodBinding extends BaseOutcomeReturningMethodBindingWithRe return Collections.singleton(RequestTypeEnum.DELETE); } - @Override - protected BaseHttpClientInvocation createClientInvocation(Object[] theArgs, IResource theResource) { - StringBuilder urlExtension = new StringBuilder(); - urlExtension.append(getContext().getResourceDefinition(theResource).getName()); - - return new HttpPostClientInvocation(getContext(), theResource, urlExtension.toString()); - } - @Override protected boolean allowVoidReturnType() { return true; } - @Override - public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException { - IIdType idDt = (IIdType) theArgs[getIdParameterIndex()]; - if (idDt == null) { - throw new NullPointerException("ID can not be null"); - } - - if (idDt.hasResourceType() == false) { - idDt = idDt.withResourceType(getResourceName()); - } else if (getResourceName().equals(idDt.getResourceType()) == false) { - throw new InvalidRequestException("ID parameter has the wrong resource type, expected '" + getResourceName() + "', found: " + idDt.getResourceType()); - } - - HttpDeleteClientInvocation retVal = createDeleteInvocation(getContext(), idDt); - - for (int idx = 0; idx < theArgs.length; idx++) { - IParameter nextParam = getParameters().get(idx); - nextParam.translateClientArgumentIntoQueryArgument(getContext(), theArgs[idx], null, null); - } - - return retVal; - } - - public static HttpDeleteClientInvocation createDeleteInvocation(FhirContext theContext, IIdType theId) { - HttpDeleteClientInvocation retVal = new HttpDeleteClientInvocation(theContext, theId); - return retVal; - } - @Override protected void addParametersForServerRequest(RequestDetails theRequest, Object[] theParams) { theParams[getIdParameterIndex()] = theRequest.getId(); @@ -105,13 +61,4 @@ public class DeleteMethodBinding extends BaseOutcomeReturningMethodBindingWithRe return null; } - public static HttpDeleteClientInvocation createDeleteInvocation(FhirContext theContext, String theSearchUrl) { - HttpDeleteClientInvocation retVal = new HttpDeleteClientInvocation(theContext, theSearchUrl); - return retVal; - } - - public static HttpDeleteClientInvocation createDeleteInvocation(FhirContext theContext, String theResourceType, Map> theParams) { - return new HttpDeleteClientInvocation(theContext, theResourceType, theParams); - } - } diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/DynamicSearchMethodBinding.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/DynamicSearchMethodBinding.java index 787c28fa336..6c642eee03b 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/DynamicSearchMethodBinding.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/DynamicSearchMethodBinding.java @@ -10,7 +10,7 @@ package ca.uhn.fhir.rest.server.method; * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -31,20 +31,25 @@ import org.hl7.fhir.instance.model.api.IBaseResource; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.RuntimeSearchParam; import ca.uhn.fhir.model.valueset.BundleTypeEnum; -import ca.uhn.fhir.rest.api.*; -import ca.uhn.fhir.rest.api.server.*; -import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; -import ca.uhn.fhir.rest.param.IParameter; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.RequestTypeEnum; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import ca.uhn.fhir.rest.api.server.IBundleProvider; +import ca.uhn.fhir.rest.api.server.IRestfulServer; +import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.param.ParameterUtil; import ca.uhn.fhir.rest.server.IDynamicSearchResourceProvider; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; public class DynamicSearchMethodBinding extends BaseResourceReturningMethodBinding { - private IDynamicSearchResourceProvider myProvider; - private List mySearchParameters; - private HashSet myParamNames; + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DynamicSearchMethodBinding.class); private Integer myIdParamIndex; + private HashSet myParamNames; + private IDynamicSearchResourceProvider myProvider; + + private List mySearchParameters; public DynamicSearchMethodBinding(Class theReturnResourceType, Method theMethod, FhirContext theContext, IDynamicSearchResourceProvider theProvider) { super(theReturnResourceType, theMethod, theContext, theProvider); @@ -57,25 +62,29 @@ public class DynamicSearchMethodBinding extends BaseResourceReturningMethodBindi myParamNames.add(next.getName()); } - myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); + myIdParamIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext()); } + @Override + public List getParameters() { + List retVal = new ArrayList(super.getParameters()); + + for (RuntimeSearchParam next : mySearchParameters) { + // TODO: what is this? + } + + return retVal; + } + @Override protected BundleTypeEnum getResponseBundleType() { return BundleTypeEnum.SEARCHSET; } - @Override - public List getParameters() { - List retVal = new ArrayList(super.getParameters()); - - for (RuntimeSearchParam next : mySearchParameters) { - // TODO: what is this? - } - - return retVal; + public RestOperationTypeEnum getRestOperationType() { + return RestOperationTypeEnum.SEARCH_TYPE; } @Override @@ -83,27 +92,14 @@ public class DynamicSearchMethodBinding extends BaseResourceReturningMethodBindi return ReturnTypeEnum.BUNDLE; } - @Override - public IBundleProvider invokeServer(IRestfulServer theServer, RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException { - if (myIdParamIndex != null) { - theMethodParams[myIdParamIndex] = theRequest.getId(); - } - - Object response = invokeServerMethod(theServer, theRequest, theMethodParams); - return toResourceList(response); + public Collection getSearchParams() { + return mySearchParameters; } - @Override - public RestOperationTypeEnum getRestOperationType() { - return RestOperationTypeEnum.SEARCH_TYPE; - } - - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DynamicSearchMethodBinding.class); - @Override public boolean incomingServerRequestMatchesMethod(RequestDetails theRequest) { if (!theRequest.getResourceName().equals(getResourceName())) { - ourLog.trace("Method {} doesn't match because resource name {} != {}", new Object[] { getMethod().getName(), theRequest.getResourceName(), getResourceName() } ); + ourLog.trace("Method {} doesn't match because resource name {} != {}", new Object[] { getMethod().getName(), theRequest.getResourceName(), getResourceName() }); return false; } if (theRequest.getId() != null && myIdParamIndex == null) { @@ -153,13 +149,13 @@ public class DynamicSearchMethodBinding extends BaseResourceReturningMethodBindi } @Override - public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException { - // there should be no way to call this.... - throw new UnsupportedOperationException("Dynamic search methods are only used for server implementations"); - } + public IBundleProvider invokeServer(IRestfulServer theServer, RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException { + if (myIdParamIndex != null) { + theMethodParams[myIdParamIndex] = theRequest.getId(); + } - public Collection getSearchParams() { - return mySearchParameters; + Object response = invokeServerMethod(theServer, theRequest, theMethodParams); + return toResourceList(response); } } diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ElementsParameter.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ElementsParameter.java index 0d098757fa6..1106ea6c583 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ElementsParameter.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ElementsParameter.java @@ -10,7 +10,7 @@ package ca.uhn.fhir.rest.server.method; * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,23 +22,15 @@ package ca.uhn.fhir.rest.server.method; import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.lang.reflect.Method; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; +import java.util.*; import org.apache.commons.lang3.StringUtils; -import org.hl7.fhir.instance.model.api.IBaseResource; import ca.uhn.fhir.context.ConfigurationException; -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.rest.api.*; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.SummaryEnum; import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.param.CollectionBinder; -import ca.uhn.fhir.rest.param.IParameter; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; @@ -47,28 +39,6 @@ public class ElementsParameter implements IParameter { @SuppressWarnings("rawtypes") private Class myInnerCollectionType; - @SuppressWarnings("unchecked") - @Override - public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map> theTargetQueryArguments, IBaseResource theTargetResource) throws InternalErrorException { - if (theSourceClientArgument instanceof Collection) { - StringBuilder values = new StringBuilder(); - for (String next : (Collection) theSourceClientArgument) { - if (isNotBlank(next)) { - if (values.length() > 0) { - values.append(','); - } - values.append(next); - } - } - theTargetQueryArguments.put(Constants.PARAM_ELEMENTS, Collections.singletonList(values.toString())); - } else { - String elements = (String) theSourceClientArgument; - if (elements != null) { - theTargetQueryArguments.put(Constants.PARAM_ELEMENTS, Collections.singletonList(elements)); - } - } - } - @Override @SuppressWarnings({ "rawtypes", "unchecked" }) public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding theMethodBinding) throws InternalErrorException, InvalidRequestException { @@ -109,10 +79,10 @@ public class ElementsParameter implements IParameter { if (retVal.isEmpty()) { return null; } - + // Always include the meta element even for subsetted values retVal.add("meta"); - + return retVal; } return null; @@ -121,7 +91,8 @@ public class ElementsParameter implements IParameter { @Override public void initializeTypes(Method theMethod, Class> theOuterCollectionType, Class> theInnerCollectionType, Class theParameterType) { if (theOuterCollectionType != null) { - throw new ConfigurationException("Method '" + theMethod.getName() + "' in type '" + theMethod.getDeclaringClass().getCanonicalName() + "' is of type " + SummaryEnum.class + " but can not be a collection of collections"); + throw new ConfigurationException("Method '" + theMethod.getName() + "' in type '" + theMethod.getDeclaringClass().getCanonicalName() + "' is of type " + SummaryEnum.class + + " but can not be a collection of collections"); } if (theInnerCollectionType != null) { myInnerCollectionType = CollectionBinder.getInstantiableCollectionType(theInnerCollectionType, SummaryEnum.class.getSimpleName()); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/GetTagsMethodBinding.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/GetTagsMethodBinding.java index 24d1feba623..e5cd9aa914f 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/GetTagsMethodBinding.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/GetTagsMethodBinding.java @@ -10,7 +10,7 @@ package ca.uhn.fhir.rest.server.method; * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -21,11 +21,8 @@ package ca.uhn.fhir.rest.server.method; */ import java.io.IOException; -import java.io.Reader; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.List; -import java.util.Map; import org.hl7.fhir.instance.model.api.IBaseResource; @@ -33,17 +30,17 @@ import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.TagList; -import ca.uhn.fhir.model.primitive.IdDt; -import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.rest.annotation.GetTags; import ca.uhn.fhir.rest.annotation.IdParam; -import ca.uhn.fhir.rest.api.*; -import ca.uhn.fhir.rest.api.server.*; -import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; -import ca.uhn.fhir.rest.param.IParameter; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.RequestTypeEnum; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import ca.uhn.fhir.rest.api.server.IRestfulServer; +import ca.uhn.fhir.rest.api.server.ParseAction; +import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.param.ParameterUtil; import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; -import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; public class GetTagsMethodBinding extends BaseMethodBinding { @@ -66,8 +63,8 @@ public class GetTagsMethodBinding extends BaseMethodBinding { myResourceName = theContext.getResourceDefinition(myType).getName(); } - myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); - myVersionIdParamIndex = MethodUtil.findVersionIdParameterIndex(theMethod); + myIdParamIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext()); + myVersionIdParamIndex = ParameterUtil.findVersionIdParameterIndex(theMethod); if (myIdParamIndex != null && myType.equals(IResource.class)) { throw new ConfigurationException("Method '" + theMethod.getName() + "' does not specify a resource type, but has an @" + IdParam.class.getSimpleName() @@ -104,60 +101,9 @@ public class GetTagsMethodBinding extends BaseMethodBinding { if ((myIdParamIndex != null) != (theRequest.getId() != null)) { return false; } - // if ((myVersionIdParamIndex != null) != (theRequest.getVersionId() != null)) { - // return false; - // } return true; } - @Override - public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException { - HttpGetClientInvocation retVal; - - IdDt id = null; - IdDt versionId = null; - if (myIdParamIndex != null) { - id = (IdDt) theArgs[myIdParamIndex]; - if (myVersionIdParamIndex != null) { - versionId = (IdDt) theArgs[myVersionIdParamIndex]; - } - } - - if (myType != IResource.class) { - if (id != null) { - if (versionId != null) { - retVal = new HttpGetClientInvocation(getContext(), getResourceName(), id.getIdPart(), Constants.PARAM_HISTORY, versionId.getValue(), Constants.PARAM_TAGS); - } else if (id.hasVersionIdPart()) { - retVal = new HttpGetClientInvocation(getContext(), getResourceName(), id.getIdPart(), Constants.PARAM_HISTORY, id.getVersionIdPart(), Constants.PARAM_TAGS); - } else { - retVal = new HttpGetClientInvocation(getContext(), getResourceName(), id.getIdPart(), Constants.PARAM_TAGS); - } - } else { - retVal = new HttpGetClientInvocation(getContext(), getResourceName(), Constants.PARAM_TAGS); - } - } else { - retVal = new HttpGetClientInvocation(getContext(), Constants.PARAM_TAGS); - } - - if (theArgs != null) { - for (int idx = 0; idx < theArgs.length; idx++) { - IParameter nextParam = getParameters().get(idx); - nextParam.translateClientArgumentIntoQueryArgument(getContext(), theArgs[idx], null, null); - } - } - - return retVal; - } - - @Override - public TagList invokeClient(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, Map> theHeaders) throws BaseServerResponseException { - if (theResponseStatusCode == Constants.STATUS_HTTP_200_OK) { - IParser parser = createAppropriateParserForParsingResponse(theResponseMimeType, theResponseReader, theResponseStatusCode, null); - TagList retVal = parser.parseTagList(theResponseReader); - return retVal; - } - throw processNon2xxResponseAndReturnExceptionToThrow(theResponseStatusCode, theResponseMimeType, theResponseReader); - } @Override public Object invokeServer(IRestfulServer theServer, RequestDetails theRequest) throws BaseServerResponseException, IOException { Object[] params = createParametersForServerRequest(theRequest); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/HistoryMethodBinding.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/HistoryMethodBinding.java index c9ecd451f1b..409d9d59403 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/HistoryMethodBinding.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/HistoryMethodBinding.java @@ -20,7 +20,6 @@ package ca.uhn.fhir.rest.server.method; * #L% */ import static org.apache.commons.lang3.StringUtils.isBlank; -import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -37,11 +36,13 @@ import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.annotation.History; -import ca.uhn.fhir.rest.api.*; -import ca.uhn.fhir.rest.api.server.*; -import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; -import ca.uhn.fhir.rest.param.IParameter; -import ca.uhn.fhir.rest.server.*; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import ca.uhn.fhir.rest.api.server.IBundleProvider; +import ca.uhn.fhir.rest.api.server.IRestfulServer; +import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.param.ParameterUtil; +import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; @@ -54,7 +55,7 @@ public class HistoryMethodBinding extends BaseResourceReturningMethodBinding { public HistoryMethodBinding(Method theMethod, FhirContext theContext, Object theProvider) { super(toReturnType(theMethod, theProvider), theMethod, theContext, theProvider); - myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); + myIdParamIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext()); History historyAnnotation = theMethod.getAnnotation(History.class); Class type = historyAnnotation.type(); @@ -128,29 +129,6 @@ public class HistoryMethodBinding extends BaseResourceReturningMethodBinding { return true; } - @Override - public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException { - IdDt id = null; - String resourceName = myResourceName; - if (myIdParamIndex != null) { - id = (IdDt) theArgs[myIdParamIndex]; - if (id == null || isBlank(id.getValue())) { - throw new NullPointerException("ID can not be null"); - } - } - - String historyId = id != null ? id.getIdPart() : null; - HttpGetClientInvocation retVal = createHistoryInvocation(getContext(), resourceName, historyId, null, null); - - if (theArgs != null) { - for (int idx = 0; idx < theArgs.length; idx++) { - IParameter nextParam = getParameters().get(idx); - nextParam.translateClientArgumentIntoQueryArgument(getContext(), theArgs[idx], retVal.getParameters(), null); - } - } - - return retVal; - } @Override public IBundleProvider invokeServer(IRestfulServer theServer, RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException { @@ -210,34 +188,6 @@ public class HistoryMethodBinding extends BaseResourceReturningMethodBinding { }; } - public static HttpGetClientInvocation createHistoryInvocation(FhirContext theContext, String theResourceName, String theId, IPrimitiveType theSince, Integer theLimit) { - StringBuilder b = new StringBuilder(); - if (theResourceName != null) { - b.append(theResourceName); - if (isNotBlank(theId)) { - b.append('/'); - b.append(theId); - } - } - if (b.length() > 0) { - b.append('/'); - } - b.append(Constants.PARAM_HISTORY); - - boolean haveParam = false; - if (theSince != null && !theSince.isEmpty()) { - haveParam = true; - b.append('?').append(Constants.PARAM_SINCE).append('=').append(theSince.getValueAsString()); - } - if (theLimit != null) { - b.append(haveParam ? '&' : '?'); - b.append(Constants.PARAM_COUNT).append('=').append(theLimit); - } - - HttpGetClientInvocation retVal = new HttpGetClientInvocation(theContext, b.toString()); - return retVal; - } - private static Class toReturnType(Method theMethod, Object theProvider) { if (theProvider instanceof IResourceProvider) { return ((IResourceProvider) theProvider).getResourceType(); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/IParameter.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/IParameter.java index c5d2b22b2af..d82816c561a 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/IParameter.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/IParameter.java @@ -24,8 +24,7 @@ import java.lang.reflect.Method; import java.util.Collection; import ca.uhn.fhir.model.api.IResource; -import ca.uhn.fhir.rest.api.server.IRequestDetails; -import ca.uhn.fhir.rest.api.server.IServerMethodBinding; +import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; @@ -42,7 +41,7 @@ public interface IParameter { * @param theMethodBinding TODO * @return Returns the argument object as it will be passed to the IResourceProvider method. */ - Object translateQueryParametersIntoServerArgument(IRequestDetails theRequest, IServerMethodBinding theMethodBinding) throws InternalErrorException, InvalidRequestException; + Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding theMethodBinding) throws InternalErrorException, InvalidRequestException; void initializeTypes(Method theMethod, Class> theOuterCollectionType, Class> theInnerCollectionType, Class theParameterType); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/IncludeParameter.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/IncludeParameter.java index f1f147dbc75..3716db6bed8 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/IncludeParameter.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/IncludeParameter.java @@ -32,8 +32,9 @@ import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.rest.annotation.IncludeParam; -import ca.uhn.fhir.rest.api.*; -import ca.uhn.fhir.rest.param.BaseQueryParameter; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.QualifiedParamList; +import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/NullParameter.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/NullParameter.java index 825e115baea..64c4fdc800e 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/NullParameter.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/NullParameter.java @@ -22,23 +22,13 @@ package ca.uhn.fhir.rest.server.method; import java.lang.reflect.Method; import java.util.Collection; -import java.util.List; -import java.util.Map; -import org.hl7.fhir.instance.model.api.IBaseResource; - -import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.param.IParameter; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; class NullParameter implements IParameter { - @Override - public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map> theTargetQueryArguments, IBaseResource theTargetResource) throws InternalErrorException { - //nothing - } @Override public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding theMethodBinding) throws InternalErrorException, InvalidRequestException { diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/OperationMethodBinding.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/OperationMethodBinding.java index ceffdfc3964..d3e20b352c5 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/OperationMethodBinding.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/OperationMethodBinding.java @@ -28,17 +28,10 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import org.hl7.fhir.instance.model.api.IBase; -import org.hl7.fhir.instance.model.api.IBaseBundle; -import org.hl7.fhir.instance.model.api.IBaseDatatype; -import org.hl7.fhir.instance.model.api.IBaseParameters; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.instance.model.api.IIdType; -import org.hl7.fhir.instance.model.api.IPrimitiveType; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; @@ -49,15 +42,15 @@ import ca.uhn.fhir.model.valueset.BundleTypeEnum; 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.api.*; -import ca.uhn.fhir.rest.api.server.*; -import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; -import ca.uhn.fhir.rest.param.IParameter; +import ca.uhn.fhir.rest.api.RequestTypeEnum; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import ca.uhn.fhir.rest.api.server.IBundleProvider; +import ca.uhn.fhir.rest.api.server.IRestfulServer; +import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.param.ParameterUtil; import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; -import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; -import ca.uhn.fhir.util.FhirTerser; public class OperationMethodBinding extends BaseResourceReturningMethodBinding { @@ -81,7 +74,7 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { myBundleType = theBundleType; myIdempotent = theIdempotent; - myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); + myIdParamIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext()); if (myIdParamIndex != null) { for (Annotation next : theMethod.getParameterAnnotations()[myIdParamIndex]) { if (next instanceof IdParam) { @@ -245,24 +238,6 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { return true; } - @Override - public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException { - String id = null; - if (myIdParamIndex != null) { - IIdType idDt = (IIdType) theArgs[myIdParamIndex]; - id = idDt.getValue(); - } - IBaseParameters parameters = (IBaseParameters) getContext().getResourceDefinition("Parameters").newInstance(); - - if (theArgs != null) { - for (int idx = 0; idx < theArgs.length; idx++) { - IParameter nextParam = getParameters().get(idx); - nextParam.translateClientArgumentIntoQueryArgument(getContext(), theArgs[idx], null, parameters); - } - } - - return createOperationInvocation(getContext(), getResourceName(), id, myName, parameters, false); - } @Override public Object invokeServer(IRestfulServer theServer, RequestDetails theRequest) throws BaseServerResponseException, IOException { diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/PageMethodBinding.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/PageMethodBinding.java index 38588baa11e..cabb343bbdc 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/PageMethodBinding.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/PageMethodBinding.java @@ -33,15 +33,20 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Bundle; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.valueset.BundleTypeEnum; -import ca.uhn.fhir.rest.api.*; -import ca.uhn.fhir.rest.api.server.*; -import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; -import ca.uhn.fhir.rest.server.*; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.api.IVersionSpecificBundleFactory; +import ca.uhn.fhir.rest.api.RequestTypeEnum; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import ca.uhn.fhir.rest.api.server.IBundleProvider; +import ca.uhn.fhir.rest.api.server.IRestfulServer; +import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.server.IPagingProvider; +import ca.uhn.fhir.rest.server.RestfulServerUtils; import ca.uhn.fhir.rest.server.RestfulServerUtils.ResponseEncoding; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; -import ca.uhn.fhir.util.CoverageIgnore; public class PageMethodBinding extends BaseResourceReturningMethodBinding { @@ -144,31 +149,6 @@ public class PageMethodBinding extends BaseResourceReturningMethodBinding { return bundle; } return bundleFactory.getResourceBundle(); - // if (bundle != null) { - // for (int i = getInterceptors().size() - 1; i >= 0; i--) { - // IServerInterceptor next = getInterceptors().get(i); - // boolean continueProcessing = next.outgoingResponse(theRequest, bundle, theRequest.getServletRequest(), - // theRequest.getServletResponse()); - // if (!continueProcessing) { - // ourLog.debug("Interceptor {} returned false, not continuing processing"); - // return; - // } - // } - // theRequest.getResponse().streamResponseAsBundle(bundle, summaryMode, respondGzip, requestIsBrowser); - // } else { - // IBaseResource resBundle = bundleFactory.getResourceBundle(); - // for (int i = getInterceptors().size() - 1; i >= 0; i--) { - // IServerInterceptor next = getInterceptors().get(i); - // boolean continueProcessing = next.outgoingResponse(theRequest, resBundle, theRequest.getServletRequest(), - // theRequest.getServletResponse()); - // if (!continueProcessing) { - // ourLog.debug("Interceptor {} returned false, not continuing processing"); - // return; - // } - // } - // theRequest.getResponse().streamResponseAsResource(resBundle, prettyPrint, summaryMode, - // Constants.STATUS_HTTP_200_OK, theRequest.isRespondGzip(), false); - // } } @Override @@ -188,10 +168,5 @@ public class PageMethodBinding extends BaseResourceReturningMethodBinding { return true; } - @CoverageIgnore - @Override - public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException { - throw new UnsupportedOperationException(); - } } diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/PatchMethodBinding.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/PatchMethodBinding.java index d011b992212..c953a268578 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/PatchMethodBinding.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/PatchMethodBinding.java @@ -22,21 +22,21 @@ package ca.uhn.fhir.rest.server.method; import java.lang.annotation.Annotation; import java.lang.reflect.Method; -import java.util.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.ListIterator; +import java.util.Set; import org.hl7.fhir.instance.model.api.IIdType; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.rest.annotation.Patch; import ca.uhn.fhir.rest.annotation.ResourceParam; -import ca.uhn.fhir.rest.api.*; +import ca.uhn.fhir.rest.api.PatchTypeEnum; +import ca.uhn.fhir.rest.api.RequestTypeEnum; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; -import ca.uhn.fhir.rest.param.IParameter; -import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; -import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; /** * Base class for an operation that has a resource type but not a resource body in the @@ -91,54 +91,7 @@ public class PatchMethodBinding extends BaseOutcomeReturningMethodBindingWithRes return Collections.singleton(RequestTypeEnum.PATCH); } - @Override - protected BaseHttpClientInvocation createClientInvocation(Object[] theArgs, IResource theResource) { - StringBuilder urlExtension = new StringBuilder(); - urlExtension.append(getContext().getResourceDefinition(theResource).getName()); - return new HttpPostClientInvocation(getContext(), theResource, urlExtension.toString()); - } - - @Override - protected boolean allowVoidReturnType() { - return true; - } - - @Override - public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException { - IIdType idDt = (IIdType) theArgs[getIdParameterIndex()]; - if (idDt == null) { - throw new NullPointerException("ID can not be null"); - } - - if (idDt.hasResourceType() == false) { - idDt = idDt.withResourceType(getResourceName()); - } else if (getResourceName().equals(idDt.getResourceType()) == false) { - throw new InvalidRequestException("ID parameter has the wrong resource type, expected '" + getResourceName() + "', found: " + idDt.getResourceType()); - } - - PatchTypeEnum patchType = (PatchTypeEnum) theArgs[myPatchTypeParameterIndex]; - String body = (String) theArgs[myResourceParamIndex]; - - HttpPatchClientInvocation retVal = createPatchInvocation(getContext(), idDt, patchType, body); - - for (int idx = 0; idx < theArgs.length; idx++) { - IParameter nextParam = getParameters().get(idx); - nextParam.translateClientArgumentIntoQueryArgument(getContext(), theArgs[idx], null, null); - } - - return retVal; - } - - public static HttpPatchClientInvocation createPatchInvocation(FhirContext theContext, IIdType theId, PatchTypeEnum thePatchType, String theBody) { - HttpPatchClientInvocation retVal = new HttpPatchClientInvocation(theContext, theId, thePatchType.getContentType(), theBody); - return retVal; - } - - public static HttpPatchClientInvocation createPatchInvocation(FhirContext theContext, String theUrlPath, PatchTypeEnum thePatchType, String theBody) { - HttpPatchClientInvocation retVal = new HttpPatchClientInvocation(theContext, theUrlPath, thePatchType.getContentType(), theBody); - return retVal; - } @Override protected void addParametersForServerRequest(RequestDetails theRequest, Object[] theParams) { @@ -152,11 +105,5 @@ public class PatchMethodBinding extends BaseOutcomeReturningMethodBindingWithRes return null; } - public static HttpPatchClientInvocation createPatchInvocation(FhirContext theContext, PatchTypeEnum thePatchType, String theBody, String theResourceType, Map> theMatchParams) { - StringBuilder urlBuilder = MethodUtil.createUrl(theResourceType, theMatchParams); - String url = urlBuilder.toString(); - HttpPatchClientInvocation retVal = new HttpPatchClientInvocation(theContext, url, thePatchType.getContentType(), theBody); - return retVal; - } } diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/PatchTypeParameter.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/PatchTypeParameter.java index 07946eb8965..ee28ab6b621 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/PatchTypeParameter.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/PatchTypeParameter.java @@ -24,23 +24,14 @@ import static org.apache.commons.lang3.StringUtils.defaultString; import java.lang.reflect.Method; import java.util.Collection; -import java.util.List; -import java.util.Map; -import org.hl7.fhir.instance.model.api.IBaseResource; - -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.rest.api.*; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.PatchTypeEnum; import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.param.IParameter; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; class PatchTypeParameter implements IParameter { - @Override - public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map> theTargetQueryArguments, IBaseResource theTargetResource) throws InternalErrorException { - // nothing - } @Override public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding theMethodBinding) throws InternalErrorException, InvalidRequestException { diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/RawParamsParmeter.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/RawParamsParmeter.java index eea96be5a47..f0d36f6efc2 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/RawParamsParmeter.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/RawParamsParmeter.java @@ -28,15 +28,12 @@ import java.util.List; import java.util.Map; import org.apache.commons.lang3.Validate; -import org.hl7.fhir.instance.model.api.IBaseResource; -import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.annotation.RawParam; import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.param.IParameter; +import ca.uhn.fhir.rest.param.QualifierDetails; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; -import ca.uhn.fhir.rest.server.method.SearchMethodBinding.QualifierDetails; public class RawParamsParmeter implements IParameter { @@ -46,12 +43,7 @@ public class RawParamsParmeter implements IParameter { myAllMethodParameters = theParameters; } - @Override - public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map> theTargetQueryArguments, IBaseResource theTargetResource) - throws InternalErrorException { - // not supported on client for now - } - + @Override public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding theMethodBinding) throws InternalErrorException, InvalidRequestException { HashMap> retVal = null; diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ReadMethodBinding.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ReadMethodBinding.java index 6a06682b8f2..1182d5d06b5 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ReadMethodBinding.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ReadMethodBinding.java @@ -2,51 +2,41 @@ package ca.uhn.fhir.rest.server.method; import static org.apache.commons.lang3.StringUtils.isNotBlank; -/* - * #%L - * HAPI FHIR - Core Library - * %% - * Copyright (C) 2014 - 2017 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import java.io.IOException; -import java.io.InputStream; import java.lang.reflect.Method; -import java.util.*; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; -import org.hl7.fhir.instance.model.api.*; +import org.hl7.fhir.instance.model.api.IAnyResource; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.instance.model.api.IIdType; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.api.*; +import ca.uhn.fhir.model.api.IResource; +import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.model.valueset.BundleTypeEnum; -import ca.uhn.fhir.rest.annotation.*; -import ca.uhn.fhir.rest.api.*; -import ca.uhn.fhir.rest.api.server.*; -import ca.uhn.fhir.rest.param.IParameter; -import ca.uhn.fhir.rest.server.*; -import ca.uhn.fhir.rest.server.exceptions.*; +import ca.uhn.fhir.rest.annotation.Elements; +import ca.uhn.fhir.rest.annotation.IdParam; +import ca.uhn.fhir.rest.annotation.Read; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.RequestTypeEnum; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import ca.uhn.fhir.rest.api.server.IBundleProvider; +import ca.uhn.fhir.rest.api.server.IRestfulServer; +import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.param.ParameterUtil; +import ca.uhn.fhir.rest.server.ETagSupportEnum; +import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; +import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; +import ca.uhn.fhir.rest.server.exceptions.NotModifiedException; import ca.uhn.fhir.util.DateUtils; -public class ReadMethodBinding extends BaseResourceReturningMethodBinding implements IClientResponseHandlerHandlesBinary { +public class ReadMethodBinding extends BaseResourceReturningMethodBinding { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ReadMethodBinding.class); private Integer myIdIndex; @@ -60,8 +50,8 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding implem Validate.notNull(theMethod, "Method must not be null"); - Integer idIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); - Integer versionIdIndex = MethodUtil.findVersionIdParameterIndex(theMethod); + Integer idIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext()); + Integer versionIdIndex = ParameterUtil.findVersionIdParameterIndex(theMethod); Class[] parameterTypes = theMethod.getParameterTypes(); @@ -147,60 +137,10 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding implem return true; } - @Override - public HttpGetClientInvocation invokeClient(Object[] theArgs) { - HttpGetClientInvocation retVal; - IIdType id = ((IIdType) theArgs[myIdIndex]); - if (myVersionIdIndex == null) { - String resourceName = getResourceName(); - if (id.hasVersionIdPart()) { - retVal = createVReadInvocation(getContext(), new IdDt(resourceName, id.getIdPart(), id.getVersionIdPart()), resourceName); - } else { - retVal = createReadInvocation(getContext(), id, resourceName); - } - } else { - IdDt vid = ((IdDt) theArgs[myVersionIdIndex]); - String resourceName = getResourceName(); - - retVal = createVReadInvocation(getContext(), new IdDt(resourceName, id.getIdPart(), vid.getVersionIdPart()), resourceName); - } - - for (int idx = 0; idx < theArgs.length; idx++) { - IParameter nextParam = getParameters().get(idx); - nextParam.translateClientArgumentIntoQueryArgument(getContext(), theArgs[idx], null, null); - } - - return retVal; - } - - @Override - public Object invokeClient(String theResponseMimeType, InputStream theResponseReader, int theResponseStatusCode, Map> theHeaders) throws IOException, BaseServerResponseException { - byte[] contents = IOUtils.toByteArray(theResponseReader); - - IBaseBinary resource = (IBaseBinary) getContext().getResourceDefinition("Binary").newInstance(); - resource.setContentType(theResponseMimeType); - resource.setContent(contents); - - switch (getMethodReturnType()) { - case BUNDLE: - return Bundle.withSingleResource((IResource) resource); - case LIST_OF_RESOURCES: - return Collections.singletonList(resource); - case RESOURCE: - return resource; - case BUNDLE_PROVIDER: - return new SimpleBundleProvider(resource); - case BUNDLE_RESOURCE: - case METHOD_OUTCOME: - break; - } - - throw new IllegalStateException("" + getMethodReturnType()); // should not happen - } @Override public IBundleProvider invokeServer(IRestfulServer theServer, RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException { - theMethodParams[myIdIndex] = MethodUtil.convertIdToType(theRequest.getId(), myIdParameterType); + theMethodParams[myIdIndex] = ParameterUtil.convertIdToType(theRequest.getId(), myIdParameterType); if (myVersionIdIndex != null) { theMethodParams[myVersionIdIndex] = new IdDt(theRequest.getId().getVersionIdPart()); } @@ -217,7 +157,7 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding implem if (theRequest.getServer().getETagSupport() == ETagSupportEnum.ENABLED) { String ifNoneMatch = theRequest.getHeader(Constants.HEADER_IF_NONE_MATCH_LC); if (StringUtils.isNotBlank(ifNoneMatch)) { - ifNoneMatch = MethodUtil.parseETagValue(ifNoneMatch); + ifNoneMatch = ParameterUtil.parseETagValue(ifNoneMatch); if (responseResource.getIdElement() != null && responseResource.getIdElement().hasVersionIdPart()) { if (responseResource.getIdElement().getVersionIdPart().equals(ifNoneMatch)) { ourLog.debug("Returning HTTP 301 because request specified {}={}", Constants.HEADER_IF_NONE_MATCH, ifNoneMatch); @@ -253,31 +193,15 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding implem return retVal; } - @Override - public boolean isBinary() { - return "Binary".equals(getResourceName()); - } +// @Override +// public boolean isBinary() { +// return "Binary".equals(getResourceName()); +// } public boolean isVread() { return mySupportsVersion || myVersionIdIndex != null; } - public static HttpGetClientInvocation createAbsoluteReadInvocation(FhirContext theContext, IIdType theId) { - return new HttpGetClientInvocation(theContext, theId.toVersionless().getValue()); - } - - public static HttpGetClientInvocation createAbsoluteVReadInvocation(FhirContext theContext, IIdType theId) { - return new HttpGetClientInvocation(theContext, theId.getValue()); - } - - public static HttpGetClientInvocation createReadInvocation(FhirContext theContext, IIdType theId, String theResourceName) { - return new HttpGetClientInvocation(theContext, new IdDt(theResourceName, theId.getIdPart()).getValue()); - } - - public static HttpGetClientInvocation createVReadInvocation(FhirContext theContext, IIdType theId, String theResourceName) { - return new HttpGetClientInvocation(theContext, new IdDt(theResourceName, theId.getIdPart(), theId.getVersionIdPart()).getValue()); - } - @Override protected BundleTypeEnum getResponseBundleType() { return null; diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/RequestDetailsParameter.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/RequestDetailsParameter.java index e32366fda76..0c07d62718e 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/RequestDetailsParameter.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/RequestDetailsParameter.java @@ -22,27 +22,14 @@ package ca.uhn.fhir.rest.server.method; import java.lang.reflect.Method; import java.util.Collection; -import java.util.List; -import java.util.Map; -import org.hl7.fhir.instance.model.api.IBaseResource; - -import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.param.IParameter; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; public class RequestDetailsParameter implements IParameter { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RequestDetailsParameter.class); - @Override - public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map> theTargetQueryArguments, IBaseResource theTargetResource) throws InternalErrorException { - /* - * Does nothing, since we just ignore HttpServletRequest arguments - */ - ourLog.trace("Ignoring RequestDetailsParameter argument: {}", theSourceClientArgument); - } @Override public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding theMethodBinding) throws InternalErrorException, InvalidRequestException { diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/RequestOperationCallbackParameter.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/RequestOperationCallbackParameter.java index cd9a3c7bc15..cbdbb05739a 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/RequestOperationCallbackParameter.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/RequestOperationCallbackParameter.java @@ -10,7 +10,7 @@ package ca.uhn.fhir.rest.server.method; * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,26 +22,12 @@ package ca.uhn.fhir.rest.server.method; import java.lang.reflect.Method; import java.util.Collection; -import java.util.List; -import java.util.Map; -import org.hl7.fhir.instance.model.api.IBaseResource; - -import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.param.IParameter; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; -import ca.uhn.fhir.util.CoverageIgnore; class RequestOperationCallbackParameter implements IParameter { -// private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ServletRequestParameter.class); - - @CoverageIgnore - @Override - public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map> theTargetQueryArguments, IBaseResource theTargetResource) throws InternalErrorException { - // nothing - } @Override public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding theMethodBinding) throws InternalErrorException, InvalidRequestException { diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ResourceParameter.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ResourceParameter.java index 158d013f577..b512d84f1a4 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ResourceParameter.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ResourceParameter.java @@ -21,7 +21,10 @@ package ca.uhn.fhir.rest.server.method; */ import static org.apache.commons.lang3.StringUtils.isBlank; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.nio.charset.Charset; @@ -34,11 +37,16 @@ import org.hl7.fhir.instance.model.api.IBaseResource; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirVersionEnum; -import ca.uhn.fhir.model.api.*; +import ca.uhn.fhir.model.api.IResource; +import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; +import ca.uhn.fhir.model.api.TagList; import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.parser.IParser; -import ca.uhn.fhir.rest.api.*; -import ca.uhn.fhir.rest.api.server.*; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.param.ParameterUtil; import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.RestfulServerUtils; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; @@ -49,7 +57,7 @@ public class ResourceParameter implements IParameter { private Mode myMode; private Class myResourceType; - public ResourceParameter(Class theParameterType, Object theProvider, Mode theMode) { + public ResourceParameter(Class theParameterType, Object theProvider, Mode theMode) { Validate.notNull(theParameterType, "theParameterType can not be null"); Validate.notNull(theMode, "theMode can not be null"); @@ -82,7 +90,7 @@ public class ResourceParameter implements IParameter { @Override - public Object translateQueryParametersIntoServerArgument(IRequestDetails theRequest, IServerMethodBinding theMethodBinding) throws InternalErrorException, InvalidRequestException { + public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding theMethodBinding) throws InternalErrorException, InvalidRequestException { switch (myMode) { case BODY: try { @@ -178,7 +186,7 @@ public class ResourceParameter implements IParameter { if (theRequest.getServer().getFhirContext().getVersion().getVersion().equals(FhirVersionEnum.DSTU1)) { TagList tagList = new TagList(); for (String nextTagComplete : theRequest.getHeaders(Constants.HEADER_CATEGORY)) { - MethodUtil.parseTagValue(tagList, nextTagComplete); + ParameterUtil.parseTagValue(tagList, nextTagComplete); } if (tagList.isEmpty() == false) { ((IResource) retVal).getResourceMetadata().put(ResourceMetadataKeyEnum.TAG_LIST, tagList); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/SearchMethodBinding.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/SearchMethodBinding.java index cd781fc48e4..38644410618 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/SearchMethodBinding.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/SearchMethodBinding.java @@ -24,12 +24,8 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.Collections; import java.util.HashSet; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import org.apache.commons.lang3.StringUtils; @@ -38,14 +34,16 @@ import org.hl7.fhir.instance.model.api.IBaseResource; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.annotation.Description; -import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.annotation.Search; -import ca.uhn.fhir.rest.api.*; -import ca.uhn.fhir.rest.api.server.*; -import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; -import ca.uhn.fhir.rest.param.BaseQueryParameter; -import ca.uhn.fhir.rest.param.IParameter; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.RequestTypeEnum; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import ca.uhn.fhir.rest.api.server.IBundleProvider; +import ca.uhn.fhir.rest.api.server.IRestfulServer; +import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.param.ParameterUtil; +import ca.uhn.fhir.rest.param.QualifierDetails; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; @@ -63,7 +61,7 @@ public class SearchMethodBinding extends BaseResourceReturningMethodBinding { Search search = theMethod.getAnnotation(Search.class); this.myQueryName = StringUtils.defaultIfBlank(search.queryName(), null); this.myCompartmentName = StringUtils.defaultIfBlank(search.compartmentName(), null); - this.myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); + this.myIdParamIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext()); this.myAllowUnknownParams = search.allowUnknownParams(); Description desc = theMethod.getAnnotation(Description.class); @@ -255,30 +253,6 @@ public class SearchMethodBinding extends BaseResourceReturningMethodBinding { return true; } - @Override - public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException { - assert (myQueryName == null || ((theArgs != null ? theArgs.length : 0) == getParameters().size())) : "Wrong number of arguments: " + (theArgs != null ? theArgs.length : "null"); - - Map> queryStringArgs = new LinkedHashMap>(); - - if (myQueryName != null) { - queryStringArgs.put(Constants.PARAM_QUERY, Collections.singletonList(myQueryName)); - } - - IdDt id = (IdDt) (myIdParamIndex != null ? theArgs[myIdParamIndex] : null); - - String resourceName = getResourceName(); - if (theArgs != null) { - for (int idx = 0; idx < theArgs.length; idx++) { - IParameter nextParam = getParameters().get(idx); - nextParam.translateClientArgumentIntoQueryArgument(getContext(), theArgs[idx], queryStringArgs, null); - } - } - - BaseHttpClientInvocation retVal = createSearchInvocation(getContext(), resourceName, queryStringArgs, id, myCompartmentName, null); - - return retVal; - } @Override public IBundleProvider invokeServer(IRestfulServer theServer, RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException { @@ -316,70 +290,52 @@ public class SearchMethodBinding extends BaseResourceReturningMethodBinding { public String toString() { return getMethod().toString(); } + public static QualifierDetails extractQualifiersFromParameterName(String theParamName) { + QualifierDetails retVal = new QualifierDetails(); + if (theParamName == null || theParamName.length() == 0) { + return retVal; + } - public static BaseHttpClientInvocation createSearchInvocation(FhirContext theContext, String theResourceName, Map> theParameters, IdDt theId, String theCompartmentName, - SearchStyleEnum theSearchStyle) { - SearchStyleEnum searchStyle = theSearchStyle; - if (searchStyle == null) { - int length = 0; - for (Entry> nextEntry : theParameters.entrySet()) { - length += nextEntry.getKey().length(); - for (String next : nextEntry.getValue()) { - length += next.length(); - } - } - - if (length < 5000) { - searchStyle = SearchStyleEnum.GET; - } else { - searchStyle = SearchStyleEnum.POST; + int dotIdx = -1; + int colonIdx = -1; + for (int idx = 0; idx < theParamName.length(); idx++) { + char nextChar = theParamName.charAt(idx); + if (nextChar == '.' && dotIdx == -1) { + dotIdx = idx; + } else if (nextChar == ':' && colonIdx == -1) { + colonIdx = idx; } } - BaseHttpClientInvocation invocation; - - boolean compartmentSearch = false; - if (theCompartmentName != null) { - if (theId == null || !theId.hasIdPart()) { - String msg = theContext.getLocalizer().getMessage(SearchMethodBinding.class.getName() + ".idNullForCompartmentSearch"); - throw new InvalidRequestException(msg); + if (dotIdx != -1 && colonIdx != -1) { + if (dotIdx < colonIdx) { + retVal.setDotQualifier(theParamName.substring(dotIdx, colonIdx)); + retVal.setColonQualifier(theParamName.substring(colonIdx)); + retVal.setParamName(theParamName.substring(0, dotIdx)); + retVal.setWholeQualifier(theParamName.substring(dotIdx)); + } else { + retVal.setColonQualifier(theParamName.substring(colonIdx, dotIdx)); + retVal.setDotQualifier(theParamName.substring(dotIdx)); + retVal.setParamName(theParamName.substring(0, colonIdx)); + retVal.setWholeQualifier(theParamName.substring(colonIdx)); } - compartmentSearch = true; + } else if (dotIdx != -1) { + retVal.setDotQualifier(theParamName.substring(dotIdx)); + retVal.setParamName(theParamName.substring(0, dotIdx)); + retVal.setWholeQualifier(theParamName.substring(dotIdx)); + } else if (colonIdx != -1) { + retVal.setColonQualifier(theParamName.substring(colonIdx)); + retVal.setParamName(theParamName.substring(0, colonIdx)); + retVal.setWholeQualifier(theParamName.substring(colonIdx)); + } else { + retVal.setParamName(theParamName); + retVal.setColonQualifier(null); + retVal.setDotQualifier(null); + retVal.setWholeQualifier(null); } - /* - * Are we doing a get (GET [base]/Patient?name=foo) or a get with search (GET [base]/Patient/_search?name=foo) or a post (POST [base]/Patient with parameters in the POST body) - */ - switch (searchStyle) { - case GET: - default: - if (compartmentSearch) { - invocation = new HttpGetClientInvocation(theContext, theParameters, theResourceName, theId.getIdPart(), theCompartmentName); - } else { - invocation = new HttpGetClientInvocation(theContext, theParameters, theResourceName); - } - break; - case GET_WITH_SEARCH: - if (compartmentSearch) { - invocation = new HttpGetClientInvocation(theContext, theParameters, theResourceName, theId.getIdPart(), theCompartmentName, Constants.PARAM_SEARCH); - } else { - invocation = new HttpGetClientInvocation(theContext, theParameters, theResourceName, Constants.PARAM_SEARCH); - } - break; - case POST: - if (compartmentSearch) { - invocation = new HttpPostClientInvocation(theContext, theParameters, theResourceName, theId.getIdPart(), theCompartmentName, Constants.PARAM_SEARCH); - } else { - invocation = new HttpPostClientInvocation(theContext, theParameters, theResourceName, Constants.PARAM_SEARCH); - } - } - - return invocation; + return retVal; } - public static BaseHttpClientInvocation createSearchInvocation(FhirContext theContext, String theSearchUrl, Map> theParams) { - return new HttpGetClientInvocation(theContext, theParams, theSearchUrl); - } - } diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ServerBaseParamBinder.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ServerBaseParamBinder.java index 6d63da34ff7..ad477cbda82 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ServerBaseParamBinder.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ServerBaseParamBinder.java @@ -22,27 +22,12 @@ package ca.uhn.fhir.rest.server.method; import java.lang.reflect.Method; import java.util.Collection; -import java.util.List; -import java.util.Map; -import org.hl7.fhir.instance.model.api.IBaseResource; - -import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.param.IParameter; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; class ServerBaseParamBinder implements IParameter { - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ServerBaseParamBinder.class); - - @Override - public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map> theTargetQueryArguments, IBaseResource theTargetResource) throws InternalErrorException { - /* - * Does nothing, since we just ignore serverbase arguments - */ - ourLog.trace("Ignoring server base argument: {}", theSourceClientArgument); - } @Override public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding theMethodBinding) throws InternalErrorException, InvalidRequestException { diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ServletRequestParameter.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ServletRequestParameter.java index 545ed872c99..d0b8a64dcb3 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ServletRequestParameter.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ServletRequestParameter.java @@ -22,14 +22,8 @@ package ca.uhn.fhir.rest.server.method; import java.lang.reflect.Method; import java.util.Collection; -import java.util.List; -import java.util.Map; -import org.hl7.fhir.instance.model.api.IBaseResource; - -import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.param.IParameter; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; @@ -41,14 +35,6 @@ class ServletRequestParameter implements IParameter { super(); } - @Override - public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map> theTargetQueryArguments, IBaseResource theTargetResource) throws InternalErrorException { - /* - * Does nothing, since we just ignore HttpServletRequest arguments - */ - ourLog.trace("Ignoring HttpServletRequest argument: {}", theSourceClientArgument); - } - @Override public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding theMethodBinding) throws InternalErrorException, InvalidRequestException { return ((ServletRequestDetails) theRequest).getServletRequest(); diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ServletResponseParameter.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ServletResponseParameter.java index dd5f43941cf..6bcea730f20 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ServletResponseParameter.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ServletResponseParameter.java @@ -10,7 +10,7 @@ package ca.uhn.fhir.rest.server.method; * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,14 +22,8 @@ package ca.uhn.fhir.rest.server.method; import java.lang.reflect.Method; import java.util.Collection; -import java.util.List; -import java.util.Map; -import org.hl7.fhir.instance.model.api.IBaseResource; - -import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.param.IParameter; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; @@ -37,20 +31,11 @@ import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; class ServletResponseParameter implements IParameter { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ServletResponseParameter.class); - @Override - public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map> theTargetQueryArguments, IBaseResource theTargetResource) throws InternalErrorException { - /* - * Does nothing, since we just ignore HttpServletResponse arguments - */ - ourLog.trace("Ignoring HttpServletResponse argument: {}", theSourceClientArgument); - } - @Override public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding theMethodBinding) throws InternalErrorException, InvalidRequestException { - return ((ServletRequestDetails) theRequest).getServletResponse(); + return ((ServletRequestDetails) theRequest).getServletResponse(); } - @Override public void initializeTypes(Method theMethod, Class> theOuterCollectionType, Class> theInnerCollectionType, Class theParameterType) { // ignore diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/SortParameter.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/SortParameter.java index c3fd51fc75a..c36d5207d51 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/SortParameter.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/SortParameter.java @@ -10,7 +10,7 @@ package ca.uhn.fhir.rest.server.method; * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -22,21 +22,13 @@ package ca.uhn.fhir.rest.server.method; import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.lang.reflect.Method; -import java.util.ArrayList; import java.util.Collection; -import java.util.List; -import java.util.Map; import java.util.StringTokenizer; -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.context.*; import ca.uhn.fhir.rest.annotation.Sort; import ca.uhn.fhir.rest.api.*; import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.param.IParameter; import ca.uhn.fhir.rest.param.ParameterUtil; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; @@ -52,51 +44,16 @@ public class SortParameter implements IParameter { @Override public void initializeTypes(Method theMethod, Class> theOuterCollectionType, Class> theInnerCollectionType, Class theParameterType) { if (theOuterCollectionType != null || theInnerCollectionType != null) { - throw new ConfigurationException("Method '" + theMethod.getName() + "' in type '" + theMethod.getDeclaringClass().getCanonicalName() + "' is annotated with @" + Sort.class.getName() + " but can not be of collection type"); + throw new ConfigurationException("Method '" + theMethod.getName() + "' in type '" + theMethod.getDeclaringClass().getCanonicalName() + "' is annotated with @" + Sort.class.getName() + + " but can not be of collection type"); } if (!theParameterType.equals(SortSpec.class)) { - throw new ConfigurationException("Method '" + theMethod.getName() + "' in type '" + theMethod.getDeclaringClass().getCanonicalName() + "' is annotated with @" + Sort.class.getName() + " but is an invalid type, must be: " + SortSpec.class.getCanonicalName()); + throw new ConfigurationException("Method '" + theMethod.getName() + "' in type '" + theMethod.getDeclaringClass().getCanonicalName() + "' is annotated with @" + Sort.class.getName() + + " but is an invalid type, must be: " + SortSpec.class.getCanonicalName()); } } - @Override - public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map> theTargetQueryArguments, IBaseResource theTargetResource) throws InternalErrorException { - SortSpec ss = (SortSpec) theSourceClientArgument; - - if (myContext.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU2)) { - String string = createSortStringDstu3(ss); - if (string.length() > 0) { - if (!theTargetQueryArguments.containsKey(Constants.PARAM_SORT)) { - theTargetQueryArguments.put(Constants.PARAM_SORT, new ArrayList()); - } - theTargetQueryArguments.get(Constants.PARAM_SORT).add(string); - } - - } else { - - while (ss != null) { - String name; - if (ss.getOrder() == null) { - name = Constants.PARAM_SORT; - } else if (ss.getOrder() == SortOrderEnum.ASC) { - name = Constants.PARAM_SORT_ASC; - } else { - name = Constants.PARAM_SORT_DESC; - } - - if (ss.getParamName() != null) { - if (!theTargetQueryArguments.containsKey(name)) { - theTargetQueryArguments.put(name, new ArrayList()); - } - - theTargetQueryArguments.get(name).add(ss.getParamName()); - } - ss = ss.getChain(); - } - } - } - @Override public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding theMethodBinding) throws InternalErrorException, InvalidRequestException { if (!theRequest.getParameters().containsKey(Constants.PARAM_SORT)) { diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/SummaryEnumParameter.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/SummaryEnumParameter.java index f195811818f..b962467a413 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/SummaryEnumParameter.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/SummaryEnumParameter.java @@ -22,22 +22,13 @@ package ca.uhn.fhir.rest.server.method; import static org.apache.commons.lang3.StringUtils.isBlank; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.hl7.fhir.instance.model.api.IBaseResource; +import java.util.*; import ca.uhn.fhir.context.ConfigurationException; -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.rest.api.*; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.SummaryEnum; import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.param.CollectionBinder; -import ca.uhn.fhir.rest.param.IParameter; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; @@ -46,24 +37,6 @@ public class SummaryEnumParameter implements IParameter { @SuppressWarnings("rawtypes") private Class myInnerCollectionType; - @SuppressWarnings("unchecked") - @Override - public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map> theTargetQueryArguments, IBaseResource theTargetResource) throws InternalErrorException { - if (theSourceClientArgument instanceof Collection) { - List values = new ArrayList(); - for (SummaryEnum next : (Collection) theSourceClientArgument) { - if (next != null) { - values.add(next.getCode()); - } - } - theTargetQueryArguments.put(Constants.PARAM_SUMMARY, values); - } else { - SummaryEnum ss = (SummaryEnum) theSourceClientArgument; - if (ss != null) { - theTargetQueryArguments.put(Constants.PARAM_SUMMARY, Collections.singletonList(ss.getCode())); - } - } - } @Override @SuppressWarnings({ "rawtypes", "unchecked" }) diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/TransactionMethodBinding.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/TransactionMethodBinding.java index eb62c3f4b37..6e1795723d3 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/TransactionMethodBinding.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/TransactionMethodBinding.java @@ -10,7 +10,7 @@ package ca.uhn.fhir.rest.server.method; * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -25,7 +25,6 @@ import java.lang.reflect.Method; import java.util.IdentityHashMap; import java.util.List; -import org.hl7.fhir.instance.model.api.IBaseBundle; import org.hl7.fhir.instance.model.api.IBaseResource; import ca.uhn.fhir.context.ConfigurationException; @@ -38,10 +37,11 @@ import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.annotation.Transaction; import ca.uhn.fhir.rest.annotation.TransactionParam; -import ca.uhn.fhir.rest.api.*; -import ca.uhn.fhir.rest.api.server.*; -import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; -import ca.uhn.fhir.rest.param.*; +import ca.uhn.fhir.rest.api.RequestTypeEnum; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import ca.uhn.fhir.rest.api.server.IBundleProvider; +import ca.uhn.fhir.rest.api.server.IRestfulServer; +import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; @@ -60,7 +60,8 @@ public class TransactionMethodBinding extends BaseResourceReturningMethodBinding for (IParameter next : getParameters()) { if (next instanceof TransactionParameter) { if (myTransactionParamIndex != -1) { - throw new ConfigurationException("Method '" + theMethod.getName() + "' in type " + theMethod.getDeclaringClass().getCanonicalName() + " has multiple parameters annotated with the @" + TransactionParam.class + " annotation, exactly one is required for @" + Transaction.class + throw new ConfigurationException("Method '" + theMethod.getName() + "' in type " + theMethod.getDeclaringClass().getCanonicalName() + " has multiple parameters annotated with the @" + + TransactionParam.class + " annotation, exactly one is required for @" + Transaction.class + " methods"); } myTransactionParamIndex = index; @@ -70,7 +71,8 @@ public class TransactionMethodBinding extends BaseResourceReturningMethodBinding } if (myTransactionParamIndex == -1) { - throw new ConfigurationException("Method '" + theMethod.getName() + "' in type " + theMethod.getDeclaringClass().getCanonicalName() + " does not have a parameter annotated with the @" + TransactionParam.class + " annotation"); + throw new ConfigurationException("Method '" + theMethod.getName() + "' in type " + theMethod.getDeclaringClass().getCanonicalName() + " does not have a parameter annotated with the @" + + TransactionParam.class + " annotation"); } } @@ -103,18 +105,6 @@ public class TransactionMethodBinding extends BaseResourceReturningMethodBinding return true; } - @Override - public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException { - FhirContext context = getContext(); - if (theArgs[myTransactionParamIndex] instanceof Bundle) { - Bundle bundle = (Bundle) theArgs[myTransactionParamIndex]; - return createTransactionInvocation(bundle, context); - } - @SuppressWarnings("unchecked") - List resources = (List) theArgs[myTransactionParamIndex]; - return createTransactionInvocation(resources, context); - } - @SuppressWarnings("unchecked") @Override public Object invokeServer(IRestfulServer theServer, RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException { @@ -166,7 +156,7 @@ public class TransactionMethodBinding extends BaseResourceReturningMethodBinding if (oldId != null && !oldId.isEmpty()) { if (!oldId.equals(newRes.getIdElement()) && newRes instanceof IResource) { - ((IResource)newRes).getResourceMetadata().put(ResourceMetadataKeyEnum.PREVIOUS_ID, oldId); + ((IResource) newRes).getResourceMetadata().put(ResourceMetadataKeyEnum.PREVIOUS_ID, oldId); } } } @@ -174,11 +164,10 @@ public class TransactionMethodBinding extends BaseResourceReturningMethodBinding return retVal; } - @Override protected void populateActionRequestDetailsForInterceptor(RequestDetails theRequestDetails, ActionRequestDetails theDetails, Object[] theMethodParams) { super.populateActionRequestDetailsForInterceptor(theRequestDetails, theDetails, theMethodParams); - + /* * If the method has no parsed resource parameter, we parse here in order to have something for the interceptor. */ @@ -191,20 +180,4 @@ public class TransactionMethodBinding extends BaseResourceReturningMethodBinding } - public static BaseHttpClientInvocation createTransactionInvocation(Bundle theBundle, FhirContext theContext) { - return new HttpPostClientInvocation(theContext, theBundle); - } - - public static BaseHttpClientInvocation createTransactionInvocation(IBaseBundle theBundle, FhirContext theContext) { - return new HttpPostClientInvocation(theContext, theBundle); - } - - public static BaseHttpClientInvocation createTransactionInvocation(List theResources, FhirContext theContext) { - return new HttpPostClientInvocation(theContext, theResources, BundleTypeEnum.TRANSACTION); - } - - public static BaseHttpClientInvocation createTransactionInvocation(String theRawBundle, FhirContext theContext) { - return new HttpPostClientInvocation(theContext, theRawBundle, true, ""); - } - } diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/TransactionParameter.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/TransactionParameter.java index 060799599f8..46768772792 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/TransactionParameter.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/TransactionParameter.java @@ -38,10 +38,8 @@ import ca.uhn.fhir.model.api.BundleEntry; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.rest.annotation.TransactionParam; -import ca.uhn.fhir.rest.method.BaseMethodBinding; -import ca.uhn.fhir.rest.method.IParameter; -import ca.uhn.fhir.rest.method.RequestDetails; -import ca.uhn.fhir.rest.server.EncodingEnum; +import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.server.RestfulServerUtils; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; @@ -92,11 +90,6 @@ public class TransactionParameter implements IParameter { } } - @Override - public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map> theTargetQueryArguments, IBaseResource theTargetResource) throws InternalErrorException { - // nothing - - } @Override public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding theMethodBinding) throws InternalErrorException, InvalidRequestException { diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/UpdateMethodBinding.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/UpdateMethodBinding.java index 222a898dab4..35369fe66bc 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/UpdateMethodBinding.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/UpdateMethodBinding.java @@ -30,23 +30,19 @@ import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.api.IResource; -import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.annotation.Update; -import ca.uhn.fhir.rest.api.*; +import ca.uhn.fhir.rest.api.Constants; +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.api.server.RequestDetails; -import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; -import ca.uhn.fhir.rest.param.IParameter; +import ca.uhn.fhir.rest.param.ParameterUtil; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; public class UpdateMethodBinding extends BaseOutcomeReturningMethodBindingWithResourceParam { - private Integer myIdParameterIndex; - public UpdateMethodBinding(Method theMethod, FhirContext theContext, Object theProvider) { super(theMethod, theContext, Update.class, theProvider); - - myIdParameterIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); } @Override @@ -89,7 +85,7 @@ public class UpdateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe public static IIdType applyETagAsVersion(RequestDetails theRequest, IIdType id) { String ifMatchValue = theRequest.getHeader(Constants.HEADER_IF_MATCH); if (isNotBlank(ifMatchValue)) { - ifMatchValue = MethodUtil.parseETagValue(ifMatchValue); + ifMatchValue = ParameterUtil.parseETagValue(ifMatchValue); if (id != null && id.hasVersionIdPart() == false) { id = id.withVersion(ifMatchValue); } @@ -97,25 +93,6 @@ public class UpdateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe return id; } - @Override - protected BaseHttpClientInvocation createClientInvocation(Object[] theArgs, IResource theResource) { - IdDt idDt = (IdDt) theArgs[myIdParameterIndex]; - if (idDt == null) { - throw new NullPointerException("ID can not be null"); - } - - FhirContext context = getContext(); - - HttpPutClientInvocation retVal = MethodUtil.createUpdateInvocation(theResource, null, idDt, context); - - for (int idx = 0; idx < theArgs.length; idx++) { - IParameter nextParam = getParameters().get(idx); - nextParam.translateClientArgumentIntoQueryArgument(getContext(), theArgs[idx], null, null); - } - - return retVal; - } - @Override protected String getMatchingOperation() { return null; @@ -154,8 +131,8 @@ public class UpdateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe throw new InvalidRequestException(msg); } } else { - theResource.setId((IIdType)null); + theResource.setId((IIdType) null); } - + } } diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ValidateMethodBindingDstu1.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ValidateMethodBindingDstu1.java index 5ef0b120862..3a69ac9a514 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ValidateMethodBindingDstu1.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ValidateMethodBindingDstu1.java @@ -24,16 +24,13 @@ import java.lang.reflect.Method; import java.util.Collections; import java.util.Set; -import org.hl7.fhir.instance.model.api.IBaseResource; - import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.api.IResource; -import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.annotation.Validate; -import ca.uhn.fhir.rest.api.*; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.RequestTypeEnum; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; -import ca.uhn.fhir.rest.param.IParameter; +import ca.uhn.fhir.rest.param.ParameterUtil; public class ValidateMethodBindingDstu1 extends BaseOutcomeReturningMethodBindingWithResourceParam { @@ -42,7 +39,7 @@ public class ValidateMethodBindingDstu1 extends BaseOutcomeReturningMethodBindin public ValidateMethodBindingDstu1(Method theMethod, FhirContext theContext, Object theProvider) { super(theMethod, theContext, Validate.class, theProvider); - myIdParameterIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); + myIdParameterIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext()); } @Override @@ -57,40 +54,6 @@ public class ValidateMethodBindingDstu1 extends BaseOutcomeReturningMethodBindin } } - @Override - protected BaseHttpClientInvocation createClientInvocation(Object[] theArgs, IResource theResource) { - FhirContext context = getContext(); - - IdDt idDt=null; - if (myIdParameterIndex != null) { - idDt = (IdDt) theArgs[myIdParameterIndex]; - } - - HttpPostClientInvocation retVal = createValidateInvocation(theResource, idDt, context); - - for (int idx = 0; idx < theArgs.length; idx++) { - IParameter nextParam = getParameters().get(idx); - nextParam.translateClientArgumentIntoQueryArgument(getContext(), theArgs[idx], null, null); - } - - return retVal; - } - - public static HttpPostClientInvocation createValidateInvocation(IBaseResource theResource, IdDt theId, FhirContext theContext) { - StringBuilder urlExtension = new StringBuilder(); - urlExtension.append(theContext.getResourceDefinition(theResource).getName()); - urlExtension.append('/'); - urlExtension.append(Constants.PARAM_VALIDATE); - - if (theId != null && theId.isEmpty() == false) { - String id = theId.getValue(); - urlExtension.append('/'); - urlExtension.append(id); - } - // TODO: is post correct here? - HttpPostClientInvocation retVal = new HttpPostClientInvocation(theContext, theResource, urlExtension.toString()); - return retVal; - } @Override diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ValidateMethodBindingDstu2Plus.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ValidateMethodBindingDstu2Plus.java index a585d41578e..e434536e711 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ValidateMethodBindingDstu2Plus.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/method/ValidateMethodBindingDstu2Plus.java @@ -10,7 +10,7 @@ package ca.uhn.fhir.rest.server.method; * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,7 +24,6 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; -import org.hl7.fhir.instance.model.api.IBaseParameters; import org.hl7.fhir.instance.model.api.IBaseResource; import ca.uhn.fhir.context.FhirContext; @@ -33,9 +32,6 @@ import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.annotation.Validate; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.EncodingEnum; -import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; -import ca.uhn.fhir.rest.param.IParameter; -import ca.uhn.fhir.util.ParametersUtil; public class ValidateMethodBindingDstu2Plus extends OperationMethodBinding { @@ -67,18 +63,5 @@ public class ValidateMethodBindingDstu2Plus extends OperationMethodBinding { setParameters(newParams); } - - - public static BaseHttpClientInvocation createValidateInvocation(FhirContext theContext, IBaseResource theResource) { - IBaseParameters parameters = (IBaseParameters) theContext.getResourceDefinition("Parameters").newInstance(); - ParametersUtil.addParameterToParameters(theContext, parameters, theResource, "resource"); - - String resourceName = theContext.getResourceDefinition(theResource).getName(); - String resourceId = theResource.getIdElement().getIdPart(); - - BaseHttpClientInvocation retVal = createOperationInvocation(theContext, resourceName, resourceId, Constants.EXTOP_VALIDATE, parameters, false); - return retVal; - } - } diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/servlet/ServletRequestDetails.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/servlet/ServletRequestDetails.java index 16d9466c6c6..936254547b2 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/servlet/ServletRequestDetails.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/servlet/ServletRequestDetails.java @@ -21,23 +21,18 @@ package ca.uhn.fhir.rest.server.servlet; */ import static org.apache.commons.lang3.StringUtils.isNotBlank; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; +import java.io.*; import java.nio.charset.Charset; -import java.util.Collections; -import java.util.Enumeration; -import java.util.List; +import java.util.*; import java.util.zip.GZIPInputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; -import org.apache.http.entity.ContentType; import ca.uhn.fhir.context.ConfigurationException; +import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.server.RestfulServer; @@ -166,14 +161,26 @@ public class ServletRequestDetails extends RequestDetails { @Override public Charset getCharset() { - String ct = getHeader(Constants.HEADER_CONTENT_TYPE); - Charset charset = null; - if (isNotBlank(ct)) { - ContentType parsedCt = ContentType.parse(ct); - charset = parsedCt.getCharset(); + + String charsetString = myServletResponse.getCharacterEncoding(); + if (isNotBlank(charsetString)) { + charset = Charset.forName(charsetString); } + +// String ct = getHeader(Constants.HEADER_CONTENT_TYPE); +// +// if (isNotBlank(ct)) { +// ContentType parsedCt = ContentType.parse(ct); +// charset = parsedCt.getCharset(); +// } + return charset; } + @Override + public FhirContext getFhirContext() { + return getServer().getFhirContext(); + } + }