Package ca.uhn.fhir.parser

Examples of ca.uhn.fhir.parser.IParser


  /**
   * @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


    theServer.addHeadersToResponse(theResponse);

    if (theE.getOperationOutcome() != null) {
      theResponse.setContentType(theEncoding.getResourceContentType());
      IParser parser = theEncoding.newParser(theServer.getFhirContext());
      parser.setPrettyPrint(RestfulServer.prettyPrintResponse(theRequest));
      Writer writer = theResponse.getWriter();
      try {
        parser.encodeResourceToWriter(theE.getOperationOutcome(), writer);
      } finally {
        writer.close();
      }
    } else {
      theResponse.setContentType(Constants.CT_TEXT);
View Full Code Here

      ByteArrayEntity entity = new ByteArrayEntity(binary.getContent(), ContentType.parse(binary.getContentType()));
      HttpRequestBase retVal = createRequest(url, entity);
      return retVal;
    }

    IParser parser;
    String contentType;
    EncodingEnum encoding = null;
    encoding = theEncoding;

    if (encoding == EncodingEnum.JSON) {
      parser = myContext.newJsonParser();
    } else {
      encoding = EncodingEnum.XML;
      parser = myContext.newXmlParser();
    }

    AbstractHttpEntity entity;
    if (myParams != null) {
      List<NameValuePair> parameters = new ArrayList<NameValuePair>();
      for (Entry<String, List<String>> nextParam : myParams.entrySet()) {
        parameters.add(new BasicNameValuePair(nextParam.getKey(), StringUtils.join(nextParam.getValue(), ',')));
      }
      try {
        entity = new UrlEncodedFormEntity(parameters, "UTF-8");
      } catch (UnsupportedEncodingException e) {
        throw new InternalErrorException("Server does not support UTF-8 (should not happen)", e);
      }
    } else {
      String contents;
      if (myTagList != null) {
        contents = parser.encodeTagListToString(myTagList);
        contentType = encoding.getResourceContentType();
      } else if (myBundle != null) {
        contents = parser.encodeBundleToString(myBundle);
        contentType = encoding.getBundleContentType();
      } else if (myResources != null) {
        Bundle bundle = RestfulServer.createBundleFromResourceList(myContext, "", myResources, "", "", myResources.size());
        contents = parser.encodeBundleToString(bundle);
        contentType = encoding.getBundleContentType();
      } else if (myContents != null) {
        contents = myContents;
        if (myContentsIsBundle) {
          contentType = encoding.getBundleContentType();
        } else {
          contentType = encoding.getResourceContentType();
        }
      } else {
        contents = parser.encodeResourceToString(myResource);
        contentType = encoding.getResourceContentType();
      }
      entity = new StringEntity(contents, ContentType.create(contentType, "UTF-8"));
    }
View Full Code Here

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

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

    }
    b.append(StringUtils.defaultString(myUrlExtension));

    appendExtraParamsWithQuestionMark(theExtraParams, b, true);

    IParser parser;
    String contentType;
    if (theEncoding == EncodingEnum.JSON) {
      parser = myContext.newJsonParser();
      contentType = Constants.CT_FHIR_JSON;
    } else {
      parser = myContext.newXmlParser();
      contentType = Constants.CT_FHIR_XML;
    }

    String contents;
    if (myTagList != null) {
      contents = parser.encodeTagListToString(myTagList);
    } else {
      contents = parser.encodeResourceToString(myResource);
    }

    StringEntity entity = new StringEntity(contents, ContentType.create(contentType, "UTF-8"));

    HttpRequestBase retVal = createRequest(b.toString(), entity);
View Full Code Here

      NonFhirResponseException ex = NonFhirResponseException.newInstance(theResponseStatusCode, theResponseMimeType, theResponseReader);
      populateException(ex, theResponseReader);
      throw ex;
    }
   
    IParser parser=encoding.newParser(getContext());
    return parser;
  }
View Full Code Here

   
    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

    }

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

        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.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.