test fixes
This commit is contained in:
parent
3392d3ee61
commit
534de22b04
|
@ -28,6 +28,7 @@ import ca.uhn.fhir.rest.client.api.HttpClientUtil;
|
||||||
import ca.uhn.fhir.rest.client.api.IHttpClient;
|
import ca.uhn.fhir.rest.client.api.IHttpClient;
|
||||||
import ca.uhn.fhir.rest.client.api.IHttpRequest;
|
import ca.uhn.fhir.rest.client.api.IHttpRequest;
|
||||||
import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation;
|
import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation;
|
||||||
|
import ca.uhn.fhir.rest.client.impl.RestfulClientFactory;
|
||||||
import ca.uhn.fhir.rest.client.method.MethodUtil;
|
import ca.uhn.fhir.rest.client.method.MethodUtil;
|
||||||
import ca.uhn.fhir.rest.param.HttpClientRequestParameters;
|
import ca.uhn.fhir.rest.param.HttpClientRequestParameters;
|
||||||
import okhttp3.Call;
|
import okhttp3.Call;
|
||||||
|
@ -45,6 +46,7 @@ import static ca.uhn.fhir.okhttp.utils.UrlStringUtils.endsWith;
|
||||||
import static ca.uhn.fhir.okhttp.utils.UrlStringUtils.everythingAfterFirstQuestionMark;
|
import static ca.uhn.fhir.okhttp.utils.UrlStringUtils.everythingAfterFirstQuestionMark;
|
||||||
import static ca.uhn.fhir.okhttp.utils.UrlStringUtils.hasQuestionMark;
|
import static ca.uhn.fhir.okhttp.utils.UrlStringUtils.hasQuestionMark;
|
||||||
import static ca.uhn.fhir.okhttp.utils.UrlStringUtils.withTrailingQuestionMarkRemoved;
|
import static ca.uhn.fhir.okhttp.utils.UrlStringUtils.withTrailingQuestionMarkRemoved;
|
||||||
|
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Http Request based on OkHttp. This is an adapter around the class
|
* A Http Request based on OkHttp. This is an adapter around the class
|
||||||
|
@ -53,6 +55,7 @@ import static ca.uhn.fhir.okhttp.utils.UrlStringUtils.withTrailingQuestionMarkRe
|
||||||
* @author Matthew Clarke | matthew.clarke@orionhealth.com | Orion Health
|
* @author Matthew Clarke | matthew.clarke@orionhealth.com | Orion Health
|
||||||
*/
|
*/
|
||||||
public class OkHttpRestfulClient implements IHttpClient {
|
public class OkHttpRestfulClient implements IHttpClient {
|
||||||
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(OkHttpRestfulClient.class);
|
||||||
|
|
||||||
private Call.Factory myClient;
|
private Call.Factory myClient;
|
||||||
private StringBuilder myUrl;
|
private StringBuilder myUrl;
|
||||||
|
@ -80,13 +83,19 @@ public class OkHttpRestfulClient implements IHttpClient {
|
||||||
@Override
|
@Override
|
||||||
public IHttpRequest createByteRequest(
|
public IHttpRequest createByteRequest(
|
||||||
FhirContext theContext, String theContents, String theContentType, EncodingEnum theEncoding) {
|
FhirContext theContext, String theContents, String theContentType, EncodingEnum theEncoding) {
|
||||||
initBaseRequest(theContext, theEncoding, createPostBody(theContents, theContentType));
|
initBaseRequest(theContext, theEncoding, createPostBody(theContents, theContentType), RequestTypeEnum.POST);
|
||||||
return myRequest;
|
return myRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initBaseRequest(FhirContext theContext, EncodingEnum theEncoding, RequestBody body) {
|
private void initBaseRequest(
|
||||||
|
FhirContext theContext,
|
||||||
|
EncodingEnum theEncoding,
|
||||||
|
RequestBody body,
|
||||||
|
RequestTypeEnum theRequestType
|
||||||
|
) {
|
||||||
|
RequestTypeEnum requestType = theRequestType != null ? theRequestType : myRequestType;
|
||||||
String sanitisedUrl = withTrailingQuestionMarkRemoved(myUrl.toString());
|
String sanitisedUrl = withTrailingQuestionMarkRemoved(myUrl.toString());
|
||||||
myRequest = new OkHttpRestfulRequest(myClient, sanitisedUrl, myRequestType, body);
|
myRequest = new OkHttpRestfulRequest(myClient, sanitisedUrl, requestType, body);
|
||||||
addHeadersToRequest(myRequest, theEncoding, theContext);
|
addHeadersToRequest(myRequest, theEncoding, theContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +106,7 @@ public class OkHttpRestfulClient implements IHttpClient {
|
||||||
@Override
|
@Override
|
||||||
public IHttpRequest createParamRequest(
|
public IHttpRequest createParamRequest(
|
||||||
FhirContext theContext, Map<String, List<String>> theParams, EncodingEnum theEncoding) {
|
FhirContext theContext, Map<String, List<String>> theParams, EncodingEnum theEncoding) {
|
||||||
initBaseRequest(theContext, theEncoding, getFormBodyFromParams(theParams));
|
initBaseRequest(theContext, theEncoding, getFormBodyFromParams(theParams), RequestTypeEnum.POST);
|
||||||
return myRequest;
|
return myRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +123,7 @@ public class OkHttpRestfulClient implements IHttpClient {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IHttpRequest createBinaryRequest(FhirContext theContext, IBaseBinary theBinary) {
|
public IHttpRequest createBinaryRequest(FhirContext theContext, IBaseBinary theBinary) {
|
||||||
initBaseRequest(theContext, null, createPostBody(theBinary.getContent(), theBinary.getContentType()));
|
initBaseRequest(theContext, null, createPostBody(theBinary.getContent(), theBinary.getContentType()), RequestTypeEnum.POST);
|
||||||
return myRequest;
|
return myRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,16 +133,35 @@ public class OkHttpRestfulClient implements IHttpClient {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IHttpRequest createGetRequest(FhirContext theContext, EncodingEnum theEncoding) {
|
public IHttpRequest createGetRequest(FhirContext theContext, EncodingEnum theEncoding) {
|
||||||
initBaseRequest(theContext, theEncoding, null);
|
initBaseRequest(theContext, theEncoding, null, RequestTypeEnum.GET);
|
||||||
return myRequest;
|
return myRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IHttpRequest createRequest(HttpClientRequestParameters theParameters) {
|
public IHttpRequest createRequest(HttpClientRequestParameters theParameters) {
|
||||||
|
RequestBody requestBody = null;
|
||||||
|
switch (theParameters.getRequestTypeEnum()) {
|
||||||
|
case POST:
|
||||||
|
case PUT:
|
||||||
|
if (theParameters.getFormParams() != null && !theParameters.getFormParams().isEmpty()) {
|
||||||
|
requestBody = getFormBodyFromParams(theParameters.getFormParams());
|
||||||
|
} else if (theParameters.getByteContents() != null) {
|
||||||
|
requestBody = createPostBody(theParameters.getByteContents(), theParameters.getContentType());
|
||||||
|
} else if (isNotBlank(theParameters.getContents())) {
|
||||||
|
requestBody = createPostBody(theParameters.getContents(), theParameters.getContentType());
|
||||||
|
} else if (theParameters.getBaseBinary() != null) {
|
||||||
|
requestBody = createPostBody(theParameters.getBaseBinary().getContent(), theParameters.getContentType());
|
||||||
|
} else {
|
||||||
|
ourLog.debug("No body contents found for HTTP-{}", theParameters.getRequestTypeEnum().name());
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
initBaseRequest(
|
initBaseRequest(
|
||||||
theParameters.getFhirContext(),
|
theParameters.getFhirContext(),
|
||||||
theParameters.getEncodingEnum(),
|
theParameters.getEncodingEnum(),
|
||||||
createPostBody(theParameters.getByteContents(), theParameters.getContents()));
|
requestBody,
|
||||||
|
theParameters.getRequestTypeEnum());
|
||||||
return myRequest;
|
return myRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,6 +114,7 @@ public abstract class BaseHttpClientInvocation {
|
||||||
HttpClientRequestParameters clientRequestParameters =
|
HttpClientRequestParameters clientRequestParameters =
|
||||||
new HttpClientRequestParameters(theParameters.getUrl(), theParameters.getRequestTypeEnum());
|
new HttpClientRequestParameters(theParameters.getUrl(), theParameters.getRequestTypeEnum());
|
||||||
clientRequestParameters.setEncodingEnum(theParameters.getEncodingEnum());
|
clientRequestParameters.setEncodingEnum(theParameters.getEncodingEnum());
|
||||||
|
clientRequestParameters.setFhirContext(getContext());
|
||||||
IHttpRequest request = httpClient.createRequest(clientRequestParameters);
|
IHttpRequest request = httpClient.createRequest(clientRequestParameters);
|
||||||
for (Header h : getHeaders()) {
|
for (Header h : getHeaders()) {
|
||||||
request.addHeader(h.getName(), h.getValue());
|
request.addHeader(h.getName(), h.getValue());
|
||||||
|
|
Loading…
Reference in New Issue