public static Reader createRequestReader(RequestDetails theRequest) { return createRequestReader(theRequest, determineRequestCharset(theRequest)); }
if (next instanceof ResourceParameter) { resourceParameter = (ResourceParameter) next; if (resourceParameter.getMode() != ResourceParameter.Mode.RESOURCE) { continue; myResourceType = resourceParameter.getResourceType();
@Override public Object invokeServer(IRestfulServer<?> theServer, RequestDetails theRequest) throws BaseServerResponseException, IOException { if (theRequest.getRequestType() == RequestTypeEnum.POST) { IBaseResource requestContents = ResourceParameter.loadResourceFromRequest(theRequest, this, null); theRequest.getUserData().put(OperationParameter.REQUEST_CONTENTS_USERDATA_KEY, requestContents); } return super.invokeServer(theServer, 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 protected byte[] getByteStreamRequestContents() { return StringUtils.defaultString(myResourceString, "") .getBytes(ResourceParameter.determineRequestCharset(this)); }
@Override protected void populateActionRequestDetailsForInterceptor(RequestDetails theRequestDetails, ActionRequestDetails theDetails, Object[] theMethodParams) { super.populateActionRequestDetailsForInterceptor(theRequestDetails, theDetails, theMethodParams); /* * If the method has no parsed resource parameter, we parse here in order to have something for the interceptor. */ if (myResourceParameterIndex != -1) { theDetails.setResource((IBaseResource) theMethodParams[myResourceParameterIndex]); } else { theDetails.setResource(ResourceParameter.parseResourceFromRequest(theRequestDetails, this, myResourceType)); } }
@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); } }
public ValidateMethodBindingDstu2Plus(Class<?> theReturnResourceType, Class<? extends IBaseResource> theReturnTypeFromRp, Method theMethod, FhirContext theContext, Object theProvider, Validate theAnnotation) { super(theReturnResourceType, theReturnTypeFromRp, theMethod, theContext, theProvider, true, Constants.EXTOP_VALIDATE, theAnnotation.type(), new OperationParam[0], BundleTypeEnum.COLLECTION); List<IParameter> newParams = new ArrayList<IParameter>(); int idx = 0; for (IParameter next : getParameters()) { if (next instanceof ResourceParameter) { if (IBaseResource.class.isAssignableFrom(((ResourceParameter) next).getResourceType())) { Class<?> parameterType = theMethod.getParameterTypes()[idx]; if (String.class.equals(parameterType) || EncodingEnum.class.equals(parameterType)) { newParams.add(next); } else { OperationParameter parameter = new OperationParameter(theContext, Constants.EXTOP_VALIDATE, Constants.EXTOP_VALIDATE_RESOURCE, 0, 1); parameter.initializeTypes(theMethod, null, null, parameterType); newParams.add(parameter); } } else { newParams.add(next); } } else { newParams.add(next); } idx++; } setParameters(newParams); }
param = new ResourceParameter((Class<? extends IBaseResource>) parameterType, theProvider, mode, methodIsOperation); } else if (nextAnnotation instanceof IdParam) { param = new NullParameter();
@Override public boolean incomingRequestPostProcessed(RequestDetails theRequestDetails, HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException { EncodingEnum encoding = RestfulServerUtils.determineRequestEncodingNoDefault(theRequestDetails); if (encoding == null) { ourLog.trace("Incoming request does not appear to be FHIR, not going to validate"); return true; } Charset charset = ResourceParameter.determineRequestCharset(theRequestDetails); String requestText = new String(theRequestDetails.loadRequestContents(), charset); if (isBlank(requestText)) { ourLog.trace("Incoming request does not have a body"); return true; } ValidationResult validationResult = validate(requestText, theRequestDetails); // The JPA server will use this theRequestDetails.getUserData().put(REQUEST_VALIDATION_RESULT, validationResult); return true; }
@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 protected void populateActionRequestDetailsForInterceptor(RequestDetails theRequestDetails, ActionRequestDetails theDetails, Object[] theMethodParams) { super.populateActionRequestDetailsForInterceptor(theRequestDetails, theDetails, theMethodParams); /* * If the method has no parsed resource parameter, we parse here in order to have something for the interceptor. */ if (myTransactionParamIndex != -1) { theDetails.setResource((IBaseResource) theMethodParams[myTransactionParamIndex]); } else { Class<? extends IBaseResource> resourceType = getContext().getResourceDefinition("Bundle").getImplementingClass(); theDetails.setResource(ResourceParameter.parseResourceFromRequest(theRequestDetails, this, resourceType)); } }
@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); } }
public ValidateMethodBindingDstu2Plus(Class<?> theReturnResourceType, Class<? extends IBaseResource> theReturnTypeFromRp, Method theMethod, FhirContext theContext, Object theProvider, Validate theAnnotation) { super(theReturnResourceType, theReturnTypeFromRp, theMethod, theContext, theProvider, true, Constants.EXTOP_VALIDATE, theAnnotation.type(), new OperationParam[0], BundleTypeEnum.COLLECTION); List<IParameter> newParams = new ArrayList<IParameter>(); int idx = 0; for (IParameter next : getParameters()) { if (next instanceof ResourceParameter) { if (IBaseResource.class.isAssignableFrom(((ResourceParameter) next).getResourceType())) { Class<?> parameterType = theMethod.getParameterTypes()[idx]; if (String.class.equals(parameterType) || EncodingEnum.class.equals(parameterType)) { newParams.add(next); } else { OperationParameter parameter = new OperationParameter(theContext, Constants.EXTOP_VALIDATE, Constants.EXTOP_VALIDATE_RESOURCE, 0, 1); parameter.initializeTypes(theMethod, null, null, parameterType); newParams.add(parameter); } } else { newParams.add(next); } } else { newParams.add(next); } idx++; } setParameters(newParams); }
param = new ResourceParameter((Class<? extends IBaseResource>) parameterType, theProvider, mode, methodIsOperation); } else if (nextAnnotation instanceof IdParam) { param = new NullParameter();
FhirContext ctx = theRequest.getServer().getFhirContext(); final Charset charset = determineRequestCharset(theRequest); Reader requestReader = createRequestReader(theRequest, charset);
@Override public boolean incomingRequestPostProcessed(RequestDetails theRequestDetails, HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException { EncodingEnum encoding = RestfulServerUtils.determineRequestEncodingNoDefault(theRequestDetails); if (encoding == null) { ourLog.trace("Incoming request does not appear to be FHIR, not going to validate"); return true; } Charset charset = ResourceParameter.determineRequestCharset(theRequestDetails); String requestText = new String(theRequestDetails.loadRequestContents(), charset); if (isBlank(requestText)) { ourLog.trace("Incoming request does not have a body"); return true; } ValidationResult validationResult = validate(requestText, theRequestDetails); // The JPA server will use this theRequestDetails.getUserData().put(REQUEST_VALIDATION_RESULT, validationResult); return true; }
if (next instanceof ResourceParameter) { resourceParameter = (ResourceParameter) next; if (resourceParameter.getMode() != ResourceParameter.Mode.RESOURCE) { continue; myResourceType = resourceParameter.getResourceType();
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 protected void populateActionRequestDetailsForInterceptor(RequestDetails theRequestDetails, ActionRequestDetails theDetails, Object[] theMethodParams) { super.populateActionRequestDetailsForInterceptor(theRequestDetails, theDetails, theMethodParams); /* * If the method has no parsed resource parameter, we parse here in order to have something for the interceptor. */ if (myResourceParameterIndex != -1) { theDetails.setResource((IBaseResource) theMethodParams[myResourceParameterIndex]); } else { theDetails.setResource(ResourceParameter.parseResourceFromRequest(theRequestDetails, this, myResourceType)); } }