Bugfixes to the testpage overlay

This commit is contained in:
James 2017-05-22 16:15:51 -04:00
parent 1ec180628f
commit 6764079129
7 changed files with 105 additions and 51 deletions

View File

@ -1,5 +1,7 @@
package ca.uhn.fhir.rest.client.apache;
import static org.hamcrest.Matchers.array;
/*
* #%L
* HAPI FHIR - Core Library
@ -28,6 +30,7 @@ import java.io.Reader;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -136,6 +139,19 @@ public class ApacheHttpResponse implements IHttpResponse {
return headers;
}
@Override
public List<String> getHeaders(String theName) {
Header[] headers = myResponse.getHeaders(theName);
if (headers == null) {
headers = new Header[0];
}
List<String> retVal = new ArrayList<String>();
for (Header next : headers) {
retVal.add(next.getValue());
}
return retVal;
}
@Override
public String getMimeType() {
ContentType ct = ContentType.get(myResponse.getEntity());

View File

@ -32,52 +32,10 @@ import java.util.Map;
public interface IHttpResponse {
/**
* Get the status code associated with the response.
*
* @return the response status code.
* @deprecated This method was deprecated in HAPI FHIR 2.2 because its name has a typo. Use {@link #bufferEntity()} instead.
*/
public int getStatus();
/**
* @return the native response, depending on the client library used
*/
Object getResponse();
/**
* Extracts {@code Content-Type} value from the response exactly as
* specified by the {@code Content-Type} header. Returns {@code null}
* if not specified.
*/
public String getMimeType();
/**
* Get map of the response headers and corresponding string values.
*
* @return response headers as a map header keys and they values.
*/
public Map<String, List<String>> getAllHeaders();
/**
* Get the response status information reason phrase associated with the response.
*
* @return the reason phrase.
*/
public String getStatusInfo();
/**
* Returna reader for the response entity
*/
public Reader createReader() throws IOException;
/**
* Read the message entity input stream as an InputStream.
*/
public InputStream readEntity() throws IOException;
/**
* Close the response
*/
public void close();
@Deprecated
void bufferEntitity() throws IOException;
/**
* Buffer the message entity data.
@ -105,9 +63,56 @@ public interface IHttpResponse {
void bufferEntity() throws IOException;
/**
* @deprecated This method was deprecated in HAPI FHIR 2.2 because its name has a typo. Use {@link #bufferEntity()} instead.
* Close the response
*/
@Deprecated
void bufferEntitity() throws IOException;
public void close();
/**
* Returna reader for the response entity
*/
public Reader createReader() throws IOException;
/**
* Get map of the response headers and corresponding string values.
*
* @return response headers as a map header keys and they values.
*/
public Map<String, List<String>> getAllHeaders();
/**
* Return all headers in the response with the given type
*/
public List<String> getHeaders(String theName);
/**
* Extracts {@code Content-Type} value from the response exactly as
* specified by the {@code Content-Type} header. Returns {@code null}
* if not specified.
*/
public String getMimeType();
/**
* @return the native response, depending on the client library used
*/
Object getResponse();
/**
* Get the status code associated with the response.
*
* @return the response status code.
*/
public int getStatus();
/**
* Get the response status information reason phrase associated with the response.
*
* @return the reason phrase.
*/
public String getStatusInfo();
/**
* Read the message entity input stream as an InputStream.
*/
public InputStream readEntity() throws IOException;
}

View File

@ -27,7 +27,7 @@ import ca.uhn.fhir.jpa.demo.FhirServerConfigDstu3;
public class RunServerCommand extends BaseCommand {
private static final String DISABLE_REFERENTIAL_INTEGRITY = "disable-referential-integrity";
private static final String OPTION_DISABLE_REFERENTIAL_INTEGRITY = "disable-referential-integrity";
private static final String OPTION_LOWMEM = "lowmem";
private static final String OPTION_ALLOW_EXTERNAL_REFS = "allow-external-refs";
private static final int DEFAULT_PORT = 8080;
@ -50,7 +50,7 @@ public class RunServerCommand extends BaseCommand {
options.addOption(OPTION_P, "port", true, "The port to listen on (default is " + DEFAULT_PORT + ")");
options.addOption(null, OPTION_LOWMEM, false, "If this flag is set, the server will operate in low memory mode (some features disabled)");
options.addOption(null, OPTION_ALLOW_EXTERNAL_REFS, false, "If this flag is set, the server will allow resources to be persisted contaning external resource references");
options.addOption(null, DISABLE_REFERENTIAL_INTEGRITY, false, "If this flag is set, the server will not enforce referential integrity");
options.addOption(null, OPTION_DISABLE_REFERENTIAL_INTEGRITY, false, "If this flag is set, the server will not enforce referential integrity");
return options;
}
@ -76,6 +76,11 @@ public class RunServerCommand extends BaseCommand {
ContextHolder.setAllowExternalRefs(true);
}
if (theCommandLine.hasOption(OPTION_DISABLE_REFERENTIAL_INTEGRITY)) {
ourLog.info("Server is configured to not enforce referential integrity");
ContextHolder.setDisableReferentialIntegrity(true);
}
ContextHolder.setCtx(getSpecVersionContext(theCommandLine));
ourLog.info("Preparing HAPI FHIR JPA server on port {}", myPort);

View File

@ -86,6 +86,11 @@ public class OkHttpRestfulResponse implements IHttpResponse {
return myResponse.headers().toMultimap();
}
@Override
public List<String> getHeaders(String theName) {
return myResponse.headers(theName);
}
@Override
public String getMimeType() {
String contentType = myResponse.header(Constants.HEADER_CONTENT_TYPE);

View File

@ -598,7 +598,7 @@ public class BaseController {
lastResponse.bufferEntity();
resultBody = IOUtils.toString(lastResponse.readEntity(), Constants.CHARSET_UTF8);
List<String> ctStrings = lastResponse.getAllHeaders().get(Constants.HEADER_CONTENT_TYPE);
List<String> ctStrings = lastResponse.getHeaders(Constants.HEADER_CONTENT_TYPE);
if (ctStrings != null && ctStrings.isEmpty() == false) {
ct = ContentType.parse(ctStrings.get(0));
mimeType = ct.getMimeType();

View File

@ -0,0 +1,21 @@
package ca.uhn.fhir.to.model;
import java.io.IOException;
import ca.uhn.fhir.rest.client.IClientInterceptor;
import ca.uhn.fhir.rest.client.api.IHttpRequest;
import ca.uhn.fhir.rest.client.api.IHttpResponse;
public class BufferResponseInterceptor implements IClientInterceptor {
@Override
public void interceptRequest(IHttpRequest theRequest) {
// nothing
}
@Override
public void interceptResponse(IHttpResponse theResponse) throws IOException {
theResponse.bufferEntity();
}
}

View File

@ -137,6 +137,8 @@ public class HomeRequest {
} else {
retVal = (GenericClient) theContext.newRestfulGenericClient(getServerBase(theRequest, theConfig));
}
retVal.registerInterceptor(new BufferResponseInterceptor());
retVal.setKeepResponses(true);