Java Code Examples for org.apache.olingo.server.api.ODataRequest#getMethod()
The following examples show how to use
org.apache.olingo.server.api.ODataRequest#getMethod() .
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: DemoEntityProcessor.java From olingo-odata4 with Apache License 2.0 | 6 votes |
public void updateEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType requestFormat, ContentType responseFormat) throws ODataApplicationException, DeserializerException, SerializerException { // 1. Retrieve the entity set which belongs to the requested entity List<UriResource> resourcePaths = uriInfo.getUriResourceParts(); // Note: only in our example we can assume that the first segment is the EntitySet UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0); EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet(); EdmEntityType edmEntityType = edmEntitySet.getEntityType(); // 2. update the data in backend // 2.1. retrieve the payload from the PUT request for the entity to be updated InputStream requestInputStream = request.getBody(); ODataDeserializer deserializer = this.odata.createDeserializer(requestFormat); DeserializerResult result = deserializer.entity(requestInputStream, edmEntityType); Entity requestEntity = result.getEntity(); // 2.2 do the modification in backend List<UriParameter> keyPredicates = uriResourceEntitySet.getKeyPredicates(); // Note that this updateEntity()-method is invoked for both PUT or PATCH operations HttpMethod httpMethod = request.getMethod(); storage.updateEntityData(edmEntitySet, keyPredicates, requestEntity, httpMethod); //3. configure the response object response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); }
Example 2
Source File: DemoEntityProcessor.java From olingo-odata4 with Apache License 2.0 | 6 votes |
public void updateEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType requestFormat, ContentType responseFormat) throws ODataApplicationException, DeserializerException, SerializerException { // 1. Retrieve the entity set which belongs to the requested entity List<UriResource> resourcePaths = uriInfo.getUriResourceParts(); // Note: only in our example we can assume that the first segment is the EntitySet UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0); EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet(); EdmEntityType edmEntityType = edmEntitySet.getEntityType(); // 2. update the data in backend // 2.1. retrieve the payload from the PUT request for the entity to be updated InputStream requestInputStream = request.getBody(); ODataDeserializer deserializer = odata.createDeserializer(requestFormat); DeserializerResult result = deserializer.entity(requestInputStream, edmEntityType); Entity requestEntity = result.getEntity(); // 2.2 do the modification in backend List<UriParameter> keyPredicates = uriResourceEntitySet.getKeyPredicates(); // Note that this updateEntity()-method is invoked for both PUT or PATCH operations HttpMethod httpMethod = request.getMethod(); storage.updateEntityData(edmEntitySet, keyPredicates, requestEntity, httpMethod); //3. configure the response object response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); }
Example 3
Source File: DemoEntityProcessor.java From olingo-odata4 with Apache License 2.0 | 6 votes |
public void updateEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType requestFormat, ContentType responseFormat) throws ODataApplicationException, DeserializerException, SerializerException { // 1. Retrieve the entity set which belongs to the requested entity List<UriResource> resourcePaths = uriInfo.getUriResourceParts(); // Note: only in our example we can assume that the first segment is the EntitySet UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0); EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet(); EdmEntityType edmEntityType = edmEntitySet.getEntityType(); // 2. update the data in backend // 2.1. retrieve the payload from the PUT request for the entity to be updated InputStream requestInputStream = request.getBody(); ODataDeserializer deserializer = this.odata.createDeserializer(requestFormat); DeserializerResult result = deserializer.entity(requestInputStream, edmEntityType); Entity requestEntity = result.getEntity(); // 2.2 do the modification in backend List<UriParameter> keyPredicates = uriResourceEntitySet.getKeyPredicates(); // Note that this updateEntity()-method is invoked for both PUT or PATCH operations HttpMethod httpMethod = request.getMethod(); storage.updateEntityData(edmEntitySet, keyPredicates, requestEntity, httpMethod); //3. configure the response object response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); }
Example 4
Source File: DemoEntityProcessor.java From olingo-odata4 with Apache License 2.0 | 6 votes |
public void updateEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType requestFormat, ContentType responseFormat) throws ODataApplicationException, DeserializerException, SerializerException { // 1. Retrieve the entity set which belongs to the requested entity List<UriResource> resourcePaths = uriInfo.getUriResourceParts(); // Note: only in our example we can assume that the first segment is the EntitySet UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0); EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet(); EdmEntityType edmEntityType = edmEntitySet.getEntityType(); // 2. update the data in backend // 2.1. retrieve the payload from the PUT request for the entity to be updated InputStream requestInputStream = request.getBody(); ODataDeserializer deserializer = odata.createDeserializer(requestFormat); DeserializerResult result = deserializer.entity(requestInputStream, edmEntityType); Entity requestEntity = result.getEntity(); // 2.2 do the modification in backend List<UriParameter> keyPredicates = uriResourceEntitySet.getKeyPredicates(); // Note that this updateEntity()-method is invoked for both PUT or PATCH operations HttpMethod httpMethod = request.getMethod(); storage.updateEntityData(edmEntitySet, keyPredicates, requestEntity, httpMethod); //3. configure the response object response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); }
Example 5
Source File: BatchReferenceRewriter.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private String getODataPath(final ODataRequest request, final ODataResponse response) throws BatchDeserializerException { String resourceUri = null; if (request.getMethod() == HttpMethod.POST) { // Create entity // The URI of the new resource will be generated by the server and published in the location header final String locationHeader = response.getHeader(HttpHeader.LOCATION); resourceUri = locationHeader == null ? null : parseODataPath(locationHeader, request.getRawBaseUri()); } else { // Update, Upsert (PUT, PATCH, Delete) // These methods still addresses a given resource, so we use the URI given by the request resourceUri = request.getRawODataPath(); } return resourceUri; }
Example 6
Source File: DemoEntityProcessor.java From olingo-odata4 with Apache License 2.0 | 6 votes |
public void updateEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType requestFormat, ContentType responseFormat) throws ODataApplicationException, DeserializerException, SerializerException { // 1. Retrieve the entity set which belongs to the requested entity List<UriResource> resourcePaths = uriInfo.getUriResourceParts(); // Note: only in our example we can assume that the first segment is the EntitySet UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0); EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet(); EdmEntityType edmEntityType = edmEntitySet.getEntityType(); // 2. update the data in backend // 2.1. retrieve the payload from the PUT request for the entity to be updated InputStream requestInputStream = request.getBody(); ODataDeserializer deserializer = odata.createDeserializer(requestFormat); DeserializerResult result = deserializer.entity(requestInputStream, edmEntityType); Entity requestEntity = result.getEntity(); // 2.2 do the modification in backend List<UriParameter> keyPredicates = uriResourceEntitySet.getKeyPredicates(); // Note that this updateEntity()-method is invoked for both PUT or PATCH operations HttpMethod httpMethod = request.getMethod(); storage.updateEntityData(edmEntitySet, keyPredicates, requestEntity, httpMethod); //3. configure the response object response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); }
Example 7
Source File: DemoEntityProcessor.java From olingo-odata4 with Apache License 2.0 | 6 votes |
public void updateEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType requestFormat, ContentType responseFormat) throws ODataApplicationException, DeserializerException, SerializerException { // 1. Retrieve the entity set which belongs to the requested entity List<UriResource> resourcePaths = uriInfo.getUriResourceParts(); // Note: only in our example we can assume that the first segment is the EntitySet UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0); EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet(); EdmEntityType edmEntityType = edmEntitySet.getEntityType(); // 2. update the data in backend // 2.1. retrieve the payload from the PUT request for the entity to be updated InputStream requestInputStream = request.getBody(); ODataDeserializer deserializer = this.odata.createDeserializer(requestFormat); DeserializerResult result = deserializer.entity(requestInputStream, edmEntityType); Entity requestEntity = result.getEntity(); // 2.2 do the modification in backend List<UriParameter> keyPredicates = uriResourceEntitySet.getKeyPredicates(); // Note that this updateEntity()-method is invoked for both PUT or PATCH operations HttpMethod httpMethod = request.getMethod(); storage.updateEntityData(edmEntitySet, keyPredicates, requestEntity, httpMethod); // 3. configure the response object response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); }
Example 8
Source File: DemoEntityProcessor.java From olingo-odata4 with Apache License 2.0 | 6 votes |
public void updateEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType requestFormat, ContentType responseFormat) throws ODataApplicationException, DeserializerException, SerializerException { // 1. Retrieve the entity set which belongs to the requested entity List<UriResource> resourcePaths = uriInfo.getUriResourceParts(); // Note: only in our example we can assume that the first segment is the EntitySet UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0); EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet(); EdmEntityType edmEntityType = edmEntitySet.getEntityType(); // 2. update the data in backend // 2.1. retrieve the payload from the PUT request for the entity to be updated InputStream requestInputStream = request.getBody(); ODataDeserializer deserializer = odata.createDeserializer(requestFormat); DeserializerResult result = deserializer.entity(requestInputStream, edmEntityType); Entity requestEntity = result.getEntity(); // 2.2 do the modification in backend List<UriParameter> keyPredicates = uriResourceEntitySet.getKeyPredicates(); // Note that this updateEntity()-method is invoked for both PUT or PATCH operations HttpMethod httpMethod = request.getMethod(); storage.updateEntityData(edmEntitySet, keyPredicates, requestEntity, httpMethod); //3. configure the response object response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); }
Example 9
Source File: DemoEntityProcessor.java From olingo-odata4 with Apache License 2.0 | 6 votes |
public void updateEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType requestFormat, ContentType responseFormat) throws ODataApplicationException, DeserializerException, SerializerException { // 1. Retrieve the entity set which belongs to the requested entity List<UriResource> resourcePaths = uriInfo.getUriResourceParts(); // Note: only in our example we can assume that the first segment is the EntitySet UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0); EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet(); EdmEntityType edmEntityType = edmEntitySet.getEntityType(); // 2. update the data in backend // 2.1. retrieve the payload from the PUT request for the entity to be updated InputStream requestInputStream = request.getBody(); ODataDeserializer deserializer = odata.createDeserializer(requestFormat); DeserializerResult result = deserializer.entity(requestInputStream, edmEntityType); Entity requestEntity = result.getEntity(); // 2.2 do the modification in backend List<UriParameter> keyPredicates = uriResourceEntitySet.getKeyPredicates(); // Note that this updateEntity()-method is invoked for both PUT or PATCH operations HttpMethod httpMethod = request.getMethod(); storage.updateEntityData(edmEntitySet, keyPredicates, requestEntity, httpMethod); //3. configure the response object response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); }
Example 10
Source File: MockedBatchHandlerTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private ODataResponse buildResponse(final ODataRequest request) { final ODataResponse oDataResponse = new ODataResponse(); if (request.getMethod() == HttpMethod.POST) { oDataResponse.setStatusCode(HttpStatusCode.CREATED.getStatusCode()); oDataResponse.setHeader(HttpHeader.LOCATION, createResourceUri(request)); } else { oDataResponse.setStatusCode(HttpStatusCode.OK.getStatusCode()); } final String contentId = request.getHeader(HttpHeader.CONTENT_ID); if (contentId != null) { oDataResponse.setHeader(HttpHeader.CONTENT_ID, contentId); } return oDataResponse; }
Example 11
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 12
Source File: ProductEntityProcessor.java From syndesis with Apache License 2.0 | 5 votes |
@Override public void updateEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType requestFormat, ContentType responseFormat) throws ODataApplicationException, DeserializerException, SerializerException { // 1. Retrieve the entity set which belongs to the requested entity List<UriResource> resourcePaths = uriInfo.getUriResourceParts(); // Note: only in our example we can assume that the first segment is the // EntitySet UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0); EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet(); EdmEntityType edmEntityType = edmEntitySet.getEntityType(); // 2. update the data in backend // 2.1. retrieve the payload from the PUT request for the entity to be // updated InputStream requestInputStream = request.getBody(); ODataDeserializer deserializer = this.odata.createDeserializer(requestFormat); DeserializerResult result = deserializer.entity(requestInputStream, edmEntityType); Entity requestEntity = result.getEntity(); LOG.info("Updating entity {}", requestEntity.getSelfLink()); // 2.2 do the modification in backend List<UriParameter> keyPredicates = uriResourceEntitySet.getKeyPredicates(); // Note that this updateEntity()-method is invoked for both PUT or PATCH // operations HttpMethod httpMethod = request.getMethod(); storage.updateEntityData(edmEntitySet, keyPredicates, requestEntity, httpMethod); // 3. configure the response object response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); }
Example 13
Source File: ODataDispatcher.java From olingo-odata4 with Apache License 2.0 | 5 votes |
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 14
Source File: ODataDispatcher.java From olingo-odata4 with Apache License 2.0 | 5 votes |
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 15
Source File: DebugTabRequest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
public DebugTabRequest(final ODataRequest request) { if (request != null) { method = request.getMethod() == null ? UNKOWN_MSG : request.getMethod().toString(); uri = request.getRawRequestUri() == null ? UNKOWN_MSG : request.getRawRequestUri(); protocol = request.getProtocol() == null ? UNKOWN_MSG : request.getProtocol(); headers = request.getAllHeaders(); } else { method = UNKOWN_MSG; uri = UNKOWN_MSG; protocol = UNKOWN_MSG; headers = Collections.emptyMap(); } }
Example 16
Source File: DefaultProcessor.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override public void readMetadata(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo, final ContentType requestedContentType) throws ODataApplicationException, ODataLibraryException { boolean isNotModified = false; ServiceMetadataETagSupport eTagSupport = serviceMetadata.getServiceMetadataETagSupport(); if (eTagSupport != null && eTagSupport.getMetadataETag() != null) { // Set application etag at response response.setHeader(HttpHeader.ETAG, eTagSupport.getMetadataETag()); // Check if metadata document has been modified ETagHelper eTagHelper = odata.createETagHelper(); isNotModified = eTagHelper.checkReadPreconditions(eTagSupport.getMetadataETag(), request .getHeaders(HttpHeader.IF_MATCH), request.getHeaders(HttpHeader.IF_NONE_MATCH)); } // Send the correct response if (isNotModified) { response.setStatusCode(HttpStatusCode.NOT_MODIFIED.getStatusCode()); } else { // HTTP HEAD requires no payload but a 200 OK response if (HttpMethod.HEAD == request.getMethod()) { response.setStatusCode(HttpStatusCode.OK.getStatusCode()); } else { ODataSerializer serializer = odata.createSerializer(requestedContentType); response.setContent(serializer.metadataDocument(serviceMetadata).getContent()); response.setStatusCode(HttpStatusCode.OK.getStatusCode()); response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString()); } } }
Example 17
Source File: DefaultProcessor.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override public void readServiceDocument(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo, final ContentType requestedContentType) throws ODataApplicationException, ODataLibraryException { boolean isNotModified = false; ServiceMetadataETagSupport eTagSupport = serviceMetadata.getServiceMetadataETagSupport(); if (eTagSupport != null && eTagSupport.getServiceDocumentETag() != null) { // Set application etag at response response.setHeader(HttpHeader.ETAG, eTagSupport.getServiceDocumentETag()); // Check if service document has been modified ETagHelper eTagHelper = odata.createETagHelper(); isNotModified = eTagHelper.checkReadPreconditions(eTagSupport.getServiceDocumentETag(), request .getHeaders(HttpHeader.IF_MATCH), request.getHeaders(HttpHeader.IF_NONE_MATCH)); } // Send the correct response if (isNotModified) { response.setStatusCode(HttpStatusCode.NOT_MODIFIED.getStatusCode()); } else { // HTTP HEAD requires no payload but a 200 OK response if (HttpMethod.HEAD == request.getMethod()) { response.setStatusCode(HttpStatusCode.OK.getStatusCode()); } else { ODataSerializer serializer = odata.createSerializer(requestedContentType); response.setContent(serializer.serviceDocument(serviceMetadata, null).getContent()); response.setStatusCode(HttpStatusCode.OK.getStatusCode()); response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString()); } } }
Example 18
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); } }
Example 19
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 20
Source File: BatchHandler.java From olingo-odata4 with Apache License 2.0 | 4 votes |
private void validateHttpMethod(final ODataRequest request) throws BatchDeserializerException { if (request.getMethod() != HttpMethod.POST) { throw new BatchDeserializerException("Invalid HTTP method", MessageKeys.INVALID_METHOD, "0"); } }