@Override public IBaseResource invokeClient(String theResponseMimeType, InputStream theResponseInputStream, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws BaseServerResponseException { /* * For operation responses, if the response content type is a FHIR content-type * (which is will probably almost always be) we just handle it normally. However, * if we get back a successful (2xx) response from an operation, and the content * type is something other than FHIR, we'll return it as a Binary wrapped in * a Parameters resource. */ EncodingEnum respType = EncodingEnum.forContentType(theResponseMimeType); if (respType != null || theResponseStatusCode < 200 || theResponseStatusCode >= 300) { return super.invokeClient(theResponseMimeType, theResponseInputStream, theResponseStatusCode, theHeaders); } // Create a Binary resource to return IBaseBinary responseBinary = BinaryUtil.newBinary(getFhirContext()); // Fetch the content type String contentType = null; List<String> contentTypeHeaders = theHeaders.get(Constants.HEADER_CONTENT_TYPE_LC); if (contentTypeHeaders != null && contentTypeHeaders.size() > 0) { contentType = contentTypeHeaders.get(0); } responseBinary.setContentType(contentType); // Fetch the content itself try { responseBinary.setContent(IOUtils.toByteArray(theResponseInputStream)); } catch (IOException e) { throw new InternalErrorException("IO failure parsing response", e); } return responseBinary; }
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; }
@Override public IBaseResource invokeClient(String theResponseMimeType, InputStream theResponseInputStream, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws BaseServerResponseException { /* * For operation responses, if the response content type is a FHIR content-type * (which is will probably almost always be) we just handle it normally. However, * if we get back a successful (2xx) response from an operation, and the content * type is something other than FHIR, we'll return it as a Binary wrapped in * a Parameters resource. */ EncodingEnum respType = EncodingEnum.forContentType(theResponseMimeType); if (respType != null || theResponseStatusCode < 200 || theResponseStatusCode >= 300) { return super.invokeClient(theResponseMimeType, theResponseInputStream, theResponseStatusCode, theHeaders); } // Create a Binary resource to return IBaseBinary responseBinary = BinaryUtil.newBinary(getFhirContext()); // Fetch the content type String contentType = null; List<String> contentTypeHeaders = theHeaders.get(Constants.HEADER_CONTENT_TYPE_LC); if (contentTypeHeaders != null && contentTypeHeaders.size() > 0) { contentType = contentTypeHeaders.get(0); } responseBinary.setContentType(contentType); // Fetch the content itself try { responseBinary.setContent(IOUtils.toByteArray(theResponseInputStream)); } catch (IOException e) { throw new InternalErrorException("IO failure parsing response", e); } return responseBinary; }
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; }