本文整理汇总了Java中org.apache.olingo.commons.api.http.HttpMethod.PATCH属性的典型用法代码示例。如果您正苦于以下问题:Java HttpMethod.PATCH属性的具体用法?Java HttpMethod.PATCH怎么用?Java HttpMethod.PATCH使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.olingo.commons.api.http.HttpMethod
的用法示例。
在下文中一共展示了HttpMethod.PATCH属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validatePropertyOperations
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());
}
}
}
示例2: negativeContentLengthRequest
@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);
}
示例3: nonNumericContentLength
@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);
}
示例4: nonStrictParserMoreCRLF
@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);
}
示例5: contentTypeCaseInsensitive
@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);
}
示例6: contentTypeBoundaryCaseInsensitive
@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());
}
示例7: handleSingleEntityDispatching
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) {
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) {
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);
handler.selectProcessor(isMedia ? MediaEntityProcessor.class : EntityProcessor.class)
.deleteEntity(request, response, uriInfo);
} else {
throwMethodNotAllowed(method);
}
}
示例8: contentLengthGreatherThanBodyLength
@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()));
}
示例9: contentLengthSmallerThanBodyLength
@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()));
}
示例10: nonStrictParser
@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());
}
示例11: handleComplexDispatching
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) {
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) {
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);
}
}
示例12: handlePrimitiveDispatching
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) {
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);
final ContentType 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) {
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);
}
}
示例13: methodsForIndividualRequests
@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());
}
示例14: isPATCH
protected boolean isPATCH() {
return this.request.getMethod() == HttpMethod.PATCH;
}
示例15: allowedMethods
@Override
public HttpMethod[] allowedMethods() {
return new HttpMethod[] { HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT,
HttpMethod.PATCH, HttpMethod.DELETE };
}