EncodingEnum linkEncoding = theRequest.getParameters().containsKey(Constants.PARAM_FORMAT) && responseEncoding != null ? responseEncoding.getEncoding() : null;
EncodingEnum retVal = EncodingEnum.forContentType(nextFormat); if (retVal != null) { return new ResponseEncoding(theReq.getServer().getFhirContext(), retVal, nextFormat); if (q > bestQ || (q == bestQ && encoding.getEncoding() == thePrefer)) {
if (contentType.equals(responseEncoding.getContentType())) { returnRawResponse(theRequestDetails, theServletResponse, contentType, data); return false;
responseEncoding = new ResponseEncoding(theServer.getFhirContext(), theServer.getDefaultResponseEncoding(), null); contentType = Constants.CT_HTML; } else { contentType = responseEncoding.getResourceContentType();
EncodingEnum linkEncoding = theRequest.getParameters().containsKey(Constants.PARAM_FORMAT) && responseEncoding != null ? responseEncoding.getEncoding() : null;
ResponseEncoding encoding = RestfulServerUtils.determineResponseEncodingNoDefault(myRequestDetails, myRequestDetails.getServer().getDefaultResponseEncoding()); if (encoding != null) { return encoding.getEncoding().name();
EncodingEnum retVal = EncodingEnum.forContentType(nextFormat); if (retVal != null) { return new ResponseEncoding(theReq.getServer().getFhirContext(), retVal, nextFormat); if (q > bestQ || (q == bestQ && encoding.getEncoding() == thePrefer)) {
encodingEnum = responseEncoding.getEncoding();
if (contentType.equals(responseEncoding.getContentType())) { returnRawResponse(theRequestDetails, theServletResponse, contentType, data); return false;
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; }
private void streamResponseHeaders(RequestDetails theRequestDetails, HttpServletResponse theServletResponse, StringBuilder b) { if (theServletResponse.getHeaderNames().isEmpty() == false) { b.append("<h1>Response Headers</h1>"); b.append("<div class=\"headersDiv\">"); for (String nextHeaderName : theServletResponse.getHeaderNames()) { for (String nextHeaderValue : theServletResponse.getHeaders(nextHeaderName)) { /* * Let's pretend we're returning a FHIR content type even though we're * actually returning an HTML one */ if (nextHeaderName.equalsIgnoreCase(Constants.HEADER_CONTENT_TYPE)) { ResponseEncoding responseEncoding = RestfulServerUtils.determineResponseEncodingNoDefault(theRequestDetails, theRequestDetails.getServer().getDefaultResponseEncoding()); if (responseEncoding != null && isNotBlank(responseEncoding.getResourceContentType())) { nextHeaderValue = responseEncoding.getResourceContentType() + ";charset=utf-8"; } } b.append("<div class=\"headersRow\">"); b.append("<span class=\"headerName\">").append(nextHeaderName).append(": ").append("</span>"); b.append("<span class=\"headerValue\">").append(nextHeaderValue).append("</span>"); b.append("</div>"); } } b.append("</div>"); } }
public Object returnResponse(ServletRequestDetails theRequest, ParseAction<?> outcome, int operationStatus, boolean allowPrefer, MethodOutcome response, String resourceName) throws IOException { HttpServletResponse servletResponse = theRequest.getServletResponse(); servletResponse.setStatus(operationStatus); servletResponse.setCharacterEncoding(Constants.CHARSET_NAME_UTF8); addHeadersToResponse(servletResponse); if (allowPrefer) { addContentLocationHeaders(theRequest, servletResponse, response, resourceName); } Writer writer; if (outcome != null) { ResponseEncoding encoding = RestfulServerUtils.determineResponseEncodingWithDefault(theRequest); servletResponse.setContentType(encoding.getResourceContentType()); writer = servletResponse.getWriter(); IParser parser = encoding.getEncoding().newParser(getFhirContext()); parser.setPrettyPrint(RestfulServerUtils.prettyPrintResponse(this, theRequest)); outcome.execute(parser, writer); } else { servletResponse.setContentType(Constants.CT_TEXT_WITH_UTF8); writer = servletResponse.getWriter(); } return writer; }
public static IParser getNewParser(FhirContext theContext, FhirVersionEnum theForVersion, RequestDetails theRequestDetails) { FhirContext context = getContextForVersion(theContext, theForVersion); // Determine response encoding EncodingEnum responseEncoding = RestfulServerUtils.determineResponseEncodingWithDefault(theRequestDetails).getEncoding(); IParser parser; switch (responseEncoding) { case JSON: parser = context.newJsonParser(); break; case XML: default: parser = context.newXmlParser(); break; } configureResponseParser(theRequestDetails, parser); return parser; }
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); }
public static EncodingEnum determineRequestEncodingNoDefault(RequestDetails theReq) { ResponseEncoding retVal = determineRequestEncodingNoDefaultReturnRE(theReq); if (retVal == null) { return null; } return retVal.getEncoding(); }
public String getResourceContentType() { if (Boolean.TRUE.equals(isNonLegacy())) { return getEncoding().getResourceContentTypeNonLegacy(); } return getEncoding().getResourceContentType(); }
/** * 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; }
responseEncoding = new ResponseEncoding(theServer.getFhirContext(), theServer.getDefaultResponseEncoding(), null); contentType = Constants.CT_HTML; } else { contentType = responseEncoding.getResourceContentType();
ResponseEncoding encoding = RestfulServerUtils.determineResponseEncodingNoDefault(myRequestDetails, myRequestDetails.getServer().getDefaultResponseEncoding()); if (encoding != null) { return encoding.getEncoding().name();
encodingEnum = responseEncoding.getEncoding();