diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java index af23c263a25..fe834f684ab 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java @@ -150,12 +150,12 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini return retVal; } - public synchronized IResource toProfile(HttpServletRequest theRequest) { + public synchronized IResource toProfile(String theServerBase) { if (myProfileDef != null) { return myProfileDef; } - IResource retVal = myContext.getVersion().generateProfile(this, theRequest); + IResource retVal = myContext.getVersion().generateProfile(this, theServerBase); myProfileDef = retVal; return retVal; diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IFhirVersion.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IFhirVersion.java index 093f99549de..24ec881c8dd 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IFhirVersion.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IFhirVersion.java @@ -28,7 +28,7 @@ import javax.servlet.http.HttpServletRequest; public interface IFhirVersion { - IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, HttpServletRequest theRequest); + IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase); Object createServerConformanceProvider(RestfulServer theServer); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java index 29bebcd146b..54eea9c63b1 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java @@ -469,7 +469,7 @@ public class RestfulServer extends HttpServlet { requestPath = requestPath.substring(1); } - fhirServerBase = determineServerBase(theRequest); + fhirServerBase = getServerBaseForRequest(theRequest); String completeUrl = StringUtils.isNotBlank(theRequest.getQueryString()) ? requestUrl + "?" + theRequest.getQueryString() : requestUrl.toString(); @@ -703,10 +703,9 @@ public class RestfulServer extends HttpServlet { theResponse.getWriter().close(); } - } - private String determineServerBase(HttpServletRequest theRequest) { + public String getServerBaseForRequest(HttpServletRequest theRequest) { String fhirServerBase; fhirServerBase = myServerAddressStrategy.determineServerBase(getServletContext(), theRequest); diff --git a/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/model/dev/FhirDev.java b/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/model/dev/FhirDev.java index dc2680aff8c..d8741447285 100644 --- a/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/model/dev/FhirDev.java +++ b/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/model/dev/FhirDev.java @@ -44,7 +44,7 @@ public class FhirDev implements IFhirVersion { } @Override - public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, HttpServletRequest theRequest) { + public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase) { Profile retVal = new Profile(); RuntimeResourceDefinition def = theRuntimeResourceDefinition; @@ -60,7 +60,7 @@ public class FhirDev implements IFhirVersion { @Override public IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer) { - return new ServerProfileProvider(theRestfulServer.getFhirContext()); + return new ServerProfileProvider(theRestfulServer); } } diff --git a/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/rest/server/provider/dev/ServerProfileProvider.java b/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/rest/server/provider/dev/ServerProfileProvider.java index 4c4321b98b1..226dba64953 100644 --- a/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/rest/server/provider/dev/ServerProfileProvider.java +++ b/hapi-fhir-structures-dev/src/main/java/ca/uhn/fhir/rest/server/provider/dev/ServerProfileProvider.java @@ -34,15 +34,18 @@ import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.Read; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.server.IResourceProvider; +import ca.uhn.fhir.rest.server.RestfulServer; import javax.servlet.http.HttpServletRequest; public class ServerProfileProvider implements IResourceProvider { - private FhirContext myContext; + private final FhirContext myContext; + private final RestfulServer myRestfulServer; - public ServerProfileProvider(FhirContext theCtx) { - myContext = theCtx; + public ServerProfileProvider(RestfulServer theServer) { + myContext = theServer.getFhirContext(); + myRestfulServer = theServer; } @Override @@ -56,7 +59,8 @@ public class ServerProfileProvider implements IResourceProvider { if (retVal==null) { return null; } - return (Profile) retVal.toProfile(theRequest); + String serverBase = getServerBase(theRequest); + return (Profile) retVal.toProfile(serverBase); } @Search() @@ -71,11 +75,15 @@ public class ServerProfileProvider implements IResourceProvider { } return cmp; }}); + String serverBase = getServerBase(theRequest); ArrayList retVal = new ArrayList(); for (RuntimeResourceDefinition next : defs) { - retVal.add((Profile) next.toProfile(theRequest)); + retVal.add((Profile) next.toProfile(serverBase)); } return retVal; } + private String getServerBase(HttpServletRequest theHttpRequest) { + return myRestfulServer.getServerBaseForRequest(theHttpRequest); + } } diff --git a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java index a1cc2fefc92..dffe8a137c8 100644 --- a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java +++ b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java @@ -130,7 +130,7 @@ public class FhirDstu1 implements IFhirVersion { } } - private void fillName(StructureElement elem, BaseRuntimeElementDefinition nextDef) { + private void fillName(StructureElement elem, BaseRuntimeElementDefinition nextDef, String theServerBase) { if (nextDef instanceof RuntimeResourceReferenceDefinition) { RuntimeResourceReferenceDefinition rr = (RuntimeResourceReferenceDefinition) nextDef; for (Class next : rr.getResourceTypes()) { @@ -139,7 +139,7 @@ public class FhirDstu1 implements IFhirVersion { if (next != IResource.class) { RuntimeResourceDefinition resDef = rr.getDefinitionForResourceType(next); - type.getProfile().setValueAsString(resDef.getResourceProfile()); + type.getProfile().setValueAsString(resDef.getResourceProfile(theServerBase)); } } @@ -155,7 +155,7 @@ public class FhirDstu1 implements IFhirVersion { type.setCode(fromCodeString); } - private void fillProfile(Structure theStruct, StructureElement theElement, BaseRuntimeElementDefinition def, LinkedList path, BaseRuntimeDeclaredChildDefinition theChild) { + private void fillProfile(Structure theStruct, StructureElement theElement, BaseRuntimeElementDefinition def, LinkedList path, BaseRuntimeDeclaredChildDefinition theChild, String theServerBase) { fillBasics(theElement, def, path, theChild); @@ -203,7 +203,7 @@ public class FhirDstu1 implements IFhirVersion { if (child instanceof RuntimeChildResourceBlockDefinition) { RuntimeResourceBlockDefinition nextDef = (RuntimeResourceBlockDefinition) child.getSingleChildOrThrow(); - fillProfile(theStruct, elem, nextDef, path, child); + fillProfile(theStruct, elem, nextDef, path, child, theServerBase); } else if (child instanceof RuntimeChildContainedResources) { // ignore } else if (child instanceof RuntimeChildDeclaredExtensionDefinition) { @@ -214,10 +214,10 @@ public class FhirDstu1 implements IFhirVersion { String nextName = childNamesIter.next(); BaseRuntimeElementDefinition nextDef = child.getChildByName(nextName); fillBasics(elem, nextDef, path, child); - fillName(elem, nextDef); + fillName(elem, nextDef, theServerBase); while (childNamesIter.hasNext()) { nextDef = child.getChildByName(childNamesIter.next()); - fillName(elem, nextDef); + fillName(elem, nextDef, theServerBase); } path.pollLast(); } else { @@ -233,7 +233,7 @@ public class FhirDstu1 implements IFhirVersion { } @Override - public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, HttpServletRequest theRequest) { + public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase) { Profile retVal = new Profile(); RuntimeResourceDefinition def = theRuntimeResourceDefinition; @@ -262,8 +262,7 @@ public class FhirDstu1 implements IFhirVersion { StructureElement element = struct.addElement(); element.getDefinition().setMin(1); element.getDefinition().setMax("1"); - - fillProfile(struct, element, def, path, null); + fillProfile(struct, element, def, path, null, theServerBase); retVal.getStructure().get(0).getElement().get(0).getDefinition().addType().getCode().setValue("Resource"); diff --git a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerProfileProvider.java b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerProfileProvider.java index 113e0bbc5ba..b41a8b4974d 100644 --- a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerProfileProvider.java +++ b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/provider/ServerProfileProvider.java @@ -35,15 +35,18 @@ import ca.uhn.fhir.rest.annotation.Read; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.RestfulServer; +import org.apache.http.HttpRequest; import javax.servlet.http.HttpServletRequest; public class ServerProfileProvider implements IResourceProvider { - private FhirContext myContext; + private final FhirContext myContext; + private final RestfulServer myRestfulServer; public ServerProfileProvider(RestfulServer theServer) { myContext = theServer.getFhirContext(); + myRestfulServer = theServer; } @Override @@ -57,7 +60,8 @@ public class ServerProfileProvider implements IResourceProvider { if (retVal==null) { return null; } - return (Profile) retVal.toProfile(theRequest); + String serverBase = getServerBase(theRequest); + return (Profile) retVal.toProfile(serverBase); } @Search() @@ -72,11 +76,15 @@ public class ServerProfileProvider implements IResourceProvider { } return cmp; }}); + String serverBase = getServerBase(theRequest); ArrayList retVal = new ArrayList(); for (RuntimeResourceDefinition next : defs) { - retVal.add((Profile) next.toProfile(theRequest)); + retVal.add((Profile) next.toProfile(serverBase)); } return retVal; } + private String getServerBase(HttpServletRequest theHttpRequest) { + return myRestfulServer.getServerBaseForRequest(theHttpRequest); + } }