public ActionRequestDetails(RequestDetails theRequestDetails, String theResourceType, IIdType theId) { this(theRequestDetails, theRequestDetails.getServer().getFhirContext(), theResourceType, theId); }
private static ResponseEncoding determineRequestEncodingNoDefaultReturnRE(RequestDetails theReq) { ResponseEncoding retVal = null; List<String> headers = theReq.getHeaders(Constants.HEADER_CONTENT_TYPE); if (headers != null) { Iterator<String> acceptValues = headers.iterator(); if (acceptValues != null) { while (acceptValues.hasNext() && retVal == null) { String nextAcceptHeaderValue = acceptValues.next(); if (nextAcceptHeaderValue != null && isNotBlank(nextAcceptHeaderValue)) { for (String nextPart : nextAcceptHeaderValue.split(",")) { int scIdx = nextPart.indexOf(';'); if (scIdx == 0) { continue; } if (scIdx != -1) { nextPart = nextPart.substring(0, scIdx); } nextPart = nextPart.trim(); EncodingEnum encoding = EncodingEnum.forContentType(nextPart); if (encoding != null) { retVal = new ResponseEncoding(theReq.getServer().getFhirContext(), encoding, nextPart); break; } } } } } } return retVal; }
/** * Fail the request by throwing an {@link UnprocessableEntityException} as a result of a validation failure. * Subclasses may change this behaviour by providing alternate behaviour. */ protected void fail(RequestDetails theRequestDetails, ValidationResult theValidationResult) { throw new UnprocessableEntityException(theRequestDetails.getServer().getFhirContext(), theValidationResult.toOperationOutcome()); }
public ActionRequestDetails(RequestDetails theRequestDetails) { myId = theRequestDetails.getId(); myResourceType = theRequestDetails.getResourceName(); myContext = theRequestDetails.getServer().getFhirContext(); myRequestDetails = theRequestDetails; }
public static IIdType fullyQualifyResourceIdOrReturnNull(IRestfulServerDefaults theServer, IBaseResource theResource, String theServerBase, IIdType theResourceId) { IIdType retVal = null; if (theResourceId.hasIdPart() && isNotBlank(theServerBase)) { String resName = theResourceId.getResourceType(); if (theResource != null && isBlank(resName)) { FhirContext context = theServer.getFhirContext(); context = getContextForVersion(context, theResource.getStructureFhirVersionEnum()); resName = context.getResourceDefinition(theResource).getName(); } if (isNotBlank(resName)) { retVal = theResourceId.withServerBase(theServerBase, resName); } } return retVal; }
EncodingEnum retVal = EncodingEnum.forContentType(nextFormat); if (retVal != null) { return new ResponseEncoding(theReq.getServer().getFhirContext(), retVal, nextFormat); encoding = getEncodingForContentType(theReq.getServer().getFhirContext(), strict, nextToken, thePreferContentType); encoding = getEncodingForContentType(theReq.getServer().getFhirContext(), strict, nextToken.substring(startSpaceIndex), thePreferContentType); encoding = getEncodingForContentType(theReq.getServer().getFhirContext(), strict, nextToken.substring(startSpaceIndex, endSpaceIndex), thePreferContentType);
public ActionRequestDetails(RequestDetails theRequestDetails, IBaseResource theResource) { this(theRequestDetails, theRequestDetails.getServer().getFhirContext().getResourceDefinition(theResource).getName(), theResource.getIdElement()); myResource = theResource; }
@Override public void extractTenant(UrlPathTokenizer theUrlPathTokenizer, RequestDetails theRequestDetails) { String tenantId = null; if (theUrlPathTokenizer.hasMoreTokens()) { tenantId = defaultIfBlank(theUrlPathTokenizer.nextTokenUnescapedAndSanitized(), null); ourLog.trace("Found tenant ID {} in request string", tenantId); theRequestDetails.setTenantId(tenantId); } if (tenantId == null) { HapiLocalizer localizer = theRequestDetails.getServer().getFhirContext().getLocalizer(); throw new InvalidRequestException(localizer.getMessage(RestfulServer.class, "rootRequest.multitenant")); } }
IRestfulResponse response = theRequestDetails.getResponse(); FhirContext ctx = theRequestDetails.getServer().getFhirContext();
if (retVal.contains(SummaryEnum.TEXT)) { if (retVal.size() > 1) { String msg = theRequest.getServer().getFhirContext().getLocalizer().getMessage(SummaryEnumParameter.class, "cantCombineText"); throw new InvalidRequestException(msg);
FhirContext ctx = theRequest.getServer().getFhirContext(); dateRangeParam.setValuesAsQueryTokens(ctx, myName, parameters); matchingParamValues.add(dateRangeParam); FhirContext ctx = theRequest.getServer().getFhirContext(); RuntimePrimitiveDatatypeDefinition def = (RuntimePrimitiveDatatypeDefinition) ctx.getElementDefinition(myParameterType.asSubclass(IBase.class)); IPrimitiveType<?> instance = def.newInstance(); HapiLocalizer localizer = theRequest.getServer().getFhirContext().getLocalizer(); String msg = localizer.getMessage(OperationParameter.class, "urlParamNotPrimitive", myOperationName, myName); throw new MethodNotAllowedException(msg, RequestTypeEnum.POST);
FhirContext ctx = theRequestDetails.getServer().getFhirContext(); RuntimeResourceDefinition resDef = ctx.getResourceDefinition(theRequestDetails.getResourceName()); HashMap<String, List<String>> parameterToOrValues = new HashMap<>();
@Override public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding<?> theMethodBinding) throws InternalErrorException, InvalidRequestException { // TODO: don't use a default encoding, just fail! EncodingEnum encoding = RestfulServerUtils.determineRequestEncoding(theRequest); IParser parser = encoding.newParser(theRequest.getServer().getFhirContext()); Reader reader = ResourceParameter.createRequestReader(theRequest); try { switch (myParamStyle) { case RESOURCE_LIST: { Class<? extends IBaseResource> type = myContext.getResourceDefinition("Bundle").getImplementingClass(); IBaseResource bundle = parser.parseResource(type, reader); List<IBaseResource> resourceList = BundleUtil.toListOfResources(myContext, (IBaseBundle) bundle); return resourceList; } case RESOURCE_BUNDLE: return parser.parseResource(myResourceBundleType, reader); } throw new IllegalStateException("Unknown type: " + myParamStyle); // should not happen } finally { IOUtils.closeQuietly(reader); } }
FhirContext fhirContext = theRequestDetails.getServer().getFhirContext(); List<IBaseResource> resources = Collections.emptyList();
/** * Determine whether a response should be given in JSON or XML format based on the incoming HttpServletRequest's * <code>"_format"</code> parameter and <code>"Accept:"</code> HTTP header. */ public static ResponseEncoding determineResponseEncodingWithDefault(RequestDetails theReq) { ResponseEncoding retVal = determineResponseEncodingNoDefault(theReq, theReq.getServer().getDefaultResponseEncoding()); if (retVal == null) { retVal = new ResponseEncoding(theReq.getServer().getFhirContext(), theReq.getServer().getDefaultResponseEncoding(), null); } return retVal; }
@Override public BaseServerResponseException preProcessOutgoingException(RequestDetails theRequestDetails, Throwable theException, HttpServletRequest theServletRequest) throws ServletException { BaseServerResponseException retVal; if (theException instanceof DataFormatException) { // Wrapping the DataFormatException as an InvalidRequestException so that it gets sent back to the client as a 400 response. retVal = new InvalidRequestException(theException); } else if (!(theException instanceof BaseServerResponseException)) { retVal = new InternalErrorException(theException); } else { retVal = (BaseServerResponseException) theException; } if (retVal.getOperationOutcome() == null) { retVal.setOperationOutcome(createOperationOutcome(theException, theRequestDetails.getServer().getFhirContext())); } return retVal; }
@SuppressWarnings("unchecked") public static <T extends IBaseResource> T loadResourceFromRequest(RequestDetails theRequest, @Nonnull BaseMethodBinding<?> theMethodBinding, Class<T> theResourceType) { FhirContext ctx = theRequest.getServer().getFhirContext(); if (ctValue != null) { if (ctValue.startsWith("application/x-www-form-urlencoded")) { String msg = theRequest.getServer().getFhirContext().getLocalizer().getMessage(ResourceParameter.class, "invalidContentTypeInRequest", ctValue, theMethodBinding.getRestOperationType()); throw new InvalidRequestException(msg);
public static IBaseResource parseResourceFromRequest(RequestDetails theRequest, BaseMethodBinding<?> theMethodBinding, Class<? extends IBaseResource> theResourceType) { IBaseResource retVal = null; if (theResourceType != null && IBaseBinary.class.isAssignableFrom(theResourceType)) { String ct = theRequest.getHeader(Constants.HEADER_CONTENT_TYPE); if (EncodingEnum.forContentTypeStrict(ct) == null) { FhirContext ctx = theRequest.getServer().getFhirContext(); IBaseBinary binary = BinaryUtil.newBinary(ctx); binary.setId(theRequest.getId()); binary.setContentType(ct); binary.setContent(theRequest.loadRequestContents()); retVal = binary; /* * Security context header, which is only in * DSTU3+ */ if (ctx.getVersion().getVersion().isEqualOrNewerThan(FhirVersionEnum.DSTU3)) { String securityContext = theRequest.getHeader(Constants.HEADER_X_SECURITY_CONTEXT); if (isNotBlank(securityContext)) { BinaryUtil.setSecurityContext(ctx, binary, securityContext); } } } } if (retVal == null) { retVal = loadResourceFromRequest(theRequest, theMethodBinding, theResourceType); } return retVal; }
FhirValidator validator = theRequestDetails.getServer().getFhirContext().newValidator(); if (myValidatorModules != null) { for (IValidatorModule next : myValidatorModules) { FhirContext ctx = theRequestDetails.getServer().getFhirContext(); outcome = OperationOutcomeUtil.newInstance(ctx); OperationOutcomeUtil.addIssue(ctx, outcome, "information", "No issues detected", "", "informational"); IParser parser = theRequestDetails.getServer().getFhirContext().newJsonParser().setPrettyPrint(false); String encoded = parser.encodeResourceToString(outcome); if (encoded.length() > getMaximumHeaderLength()) {
IBaseReference securityContext = BinaryUtil.getSecurityContext(theServer.getFhirContext(), bin); if (securityContext != null) { String securityContextRef = securityContext.getReferenceElement().getValue(); responseEncoding = new ResponseEncoding(theServer.getFhirContext(), theServer.getDefaultResponseEncoding(), null); if ("Bundle".equals(theServer.getFhirContext().getResourceDefinition(theResource).getName())) { encodingDomainResourceAsText = false; IParser parser = getNewParser(theServer.getFhirContext(), forVersion, theRequestDetails); parser.encodeResourceToWriter(theResource, writer);