Package ca.uhn.fhir.rest.server

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


    if (locationHeaders != null && locationHeaders.size() > 0) {
      String locationHeader = locationHeaders.get(0);
      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) {
            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(theContext);
          IResource outcome = parser.parseResource(reader);
          if (outcome instanceof OperationOutcome) {
            retVal.setOperationOutcome((OperationOutcome) outcome);
          }
        }
View Full Code Here


    // Narrative mode
    NarrativeModeEnum narrativeMode = RestfulServer.determineNarrativeMode(theRequest);

    // Determine response encoding
    EncodingEnum responseEncoding = RestfulServer.determineResponseEncoding(theRequest.getServletRequest());

    // Is this request coming from a browser
    String uaHeader = theRequest.getServletRequest().getHeader("user-agent");
    boolean requestIsBrowser = false;
    if (uaHeader != null && uaHeader.contains("Mozilla")) {
View Full Code Here

    } finally {
      reader.close();
    }
    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);
View Full Code Here

  public void setParameters(List<IParameter> theParameters) {
    myParameters = theParameters;
  }

  protected IParser createAppropriateParserForParsingResponse(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode) {
    EncodingEnum encoding = EncodingEnum.forContentType(theResponseMimeType);
    if (encoding == null) {
      NonFhirResponseException ex = NonFhirResponseException.newInstance(theResponseStatusCode, theResponseMimeType, theResponseReader);
      populateException(ex, theResponseReader);
      throw ex;
    }

    IParser parser = encoding.newParser(getContext());
    return parser;
  }
View Full Code Here

    return parser;
  }

  protected IParser createAppropriateParserForParsingServerRequest(Request theRequest) {
    String contentTypeHeader = theRequest.getServletRequest().getHeader("content-type");
    EncodingEnum encoding;
    if (isBlank(contentTypeHeader)) {
      encoding = EncodingEnum.XML;
    } else {
      int semicolon = contentTypeHeader.indexOf(';');
      if (semicolon != -1) {
        contentTypeHeader = contentTypeHeader.substring(0, semicolon);
      }
      encoding = EncodingEnum.forContentType(contentTypeHeader);
    }

    if (encoding == null) {
      throw new InvalidRequestException("Request contins non-FHIR conent-type header value: " + contentTypeHeader);
    }

    IParser parser = encoding.newParser(getContext());
    return parser;
  }
View Full Code Here

    // Narrative mode
    NarrativeModeEnum narrativeMode = RestfulServer.determineNarrativeMode(theRequest);

    // Determine response encoding
    EncodingEnum responseEncoding = RestfulServer.determineResponseEncoding(theRequest.getServletRequest());

    // Is this request coming from a browser
    String uaHeader = theRequest.getServletRequest().getHeader("user-agent");
    boolean requestIsBrowser = false;
    if (uaHeader != null && uaHeader.contains("Mozilla")) {
View Full Code Here

      if (!continueProcessing) {
        return;
      }
    }

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

    HttpServletResponse response = theRequest.getServletResponse();
    response.setContentType(responseEncoding.getResourceContentType());
    response.setStatus(Constants.STATUS_HTTP_200_OK);
    response.setCharacterEncoding(Constants.CHARSET_UTF_8);

    theServer.addHeadersToResponse(response);
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

      if (!continueProcessing) {
        return;
      }
    }
   
    EncodingEnum responseEncoding = RestfulServer.determineResponseEncoding(theRequest.getServletRequest());

    HttpServletResponse response = theRequest.getServletResponse();
    response.setContentType(responseEncoding.getResourceContentType());
    response.setStatus(Constants.STATUS_HTTP_200_OK);
    response.setCharacterEncoding(Constants.CHARSET_UTF_8);

    theServer.addHeadersToResponse(response);

    IParser parser = responseEncoding.newParser(getContext());
    parser.setPrettyPrint(RestfulServer.prettyPrintResponse(theRequest));
    PrintWriter writer = response.getWriter();
    try {
      parser.encodeTagListToWriter(resp, writer);
    } finally {
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.