Package org.apache.olingo.odata2.core.commons

Examples of org.apache.olingo.odata2.core.commons.ContentType


*/
public class ContentNegotiatorTest {

  private void negotiateContentType(final List<ContentType> contentTypes, final List<ContentType> supportedTypes,
      final String expected) throws ODataException {
    final ContentType contentType = new ContentNegotiator().contentNegotiation(contentTypes, supportedTypes);
    assertEquals(expected, contentType.toContentTypeString());
  }
View Full Code Here


    assertEquals(expected, contentType.toContentTypeString());
  }

  @Test(expected = IllegalArgumentException.class)
  public void invalidContentNegotiatorCreation() throws ODataException {
    final ContentType contentType = new ContentNegotiator().doContentNegotiation(null, null, null);
    assertNull(contentType);
  }
View Full Code Here

  }

  @Test(expected = IllegalArgumentException.class)
  public void invalidContentNegotiatorCreationNullRequest() throws ODataException {
    UriInfoImpl uriInfo = Mockito.mock(UriInfoImpl.class);
    final ContentType contentType =
        new ContentNegotiator().doContentNegotiation(null, uriInfo, new ArrayList<String>());
    assertNull(contentType);
  }
View Full Code Here

  }

  @Test(expected = IllegalArgumentException.class)
  public void invalidContentNegotiatorCreationNullUri() throws ODataException {
    ODataRequest request = Mockito.mock(ODataRequest.class);
    final ContentType contentType =
        new ContentNegotiator().doContentNegotiation(request, null, new ArrayList<String>());
    assertNull(contentType);
  }
View Full Code Here

  @Test(expected = IllegalArgumentException.class)
  public void invalidContentNegotiatorCreationNullSupported() throws ODataException {
    ODataRequest request = Mockito.mock(ODataRequest.class);
    UriInfoImpl uriInfo = Mockito.mock(UriInfoImpl.class);
    final ContentType contentType = new ContentNegotiator().doContentNegotiation(request, uriInfo, null);
    assertNull(contentType);
  }
View Full Code Here

          || method == ODataHttpMethod.MERGE) {
        checkRequestContentType(uriInfo, request.getContentType());
      }

      List<String> supportedContentTypes = getSupportedContentTypes(uriInfo, method);
      ContentType acceptContentType =
          new ContentNegotiator().doContentNegotiation(request, uriInfo, supportedContentTypes);

      checkConditions(method, uriInfo,
          context.getRequestHeader(HttpHeaders.IF_MATCH),
          context.getRequestHeader(HttpHeaders.IF_NONE_MATCH),
          context.getRequestHeader(HttpHeaders.IF_MODIFIED_SINCE),
          context.getRequestHeader(HttpHeaders.IF_UNMODIFIED_SINCE));

      timingHandle2 = context.startRuntimeMeasurement("Dispatcher", "dispatch");
      odataResponse =
          dispatcher.dispatch(method, uriInfo, request.getBody(), request.getContentType(), acceptContentType
              .toContentTypeString());
      context.stopRuntimeMeasurement(timingHandle2);

      ODataResponseBuilder extendedResponse = ODataResponse.fromResponse(odataResponse);
      final UriType uriType = uriInfo.getUriType();
      final String location =
          (method == ODataHttpMethod.POST && (uriType == UriType.URI1 || uriType == UriType.URI6B)) ? odataResponse
              .getIdLiteral() : null;
      final HttpStatusCodes s = getStatusCode(odataResponse, method, uriType);
      extendedResponse = extendedResponse.idLiteral(location).status(s);

      if (!odataResponse.containsHeader(ODataHttpHeaders.DATASERVICEVERSION)) {
        extendedResponse = extendedResponse.header(ODataHttpHeaders.DATASERVICEVERSION, serverDataServiceVersion);
      }
      if (!HttpStatusCodes.NO_CONTENT.equals(s) && !odataResponse.containsHeader(HttpHeaders.CONTENT_TYPE)) {
        extendedResponse.header(HttpHeaders.CONTENT_TYPE, acceptContentType.toContentTypeString());
      }

      odataResponse = extendedResponse.build();
    } catch (final Exception e) {
      exception = e;
View Full Code Here

          EntityProcessor.class; // The request must contain a single entity!
    } else if (processorFeature == EntityLinksProcessor.class) {
      processorFeature = EntityLinkProcessor.class; // The request must contain a single link!
    }

    final ContentType parsedContentType = ContentType.parse(contentType);
    if (parsedContentType == null || parsedContentType.hasWildcard()) {
      throw new ODataUnsupportedMediaTypeException(ODataUnsupportedMediaTypeException.NOT_SUPPORTED
          .addContent(parsedContentType));
    }

    // Get list of supported content types based on processor feature.
View Full Code Here

   * @param allowedContentTypes list against which is checked for possible matching {@link ContentType}s
   * @return <code>true</code> if a matching content type is in given list, otherwise <code>false</code>
   */
  private static boolean hasMatchingContentType(final ContentType contentType,
      final List<ContentType> allowedContentTypes) {
    final ContentType requested = contentType.receiveWithCharsetParameter(ContentNegotiator.DEFAULT_CHARSET);
    if (requested.getODataFormat() == ODataFormat.CUSTOM || requested.getODataFormat() == ODataFormat.MIME) {
      return requested.hasCompatible(allowedContentTypes);
    }
    return requested.hasMatch(allowedContentTypes);
  }
View Full Code Here

  }

  private ContentType doContentNegotiationForFormat(final UriInfoImpl uriInfo,
      final List<ContentType> supportedContentTypes) throws ODataException {
    validateFormatQuery(uriInfo);
    ContentType formatContentType = mapFormat(uriInfo);
    formatContentType = ensureCharset(formatContentType);

    for (final ContentType contentType : supportedContentTypes) {
      if (contentType.equals(formatContentType)) {
        return formatContentType;
View Full Code Here

        return supportedContentTypes.get(0);
      }
    } else {
      for (ContentType contentType : acceptedContentTypes) {
        contentType = ensureCharset(contentType);
        final ContentType match = contentType.match(supportedContentTypes);
        if (match != null) {
          return match;
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.apache.olingo.odata2.core.commons.ContentType

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.