allow urls in batch transactions to start with /

This commit is contained in:
Ken Stevens 2019-08-16 11:24:45 -04:00 committed by James Agnew
parent f252cda126
commit 970c421311
2 changed files with 27 additions and 2 deletions

View File

@ -423,6 +423,10 @@ public class TransactionProcessor<BUNDLE extends IBaseBundle, BUNDLEENTRY> {
url = url.substring(0, qIndex);
}
if (url.length() > 0 && url.charAt(0) == '/') {
url = url.substring(1);
}
requestDetails.setRequestPath(url);
requestDetails.setFhirServerBase(theRequestDetails.getFhirServerBase());

View File

@ -5,6 +5,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
@ -14,10 +15,10 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.dstu3.model.Bundle.*;
import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.*;
import ca.uhn.fhir.context.FhirContext;
@ -31,6 +32,8 @@ import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.test.utilities.JettyUtil;
import ca.uhn.fhir.util.TestUtil;
import javax.validation.constraints.NotNull;
public class SystemProviderTransactionSearchDstu3Test extends BaseJpaDstu3Test {
private static RestfulServer myRestServer;
@ -262,6 +265,24 @@ public class SystemProviderTransactionSearchDstu3Test extends BaseJpaDstu3Test {
}
}
@Test
public void testTransactionGetStartsWithSlash() {
IIdType patientId = ourClient.create().resource(new Patient()).execute().getId().toUnqualifiedVersionless();
Bundle input = new Bundle();
input.setType(BundleType.BATCH);
input.setId("bundle-batch-test");
input.addEntry().getRequest().setMethod(HTTPVerb.GET)
.setUrl("/Patient?_id="+patientId.getIdPart());
Bundle output = ourClient.transaction().withBundle(input).execute();
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(output));
assertThat(output.getEntryFirstRep().getResponse().getStatus(), startsWith("200"));
Bundle respBundle = (Bundle) output.getEntry().get(0).getResource();
List<String> actualIds = toIds(respBundle);
assertThat(actualIds, containsInAnyOrder(patientId.getValue()));
}
private List<String> toIds(Bundle theRespBundle) {
ArrayList<String> retVal = new ArrayList<String>();
for (BundleEntryComponent next : theRespBundle.getEntry()) {