Package ca.uhn.fhir.parser

Examples of ca.uhn.fhir.parser.IParser


  }
 
  @Override
  public void invokeServer(RestfulServer theServer, Request theRequest, HttpServletResponse theResponse) throws BaseServerResponseException, IOException {
    EncodingUtil encoding = BaseMethodBinding.determineResponseEncoding(theRequest.getServletRequest(), theRequest.getParameters());
    IParser parser = encoding.newParser(getContext());
    IResource resource = parser.parseResource(theRequest.getInputReader());

    Object[] params = new Object[getParameters().size()];
    for (int i = 0; i < getParameters().size(); i++) {
      IParameter param = getParameters().get(i);
      if (param == null) {
View Full Code Here


  public abstract RestfulOperationSystemEnum getSystemOperationType();

  public abstract boolean matches(Request theRequest);

  protected IParser createAppropriateParser(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode) throws IOException {
    IParser parser;
    if (Constants.CT_ATOM_XML.equals(theResponseMimeType)) {
      parser = getContext().newXmlParser();
    } else if (Constants.CT_FHIR_XML.equals(theResponseMimeType)) {
      parser = getContext().newXmlParser();
    } else {
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 = createAppropriateParser(theResponseMimeType, theResponseReader, theResponseStatusCode);

    switch (getReturnType()) {
    case BUNDLE: {
      Bundle 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("FHIR server call returned a bundle with multiple resources, but this method is only able to returns one.");
        }
      }
      break;
    }
    case RESOURCE: {
      IResource resource = parser.parseResource(theResponseReader);
      switch (getMethodReturnType()) {
      case BUNDLE:
        return Bundle.withSingleResource(resource);
      case LIST_OF_RESOURCES:
        return Collections.singletonList(resource);
View Full Code Here

    }
    throw new InternalErrorException("Found an object of type '" + retValObj.getClass().getCanonicalName() + "' in resource metadata for key " + theKey.name() + " - Expected " + InstantDt.class.getCanonicalName());
  }

  private IParser getNewParser(EncodingUtil theResponseEncoding, boolean thePrettyPrint, NarrativeModeEnum theNarrativeMode) {
    IParser parser;
    switch (theResponseEncoding) {
    case JSON:
      parser = getContext().newJsonParser();
      break;
    case XML:
    default:
      parser = getContext().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 = ClientInvocationHandler.createReaderFromResponse(response);
      myResource = parser.parseResource(responseReader);

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

    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();
      }
    } else {
      theResponse.setContentType(Constants.CT_TEXT);
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

    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();
    }

    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();
    }

    StringEntity entity = new StringEntity(contents, ContentType.create(contentType, "UTF-8"));
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

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.