private static ResponseEncoding getEncodingForContentType(FhirContext theFhirContext, boolean theStrict, String theContentType, String thePreferContentType) { EncodingEnum encoding; if (theStrict) { encoding = EncodingEnum.forContentTypeStrict(theContentType); } else { encoding = EncodingEnum.forContentType(theContentType); } if (isNotBlank(thePreferContentType)) { if (thePreferContentType.equals(theContentType)) { return new ResponseEncoding(theFhirContext, encoding, theContentType); } } if (encoding == null) { return null; } return new ResponseEncoding(theFhirContext, encoding, theContentType); }
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; }
protected IParser createAppropriateParserForParsingServerRequest(RequestDetails theRequest) { String contentTypeHeader = theRequest.getHeader(Constants.HEADER_CONTENT_TYPE); EncodingEnum encoding; if (isBlank(contentTypeHeader)) { encoding = EncodingEnum.XML; } else { int semicolon = contentTypeHeader.indexOf(';'); if (semicolon != -1) { contentTypeHeader = contentTypeHeader.substring(0, semicolon); } encoding = EncodingEnum.forContentType(contentTypeHeader); } if (encoding == null) { throw new InvalidRequestException("Request contins non-FHIR conent-type header value: " + contentTypeHeader); } IParser parser = encoding.newParser(getContext()); return parser; }
@Override public IBaseOperationOutcome invokeClient(String theResponseMimeType, InputStream theResponseInputStream, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws BaseServerResponseException { EncodingEnum respType = EncodingEnum.forContentType(theResponseMimeType); if (respType == null) { return null; } IParser parser = respType.newParser(myContext); IBaseOperationOutcome retVal; try { // TODO: handle if something else than OO comes back retVal = (IBaseOperationOutcome) parser.parseResource(theResponseInputStream); } catch (DataFormatException e) { ourLog.warn("Failed to parse OperationOutcome response", e); return null; } MethodUtil.parseClientRequestResourceHeaders(null, theHeaders, retVal); return retVal; } }
EncodingEnum ct = EncodingEnum.forContentType(theResponseMimeType); if (ct != null) { PushbackInputStream reader = new PushbackInputStream(theResponseReader);
@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; }
EncodingEnum encoding = EncodingEnum.forContentType(contentType); if (encoding != null) { byte[] requestContents = myRequestDetails.loadRequestContents();
protected void validateChannelPayload(Subscription theResource) { if (!isBlank(theResource.getChannel().getPayload()) && EncodingEnum.forContentType(theResource.getChannel().getPayload()) == null) { throw new UnprocessableEntityException("Invalid value for Subscription.channel.payload: " + theResource.getChannel().getPayload()); } }
protected void validateChannelPayload(Subscription theResource) { if (!isBlank(theResource.getChannel().getPayload()) && EncodingEnum.forContentType(theResource.getChannel().getPayload()) == null) { throw new UnprocessableEntityException("Invalid value for Subscription.channel.payload: " + theResource.getChannel().getPayload()); } }
protected IParser createAppropriateParserForParsingResponse(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, List<Class<? extends IBaseResource>> thePreferTypes) { EncodingEnum encoding = EncodingEnum.forContentType(theResponseMimeType); if (encoding == null) { NonFhirResponseException ex = NonFhirResponseException.newInstance(theResponseStatusCode, theResponseMimeType, theResponseReader); populateException(ex, theResponseReader); throw ex; } IParser parser = encoding.newParser(getContext()); parser.setPreferTypes(thePreferTypes); return parser; }
protected IParser createAppropriateParserForParsingResponse(String theResponseMimeType, InputStream theResponseInputStream, int theResponseStatusCode, List<Class<? extends IBaseResource>> thePreferTypes) { EncodingEnum encoding = EncodingEnum.forContentType(theResponseMimeType); if (encoding == null) { NonFhirResponseException ex = NonFhirResponseException.newInstance(theResponseStatusCode, theResponseMimeType, theResponseInputStream); populateException(ex, theResponseInputStream); throw ex; } IParser parser = encoding.newParser(getContext()); parser.setPreferTypes(thePreferTypes); return parser; }
if (format != null) { for (String nextFormat : format) { EncodingEnum retVal = EncodingEnum.forContentType(nextFormat); if (retVal != null) { return new ResponseEncoding(theReq.getServer().getFhirContext(), retVal, nextFormat);
@Override public T invokeClient(String theResponseMimeType, InputStream theResponseInputStream, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws BaseServerResponseException { EncodingEnum respType = EncodingEnum.forContentType(theResponseMimeType); if (respType == null) { if (myAllowHtmlResponse && theResponseMimeType.toLowerCase().contains(Constants.CT_HTML) && myReturnType != null) { return readHtmlResponse(theResponseInputStream); } throw NonFhirResponseException.newInstance(theResponseStatusCode, theResponseMimeType, theResponseInputStream); } IParser parser = respType.newParser(getFhirContext()); parser.setServerBaseUrl(getUrlBase()); if (myPreferResponseTypes != null) { parser.setPreferTypes(myPreferResponseTypes); } T retVal = parser.parseResource(myReturnType, theResponseInputStream); MethodUtil.parseClientRequestResourceHeaders(myId, theHeaders, retVal); return retVal; }
payloadType = EncodingEnum.forContentType(payloadString);
@SuppressWarnings("unchecked") @Override public T invokeClient(String theResponseMimeType, InputStream theResponseInputStream, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws BaseServerResponseException { EncodingEnum respType = EncodingEnum.forContentType(theResponseMimeType); if (respType == null) { throw NonFhirResponseException.newInstance(theResponseStatusCode, theResponseMimeType, theResponseInputStream); } IParser parser = respType.newParser(myContext); RuntimeResourceDefinition type = myContext.getResourceDefinition("Parameters"); IBaseResource retVal = parser.parseResource(type.getImplementingClass(), theResponseInputStream); BaseRuntimeChildDefinition paramChild = type.getChildByName("parameter"); BaseRuntimeElementCompositeDefinition<?> paramChildElem = (BaseRuntimeElementCompositeDefinition<?>) paramChild.getChildByName("parameter"); List<IBase> parameter = paramChild.getAccessor().getValues(retVal); if (parameter == null || parameter.isEmpty()) { return (T) myContext.getElementDefinition(myType).newInstance(); } IBase param = parameter.get(0); List<IBase> meta = paramChildElem.getChildByName("value[x]").getAccessor().getValues(param); if (meta.isEmpty()) { return (T) myContext.getElementDefinition(myType).newInstance(); } return (T) meta.get(0); } }
message = message + ": " + body; } else { EncodingEnum enc = EncodingEnum.forContentType(mimeType); if (enc != null) { IParser p = enc.newParser(theContext);
protected IParser createAppropriateParserForParsingResponse(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, List<Class<? extends IBaseResource>> thePreferTypes) { EncodingEnum encoding = EncodingEnum.forContentType(theResponseMimeType); if (encoding == null) { NonFhirResponseException ex = NonFhirResponseException.newInstance(theResponseStatusCode, theResponseMimeType, theResponseReader); populateException(ex, theResponseReader); throw ex; } IParser parser = encoding.newParser(getContext()); parser.setPreferTypes(thePreferTypes); return parser; }
protected void validateChannelPayload(Subscription theResource) { if (!isBlank(theResource.getChannel().getPayload()) && EncodingEnum.forContentType(theResource.getChannel().getPayload()) == null) { throw new UnprocessableEntityException("Invalid value for Subscription.channel.payload: " + theResource.getChannel().getPayload()); } }
protected void validateChannelPayload(Subscription theResource) { if (!isBlank(theResource.getChannel().getPayload()) && EncodingEnum.forContentType(theResource.getChannel().getPayload()) == null) { throw new UnprocessableEntityException("Invalid value for Subscription.channel.payload: " + theResource.getChannel().getPayload()); } }
protected IParser createAppropriateParserForParsingResponse(String theResponseMimeType, InputStream theResponseInputStream, int theResponseStatusCode, List<Class<? extends IBaseResource>> thePreferTypes) { EncodingEnum encoding = EncodingEnum.forContentType(theResponseMimeType); if (encoding == null) { NonFhirResponseException ex = NonFhirResponseException.newInstance(theResponseStatusCode, theResponseMimeType, theResponseInputStream); populateException(ex, theResponseInputStream); throw ex; } IParser parser = encoding.newParser(getContext()); parser.setPreferTypes(thePreferTypes); return parser; }