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; }
public static String createPagingLink(Set<Include> theIncludes, String theServerBase, String theSearchId, int theOffset, int theCount, Map<String, String[]> theRequestParameters, boolean thePrettyPrint, BundleTypeEnum theBundleType) { return createPagingLink(theIncludes, theServerBase, theSearchId, theOffset, theCount, theRequestParameters, thePrettyPrint, theBundleType, null); }
if (parameters.containsKey(Constants.PARAM_FORMAT)) { FhirVersionEnum forVersion = theResource.getStructureFhirVersionEnum(); p = RestfulServerUtils.getNewParser(theRequestDetails.getServer().getFhirContext(), forVersion, theRequestDetails); } else { EncodingEnum defaultResponseEncoding = theRequestDetails.getServer().getDefaultResponseEncoding(); p = defaultResponseEncoding.newParser(theRequestDetails.getServer().getFhirContext()); RestfulServerUtils.configureResponseParser(theRequestDetails, p);
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; }
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); retVal = determineRequestEncodingNoDefaultReturnRE(theReq);
ResponseEncoding responseEncoding = RestfulServerUtils.determineResponseEncodingNoDefault(theRequestDetails, theServer.getDefaultResponseEncoding()); if (theResource.getIdElement() != null) { IIdType resourceId = theResource.getIdElement(); fullId = fullyQualifyResourceIdOrReturnNull(theServer, theResource, serverBase, resourceId); if (fullId != null && fullId.hasVersionIdPart()) { String versionIdPart = fullId.getVersionIdPart(); response.addHeader(Constants.HEADER_ETAG, createEtag(versionIdPart)); } else if (theResource != null && theResource.getMeta() != null && isNotBlank(theResource.getMeta().getVersionId())) { String versionId = theResource.getMeta().getVersionId(); response.addHeader(Constants.HEADER_ETAG, createEtag(versionId)); lastUpdated = theOperationResourceLastUpdated; } else { lastUpdated = extractLastUpdatedFromResource(theResource); IParser parser = getNewParser(theServer.getFhirContext(), forVersion, theRequestDetails); parser.encodeResourceToWriter(theResource, writer);
PreferReturnEnum preferReturn = RestfulServerUtils.parsePreferHeader(prefer); if (preferReturn == null) { preferReturn = theServer.getDefaultPreferReturn(); restfulResponse.setOperationResourceLastUpdated(RestfulServerUtils.extractLastUpdatedFromResource(response.getResource())); responseId = RestfulServerUtils.fullyQualifyResourceIdOrReturnNull(theServer, resource, serverBase, responseId); restfulResponse.setOperationResourceId(responseId); boolean prettyPrint = RestfulServerUtils.prettyPrintResponse(theServer, theRequest); Set<SummaryEnum> summaryMode = Collections.emptySet();
resourceList = Collections.emptyList(); RestfulServerUtils.validateResourceListNotNull(resourceList); resourceList = Collections.emptyList(); RestfulServerUtils.validateResourceListNotNull(resourceList); boolean prettyPrint = RestfulServerUtils.prettyPrintResponse(theServer, theRequest); linkNext = RestfulServerUtils.createPagingLink(theIncludes, serverBase, searchId, theResult.getNextPageId(), theRequest.getParameters(), prettyPrint, theBundleType); linkPrev = RestfulServerUtils.createPagingLink(theIncludes, serverBase, searchId, theResult.getPreviousPageId(), theRequest.getParameters(), prettyPrint, theBundleType); linkNext = (RestfulServerUtils.createPagingLink(theIncludes, serverBase, searchId, theOffset + numToReturn, numToReturn, theRequest.getParameters(), prettyPrint, theBundleType)); linkPrev = RestfulServerUtils.createPagingLink(theIncludes, serverBase, searchId, start, theLimit, theRequest.getParameters(), prettyPrint, theBundleType);
numToReturn = numTotalResults; resourceList = theResult.getResources(0, numToReturn); RestfulServerUtils.validateResourceListNotNull(resourceList); RestfulServerUtils.validateResourceListNotNull(resourceList); if (numTotalResults == null || theOffset + numToReturn < numTotalResults) { myBundle.getLinkNext() .setValue(RestfulServerUtils.createPagingLink(theIncludes, theServerBase, searchId, theOffset + numToReturn, numToReturn, theResponseEncoding, thePrettyPrint, theBundleType)); myBundle.getLinkPrevious().setValue(RestfulServerUtils.createPagingLink(theIncludes, theServerBase, searchId, start, limit, theResponseEncoding, thePrettyPrint, theBundleType));
/** * This method is called for nested bundles (e.g. if we received a transaction with an entry that * was a GET search, this method is called on the bundle for the search result, that will be placed in the * outer bundle). This method applies the _summary and _content parameters to the output of * that bundle. * <p> * TODO: This isn't the most efficient way of doing this.. hopefully we can come up with something better in the future. */ private IBaseResource filterNestedBundle(RequestDetails theRequestDetails, IBaseResource theResource) { IParser p = myContext.newJsonParser(); RestfulServerUtils.configureResponseParser(theRequestDetails, p); return p.parseResource(theResource.getClass(), p.encodeResourceToString(theResource)); }
/** * @TODO: this method is only called from one place and should be removed anyway */ public static EncodingEnum determineRequestEncoding(RequestDetails theReq) { EncodingEnum retVal = determineRequestEncodingNoDefault(theReq); if (retVal != null) { return retVal; } return EncodingEnum.XML; }
if (outcome.getResource() != null) { String prefer = theRequestDetails.getHeader(Constants.HEADER_PREFER); PreferReturnEnum preferReturn = RestfulServerUtils.parsePreferHeader(prefer); if (preferReturn != null) { if (preferReturn == PreferReturnEnum.REPRESENTATION) {
entry.getResponse().setEtag(RestfulServerUtils.createEtag(id.getVersionIdPart()));
protected String getParserType() { EncodingEnum encodingEnum = RestfulServerUtils.determineResponseEncodingWithDefault(getRequestDetails()).getEncoding(); return encodingEnum == EncodingEnum.JSON ? MediaType.APPLICATION_JSON : MediaType.APPLICATION_XML; }
@Override public Response returnResponse(ParseAction<?> outcome, int operationStatus, boolean allowPrefer, MethodOutcome response, String resourceName) throws IOException { StringWriter writer = new StringWriter(); if (outcome != null) { FhirContext fhirContext = getRequestDetails().getServer().getFhirContext(); IParser parser = RestfulServerUtils.getNewParser(fhirContext, fhirContext.getVersion().getVersion(), getRequestDetails()); outcome.execute(parser, writer); } return sendWriterResponse(operationStatus, getParserType(), null, writer); }
public static EncodingEnum determineRequestEncodingNoDefault(RequestDetails theReq) { ResponseEncoding retVal = determineRequestEncodingNoDefaultReturnRE(theReq); if (retVal == null) { return null; } return retVal.getEncoding(); }
@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); } }
ResponseEncoding responseEncoding = RestfulServerUtils.determineResponseEncodingNoDefault(theRequestDetails, theServer.getDefaultResponseEncoding()); if (theResource.getIdElement() != null) { IIdType resourceId = theResource.getIdElement(); fullId = fullyQualifyResourceIdOrReturnNull(theServer, theResource, serverBase, resourceId); if (fullId != null && fullId.hasVersionIdPart()) { String versionIdPart = fullId.getVersionIdPart(); response.addHeader(Constants.HEADER_ETAG, createEtag(versionIdPart)); } else if (theResource != null && theResource.getMeta() != null && isNotBlank(theResource.getMeta().getVersionId())) { String versionId = theResource.getMeta().getVersionId(); response.addHeader(Constants.HEADER_ETAG, createEtag(versionId)); lastUpdated = theOperationResourceLastUpdated; } else { lastUpdated = extractLastUpdatedFromResource(theResource); IParser parser = getNewParser(theServer.getFhirContext(), forVersion, theRequestDetails); parser.encodeResourceToWriter(theResource, writer);
PreferReturnEnum preferReturn = RestfulServerUtils.parsePreferHeader(prefer); if (preferReturn == null) { preferReturn = theServer.getDefaultPreferReturn(); restfulResponse.setOperationResourceLastUpdated(RestfulServerUtils.extractLastUpdatedFromResource(response.getResource())); responseId = RestfulServerUtils.fullyQualifyResourceIdOrReturnNull(theServer, resource, serverBase, responseId); restfulResponse.setOperationResourceId(responseId); boolean prettyPrint = RestfulServerUtils.prettyPrintResponse(theServer, theRequest); Set<SummaryEnum> summaryMode = Collections.emptySet();
resourceList = Collections.emptyList(); RestfulServerUtils.validateResourceListNotNull(resourceList); resourceList = Collections.emptyList(); RestfulServerUtils.validateResourceListNotNull(resourceList); boolean prettyPrint = RestfulServerUtils.prettyPrintResponse(theServer, theRequest); linkNext = RestfulServerUtils.createPagingLink(theIncludes, theRequest, searchId, theResult.getNextPageId(), theRequest.getParameters(), prettyPrint, theBundleType); linkPrev = RestfulServerUtils.createPagingLink(theIncludes, theRequest, searchId, theResult.getPreviousPageId(), theRequest.getParameters(), prettyPrint, theBundleType); linkNext = (RestfulServerUtils.createPagingLink(theIncludes, theRequest, searchId, theOffset + numToReturn, numToReturn, theRequest.getParameters(), prettyPrint, theBundleType)); linkPrev = RestfulServerUtils.createPagingLink(theIncludes, theRequest, searchId, start, theLimit, theRequest.getParameters(), prettyPrint, theBundleType);