Package ca.uhn.fhir.rest.server

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


  }

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


    } finally {
      reader.close();
    }
    invokeServerMethod(params);

    EncodingEnum responseEncoding = determineResponseEncoding(theRequest);

    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 abstract void invokeServer(RestfulServer theServer, Request theRequest, HttpServletResponse theResponse) throws BaseServerResponseException, IOException;

  public abstract boolean incomingServerRequestMatchesMethod(Request theRequest);

  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

  public static EncodingEnum determineResponseEncoding(Request theReq) {
    String[] format = theReq.getParameters().remove(Constants.PARAM_FORMAT);
    if (format != null) {
      for (String nextFormat : format) {
        EncodingEnum retVal = Constants.FORMAT_VAL_TO_ENCODING.get(nextFormat);
        if (retVal != null) {
          return retVal;
        }
      }
    }

    Enumeration<String> acceptValues = theReq.getServletRequest().getHeaders("Accept");
    if (acceptValues != null) {
      while (acceptValues.hasMoreElements()) {
        EncodingEnum retVal = Constants.FORMAT_VAL_TO_ENCODING.get(acceptValues.nextElement());
        if (retVal != null) {
          return retVal;
        }
      }
    }
View Full Code Here

    return EncodingEnum.XML;
  }

  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

      myType = theType;
    }

    @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

    }

    @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 (narrativeMode == null) {
      narrativeMode = NarrativeModeEnum.NORMAL;
    }

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

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

      params[myVersionIdParamIndex] = theRequest.getVersionId();
    }

    TagList resp = (TagList) invokeServerMethod(params);

    EncodingEnum responseEncoding = determineResponseEncoding(theRequest);

    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(prettyPrintResponse(theRequest));
    PrintWriter writer = theResponse.getWriter();
    try {
      parser.encodeTagListToWriter(resp, writer);
    } finally {
View Full Code Here

  }

  @Override
  public void invokeServer(RestfulServer theServer, Request theRequest, HttpServletResponse theResponse) throws BaseServerResponseException, IOException {
    EncodingEnum encoding = determineResponseEncoding(theRequest);
    IParser parser = encoding.newParser(getContext());
    IResource resource;
    if (requestContainsResource()) {
      resource = parser.parseResource(theRequest.getInputReader());
      TagList tagList = new TagList();
      for (Enumeration<String> enumeration = theRequest.getServletRequest().getHeaders(Constants.HEADER_CATEGORY); enumeration.hasMoreElements();) {
        String nextTagComplete = enumeration.nextElement();
        StringBuilder next = new StringBuilder(nextTagComplete);
        parseTagValue(tagList, nextTagComplete, next);
      }
      if (tagList.isEmpty() == false) {
        resource.getResourceMetadata().put(ResourceMetadataKeyEnum.TAG_LIST, tagList);
      }
    } else {
      resource = null;
    }

    Object[] params = createParametersForServerRequest(theRequest, resource);
    addParametersForServerRequest(theRequest, params);

    MethodOutcome response;
    try {
      response = (MethodOutcome) invokeServerMethod(params);
    } catch (InternalErrorException e) {
      ourLog.error("Internal error during method invocation", e);
      streamOperationOutcome(e, theServer, encoding, theResponse, theRequest);
      return;
    } catch (BaseServerResponseException e) {
      ourLog.info("Exception during method invocation: " + e.getMessage());
      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) {
      theResponse.setContentType(encoding.getResourceContentType());
      Writer writer = theResponse.getWriter();
      parser.setPrettyPrint(prettyPrintResponse(theRequest));
      try {
        parser.encodeResourceToWriter(response.getOperationOutcome(), 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.