Package ca.uhn.fhir.parser

Examples of ca.uhn.fhir.parser.IParser


    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


      break;
    case Constants.STATUS_HTTP_412_PRECONDITION_FAILED:
      ex = new ResourceVersionNotSpecifiedException("Server responded with HTTP 412");
      break;
    case Constants.STATUS_HTTP_422_UNPROCESSABLE_ENTITY:
      IParser parser = createAppropriateParserForParsingResponse(theResponseMimeType, theResponseReader, theStatusCode);
      OperationOutcome operationOutcome = parser.parseResource(OperationOutcome.class, theResponseReader);
      ex = new UnprocessableEntityException(operationOutcome);
      break;
    default:
      ex = new UnclassifiedServerFailureException(theStatusCode, "Server responded with HTTP " + theStatusCode);
      break;
View Full Code Here

    if (myVersionIdParamIndex != null) {
      params[myVersionIdParamIndex] = theRequest.getVersionId();
    }

    IParser parser = createAppropriateParserForParsingServerRequest(theRequest);
    Reader reader = theRequest.getServletRequest().getReader();
    try {
      TagList tagList = parser.parseTagList(reader);
      params[myTagListParamIndex] = tagList;
    } finally {
      reader.close();
    }
    invokeServerMethod(params);
View Full Code Here

  public abstract ReturnTypeEnum getReturnType();

  @Override
  public Object invokeClient(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws IOException {
    IParser parser = createAppropriateParserForParsingResponse(theResponseMimeType, theResponseReader, theResponseStatusCode);

    switch (getReturnType()) {
    case BUNDLE: {
      Bundle bundle;
      if (myResourceType != null) {
        bundle = parser.parseBundle(myResourceType, theResponseReader);
      } else {
        bundle = parser.parseBundle(theResponseReader);
      }
      switch (getMethodReturnType()) {
      case BUNDLE:
        return bundle;
      case LIST_OF_RESOURCES:
        return bundle.toListOfResources();
      case RESOURCE:
        List<IResource> list = bundle.toListOfResources();
        if (list.size() == 0) {
          return null;
        } else if (list.size() == 1) {
          return list.get(0);
        } else {
          throw new InvalidResponseException(theResponseStatusCode, "FHIR server call returned a bundle with multiple resources, but this method is only able to returns one.");
        }
      case BUNDLE_PROVIDER:
        throw new IllegalStateException("Return type of " + IBundleProvider.class.getSimpleName() + " is not supported in clients");
      }
      break;
    }
    case RESOURCE: {
      IResource resource;
      if (myResourceType != null) {
        resource = parser.parseResource(myResourceType, theResponseReader);
      } else {
        resource = parser.parseResource(theResponseReader);
      }

      MethodUtil.parseClientRequestResourceHeaders(theHeaders, resource);

      switch (getMethodReturnType()) {
View Full Code Here

  }

  @Override
  public TagList invokeClient(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws IOException, BaseServerResponseException {
    if (theResponseStatusCode == Constants.STATUS_HTTP_200_OK) {
      IParser parser = createAppropriateParserForParsingResponse(theResponseMimeType, theResponseReader, theResponseStatusCode);
      TagList retVal = parser.parseTagList(theResponseReader);
      return retVal;
    } else {
      throw processNon2xxResponseAndReturnExceptionToThrow(theResponseStatusCode, theResponseMimeType, theResponseReader);
    }
View Full Code Here

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

    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

    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

    String name = Constants.PARAM_COUNT;
    return tryToExtractNamedParameter(theRequest, name);
  }

  public static IParser getNewParser(FhirContext theContext, EncodingEnum theResponseEncoding, boolean thePrettyPrint, NarrativeModeEnum theNarrativeMode) {
    IParser parser;
    switch (theResponseEncoding) {
    case JSON:
      parser = theContext.newJsonParser();
      break;
    case XML:
    default:
      parser = theContext.newXmlParser();
      break;
    }
    return parser.setPrettyPrint(thePrettyPrint).setSuppressNarratives(theNarrativeMode == NarrativeModeEnum.SUPPRESS);
  }
View Full Code Here

    HttpGet get = new HttpGet(resourceUrl);
    HttpResponse response = httpClient.execute(get);
    try {
      // TODO: choose appropriate parser based on response CT
      IParser parser = context.newXmlParser();

      Reader responseReader = BaseClient.createReaderFromResponse(response);
      myResource = parser.parseResource(responseReader);

    } finally {
      if (response instanceof CloseableHttpResponse) {
        ((CloseableHttpResponse) response).close();
      }
View Full Code Here

TOP

Related Classes of ca.uhn.fhir.parser.IParser

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.