Java Code Examples for org.apache.olingo.commons.api.format.ContentType#APPLICATION_JSON

The following examples show how to use org.apache.olingo.commons.api.format.ContentType#APPLICATION_JSON . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ODataDispatcher.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private ContentType getSupportedContentType(final String contentTypeHeader,
    final RepresentationType representationType, final boolean mustNotBeNull)
    throws ODataHandlerException, ContentNegotiatorException {
  if (contentTypeHeader == null) {
    if (mustNotBeNull) {
      throw new ODataHandlerException("ContentTypeHeader parameter is null",
          ODataHandlerException.MessageKeys.MISSING_CONTENT_TYPE);
    }
    return ContentType.APPLICATION_JSON;
  }
  ContentType contentType;
  try {
    contentType = ContentType.create(contentTypeHeader);
  } catch (final IllegalArgumentException e) {
    throw new ODataHandlerException("Illegal content type.", e,
        ODataHandlerException.MessageKeys.INVALID_CONTENT_TYPE, contentTypeHeader);
  }
  ContentNegotiator.checkSupport(contentType, handler.getCustomContentTypeSupport(), representationType);
  return contentType;
}
 
Example 2
Source File: ContentNegotiator.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private static ContentType mapContentType(final String formatString, 
    RepresentationType representationType) {
  if (representationType.name().equals(METADATA)) {
    return JSON.equalsIgnoreCase(formatString) ||
        APPLICATION_JSON.equalsIgnoreCase(formatString) ? ContentType.APPLICATION_JSON :
      XML.equalsIgnoreCase(formatString) ? ContentType.APPLICATION_XML :
        ATOM.equalsIgnoreCase(formatString) ? ContentType.APPLICATION_ATOM_XML : null;
  } else {
    return JSON.equalsIgnoreCase(formatString) ? ContentType.JSON :
        XML.equalsIgnoreCase(formatString) ? ContentType.APPLICATION_XML :
            ATOM.equalsIgnoreCase(formatString) ? ContentType.APPLICATION_ATOM_XML : 
              APPLICATION_JSON.equalsIgnoreCase(formatString)? ContentType.APPLICATION_JSON: null;
  }
}
 
Example 3
Source File: ServiceDispatcher.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
private void internalExecute(UriInfo uriInfo, ODataRequest odRequest,
    ODataResponse odResponse) throws ODataLibraryException,
    ODataApplicationException {

  new UriValidator().validate(uriInfo, odRequest.getMethod());

  // part1, 8.2.6
  String isolation = odRequest.getHeader(HttpHeader.ODATA_ISOLATION);
  if (isolation != null && "snapshot".equals(isolation) && !this.handler.supportsDataIsolation()) {
    odResponse.setStatusCode(HttpStatusCode.PRECONDITION_FAILED.getStatusCode());
    return;
  }
  
  visit(uriInfo);

  // this should cover for any unsupported calls until they are implemented
  if (this.request == null) {
    this.request = new ServiceRequest(this.odata, this.metadata) {
      @Override
      public ContentType getResponseContentType() throws ContentNegotiatorException {
        return ContentType.APPLICATION_JSON;
      }

      @Override
      public void execute(ServiceHandler handler, ODataResponse response)
          throws ODataLibraryException, ODataApplicationException {
        handler.anyUnsupported(getODataRequest(), response);
      }
    };
  }

  // To handle $entity?$id=http://localhost/EntitySet(key) as
  // http://localhost/EntitySet(key)
  if (this.idOption != null) {
    try {
      this.request.setODataRequest(odRequest);
      this.request = this.request.parseLink(new URI(this.idOption));
    } catch (URISyntaxException e) {
      throw new ODataHandlerException("Invalid $id value",
          ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED, this.idOption);
    }
  }

  this.request.setODataRequest(odRequest);
  this.request.setUriInfo(uriInfo);
  this.request.setCustomContentTypeSupport(this.customContentSupport);
  this.request.execute(this.handler, odResponse);
}