Package ca.uhn.fhir.rest.api

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


    case Constants.STATUS_HTTP_204_NO_CONTENT:
      if (myReturnVoid) {
        return null;
      }
      List<String> locationHeaders = theHeaders.get("location");
      MethodOutcome retVal = new MethodOutcome();
      if (locationHeaders != null && locationHeaders.size() > 0) {
        String locationHeader = locationHeaders.get(0);
        parseContentLocation(retVal, locationHeader);
      }
      if (theResponseStatusCode != Constants.STATUS_HTTP_204_NO_CONTENT) {
        EncodingUtil ct = EncodingUtil.forContentType(theResponseMimeType);
        if (ct != null) {
          PushbackReader reader = new PushbackReader(theResponseReader);

          try {
            int firstByte = reader.read();
            if (firstByte == -1) {
              ourLog.debug("No content in response, not going to read");
              reader = null;
            } else {
              reader.unread(firstByte);
            }
          } catch (IOException e) {
            ourLog.debug("No content in response, not going to read", e);
            reader = null;
          }

          if (reader != null) {
            IParser parser = ct.newParser(getContext());
            OperationOutcome outcome = parser.parseResource(OperationOutcome.class, reader);
            retVal.setOperationOutcome(outcome);
          }

        } else {
          ourLog.debug("Ignoring response content of type: {}", theResponseMimeType);
        }
View Full Code Here


  public void invokeServer(RestfulServer theServer, Request theRequest, HttpServletResponse theResponse) throws BaseServerResponseException, IOException {
    Object[] params = new Object[myParameters.size()];

    addParametersForServerRequest(theRequest, params);

    MethodOutcome response;
    try {
      response = (MethodOutcome) this.getMethod().invoke(getProvider(), params);
    } catch (IllegalAccessException e) {
      throw new InternalErrorException(e);
    } catch (IllegalArgumentException e) {
      throw new InternalErrorException(e);
    } catch (InvocationTargetException e) {
      throw new InternalErrorException(e);
    }

    if (response == null) {
      if (myReturnVoid == false) {
        throw new ConfigurationException("Method " + getMethod().getName() + " in type " + getMethod().getDeclaringClass().getCanonicalName() + " returned null");
      } else {
        theResponse.setStatus(Constants.STATUS_HTTP_204_NO_CONTENT);
      }
    } else if (!myReturnVoid) {
      if (response.isCreated()) {
        theResponse.setStatus(Constants.STATUS_HTTP_201_CREATED);
        StringBuilder b = new StringBuilder();
        b.append(theRequest.getFhirServerBase());
        b.append('/');
        b.append(getResourceName());
        b.append('/');
        b.append(response.getId().getValue());
        if (response.getVersionId() != null && response.getVersionId().isEmpty() == false) {
          b.append("/_history/");
          b.append(response.getVersionId().getValue());
        }
        theResponse.addHeader("Location", b.toString());
      } else {
        theResponse.setStatus(Constants.STATUS_HTTP_200_OK);
      }
    } else {
      theResponse.setStatus(Constants.STATUS_HTTP_204_NO_CONTENT);
    }

    theServer.addHapiHeader(theResponse);

    Writer writer = theResponse.getWriter();
    try {
      if (response != null) {
        OperationOutcome outcome = new OperationOutcome();
        if (response.getOperationOutcome() != null && response.getOperationOutcome().getIssue() != null) {
          outcome.getIssue().addAll(response.getOperationOutcome().getIssue());
        }
        EncodingUtil encoding = BaseMethodBinding.determineResponseEncoding(theRequest.getServletRequest(), theRequest.getParameters());
        theResponse.setContentType(encoding.getResourceContentType());
        IParser parser = encoding.newParser(getContext());
        parser.encodeResourceToWriter(outcome, writer);
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, 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());
      }
    }

    // TODO: we should send an HTTP 412 automatically if the server
    // only has a method which requires a version ID, and no
View Full Code Here

      params[i] = param.translateQueryParametersIntoServerArgument(theRequest.getParameters(), resource);
    }

    addParametersForServerRequest(theRequest, params);

    MethodOutcome response;
    try {
      response = (MethodOutcome) this.getMethod().invoke(getProvider(), params);
    } catch (IllegalAccessException e) {
      throw new InternalErrorException(e);
    } catch (IllegalArgumentException e) {
      throw new InternalErrorException(e);
    } catch (InvocationTargetException e) {
      throw new InternalErrorException(e);
    }

    if (response == null) {
      if (isReturnVoid() == false) {
        throw new ConfigurationException("Method " + getMethod().getName() + " in type " + getMethod().getDeclaringClass().getCanonicalName() + " returned null");
      }
    } else if (!isReturnVoid()) {
      if (response.isCreated()) {
        theResponse.setStatus(Constants.STATUS_HTTP_201_CREATED);
        StringBuilder b = new StringBuilder();
        b.append(theRequest.getFhirServerBase());
        b.append('/');
        b.append(getResourceName());
        b.append('/');
        b.append(response.getId().getValue());
        if (response.getVersionId() != null && response.getVersionId().isEmpty() == false) {
          b.append("/_history/");
          b.append(response.getVersionId().getValue());
        }
        theResponse.addHeader("Location", b.toString());
      } else {
        theResponse.setStatus(Constants.STATUS_HTTP_200_OK);
      }
View Full Code Here

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

    OutcomeResponseHandler binding = new OutcomeResponseHandler(resourceName);

    MethodOutcome resp = invokeClient(binding, invocation, myLogRequestAndResponse);
    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, myLogRequestAndResponse);
    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, myLogRequestAndResponse);
    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, myLogRequestAndResponse);
    return resp;
  }
View Full Code Here

      myResourceName = theResourceName;
    }

    @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

    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

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.