public static Reader createRequestReader(RequestDetails theRequest) { return createRequestReader(theRequest, determineRequestCharset(theRequest)); }
@Override public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding<?> theMethodBinding) throws InternalErrorException, InvalidRequestException { switch (myMode) { case BODY: try { return IOUtils.toString(createRequestReader(theRequest)); } catch (IOException e) { // Shouldn't happen since we're reading from a byte array throw new InternalErrorException("Failed to load request", e); } case BODY_BYTE_ARRAY: return theRequest.loadRequestContents(); case ENCODING: return RestfulServerUtils.determineRequestEncodingNoDefault(theRequest); case RESOURCE: default: Class<? extends IBaseResource> resourceTypeToParse = myResourceType; if (myMethodIsOperation) { // Operations typically have a Parameters resource as the body resourceTypeToParse = null; } return parseResourceFromRequest(theRequest, theMethodBinding, resourceTypeToParse); } // } }
@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); } }
Reader requestReader = createRequestReader(theRequest, charset);
public static Reader createRequestReader(RequestDetails theRequest) { return createRequestReader(theRequest, determineRequestCharset(theRequest)); }
@Override public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding<?> theMethodBinding) throws InternalErrorException, InvalidRequestException { switch (myMode) { case BODY: try { return IOUtils.toString(createRequestReader(theRequest)); } catch (IOException e) { // Shouldn't happen since we're reading from a byte array throw new InternalErrorException("Failed to load request", e); } case BODY_BYTE_ARRAY: return theRequest.loadRequestContents(); case ENCODING: return RestfulServerUtils.determineRequestEncodingNoDefault(theRequest); case RESOURCE: default: Class<? extends IBaseResource> resourceTypeToParse = myResourceType; if (myMethodIsOperation) { // Operations typically have a Parameters resource as the body resourceTypeToParse = null; } return parseResourceFromRequest(theRequest, theMethodBinding, resourceTypeToParse); } // } }
@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); } }
Reader requestReader = createRequestReader(theRequest, charset);