Package ca.uhn.fhir.rest.server

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


      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


      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

    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

      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

  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

  }

  private class SetEncodingLambda implements ILambda {
    @Override
    public Object handle(Object[] theArgs) {
      EncodingEnum encoding = (EncodingEnum) theArgs[0];
      setEncoding(encoding);
      return null;
    }
View Full Code Here

    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, theResponse, theRequest);
      return;
    } catch (BaseServerResponseException e) {
      ourLog.info("Exception during method invocation: " + e.getMessage());
      EncodingEnum encoding = RestfulServer.determineResponseEncoding(theRequest.getServletRequest());
      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) {
      EncodingEnum encoding = RestfulServer.determineResponseEncoding(theRequest.getServletRequest());
      theResponse.setContentType(encoding.getResourceContentType());
      Writer writer = theResponse.getWriter();
      IParser parser = encoding.newParser(getContext());
      parser.setPrettyPrint(RestfulServer.prettyPrintResponse(theRequest));
      try {
        parser.encodeResourceToWriter(response.getOperationOutcome(), writer);
      } finally {
        writer.close();
View Full Code Here

  /**
   * @throws IOException 
   */
  protected IResource parseIncomingServerResource(Request theRequest) throws IOException {
    EncodingEnum encoding = RestfulServer.determineRequestEncoding(theRequest);
    IParser parser = encoding.newParser(getContext());
    IResource resource = parser.parseResource(theRequest.getServletRequest().getReader());
    return resource;
  }
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.