Package ca.uhn.fhir.rest.server

Examples of ca.uhn.fhir.rest.server.EncodingEnum


      params[myVersionIdParamIndex] = theRequest.getVersionId();
    }

    TagList resp = (TagList) invokeServerMethod(params);

    EncodingEnum responseEncoding = RestfulServer.determineResponseEncoding(theRequest.getServletRequest());

    theResponse.setContentType(responseEncoding.getResourceContentType());
    theResponse.setStatus(Constants.STATUS_HTTP_200_OK);
    theResponse.setCharacterEncoding(Constants.CHARSET_UTF_8);

    theServer.addHeadersToResponse(theResponse);

    IParser parser = responseEncoding.newParser(getContext());
    parser.setPrettyPrint(RestfulServer.prettyPrintResponse(theRequest));
    PrintWriter writer = theResponse.getWriter();
    try {
      parser.encodeTagListToWriter(resp, writer);
    } finally {
View Full Code Here


  private final class OperationOutcomeResponseHandler implements IClientResponseHandler<OperationOutcome> {

    @Override
    public OperationOutcome invokeClient(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws IOException, BaseServerResponseException {
      EncodingEnum respType = EncodingEnum.forContentType(theResponseMimeType);
      if (respType == null) {
        return null;
      }
      IParser parser = respType.newParser(myContext);
      OperationOutcome retVal;
      try {
        retVal = parser.parseResource(OperationOutcome.class, theResponseReader);
      } catch (DataFormatException e) {
        ourLog.warn("Failed to parse OperationOutcome response", e);
View Full Code Here

      myId = theId;
    }

    @Override
    public T invokeClient(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws IOException, BaseServerResponseException {
      EncodingEnum respType = EncodingEnum.forContentType(theResponseMimeType);
      if (respType == null) {
        throw NonFhirResponseException.newInstance(theResponseStatusCode, theResponseMimeType, theResponseReader);
      }
      IParser parser = respType.newParser(myContext);
      T retVal = parser.parseResource(myType, theResponseReader);

      if (myId != null) {
        retVal.setId(myId);
      }
View Full Code Here

  private final class TagListResponseHandler implements IClientResponseHandler<TagList> {

    @Override
    public TagList invokeClient(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws IOException, BaseServerResponseException {
      EncodingEnum respType = EncodingEnum.forContentType(theResponseMimeType);
      if (respType == null) {
        throw NonFhirResponseException.newInstance(theResponseStatusCode, theResponseMimeType, theResponseReader);
      }
      IParser parser = respType.newParser(myContext);
      return parser.parseTagList(theResponseReader);
    }
View Full Code Here

    return retVal;
  }

  @Override
  protected Object parseRequestObject(Request theRequest) throws IOException {
    EncodingEnum encoding = RestfulServer.determineResponseEncoding(theRequest.getServletRequest());
    IParser parser = encoding.newParser(getContext());
    Bundle bundle = parser.parseBundle(theRequest.getServletRequest().getReader());
    return bundle;
  }
View Full Code Here

    if (locationHeaders != null && locationHeaders.size() > 0) {
      String locationHeader = locationHeaders.get(0);
      BaseOutcomeReturningMethodBinding.parseContentLocation(retVal, theResourceName, locationHeader);
    }
    if (theResponseStatusCode != Constants.STATUS_HTTP_204_NO_CONTENT) {
      EncodingEnum ct = EncodingEnum.forContentType(theResponseMimeType);
      if (ct != null) {
        PushbackReader reader = new PushbackReader(theResponseReader);

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

        if (reader != null) {
          IParser parser = ct.newParser(theContext);
          IResource outcome = parser.parseResource(reader);
          if (outcome instanceof OperationOutcome) {
            retVal.setOperationOutcome((OperationOutcome) outcome);
          }
        }
View Full Code Here

      myQueryLogRequestAndResponse = theLogRequestAndResponse;
      return (T) this;
    }

    protected IResource parseResourceBody(String theResourceBody) {
      EncodingEnum encoding = null;
      for (int i = 0; i < theResourceBody.length() && encoding == null; i++) {
        switch (theResourceBody.charAt(i)) {
        case '<':
          encoding = EncodingEnum.XML;
          break;
        case '{':
          encoding = EncodingEnum.JSON;
          break;
        }
      }
      if (encoding == null) {
        throw new InvalidRequestException("FHIR client can't determine resource encoding");
      }
      return encoding.newParser(myContext).parseResource(theResourceBody);
    }
View Full Code Here

      myType = theType;
    }

    @Override
    public Bundle invokeClient(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws IOException, BaseServerResponseException {
      EncodingEnum respType = EncodingEnum.forContentType(theResponseMimeType);
      if (respType == null) {
        throw NonFhirResponseException.newInstance(theResponseStatusCode, theResponseMimeType, theResponseReader);
      }
      IParser parser = respType.newParser(myContext);
      return parser.parseBundle(myType, theResponseReader);
    }
View Full Code Here

TOP

Related Classes of ca.uhn.fhir.rest.server.EncodingEnum

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.