Paul Graystone
Paul Graystone

Reputation: 57

How to make a PUT request with Apache Olingo?

I am trying to transfer an entity via a HTTP PUT request using following code.

public ClientEntity createEntity(URI absoluteUri,
        ClientEntity ce) {

    ODataEntityCreateRequest<ClientEntity> request = client
            .getCUDRequestFactory().getEntityCreateRequest(absoluteUri, ce);
    request.setAccept("application/json;odata.metadata=minimal");       
    ODataEntityCreateResponse<ClientEntity> response = request.execute();
    return response.getBody();
}

The function getEntityCreateRequest, however, only creates a POST request and allows (as far as I know) no alteration of the used HttpMethod.

Unfortunately, ODataEntityUpdateRequest is also not an option, because this request only allows the HttpMethod PATCH or REPLACE.

Within the documentation I have found a function setMethod(HttpMethod method), but this method is only available for the server not the client implementation (https://olingo.apache.org/javadoc/odata4/org/apache/olingo/server/api/ODataRequest.html).

Further I discovered setUseXHTTPMethod(boolean value), which tunnels PUT, MERGE, PATCH, DELETE via POST. I checked my client's configuration to make sure, that isUseXHTTPMethod is false, which it is. (Reference to functions: https://olingo.apache.org/javadoc/odata4/org/apache/olingo/client/api/Configuration.html)

Hence I am wondering how to make a PUT request with Apache Olingo?

Thank you very much for your input.

Upvotes: 0

Views: 1086

Answers (2)

Chris Neve
Chris Neve

Reputation: 2424

Implement the updateEntity method.

Upvotes: 1

GeoK
GeoK

Reputation: 106

ODataEntityUpdateRequest with UpdateType.REPLACE should be equivalent to a PUT method.

Notice the source code, line 31.

Upvotes: 1

Related Questions