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

The following examples show how to use org.apache.olingo.commons.api.format.ContentType#APPLICATION_ATOM_XML . 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: HeaderTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void multipleValues() {
  Header header = new Header(1);
  header.addHeader(HttpHeader.CONTENT_TYPE, ContentType.MULTIPART_MIXED.toContentTypeString(), 1);
  header.addHeader(HttpHeader.CONTENT_TYPE, ContentType.APPLICATION_ATOM_SVC.toContentTypeString(), 2);
  header.addHeader(HttpHeader.CONTENT_TYPE, ContentType.APPLICATION_ATOM_XML.toContentTypeString(), 3);

  final String fullHeaderString =
      ContentType.MULTIPART_MIXED + ", " + ContentType.APPLICATION_ATOM_SVC + ", "
          + ContentType.APPLICATION_ATOM_XML;

  assertEquals(fullHeaderString, header.getHeader(HttpHeader.CONTENT_TYPE));
  assertEquals(3, header.getHeaders(HttpHeader.CONTENT_TYPE).size());
  assertEquals(ContentType.MULTIPART_MIXED.toContentTypeString(),
      header.getHeaders(HttpHeader.CONTENT_TYPE).get(0));
  assertEquals(ContentType.APPLICATION_ATOM_SVC.toContentTypeString(),
      header.getHeaders(HttpHeader.CONTENT_TYPE).get(1));
  assertEquals(ContentType.APPLICATION_ATOM_XML.toContentTypeString(),
      header.getHeaders(HttpHeader.CONTENT_TYPE).get(2));
}
 
Example 2
Source File: AbstractTestITCase.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
protected ClientEntity read(final ContentType contentType, final URI editLink) {
  final ODataEntityRequest<ClientEntity> req = getClient().getRetrieveRequestFactory().getEntityRequest(editLink);
  req.setFormat(contentType);

  final ODataRetrieveResponse<ClientEntity> res = req.execute();
  final ClientEntity entity = res.getBody();

  assertNotNull(entity);

  if (ContentType.JSON_FULL_METADATA == contentType || ContentType.APPLICATION_ATOM_XML == contentType) {
    assertEquals(req.getURI(), entity.getEditLink());
  }

  return entity;
}
 
Example 3
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 4
Source File: ErrorHandlerTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Test
public void testError(){
  EdmxReference reference = new EdmxReference
      (URI.create("../v4.0/cs02/vocabularies/Org.OData.Core.V1.xml"));
  reference.addInclude(new EdmxReferenceInclude("Org.OData.Core.V1", "Core"));
  ServiceHandler handler = new ProcessorServiceHandler();
  ServiceMetadata metadata = new ServiceMetadataImpl(provider,  
      Collections.singletonList(reference), new ServiceMetadataETagSupport() {
    @Override
    public String getServiceDocumentETag() {
      return "W/\"serviceDocumentETag\"";
    }
    @Override
    public String getMetadataETag() {
      return "W/\"metadataETag\"";
    }
  } );
  OData odata = new ODataImpl();
  ErrorHandler error = new ErrorHandler(odata , metadata, handler,
      ContentType.APPLICATION_ATOM_XML);
  assertNotNull(error);
  UriValidationException e =new UriValidationException("message", 
      UriValidationException.MessageKeys.DOUBLE_KEY_PROPERTY , "param"); 
  ODataRequest request = new ODataRequest();
  ODataResponse response = new ODataResponse();
  error.handleException(e, request , response);
  error.handleException(new UriParserSemanticException("message",
      UriParserSemanticException.MessageKeys.COLLECTION_NOT_ALLOWED, "param")
      , request , response);
  error.handleException(new UriParserSyntaxException("message",
      UriParserSyntaxException.MessageKeys.DOUBLE_SYSTEM_QUERY_OPTION, "param")
      , request , response);
  String[] param = new String[2];
  error.handleException(new UriParserExceptionCustom("message",
      UriParserSyntaxException.MessageKeys.DOUBLE_SYSTEM_QUERY_OPTION, param)
      , request , response);
  error.handleException(new BatchDeserializerException("message",
      BatchDeserializerException.MessageKeys.INVALID_BASE_URI, "param")
      , request , response);
  error.handleException(new SerializerException("message",
      SerializerException.MessageKeys.IO_EXCEPTION, "param")
      , request , response);
  error.handleException(new ContentNegotiatorException("message",
      ContentNegotiatorException.MessageKeys.NO_CONTENT_TYPE_SUPPORTED, "param")
      , request , response);
  error.handleException(new UriParserSyntaxException("message",
      UriParserSyntaxException.MessageKeys.DUPLICATED_ALIAS, "param")
      , request , response);
  error.handleException(new DeserializerException("message",
      DeserializerException.MessageKeys.DUPLICATE_PROPERTY, "param")
      , request , response);
  error.handleException(new ODataHandlerException("message",
      ODataHandlerException.MessageKeys.AMBIGUOUS_XHTTP_METHOD, "param")
      , request , response);
  error.handleException(new ODataApplicationException("message",
      500, Locale.ENGLISH)
      , request , response);
  error.handleException(new NullPointerException("message")
      , request , response);
  error.handleServerError(request, response, new ODataServerError());
}
 
Example 5
Source File: ConfigurationImpl.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Override
public ContentType getDefaultFormat() {
  final ContentType contenType = getDefaultPubFormat();
  return contenType == ContentType.APPLICATION_ATOM_XML ? ContentType.APPLICATION_XML : contenType;
}
 
Example 6
Source File: AtomTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Override
protected ContentType getODataPubFormat() {
  return ContentType.APPLICATION_ATOM_XML;
}