Java Code Examples for org.apache.olingo.commons.api.http.HttpMethod#PATCH
The following examples show how to use
org.apache.olingo.commons.api.http.HttpMethod#PATCH .
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 |
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: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void negativeContentLengthRequest() throws Exception { final String batch = "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; boundary=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.PATCH + " ESAllPrim(32767)" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + HttpHeader.CONTENT_LENGTH + ": -2" + CRLF + CRLF + "{\"PropertyString\":\"new\"}" + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + CRLF + "--" + BOUNDARY + "--"; parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_CONTENT_LENGTH); }
Example 3
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void nonNumericContentLength() throws Exception { final String batch = "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; boundary=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.PATCH + " ESAllPrim(32767)" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + HttpHeader.CONTENT_LENGTH + ": 10abc" + CRLF + CRLF + "{\"PropertyString\":\"new\"}" + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + CRLF + "--" + BOUNDARY + "--"; parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_CONTENT_LENGTH); }
Example 4
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void nonStrictParserMoreCRLF() throws Exception { final String batch = "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + ";boundary=" + CHANGESET_BOUNDARY + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + CRLF // Only one CRLF allowed + HttpMethod.PATCH + " ESAllPrim(32767)" + HTTP_VERSION + CRLF + ACCEPT_HEADER + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + "{\"PropertyString\":\"new\"}" + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + "--" + BOUNDARY + "--"; parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_STATUS_LINE, false); }
Example 5
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void contentTypeCaseInsensitive() throws Exception { final String batch = "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; boundary=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + HttpHeader.CONTENT_LENGTH + ": 200" + CRLF + CRLF + HttpMethod.PATCH + " ESAllPrim(32767)" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + CRLF + "{\"PropertyString\":\"new\"}" + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + CRLF + "--" + BOUNDARY + "--"; parse(batch); }
Example 6
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void contentTypeBoundaryCaseInsensitive() throws Exception { final String batch = "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; bOunDaRy=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.PATCH + " ESAllPrim(32767)" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + CRLF + "{\"PropertyString\":\"new\"}" + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + CRLF + "--" + BOUNDARY + "--"; final List<BatchRequestPart> batchRequestParts = parse(batch); Assert.assertNotNull(batchRequestParts); Assert.assertEquals(1, batchRequestParts.size()); Assert.assertTrue(batchRequestParts.get(0).isChangeSet()); Assert.assertEquals(1, batchRequestParts.get(0).getRequests().size()); }
Example 7
Source File: ODataDispatcher.java From olingo-odata4 with Apache License 2.0 | 5 votes |
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 8
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void contentLengthGreatherThanBodyLength() throws Exception { final String batch = "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; boundary=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.PATCH + " ESAllPrim(32767)" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + HttpHeader.CONTENT_LENGTH + ": 100000" + CRLF + CRLF + "{\"PropertyString\":\"new\"}" + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + CRLF + "--" + BOUNDARY + "--"; final List<BatchRequestPart> batchRequestParts = parse(batch); Assert.assertNotNull(batchRequestParts); Assert.assertEquals(1, batchRequestParts.size()); final BatchRequestPart part = batchRequestParts.get(0); Assert.assertTrue(part.isChangeSet()); Assert.assertEquals(1, part.getRequests().size()); final ODataRequest request = part.getRequests().get(0); Assert.assertEquals("{\"PropertyString\":\"new\"}", IOUtils.toString(request.getBody())); }
Example 9
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void contentLengthSmallerThanBodyLength() throws Exception { final String batch = "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; boundary=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.PATCH + " ESAllPrim(32767)" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + HttpHeader.CONTENT_LENGTH + ": 10" + CRLF + CRLF + "{\"PropertyString\":\"new\"}" + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + CRLF + "--" + BOUNDARY + "--"; final List<BatchRequestPart> batchRequestParts = parse(batch); Assert.assertNotNull(batchRequestParts); Assert.assertEquals(1, batchRequestParts.size()); final BatchRequestPart part = batchRequestParts.get(0); Assert.assertTrue(part.isChangeSet()); Assert.assertEquals(1, part.getRequests().size()); final ODataRequest request = part.getRequests().get(0); Assert.assertEquals("{\"Property", IOUtils.toString(request.getBody())); }
Example 10
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void nonStrictParser() throws Exception { final String batch = "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + ";boundary=" + CHANGESET_BOUNDARY + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": myRequest" + CRLF + HttpMethod.PATCH + " ESAllPrim(32767)" + HTTP_VERSION + CRLF + ACCEPT_HEADER + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + "{\"PropertyString\":\"new\"}" + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + "--" + BOUNDARY + "--"; final List<BatchRequestPart> requests = parse(batch, false); Assert.assertNotNull(requests); Assert.assertEquals(1, requests.size()); final BatchRequestPart part = requests.get(0); Assert.assertTrue(part.isChangeSet()); Assert.assertNotNull(part.getRequests()); Assert.assertEquals(1, part.getRequests().size()); final ODataRequest changeRequest = part.getRequests().get(0); Assert.assertEquals("{\"PropertyString\":\"new\"}", IOUtils.toString(changeRequest.getBody())); Assert.assertEquals(APPLICATION_JSON, changeRequest.getHeader(HttpHeader.CONTENT_TYPE)); Assert.assertEquals(HttpMethod.PATCH, changeRequest.getMethod()); }
Example 11
Source File: FunctionRequest.java From olingo-odata4 with Apache License 2.0 | 4 votes |
@Override public HttpMethod[] allowedMethods() { return new HttpMethod[] { HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.PATCH, HttpMethod.DELETE }; }
Example 12
Source File: ODataDispatcher.java From olingo-odata4 with Apache License 2.0 | 4 votes |
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 13
Source File: DataRequest.java From olingo-odata4 with Apache License 2.0 | 4 votes |
@Override public HttpMethod[] allowedMethods() { return new HttpMethod[] { HttpMethod.GET, HttpMethod.PUT, HttpMethod.PATCH, HttpMethod.DELETE }; }
Example 14
Source File: DataRequest.java From olingo-odata4 with Apache License 2.0 | 4 votes |
@Override public HttpMethod[] allowedMethods() { return new HttpMethod[] { HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.PATCH, HttpMethod.DELETE }; }
Example 15
Source File: ServiceRequest.java From olingo-odata4 with Apache License 2.0 | 4 votes |
protected boolean isPATCH() { return this.request.getMethod() == HttpMethod.PATCH; }
Example 16
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 4 votes |
@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 17
Source File: ODataDispatcher.java From olingo-odata4 with Apache License 2.0 | 4 votes |
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); } }