Package ca.uhn.fhir.rest.api

Examples of ca.uhn.fhir.rest.api.MethodOutcome


    case Constants.STATUS_HTTP_201_CREATED:
    case Constants.STATUS_HTTP_204_NO_CONTENT:
      if (myReturnVoid) {
        return null;
      }
      MethodOutcome retVal = MethodUtil.process2xxResponse(getContext(), getResourceName(), theResponseStatusCode, theResponseMimeType, theResponseReader, theHeaders);
      return retVal;
    default:
      throw processNon2xxResponseAndReturnExceptionToThrow(theResponseStatusCode, theResponseMimeType, theResponseReader);
    }
View Full Code Here


    Object[] params = createParametersForServerRequest(theRequest, resource);
    addParametersForServerRequest(theRequest, params);

    HttpServletResponse servletResponse = theRequest.getServletResponse();
    MethodOutcome response;
    try {
      response = (MethodOutcome) invokeServerMethod(params);
    } catch (InternalErrorException e) {
      ourLog.error("Internal error during method invocation", e);
      EncodingEnum encoding = RestfulServer.determineResponseEncoding(theRequest.getServletRequest());
      streamOperationOutcome(e, theServer, encoding, servletResponse, theRequest);
      return;
    } catch (BaseServerResponseException e) {
      ourLog.info("Exception during method invocation: " + e.getMessage());
      EncodingEnum encoding = RestfulServer.determineResponseEncoding(theRequest.getServletRequest());
      streamOperationOutcome(e, theServer, encoding, servletResponse, theRequest);
      return;
    }

    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());
      }
    }
   
    OperationOutcome outcome = response != null ? response.getOperationOutcome():null;
    for (int i = theServer.getInterceptors().size() - 1; i >= 0; i--) {
      IServerInterceptor next = theServer.getInterceptors().get(i);
      boolean continueProcessing = next.outgoingResponse(theRequest, outcome, theRequest.getServletRequest(), theRequest.getServletResponse());
      if (!continueProcessing) {
        return;
      }
    }
   
    switch (getResourceOperationType()) {
    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");
      }
      if (response.getCreated() == null || Boolean.TRUE.equals(response.getCreated())) {
        servletResponse.setStatus(Constants.STATUS_HTTP_201_CREATED);
      } else {
        servletResponse.setStatus(Constants.STATUS_HTTP_200_OK);
      }
      addLocationHeader(theRequest, servletResponse, response);
      break;

    case UPDATE:
      if (response.getCreated() == null || Boolean.FALSE.equals(response.getCreated())) {
        servletResponse.setStatus(Constants.STATUS_HTTP_200_OK);
      } else {
        servletResponse.setStatus(Constants.STATUS_HTTP_201_CREATED);
      }
      addLocationHeader(theRequest, servletResponse, response);
      break;

    case VALIDATE:
    case DELETE:
    default:
      if (response == null) {
        if (isReturnVoid() == false) {
          throw new InternalErrorException("Method " + getMethod().getName() + " in type " + getMethod().getDeclaringClass().getCanonicalName() + " returned null");
        }
        servletResponse.setStatus(Constants.STATUS_HTTP_204_NO_CONTENT);
      } else {
        if (response.getOperationOutcome() == null) {
          servletResponse.setStatus(Constants.STATUS_HTTP_204_NO_CONTENT);
        } else {
          servletResponse.setStatus(Constants.STATUS_HTTP_200_OK);
        }
      }

    }

    theServer.addHeadersToResponse(servletResponse);

    if (outcome != null) {
      EncodingEnum encoding = RestfulServer.determineResponseEncoding(theRequest.getServletRequest());
      servletResponse.setContentType(encoding.getResourceContentType());
      Writer writer = servletResponse.getWriter();
      IParser parser = encoding.newParser(getContext());
      parser.setPrettyPrint(RestfulServer.prettyPrintResponse(theRequest));
      try {
        parser.encodeResourceToWriter(response.getOperationOutcome(), writer);
      } finally {
        writer.close();
      }
    } else {
      servletResponse.setContentType(Constants.CT_TEXT);
View Full Code Here

    RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
    final String resourceName = def.getName();

    OutcomeResponseHandler binding = new OutcomeResponseHandler(resourceName);

    MethodOutcome resp = invokeClient(binding, invocation);
    return resp;

  }
View Full Code Here

      myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
    }

    final String resourceName = myContext.getResourceDefinition(theType).getName();
    OutcomeResponseHandler binding = new OutcomeResponseHandler(resourceName);
    MethodOutcome resp = invokeClient(binding, invocation);
    return resp;
  }
View Full Code Here

    RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
    final String resourceName = def.getName();

    OutcomeResponseHandler binding = new OutcomeResponseHandler(resourceName);
    MethodOutcome resp = invokeClient(binding, invocation);
    return resp;
  }
View Full Code Here

    RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
    final String resourceName = def.getName();

    OutcomeResponseHandler binding = new OutcomeResponseHandler(resourceName);
    MethodOutcome resp = invokeClient(binding, invocation);
    return resp;
  }
View Full Code Here

    }

    @Override
    public MethodOutcome invokeClient(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws IOException,
        BaseServerResponseException {
      MethodOutcome response = BaseOutcomeReturningMethodBinding.process2xxResponse(myContext, myResourceName, theResponseStatusCode, theResponseMimeType, theResponseReader, theHeaders);
      return response;
    }
View Full Code Here

     * supposed to include the version in the Content-Location header, but
     * we allow it in the PUT URL as well..
     */
    String locationHeader = theRequest.getServletRequest().getHeader(Constants.HEADER_CONTENT_LOCATION);
    if (isNotBlank(locationHeader)) {
      MethodOutcome mo = new MethodOutcome();
      parseContentLocation(mo, getResourceName(), locationHeader);
      if (mo.getId() == null || mo.getId().isEmpty()) {
        throw new InvalidRequestException("Invalid Content-Location header for resource " + getResourceName() + ": " + locationHeader);
      }
      if (mo.getVersionId() != null && mo.getVersionId().isEmpty() == false) {
        theRequest.setVersion(mo.getVersionId());
      }
    }

    theParams[myIdParameterIndex] = theRequest.getId();
    if (myVersionIdParameterIndex != null) {
View Full Code Here

    case Constants.STATUS_HTTP_201_CREATED:
    case Constants.STATUS_HTTP_204_NO_CONTENT:
      if (myReturnVoid) {
        return null;
      }
      MethodOutcome retVal = process2xxResponse(getContext(), getResourceName(), theResponseStatusCode, theResponseMimeType, theResponseReader, theHeaders);
      return retVal;
    default:
      throw processNon2xxResponseAndReturnExceptionToThrow(theResponseStatusCode, theResponseMimeType, theResponseReader);
    }
View Full Code Here

    }

    Object[] params = createParametersForServerRequest(theRequest, resource);
    addParametersForServerRequest(theRequest, params);

    MethodOutcome response;
    try {
      response = (MethodOutcome) invokeServerMethod(params);
    } catch (InternalErrorException e) {
      ourLog.error("Internal error during method invocation", e);
      streamOperationOutcome(e, theServer, encoding, theResponse, theRequest);
      return;
    } catch (BaseServerResponseException e) {
      ourLog.info("Exception during method invocation: " + e.getMessage());
      streamOperationOutcome(e, theServer, encoding, theResponse, theRequest);
      return;
    }

    if (getResourceOperationType() == RestfulOperationTypeEnum.CREATE) {
      if (response == null) {
        throw new InternalErrorException("Method " + getMethod().getName() + " in type " + getMethod().getDeclaringClass().getCanonicalName() + " returned null, which is not allowed for create operation");
      }
      theResponse.setStatus(Constants.STATUS_HTTP_201_CREATED);
      addLocationHeader(theRequest, theResponse, response);
    } else if (response == null) {
      if (isReturnVoid() == false) {
        throw new InternalErrorException("Method " + getMethod().getName() + " in type " + getMethod().getDeclaringClass().getCanonicalName() + " returned null");
      }
      theResponse.setStatus(Constants.STATUS_HTTP_204_NO_CONTENT);
    } else {
      if (response.getOperationOutcome() == null) {
        theResponse.setStatus(Constants.STATUS_HTTP_204_NO_CONTENT);
      } else {
        theResponse.setStatus(Constants.STATUS_HTTP_200_OK);
      }
      if (getResourceOperationType() == RestfulOperationTypeEnum.UPDATE) {
        addLocationHeader(theRequest, theResponse, response);
      }

    }

    theServer.addHeadersToResponse(theResponse);

    if (response != null && response.getOperationOutcome() != null) {
      theResponse.setContentType(encoding.getResourceContentType());
      Writer writer = theResponse.getWriter();
      parser.setPrettyPrint(prettyPrintResponse(theRequest));
      try {
        parser.encodeResourceToWriter(response.getOperationOutcome(), writer);
      } finally {
        writer.close();
      }
    } else {
      theResponse.setContentType(Constants.CT_TEXT);
View Full Code Here

TOP

Related Classes of ca.uhn.fhir.rest.api.MethodOutcome

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.