@Override public IHttpRequest createBinaryRequest(FhirContext theContext, IBaseBinary theBinary) { initBaseRequest(theContext, null, createPostBody(theBinary.getContent(), theBinary.getContentType())); return myRequest; }
@Override public IHttpRequest createBinaryRequest(FhirContext theContext, IBaseBinary theBinary) { Entity<String> entity = Entity.entity(theBinary.getContentAsBase64(), theBinary.getContentType()); JaxRsHttpRequest retVal = createHttpRequest(entity); addHeadersToRequest(retVal, null, theContext); return retVal; }
@Override public Object invokeClientForBinary(String theResponseMimeType, InputStream theResponseReader, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws IOException, BaseServerResponseException { byte[] contents = IOUtils.toByteArray(theResponseReader); IBaseBinary resource = (IBaseBinary) getContext().getResourceDefinition("Binary").newInstance(); resource.setContentType(theResponseMimeType); resource.setContent(contents); switch (getMethodReturnType()) { case LIST_OF_RESOURCES: return Collections.singletonList(resource); case RESOURCE: return resource; case BUNDLE_RESOURCE: case METHOD_OUTCOME: break; } throw new IllegalStateException("" + getMethodReturnType()); // should not happen }
if (isNotBlank(binary.getContentType()) && EncodingEnum.forContentTypeStrict(binary.getContentType()) == null) { return httpClient.createBinaryRequest(getContext(), binary);
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 Response sendAttachmentResponse(IBaseBinary bin, int statusCode, String contentType) throws IOException { ResponseBuilder response = buildResponse(statusCode); if (bin.getContent() != null && bin.getContent().length > 0) { response.header(Constants.HEADER_CONTENT_TYPE, contentType).entity(bin.getContent()); } return response.build(); }
if (isNotBlank(bin.getContentType())) { contentType = bin.getContentType(); } else { contentType = Constants.CT_OCTET_STREAM;
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 Object sendAttachmentResponse(IBaseBinary bin, int stausCode, String contentType) throws IOException { addHeaders(); HttpServletResponse theHttpResponse = getRequestDetails().getServletResponse(); theHttpResponse.setStatus(stausCode); theHttpResponse.setContentType(contentType); theHttpResponse.setCharacterEncoding(null); if (bin.getContent() == null || bin.getContent().length == 0) { return theHttpResponse.getOutputStream(); } theHttpResponse.setContentLength(bin.getContent().length); ServletOutputStream oos = theHttpResponse.getOutputStream(); oos.write(bin.getContent()); return oos; }
@Override public IHttpRequest createBinaryRequest(FhirContext theContext, IBaseBinary theBinary) { byte[] content = theBinary.getContent(); IHttpRequest retVal = createHttpRequest(content); addHeadersToRequest(retVal, null, theContext); retVal.addHeader(Constants.HEADER_CONTENT_TYPE, theBinary.getContentType()); return retVal; }
writeOptionalTagWithValue(theEventWriter, "contentType", bin.getContentType()); writeOptionalTagWithValue(theEventWriter, "content", bin.getContentAsBase64()); } else { encodeCompositeElementToStreamWriter(theResource, theResource, theEventWriter, theContainedResource, theSubResource, new CompositeChildElement(resDef, theSubResource));
if (isNotBlank(binary.getContentType()) && EncodingEnum.forContentTypeStrict(binary.getContentType()) == null) { return httpClient.createBinaryRequest(getContext(), binary);
@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; }
@Override public Object sendAttachmentResponse(IBaseBinary bin, int stausCode, String contentType) throws IOException { addHeaders(); HttpServletResponse theHttpResponse = getRequestDetails().getServletResponse(); theHttpResponse.setStatus(stausCode); theHttpResponse.setContentType(contentType); theHttpResponse.setCharacterEncoding(null); if (bin.getContent() == null || bin.getContent().length == 0) { return theHttpResponse.getOutputStream(); } theHttpResponse.setContentLength(bin.getContent().length); ServletOutputStream oos = theHttpResponse.getOutputStream(); oos.write(bin.getContent()); return oos; }
@Override public IHttpRequest createBinaryRequest(FhirContext theContext, IBaseBinary theBinary) { byte[] content = theBinary.getContent(); IHttpRequest retVal = createHttpRequest(content); addHeadersToRequest(retVal, null, theContext); retVal.addHeader(Constants.HEADER_CONTENT_TYPE, theBinary.getContentType()); return retVal; }
writeOptionalTagWithValue(theEventWriter, "contentType", bin.getContentType()); writeOptionalTagWithValue(theEventWriter, "content", bin.getContentAsBase64()); } else { encodeCompositeElementToStreamWriter(theResource, theResource, theEventWriter, theContainedResource, new CompositeChildElement(resDef, theEncodeContext), theEncodeContext);
if (isNotBlank(bin.getContentType())) { contentType = bin.getContentType(); } else { contentType = Constants.CT_OCTET_STREAM;
@Override public Object invokeClientForBinary(String theResponseMimeType, InputStream theResponseReader, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws IOException, BaseServerResponseException { byte[] contents = IOUtils.toByteArray(theResponseReader); IBaseBinary resource = (IBaseBinary) getContext().getResourceDefinition("Binary").newInstance(); resource.setContentType(theResponseMimeType); resource.setContent(contents); switch (getMethodReturnType()) { case LIST_OF_RESOURCES: return Collections.singletonList(resource); case RESOURCE: return resource; case BUNDLE_RESOURCE: case METHOD_OUTCOME: break; } throw new IllegalStateException("" + getMethodReturnType()); // should not happen }
@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; }