implementing most
This commit is contained in:
parent
baf3933fbf
commit
5671c8c09b
|
@ -29,6 +29,7 @@ import ca.uhn.fhir.rest.client.api.IHttpClient;
|
|||
import ca.uhn.fhir.rest.client.api.IHttpRequest;
|
||||
import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation;
|
||||
import ca.uhn.fhir.rest.client.method.MethodUtil;
|
||||
import ca.uhn.fhir.rest.param.HttpClientRequestParameters;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.MediaType;
|
||||
|
@ -127,6 +128,15 @@ public class OkHttpRestfulClient implements IHttpClient {
|
|||
return myRequest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IHttpRequest createRequest(HttpClientRequestParameters theParameters) {
|
||||
initBaseRequest(
|
||||
theParameters.getFhirContext(),
|
||||
theParameters.getEncodingEnum(),
|
||||
createPostBody(theParameters.getByteContents(), theParameters.getContents()));
|
||||
return myRequest;
|
||||
}
|
||||
|
||||
private void addHeadersToRequest(
|
||||
OkHttpRestfulRequest theHttpRequest, EncodingEnum theEncoding, FhirContext theContext) {
|
||||
if (myHeaders != null) {
|
||||
|
|
|
@ -132,12 +132,6 @@ public class ApacheHttpClient extends BaseHttpClient implements IHttpClient {
|
|||
return new ApacheHttpRequest(myClient, request);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public IHttpRequest createHttpRequest(CreateHttpRequestParameters theCreateHttpRequestParameters) {
|
||||
// HttpRequestBase request = constructRequestBase(theCreateHttpRequestParameters);
|
||||
// return new ApacheHttpRequest(myClient, request);
|
||||
// }
|
||||
|
||||
@Override
|
||||
protected IHttpRequest createHttpRequest() {
|
||||
return createHttpRequest((HttpEntity) null);
|
||||
|
|
|
@ -29,6 +29,7 @@ import ca.uhn.fhir.rest.client.api.IHttpClient;
|
|||
import ca.uhn.fhir.rest.client.api.IHttpRequest;
|
||||
import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation;
|
||||
import ca.uhn.fhir.rest.client.method.MethodUtil;
|
||||
import ca.uhn.fhir.rest.param.HttpClientRequestParameters;
|
||||
import jakarta.ws.rs.client.Client;
|
||||
import jakarta.ws.rs.client.Entity;
|
||||
import jakarta.ws.rs.client.Invocation.Builder;
|
||||
|
@ -37,9 +38,12 @@ import jakarta.ws.rs.core.MultivaluedHashMap;
|
|||
import jakarta.ws.rs.core.MultivaluedMap;
|
||||
import org.hl7.fhir.instance.model.api.IBaseBinary;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
/**
|
||||
* A Http Request based on JaxRs. This is an adapter around the class
|
||||
* {@link jakarta.ws.rs.client.Client Client}
|
||||
|
@ -83,7 +87,14 @@ public class JaxRsHttpClient implements IHttpClient {
|
|||
@Override
|
||||
public IHttpRequest createParamRequest(
|
||||
FhirContext theContext, Map<String, List<String>> theParams, EncodingEnum theEncoding) {
|
||||
MultivaluedMap<String, String> map = new MultivaluedHashMap<String, String>();
|
||||
Entity<Form> entity = getFormEntity(theParams);
|
||||
JaxRsHttpRequest retVal = createHttpRequest(entity);
|
||||
addHeadersToRequest(retVal, theEncoding, theContext);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
private static Entity<Form> getFormEntity(Map<String, List<String>> theParams) {
|
||||
MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
|
||||
for (Map.Entry<String, List<String>> nextParam : theParams.entrySet()) {
|
||||
List<String> value = nextParam.getValue();
|
||||
for (String s : value) {
|
||||
|
@ -91,9 +102,7 @@ public class JaxRsHttpClient implements IHttpClient {
|
|||
}
|
||||
}
|
||||
Entity<Form> entity = Entity.form(map);
|
||||
JaxRsHttpRequest retVal = createHttpRequest(entity);
|
||||
addHeadersToRequest(retVal, theEncoding, theContext);
|
||||
return retVal;
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -111,6 +120,36 @@ public class JaxRsHttpClient implements IHttpClient {
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IHttpRequest createRequest(HttpClientRequestParameters theParameters) {
|
||||
Map<String, String> additionalHeaders = new HashMap<>();
|
||||
Entity<?> entity;
|
||||
switch (theParameters.getRequestTypeEnum()) {
|
||||
case POST:
|
||||
case PUT:
|
||||
if (theParameters.getBaseBinary() != null) {
|
||||
entity = Entity.entity(theParameters.getBaseBinary().getContentAsBase64(), theParameters.getBaseBinary().getContentType());
|
||||
} else if (theParameters.getByteContents() != null) {
|
||||
entity = Entity.entity(theParameters.getByteContents(), theParameters.getContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
|
||||
additionalHeaders.put(Constants.HEADER_CONTENT_TYPE, theParameters.getContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
|
||||
} else if (isNotBlank(theParameters.getContents())) {
|
||||
entity = Entity.entity(theParameters.getContents(), theParameters.getContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
|
||||
additionalHeaders.put(Constants.HEADER_CONTENT_TYPE, theParameters.getContentType() + Constants.HEADER_SUFFIX_CT_UTF_8);
|
||||
} else {
|
||||
entity = getFormEntity(theParameters.getFormParams());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
entity = null;
|
||||
}
|
||||
JaxRsHttpRequest request = createHttpRequest(entity);
|
||||
for (Map.Entry<String, String> entrySet : additionalHeaders.entrySet()) {
|
||||
request.addHeader(entrySet.getKey(), entrySet.getValue());
|
||||
}
|
||||
addHeadersToRequest(request, theParameters.getEncodingEnum(), theParameters.getFhirContext());
|
||||
return request;
|
||||
}
|
||||
|
||||
public void addHeadersToRequest(JaxRsHttpRequest theHttpRequest, EncodingEnum theEncoding, FhirContext theContext) {
|
||||
if (myHeaders != null) {
|
||||
for (Header next : myHeaders) {
|
||||
|
|
Loading…
Reference in New Issue