From 2f367a1a4e0f7410ca4b52574ceab39cfdd6abb1 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 16 Mar 2017 21:32:59 -0400 Subject: [PATCH] Get process message working --- .../uhn/fhir/rest/client/GenericClient.java | 221 +++++++++++++++--- .../rest/method/OperationMethodBinding.java | 61 ++--- 2 files changed, 229 insertions(+), 53 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java index 67251bdbd0a..53d61b986d3 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java @@ -24,15 +24,41 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.io.IOException; import java.io.Reader; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +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.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.IBase; +import org.hl7.fhir.instance.model.api.IBaseBundle; +import org.hl7.fhir.instance.model.api.IBaseConformance; +import org.hl7.fhir.instance.model.api.IBaseDatatype; +import org.hl7.fhir.instance.model.api.IBaseMetaType; +import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; +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.*; +import ca.uhn.fhir.context.BaseRuntimeChildDefinition; +import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition; +import ca.uhn.fhir.context.BaseRuntimeElementDefinition; +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; +import ca.uhn.fhir.context.IRuntimeDatatypeDefinition; +import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.model.api.Bundle; import ca.uhn.fhir.model.api.IQueryParameterType; import ca.uhn.fhir.model.api.Include; @@ -45,13 +71,84 @@ import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.model.primitive.UriDt; import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.parser.IParser; -import ca.uhn.fhir.rest.api.*; +import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.api.PatchTypeEnum; +import ca.uhn.fhir.rest.api.PreferReturnEnum; +import ca.uhn.fhir.rest.api.SortOrderEnum; +import ca.uhn.fhir.rest.api.SortSpec; +import ca.uhn.fhir.rest.api.SummaryEnum; import ca.uhn.fhir.rest.client.api.IHttpClient; import ca.uhn.fhir.rest.client.api.IHttpRequest; import ca.uhn.fhir.rest.client.exceptions.NonFhirResponseException; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; -import ca.uhn.fhir.rest.gclient.*; -import ca.uhn.fhir.rest.method.*; +import ca.uhn.fhir.rest.gclient.IClientExecutable; +import ca.uhn.fhir.rest.gclient.ICreate; +import ca.uhn.fhir.rest.gclient.ICreateTyped; +import ca.uhn.fhir.rest.gclient.ICreateWithQuery; +import ca.uhn.fhir.rest.gclient.ICreateWithQueryTyped; +import ca.uhn.fhir.rest.gclient.ICriterion; +import ca.uhn.fhir.rest.gclient.ICriterionInternal; +import ca.uhn.fhir.rest.gclient.IDelete; +import ca.uhn.fhir.rest.gclient.IDeleteTyped; +import ca.uhn.fhir.rest.gclient.IDeleteWithQuery; +import ca.uhn.fhir.rest.gclient.IDeleteWithQueryTyped; +import ca.uhn.fhir.rest.gclient.IFetchConformanceTyped; +import ca.uhn.fhir.rest.gclient.IFetchConformanceUntyped; +import ca.uhn.fhir.rest.gclient.IGetPage; +import ca.uhn.fhir.rest.gclient.IGetPageTyped; +import ca.uhn.fhir.rest.gclient.IGetPageUntyped; +import ca.uhn.fhir.rest.gclient.IGetTags; +import ca.uhn.fhir.rest.gclient.IHistory; +import ca.uhn.fhir.rest.gclient.IHistoryTyped; +import ca.uhn.fhir.rest.gclient.IHistoryUntyped; +import ca.uhn.fhir.rest.gclient.IMeta; +import ca.uhn.fhir.rest.gclient.IMetaAddOrDeleteSourced; +import ca.uhn.fhir.rest.gclient.IMetaAddOrDeleteUnsourced; +import ca.uhn.fhir.rest.gclient.IMetaGetUnsourced; +import ca.uhn.fhir.rest.gclient.IOperation; +import ca.uhn.fhir.rest.gclient.IOperationProcessMsg; +import ca.uhn.fhir.rest.gclient.IOperationProcessMsgMode; +import ca.uhn.fhir.rest.gclient.IOperationUnnamed; +import ca.uhn.fhir.rest.gclient.IOperationUntyped; +import ca.uhn.fhir.rest.gclient.IOperationUntypedWithInput; +import ca.uhn.fhir.rest.gclient.IOperationUntypedWithInputAndPartialOutput; +import ca.uhn.fhir.rest.gclient.IParam; +import ca.uhn.fhir.rest.gclient.IPatch; +import ca.uhn.fhir.rest.gclient.IPatchExecutable; +import ca.uhn.fhir.rest.gclient.IPatchWithBody; +import ca.uhn.fhir.rest.gclient.IPatchWithQuery; +import ca.uhn.fhir.rest.gclient.IPatchWithQueryTyped; +import ca.uhn.fhir.rest.gclient.IQuery; +import ca.uhn.fhir.rest.gclient.IRead; +import ca.uhn.fhir.rest.gclient.IReadExecutable; +import ca.uhn.fhir.rest.gclient.IReadIfNoneMatch; +import ca.uhn.fhir.rest.gclient.IReadTyped; +import ca.uhn.fhir.rest.gclient.ISort; +import ca.uhn.fhir.rest.gclient.ITransaction; +import ca.uhn.fhir.rest.gclient.ITransactionTyped; +import ca.uhn.fhir.rest.gclient.IUntypedQuery; +import ca.uhn.fhir.rest.gclient.IUpdate; +import ca.uhn.fhir.rest.gclient.IUpdateExecutable; +import ca.uhn.fhir.rest.gclient.IUpdateTyped; +import ca.uhn.fhir.rest.gclient.IUpdateWithQuery; +import ca.uhn.fhir.rest.gclient.IUpdateWithQueryTyped; +import ca.uhn.fhir.rest.gclient.IValidate; +import ca.uhn.fhir.rest.gclient.IValidateUntyped; +import ca.uhn.fhir.rest.method.DeleteMethodBinding; +import ca.uhn.fhir.rest.method.HistoryMethodBinding; +import ca.uhn.fhir.rest.method.HttpDeleteClientInvocation; +import ca.uhn.fhir.rest.method.HttpGetClientInvocation; +import ca.uhn.fhir.rest.method.HttpSimpleGetClientInvocation; +import ca.uhn.fhir.rest.method.IClientResponseHandler; +import ca.uhn.fhir.rest.method.MethodUtil; +import ca.uhn.fhir.rest.method.OperationMethodBinding; +import ca.uhn.fhir.rest.method.ReadMethodBinding; +import ca.uhn.fhir.rest.method.SearchMethodBinding; +import ca.uhn.fhir.rest.method.SearchStyleEnum; +import ca.uhn.fhir.rest.method.SortParameter; +import ca.uhn.fhir.rest.method.TransactionMethodBinding; +import ca.uhn.fhir.rest.method.ValidateMethodBindingDstu1; +import ca.uhn.fhir.rest.method.ValidateMethodBindingDstu2Plus; import ca.uhn.fhir.rest.param.DateParam; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.TokenParam; @@ -87,7 +184,7 @@ public class GenericClient extends BaseClient implements IGenericClient { myContext = theContext; } - @Deprecated //override deprecated method + @Deprecated // override deprecated method @Override public IBaseConformance conformance() { if (myContext.getVersion().getVersion().isRi()) { @@ -112,7 +209,7 @@ public class GenericClient extends BaseClient implements IGenericClient { return new CreateInternal(); } - @Deprecated //overide deprecated method + @Deprecated // overide deprecated method @Override public MethodOutcome create(IBaseResource theResource) { BaseHttpClientInvocation invocation = MethodUtil.createCreateInvocation(theResource, myContext); @@ -135,7 +232,7 @@ public class GenericClient extends BaseClient implements IGenericClient { return new DeleteInternal(); } - @Deprecated //override deprecated method + @Deprecated // override deprecated method @Override public MethodOutcome delete(final Class theType, IdDt theId) { HttpDeleteClientInvocation invocation = DeleteMethodBinding.createDeleteInvocation(getFhirContext(), theId.withResourceType(toResourceName(theType))); @@ -149,7 +246,7 @@ public class GenericClient extends BaseClient implements IGenericClient { return resp; } - @Deprecated //override deprecated method + @Deprecated // override deprecated method @Override public MethodOutcome delete(Class theType, String theId) { return delete(theType, new IdDt(theId)); @@ -248,7 +345,7 @@ public class GenericClient extends BaseClient implements IGenericClient { return new HistoryInternal(); } - @Deprecated //override deprecated method + @Deprecated // override deprecated method @Override public Bundle history(final Class theType, IdDt theIdDt, DateTimeDt theSince, Integer theLimit) { String resourceName = theType != null ? toResourceName(theType) : null; @@ -264,7 +361,7 @@ public class GenericClient extends BaseClient implements IGenericClient { } - @Deprecated //override deprecated method + @Deprecated // override deprecated method @Override public Bundle history(Class theType, String theId, DateTimeDt theSince, Integer theLimit) { return history(theType, new IdDt(theId), theSince, theLimit); @@ -414,7 +511,7 @@ public class GenericClient extends BaseClient implements IGenericClient { myLastRequest = theLastRequest; } - @Deprecated //override deprecated method + @Deprecated // override deprecated method @Override public void setLogRequestAndResponse(boolean theLogRequestAndResponse) { myLogRequestAndResponse = theLogRequestAndResponse; @@ -429,7 +526,7 @@ public class GenericClient extends BaseClient implements IGenericClient { return new TransactionInternal(); } - @Deprecated //override deprecated method + @Deprecated // override deprecated method @Override public List transaction(List theResources) { BaseHttpClientInvocation invocation = TransactionMethodBinding.createTransactionInvocation(theResources, myContext); @@ -576,7 +673,7 @@ public class GenericClient extends BaseClient implements IGenericClient { protected SummaryEnum mySummaryMode; - @Deprecated //override deprecated method + @Deprecated // override deprecated method @SuppressWarnings("unchecked") @Override public T andLogRequestAndResponse(boolean theLogRequestAndResponse) { @@ -1214,7 +1311,7 @@ public class GenericClient extends BaseClient implements IGenericClient { return nextOrPrevious(PREVIOUS, theBundle); } - @Deprecated //override deprecated method + @Deprecated // override deprecated method @Override public IGetPageTyped url(String thePageUrl) { return new GetPageInternal(thePageUrl); @@ -1371,7 +1468,8 @@ public class GenericClient extends BaseClient implements IGenericClient { } @SuppressWarnings("rawtypes") - private class OperationInternal extends BaseClientExecutable implements IOperation, IOperationUnnamed, IOperationUntyped, IOperationUntypedWithInput, IOperationUntypedWithInputAndPartialOutput { + private class OperationInternal extends BaseClientExecutable + implements IOperation, IOperationUnnamed, IOperationUntyped, IOperationUntypedWithInput, IOperationUntypedWithInputAndPartialOutput, IOperationProcessMsg, IOperationProcessMsgMode { private IIdType myId; private String myOperationName; @@ -1380,6 +1478,50 @@ public class GenericClient extends BaseClient implements IGenericClient { private Class myType; private boolean myUseHttpGet; private Class myReturnResourceType; + private IBaseBundle myMsgBundle; + private String myResponseUrl; + private Boolean myIsAsync; + + @SuppressWarnings("unchecked") + @Override + public IOperationProcessMsgMode setMessageBundle(IBaseBundle theMsgBundle) { + + Validate.notNull(theMsgBundle, "theMsgBundle must not be null"); + /* + * Validate.isTrue(theMsgBundle.getType().getValueAsEnum() == BundleTypeEnum.MESSAGE); + * Validate.isTrue(theMsgBundle.getEntries().size() > 0); + * Validate.notNull(theMsgBundle.getEntries().get(0).getResource(), "Message Bundle first entry must be a MessageHeader resource"); + * Validate.isTrue(theMsgBundle.getEntries().get(0).getResource().getResourceName().equals("MessageHeader"), "Message Bundle first entry must be a MessageHeader resource"); + */ + myMsgBundle = theMsgBundle; + return this; + } + + @Override + public IOperationProcessMsg setResponseUrlParam(String responseUrl) { + Validate.notEmpty(responseUrl, "responseUrl must not be null"); + Validate.matchesPattern(responseUrl, "^(https?)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]", "responseUrl must be a valid URL"); + myResponseUrl = responseUrl; + return this; + } + + @Override + public IOperationProcessMsgMode asynchronous(Class theResponseClass) { + myIsAsync = true; + Validate.notNull(theResponseClass, "theReturnType must not be null"); + Validate.isTrue(IBaseResource.class.isAssignableFrom(theResponseClass), "theReturnType must be a class which extends from IBaseResource"); + myReturnResourceType = theResponseClass; + return this; + } + + @Override + public IOperationProcessMsgMode synchronous(Class theResponseClass) { + myIsAsync = false; + Validate.notNull(theResponseClass, "theReturnType must not be null"); + Validate.isTrue(IBaseResource.class.isAssignableFrom(theResponseClass), "theReturnType must be a class which extends from IBaseResource"); + myReturnResourceType = theResponseClass; + return this; + } @SuppressWarnings("unchecked") private void addParam(String theName, IBase theValue) { @@ -1411,6 +1553,12 @@ public class GenericClient extends BaseClient implements IGenericClient { } } + @Override + public IOperationProcessMsg processMessage() { + myOperationName = Constants.EXTOP_PROCESS_MESSAGE; + return this; + } + private void addParam(String theName, IQueryParameterType theValue) { IPrimitiveType stringType = ParametersUtil.createString(myContext, theValue.getValueAsQueryToken(myContext)); addParam(theName, stringType); @@ -1434,6 +1582,26 @@ public class GenericClient extends BaseClient implements IGenericClient { @SuppressWarnings("unchecked") @Override public Object execute() { + if (myOperationName != null && myOperationName.equals(Constants.EXTOP_PROCESS_MESSAGE)) { + Map> urlParams = new LinkedHashMap>(); + // Set Url parameter Async and Response-Url + if (myIsAsync != null) { + urlParams.put(Constants.PARAM_ASYNC, Arrays.asList(String.valueOf(myIsAsync))); + } + + if (myResponseUrl != null && isNotBlank(myResponseUrl)) { + urlParams.put(Constants.PARAM_RESPONSE_URL, Arrays.asList(String.valueOf(myResponseUrl))); + } + // If is $process-message operation + BaseHttpClientInvocation invocation = OperationMethodBinding.createProcessMsgInvocation(myContext, myOperationName, myMsgBundle, urlParams); + + ResourceResponseHandler handler = new ResourceResponseHandler(); + handler.setPreferResponseTypes(getPreferResponseTypes(myType)); + + Object retVal = invoke(null, handler, invocation); + return retVal; + } + String resourceName; String id; if (myType != null) { @@ -1597,10 +1765,10 @@ public class GenericClient extends BaseClient implements IGenericClient { private final class OutcomeResponseHandler implements IClientResponseHandler { private PreferReturnEnum myPrefer; -// private final String myResourceName; + // private final String myResourceName; private OutcomeResponseHandler(String theResourceName) { -// myResourceName = theResourceName; + // myResourceName = theResourceName; } private OutcomeResponseHandler(String theResourceName, PreferReturnEnum thePrefer) { @@ -1854,7 +2022,7 @@ public class GenericClient extends BaseClient implements IGenericClient { return this; } - @Deprecated //override deprecated method + @Deprecated // override deprecated method @Override public IBase execute() { @@ -1911,11 +2079,11 @@ public class GenericClient extends BaseClient implements IGenericClient { if (rootSs == null) { rootSs = nextSortSpec; } else { - //FIXME lastSs is null never set - //TODO unused assignment + // FIXME lastSs is null never set + // TODO unused assignment lastSs.setChain(nextSortSpec); } - //TODO unused assignment + // TODO unused assignment lastSs = nextSortSpec; } if (rootSs != null) { @@ -1991,7 +2159,7 @@ public class GenericClient extends BaseClient implements IGenericClient { return this; } - @Deprecated //override deprecated method + @Deprecated // override deprecated method @Override public IQuery limitTo(int theLimitTo) { return count(theLimitTo); @@ -2325,7 +2493,6 @@ public class GenericClient extends BaseClient implements IGenericClient { return this; } - @Override public IPatchWithQueryTyped where(ICriterion theCriterion) { myCriterionList.add((ICriterionInternal) theCriterion); @@ -2359,7 +2526,7 @@ public class GenericClient extends BaseClient implements IGenericClient { @Override public IPatchWithBody withBody(String thePatchBody) { Validate.notBlank(thePatchBody, "thePatchBody must not be blank"); - + myPatchBody = thePatchBody; EncodingEnum encoding = MethodUtil.detectEncodingNoDefault(thePatchBody); @@ -2370,7 +2537,7 @@ public class GenericClient extends BaseClient implements IGenericClient { } else { throw new IllegalArgumentException("Unable to determine encoding of patch"); } - + return this; } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationMethodBinding.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationMethodBinding.java index f056a4d19e6..68837e77dd4 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationMethodBinding.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/OperationMethodBinding.java @@ -10,7 +10,7 @@ package ca.uhn.fhir.rest.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, @@ -33,6 +33,7 @@ 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; @@ -75,7 +76,8 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { private List myReturnParams; private final ReturnTypeEnum myReturnType; - protected OperationMethodBinding(Class theReturnResourceType, Class theReturnTypeFromRp, Method theMethod, FhirContext theContext, Object theProvider, boolean theIdempotent, String theOperationName, Class theOperationType, + protected OperationMethodBinding(Class theReturnResourceType, Class theReturnTypeFromRp, Method theMethod, FhirContext theContext, Object theProvider, + boolean theIdempotent, String theOperationName, Class theOperationType, OperationParam[] theReturnParams, BundleTypeEnum theBundleType) { super(theReturnResourceType, theMethod, theContext, theProvider); @@ -104,7 +106,8 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { } if (isBlank(theOperationName)) { - throw new ConfigurationException("Method '" + theMethod.getName() + "' on type " + theMethod.getDeclaringClass().getName() + " is annotated with @" + Operation.class.getSimpleName() + " but this annotation has no name defined"); + throw new ConfigurationException("Method '" + theMethod.getName() + "' on type " + theMethod.getDeclaringClass().getName() + " is annotated with @" + Operation.class.getSimpleName() + + " but this annotation has no name defined"); } if (theOperationName.startsWith("$") == false) { theOperationName = "$" + theOperationName; @@ -112,7 +115,8 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { myName = theOperationName; if (theContext.getVersion().getVersion().isEquivalentTo(FhirVersionEnum.DSTU1)) { - throw new ConfigurationException("@" + Operation.class.getSimpleName() + " methods are not supported on servers for FHIR version " + theContext.getVersion().getVersion().name() + " - Found one on class " + theMethod.getDeclaringClass().getName()); + throw new ConfigurationException("@" + Operation.class.getSimpleName() + " methods are not supported on servers for FHIR version " + theContext.getVersion().getVersion().name() + + " - Found one on class " + theMethod.getDeclaringClass().getName()); } if (theReturnTypeFromRp != null) { @@ -126,7 +130,8 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { } if (theMethod.getReturnType().isAssignableFrom(Bundle.class)) { - throw new ConfigurationException("Can not return a DSTU1 bundle from an @" + Operation.class.getSimpleName() + " method. Found in method " + theMethod.getName() + " defined in type " + theMethod.getDeclaringClass().getName()); + throw new ConfigurationException("Can not return a DSTU1 bundle from an @" + Operation.class.getSimpleName() + " method. Found in method " + theMethod.getName() + " defined in type " + + theMethod.getDeclaringClass().getName()); } if (theMethod.getReturnType().equals(IBundleProvider.class)) { @@ -172,8 +177,10 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { } - public OperationMethodBinding(Class theReturnResourceType, Class theReturnTypeFromRp, Method theMethod, FhirContext theContext, Object theProvider, Operation theAnnotation) { - this(theReturnResourceType, theReturnTypeFromRp, theMethod, theContext, theProvider, theAnnotation.idempotent(), theAnnotation.name(), theAnnotation.type(), theAnnotation.returnParameters(), theAnnotation.bundleType()); + public OperationMethodBinding(Class theReturnResourceType, Class theReturnTypeFromRp, Method theMethod, FhirContext theContext, Object theProvider, + Operation theAnnotation) { + this(theReturnResourceType, theReturnTypeFromRp, theMethod, theContext, theProvider, theAnnotation.idempotent(), theAnnotation.name(), theAnnotation.type(), theAnnotation.returnParameters(), + theAnnotation.bundleType()); } public String getDescription() { @@ -321,24 +328,8 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { myDescription = theDescription; } - public static BaseHttpClientInvocation createProcessMsgInvocation(FhirContext theContext, String theOperationName, IBaseBundle theInput, Map> urlParams) { - StringBuilder b = new StringBuilder(); - - if (b.length() > 0) { - b.append('/'); - } - if (!theOperationName.startsWith("$")) { - b.append("$"); - } - b.append(theOperationName); - - BaseHttpClientInvocation.appendExtraParamsWithQuestionMark(urlParams,b, b.indexOf("?") == -1); - - return new HttpPostClientInvocation(theContext, theInput, b.toString()); - - } - - public static BaseHttpClientInvocation createOperationInvocation(FhirContext theContext, String theResourceName, String theId, String theOperationName, IBaseParameters theInput, boolean theUseHttpGet) { + public static BaseHttpClientInvocation createOperationInvocation(FhirContext theContext, String theResourceName, String theId, String theOperationName, IBaseParameters theInput, + boolean theUseHttpGet) { StringBuilder b = new StringBuilder(); if (theResourceName != null) { b.append(theResourceName); @@ -378,7 +369,8 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { continue; } if (!(value instanceof IPrimitiveType)) { - throw new IllegalArgumentException("Can not invoke operation as HTTP GET when it has parameters with a composite (non priitive) datatype as the value. Found value: " + value.getClass().getName()); + throw new IllegalArgumentException( + "Can not invoke operation as HTTP GET when it has parameters with a composite (non priitive) datatype as the value. Found value: " + value.getClass().getName()); } IPrimitiveType primitive = (IPrimitiveType) value; params.get(nextName).add(primitive.getValueAsString()); @@ -386,6 +378,23 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding { return new HttpGetClientInvocation(theContext, params, b.toString()); } + public static BaseHttpClientInvocation createProcessMsgInvocation(FhirContext theContext, String theOperationName, IBaseBundle theInput, Map> urlParams) { + StringBuilder b = new StringBuilder(); + + if (b.length() > 0) { + b.append('/'); + } + if (!theOperationName.startsWith("$")) { + b.append("$"); + } + b.append(theOperationName); + + BaseHttpClientInvocation.appendExtraParamsWithQuestionMark(urlParams, b, b.indexOf("?") == -1); + + return new HttpPostClientInvocation(theContext, theInput, b.toString()); + + } + public static class ReturnType { private int myMax; private int myMin;