Java Code Examples for org.apache.olingo.commons.api.http.HttpMethod#DELETE

The following examples show how to use org.apache.olingo.commons.api.http.HttpMethod#DELETE . 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: UriValidator.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void validatePropertyOperations(final UriInfo uriInfo, final HttpMethod method)
    throws UriValidationException {
  final List<UriResource> parts = uriInfo.getUriResourceParts();
  final UriResource last = !parts.isEmpty() ? parts.get(parts.size() - 1) : null;
  final UriResource previous = parts.size() > 1 ? parts.get(parts.size() - 2) : null;
  if (last != null
      && (last.getKind() == UriResourceKind.primitiveProperty
      || last.getKind() == UriResourceKind.complexProperty
      || (last.getKind() == UriResourceKind.value
          && previous != null && previous.getKind() == UriResourceKind.primitiveProperty))) {
    final EdmProperty property = ((UriResourceProperty)
        (last.getKind() == UriResourceKind.value ? previous : last)).getProperty();
    if (method == HttpMethod.PATCH && property.isCollection()) {
      throw new UriValidationException("Attempt to patch collection property.",
          UriValidationException.MessageKeys.UNSUPPORTED_HTTP_METHOD, method.toString());
    }
    if (method == HttpMethod.DELETE && !property.isNullable()) {
      throw new UriValidationException("Attempt to delete non-nullable property.",
          UriValidationException.MessageKeys.UNSUPPORTED_HTTP_METHOD, method.toString());
    }
  }
}
 
Example 2
Source File: ODataDispatcher.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void handleMediaValueDispatching(final ODataRequest request, final ODataResponse response,
    final UriResource resource) throws ContentNegotiatorException, 
   ODataApplicationException, ODataLibraryException,
    ODataHandlerException, PreconditionException {
  final HttpMethod method = request.getMethod();
  validatePreferHeader(request);
  if (method == HttpMethod.GET) {
    // This can be a GET on an EntitySet, Navigation or Function
    final ContentType requestedContentType = ContentNegotiator.
        doContentNegotiation(uriInfo.getFormatOption(),
        request, handler.getCustomContentTypeSupport(), RepresentationType.MEDIA);
    handler.selectProcessor(MediaEntityProcessor.class)
        .readMediaEntity(request, response, uriInfo, requestedContentType);
    // PUT and DELETE can only be called on EntitySets or Navigation properties which are media resources
  } else if (method == HttpMethod.PUT && (isEntityOrNavigationMedia(resource) 
      || isSingletonMedia(resource))) {
    validatePreconditions(request, true);
    final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
    final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
        request, handler.getCustomContentTypeSupport(), RepresentationType.ENTITY);
    handler.selectProcessor(MediaEntityProcessor.class)
        .updateMediaEntity(request, response, uriInfo, requestFormat, responseFormat);
  } else if (method == HttpMethod.DELETE && isEntityOrNavigationMedia(resource)) {
    validatePreconditions(request, true);
    handler.selectProcessor(MediaEntityProcessor.class)
        .deleteMediaEntity(request, response, uriInfo);
  } else {
    throwMethodNotAllowed(method);
  }
}
 
Example 3
Source File: ODataDispatcher.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void handlePrimitiveValueDispatching(final ODataRequest request, final ODataResponse response,
    final UriResource resource) throws ContentNegotiatorException, 
ODataApplicationException, ODataLibraryException,
    ODataHandlerException, PreconditionException {
  final HttpMethod method = request.getMethod();
  final EdmType type = resource instanceof UriResourceProperty ?
      ((UriResourceProperty) resource).getType() : ((UriResourceFunction) resource).getType();
  final RepresentationType valueRepresentationType =
      type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary) ?
          RepresentationType.BINARY : RepresentationType.VALUE;
  if (method == HttpMethod.GET) {
    validatePreferHeader(request);
    final ContentType requestedContentType = ContentNegotiator.
        doContentNegotiation(uriInfo.getFormatOption(),
        request, handler.getCustomContentTypeSupport(), valueRepresentationType);

    handler.selectProcessor(PrimitiveValueProcessor.class)
        .readPrimitiveValue(request, response, uriInfo, requestedContentType);
  } else if (method == HttpMethod.PUT && resource instanceof UriResourceProperty) {
    validatePreconditions(request, false);
    final ContentType requestFormat = getSupportedContentType(request.getHeader(HttpHeader.CONTENT_TYPE),
        valueRepresentationType, true);
    final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
        request, handler.getCustomContentTypeSupport(), valueRepresentationType);
    handler.selectProcessor(PrimitiveValueProcessor.class)
        .updatePrimitiveValue(request, response, uriInfo, requestFormat, responseFormat);
  } else if (method == HttpMethod.DELETE && resource instanceof UriResourceProperty) {
    validatePreferHeader(request);
    validatePreconditions(request, false);
    handler.selectProcessor(PrimitiveValueProcessor.class)
        .deletePrimitiveValue(request, response, uriInfo);
  } else {
    throwMethodNotAllowed(method);
  }
}
 
Example 4
Source File: ODataDispatcher.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private void handleSingleEntityDispatching(final ODataRequest request, final ODataResponse response,
    final boolean isMedia, final boolean isSingleton) throws 
ContentNegotiatorException, ODataApplicationException,
    ODataLibraryException, ODataHandlerException, PreconditionException {
  final HttpMethod method = request.getMethod();
  if (method == HttpMethod.GET) {
    validatePreferHeader(request);
    final ContentType requestedContentType = ContentNegotiator.
        doContentNegotiation(uriInfo.getFormatOption(),
        request, handler.getCustomContentTypeSupport(), RepresentationType.ENTITY);
    handler.selectProcessor(EntityProcessor.class)
        .readEntity(request, response, uriInfo, requestedContentType);
  } else if (method == HttpMethod.PUT || method == HttpMethod.PATCH) {
    if (isMedia) {
      validatePreferHeader(request);
    }
    validatePreconditions(request, false);
    final ContentType requestFormat = getSupportedContentType(
        request.getHeader(HttpHeader.CONTENT_TYPE),
        RepresentationType.ENTITY, true);
    final ContentType responseFormat = ContentNegotiator.
        doContentNegotiation(uriInfo.getFormatOption(),
        request, handler.getCustomContentTypeSupport(), RepresentationType.ENTITY);
    handler.selectProcessor(EntityProcessor.class)
        .updateEntity(request, response, uriInfo, requestFormat, responseFormat);
  } else if (method == HttpMethod.DELETE && !isSingleton) {
    validateIsSingleton(method);
    validatePreconditions(request, false);
    validatePreferHeader(request);
    if (isMedia) {
      ((MediaEntityProcessor) handler.selectProcessor(MediaEntityProcessor.class))
      .deleteEntity(request, response, uriInfo);
      } else {
      ((EntityProcessor) handler.selectProcessor(EntityProcessor.class))
      .deleteEntity(request, response, uriInfo);
    }
  } else {
    throwMethodNotAllowed(method);
  }
}
 
Example 5
Source File: CUDRequestFactoryImpl.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public ODataDeleteRequest getDeleteRequest(final URI targetURI) {
  final ODataDeleteRequest req;

  if (client.getConfiguration().isUseXHTTPMethod()) {
    req = new ODataDeleteRequestImpl(client, HttpMethod.POST, targetURI);
    req.setXHTTPMethod(HttpMethod.DELETE.name());
  } else {
    req = new ODataDeleteRequestImpl(client, HttpMethod.DELETE, targetURI);
  }

  return req;
}
 
Example 6
Source File: ODataDispatcher.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
private void handleComplexDispatching(final ODataRequest request, final ODataResponse response,
    final boolean isCollection) throws ODataApplicationException, ODataLibraryException {
  final HttpMethod method = request.getMethod();
  final RepresentationType complexRepresentationType = isCollection ? RepresentationType.COLLECTION_COMPLEX
      : RepresentationType.COMPLEX;
  if (method == HttpMethod.GET) {
    validatePreferHeader(request);
    final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
        request, handler.getCustomContentTypeSupport(), complexRepresentationType);
    if (isCollection) {
      handler.selectProcessor(ComplexCollectionProcessor.class)
          .readComplexCollection(request, response, uriInfo, requestedContentType);
    } else {
      handler.selectProcessor(ComplexProcessor.class)
          .readComplex(request, response, uriInfo, requestedContentType);
    }
  } else if (method == HttpMethod.PUT || method == HttpMethod.PATCH) {
    validatePreconditions(request, false);
    final ContentType requestFormat = getSupportedContentType(request.getHeader(HttpHeader.CONTENT_TYPE),
        complexRepresentationType, true);
    final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
        request, handler.getCustomContentTypeSupport(), complexRepresentationType);
    if (isCollection) {
      handler.selectProcessor(ComplexCollectionProcessor.class)
          .updateComplexCollection(request, response, uriInfo, requestFormat, responseFormat);
    } else {
      handler.selectProcessor(ComplexProcessor.class)
          .updateComplex(request, response, uriInfo, requestFormat, responseFormat);
    }
  } else if (method == HttpMethod.DELETE) {
    validatePreferHeader(request);
    validatePreconditions(request, false);
    if (isCollection) {
      handler.selectProcessor(ComplexCollectionProcessor.class)
          .deleteComplexCollection(request, response, uriInfo);
    } else {
      handler.selectProcessor(ComplexProcessor.class)
          .deleteComplex(request, response, uriInfo);
    }
  } else {
    throwMethodNotAllowed(method);
  }
}
 
Example 7
Source File: ODataDispatcher.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
private void handlePrimitiveDispatching(final ODataRequest request, final ODataResponse response,
    final boolean isCollection) throws ODataApplicationException, ODataLibraryException {
  final HttpMethod method = request.getMethod();
  final RepresentationType representationType = isCollection ? RepresentationType.COLLECTION_PRIMITIVE
      : RepresentationType.PRIMITIVE;
  if (method == HttpMethod.GET) {
    validatePreferHeader(request);
    final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
        request, handler.getCustomContentTypeSupport(), representationType);
    if (isCollection) {
      handler.selectProcessor(PrimitiveCollectionProcessor.class)
          .readPrimitiveCollection(request, response, uriInfo, requestedContentType);
    } else {
      handler.selectProcessor(PrimitiveProcessor.class)
          .readPrimitive(request, response, uriInfo, requestedContentType);
    }
  } else if (method == HttpMethod.PUT || method == HttpMethod.PATCH) {
    validatePreconditions(request, false);
    ContentType requestFormat = null;
    List<UriResource> uriResources = uriInfo.getUriResourceParts();
    UriResource uriResource = uriResources.get(uriResources.size() - 1);
    if (uriResource instanceof UriResourcePrimitiveProperty &&
  		  ((UriResourcePrimitiveProperty)uriResource).getType()
  		  .getFullQualifiedName().getFullQualifiedNameAsString().equalsIgnoreCase(EDMSTREAM)) {
  	 requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
    } else {
  	  requestFormat = getSupportedContentType(request.getHeader(HttpHeader.CONTENT_TYPE),
  	          representationType, true);
    }
    final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
        request, handler.getCustomContentTypeSupport(), representationType);
    if (isCollection) {
      handler.selectProcessor(PrimitiveCollectionProcessor.class)
          .updatePrimitiveCollection(request, response, uriInfo, requestFormat, responseFormat);
    } else {
      handler.selectProcessor(PrimitiveProcessor.class)
          .updatePrimitive(request, response, uriInfo, requestFormat, responseFormat);
    }
  } else if (method == HttpMethod.DELETE) {
    validatePreferHeader(request);
    validatePreconditions(request, false);
    if (isCollection) {
      handler.selectProcessor(PrimitiveCollectionProcessor.class)
          .deletePrimitiveCollection(request, response, uriInfo);
    } else {
      handler.selectProcessor(PrimitiveProcessor.class)
          .deletePrimitive(request, response, uriInfo);
    }
  } else {
    throwMethodNotAllowed(method);
  }
}
 
Example 8
Source File: BatchRequestParserTest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Test
public void methodsForIndividualRequests() throws Exception {
  final String batch = "--" + BOUNDARY + CRLF
      + MIME_HEADERS
      + CRLF
      + HttpMethod.POST + " ESAllPrim" + HTTP_VERSION + CRLF
      + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF
      + CRLF
      + "{ \"PropertyString\": \"Foo\" }"
      + CRLF
      + "--" + BOUNDARY + CRLF
      + MIME_HEADERS
      + CRLF
      + HttpMethod.DELETE + " ESAllPrim(32767)" + HTTP_VERSION + CRLF
      + CRLF
      + CRLF
      + "--" + BOUNDARY + CRLF
      + MIME_HEADERS
      + CRLF
      + HttpMethod.PATCH + " ESAllPrim(32767)" + HTTP_VERSION + CRLF
      + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF
      + CRLF
      + "{ \"PropertyString\": \"Foo\" }" + CRLF
      + "--" + BOUNDARY + CRLF
      + MIME_HEADERS
      + CRLF
      + HttpMethod.PUT + " ESAllPrim(32767)" + HTTP_VERSION + CRLF
      + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF
      + CRLF
      + "{ \"PropertyString\": \"Foo\" }" + CRLF
      + "--" + BOUNDARY + CRLF
      + MIME_HEADERS
      + CRLF
      + HttpMethod.GET + " ESAllPrim(32767)" + HTTP_VERSION + CRLF
      + ACCEPT_HEADER
      + CRLF
      + CRLF
      + "--" + BOUNDARY + "--";

  final List<BatchRequestPart> requests = parse(batch);

  Assert.assertEquals(HttpMethod.POST, requests.get(0).getRequests().get(0).getMethod());
  Assert.assertEquals("/ESAllPrim", requests.get(0).getRequests().get(0).getRawODataPath());
  Assert.assertEquals("{ \"PropertyString\": \"Foo\" }",
      IOUtils.toString(requests.get(0).getRequests().get(0).getBody()));

  Assert.assertEquals(HttpMethod.DELETE, requests.get(1).getRequests().get(0).getMethod());
  Assert.assertEquals("/ESAllPrim(32767)", requests.get(1).getRequests().get(0).getRawODataPath());

  Assert.assertEquals(HttpMethod.PATCH, requests.get(2).getRequests().get(0).getMethod());
  Assert.assertEquals("/ESAllPrim(32767)", requests.get(2).getRequests().get(0).getRawODataPath());
  Assert.assertEquals("{ \"PropertyString\": \"Foo\" }",
      IOUtils.toString(requests.get(2).getRequests().get(0).getBody()));

  Assert.assertEquals(HttpMethod.PUT, requests.get(3).getRequests().get(0).getMethod());
  Assert.assertEquals("/ESAllPrim(32767)", requests.get(3).getRequests().get(0).getRawODataPath());
  Assert.assertEquals("{ \"PropertyString\": \"Foo\" }",
      IOUtils.toString(requests.get(3).getRequests().get(0).getBody()));

  Assert.assertEquals(HttpMethod.GET, requests.get(4).getRequests().get(0).getMethod());
  Assert.assertEquals("/ESAllPrim(32767)", requests.get(4).getRequests().get(0).getRawODataPath());
}
 
Example 9
Source File: ServiceRequest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
protected boolean isDELETE() {
  return this.request.getMethod() == HttpMethod.DELETE;
}
 
Example 10
Source File: DataRequest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Override
public HttpMethod[] allowedMethods() {
  return new HttpMethod[] { HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT,
      HttpMethod.PATCH, HttpMethod.DELETE };
}
 
Example 11
Source File: DataRequest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Override
public HttpMethod[] allowedMethods() {
  return new HttpMethod[] { HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT,
      HttpMethod.DELETE };
}
 
Example 12
Source File: DataRequest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Override
public HttpMethod[] allowedMethods() {
  return new HttpMethod[] { HttpMethod.GET, HttpMethod.PUT,
      HttpMethod.PATCH, HttpMethod.DELETE };
}
 
Example 13
Source File: DataRequest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Override
public HttpMethod[] allowedMethods() {
  return new HttpMethod[] { HttpMethod.GET, HttpMethod.PUT, HttpMethod.DELETE };
}
 
Example 14
Source File: FunctionRequest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Override
public HttpMethod[] allowedMethods() {
  return new HttpMethod[] { HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT,
      HttpMethod.PATCH, HttpMethod.DELETE };
}
 
Example 15
Source File: MediaRequest.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Override
public HttpMethod[] allowedMethods() {
  return new HttpMethod[] { HttpMethod.GET, HttpMethod.PUT, HttpMethod.DELETE };
}