@Override public Object invokeServer(IRestfulServer<?> theServer, RequestDetails theRequest) throws BaseServerResponseException, IOException { Object[] params = createParametersForServerRequest(theRequest); addParametersForServerRequest(theRequest, params); /* * No need to catch and handle exceptions here, we already handle them one level up including invoking interceptors * on them */ MethodOutcome response; Object methodReturn = invokeServerMethod(theServer, theRequest, params); if (methodReturn instanceof IBaseOperationOutcome) { response = new MethodOutcome(); response.setOperationOutcome((IBaseOperationOutcome) methodReturn); } else { response = (MethodOutcome) methodReturn; } if (response != null && response.getId() != null && response.getId().hasResourceType()) { if (getContext().getResourceDefinition(response.getId().getResourceType()) == null) { throw new InternalErrorException("Server method returned invalid resource ID: " + response.getId().getValue()); } } IBaseOperationOutcome outcome = response != null ? response.getOperationOutcome() : null; IBaseResource resource = response != null ? response.getResource() : null; return returnResponse(theServer, theRequest, response, outcome, resource); }
public BaseOutcomeReturningMethodBinding(Method theMethod, FhirContext theContext, Class<?> theMethodAnnotation, Object theProvider) { super(theMethod, theContext, theProvider); if (!theMethod.getReturnType().equals(MethodOutcome.class)) { if (!allowVoidReturnType()) { throw new ConfigurationException("Method " + theMethod.getName() + " in type " + theMethod.getDeclaringClass().getCanonicalName() + " is a @" + theMethodAnnotation.getSimpleName() + " method but it does not return " + MethodOutcome.class); } else if (theMethod.getReturnType() == void.class) { myReturnVoid = true; } } }
@Override public boolean incomingServerRequestMatchesMethod(RequestDetails theRequest) { Set<RequestTypeEnum> allowableRequestTypes = provideAllowableRequestTypes(); RequestTypeEnum requestType = theRequest.getRequestType(); if (!allowableRequestTypes.contains(requestType)) { return false; } if (!getResourceName().equals(theRequest.getResourceName())) { return false; } if (getMatchingOperation() == null && StringUtils.isNotBlank(theRequest.getOperation())) { return false; } if (getMatchingOperation() != null && !getMatchingOperation().equals(theRequest.getOperation())) { return false; } /* * Note: Technically this will match an update (PUT) method even if * there is no ID in the URL - We allow this here because there is no * better match for that, and this allows the update/PUT method to give * a helpful error if the client has forgotten to include the * ID in the URL. * * It's also needed for conditional update.. */ return true; }
private int getOperationStatus(MethodOutcome response) { switch (getRestOperationType()) { case CREATE: if (response == null) { throw new InternalErrorException("Method " + getMethod().getName() + " in type " + getMethod().getDeclaringClass().getCanonicalName() + " returned null, which is not allowed for create operation"); default: if (response == null) { if (isReturnVoid() == false) { throw new InternalErrorException("Method " + getMethod().getName() + " in type " + getMethod().getDeclaringClass().getCanonicalName() + " returned null");
private Object returnResponse(IRestfulServer<?> theServer, RequestDetails theRequest, MethodOutcome response, IBaseResource originalOutcome, IBaseResource resource) throws IOException { boolean allowPrefer = false; int operationStatus = getOperationStatus(response); IBaseResource outcome = originalOutcome; if (ourOperationsWhichAllowPreferHeader.contains(getRestOperationType())) { allowPrefer = true; responseId = responseId.withResourceType(getResourceName());
private int getOperationStatus(MethodOutcome response) { switch (getRestOperationType()) { case CREATE: if (response == null) { throw new InternalErrorException("Method " + getMethod().getName() + " in type " + getMethod().getDeclaringClass().getCanonicalName() + " returned null, which is not allowed for create operation"); default: if (response == null) { if (isReturnVoid() == false) { throw new InternalErrorException("Method " + getMethod().getName() + " in type " + getMethod().getDeclaringClass().getCanonicalName() + " returned null");
private Object returnResponse(IRestfulServer<?> theServer, RequestDetails theRequest, MethodOutcome response, IBaseResource originalOutcome, IBaseResource resource) throws IOException { boolean allowPrefer = false; int operationStatus = getOperationStatus(response); IBaseResource outcome = originalOutcome; if (ourOperationsWhichAllowPreferHeader.contains(getRestOperationType())) { allowPrefer = true; responseId = responseId.withResourceType(getResourceName());
@Override public Object invokeServer(IRestfulServer<?> theServer, RequestDetails theRequest) throws BaseServerResponseException, IOException { Object[] params = createParametersForServerRequest(theRequest); addParametersForServerRequest(theRequest, params); /* * No need to catch and handle exceptions here, we already handle them one level up including invoking interceptors * on them */ MethodOutcome response; Object methodReturn = invokeServerMethod(theServer, theRequest, params); if (methodReturn instanceof IBaseOperationOutcome) { response = new MethodOutcome(); response.setOperationOutcome((IBaseOperationOutcome) methodReturn); } else { response = (MethodOutcome) methodReturn; } if (response != null && response.getId() != null && response.getId().hasResourceType()) { if (getContext().getResourceDefinition(response.getId().getResourceType()) == null) { throw new InternalErrorException("Server method returned invalid resource ID: " + response.getId().getValue()); } } IBaseOperationOutcome outcome = response != null ? response.getOperationOutcome() : null; IBaseResource resource = response != null ? response.getResource() : null; return returnResponse(theServer, theRequest, response, outcome, resource); }
@Override public boolean incomingServerRequestMatchesMethod(RequestDetails theRequest) { Set<RequestTypeEnum> allowableRequestTypes = provideAllowableRequestTypes(); RequestTypeEnum requestType = theRequest.getRequestType(); if (!allowableRequestTypes.contains(requestType)) { return false; } if (!getResourceName().equals(theRequest.getResourceName())) { return false; } if (getMatchingOperation() == null && StringUtils.isNotBlank(theRequest.getOperation())) { return false; } if (getMatchingOperation() != null && !getMatchingOperation().equals(theRequest.getOperation())) { return false; } /* * Note: Technically this will match an update (PUT) method even if * there is no ID in the URL - We allow this here because there is no * better match for that, and this allows the update/PUT method to give * a helpful error if the client has forgotten to include the * ID in the URL. * * It's also needed for conditional update.. */ return true; }
public BaseOutcomeReturningMethodBinding(Method theMethod, FhirContext theContext, Class<?> theMethodAnnotation, Object theProvider) { super(theMethod, theContext, theProvider); if (!theMethod.getReturnType().equals(MethodOutcome.class)) { if (!allowVoidReturnType()) { throw new ConfigurationException("Method " + theMethod.getName() + " in type " + theMethod.getDeclaringClass().getCanonicalName() + " is a @" + theMethodAnnotation.getSimpleName() + " method but it does not return " + MethodOutcome.class); } else if (theMethod.getReturnType() == void.class) { myReturnVoid = true; } } }