[OLINGO-712] HeaderName is redundant (there is HttpHeader)

Signed-off-by: Christian Amend <christian.amend@sap.com>
This commit is contained in:
Klaus Straubinger 2015-06-23 13:09:23 +02:00 committed by Christian Amend
parent a3fbf39f53
commit d54b071198
24 changed files with 107 additions and 438 deletions

View File

@ -33,7 +33,6 @@ import java.util.TimeZone;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.communication.ODataClientErrorException;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest;
import org.apache.olingo.client.api.communication.response.ODataInvokeResponse;
import org.apache.olingo.client.api.domain.ClientCollectionValue;
@ -45,6 +44,7 @@ import org.apache.olingo.client.api.domain.ClientValue;
import org.apache.olingo.client.core.ODataClientFactory;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.commons.api.http.HttpStatusCode;
import org.apache.olingo.fit.AbstractBaseTestITCase;
import org.apache.olingo.fit.tecsvc.TecSvcConst;
@ -80,7 +80,7 @@ public class ActionImportITCase extends AbstractBaseTestITCase {
request.setPrefer(getClient().newPreferences().returnMinimal());
final ODataInvokeResponse<ClientProperty> response = request.execute();
assertEquals(HttpStatusCode.NO_CONTENT.getStatusCode(), response.getStatusCode());
assertEquals("return=minimal", response.getHeader(HeaderName.preferenceApplied).iterator().next());
assertEquals("return=minimal", response.getHeader(HttpHeader.PREFERENCE_APPLIED).iterator().next());
}
@Test

View File

@ -37,7 +37,6 @@ import java.util.List;
import org.apache.olingo.client.api.EdmEnabledODataClient;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.communication.ODataClientErrorException;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest;
import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
@ -415,7 +414,7 @@ public class BasicITCase extends AbstractBaseTestITCase {
final ODataEntityCreateResponse<ClientEntity> response = request.execute();
assertEquals(HttpStatusCode.NO_CONTENT.getStatusCode(), response.getStatusCode());
assertEquals("return=minimal", response.getHeader(HeaderName.preferenceApplied).iterator().next());
assertEquals("return=minimal", response.getHeader(HttpHeader.PREFERENCE_APPLIED).iterator().next());
assertEquals(SERVICE_URI + "/ESTwoPrim(1)", response.getHeader(HttpHeader.LOCATION).iterator().next());
}
@ -696,7 +695,7 @@ public class BasicITCase extends AbstractBaseTestITCase {
final ODataEntityUpdateResponse<ClientEntity> response = request.execute();
assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
assertEquals("return=representation", response.getHeader(HeaderName.preferenceApplied).iterator().next());
assertEquals("return=representation", response.getHeader(HttpHeader.PREFERENCE_APPLIED).iterator().next());
assertTrue(response.getBody().getProperty("PropertyString").hasNullValue());
assertEquals(34, response.getBody().getProperty("PropertyDecimal").getPrimitiveValue().toValue());
}
@ -843,7 +842,7 @@ public class BasicITCase extends AbstractBaseTestITCase {
request.setPrefer(getClient().newPreferences().returnMinimal());
final ODataEntityUpdateResponse<ClientEntity> response = request.execute();
assertEquals(HttpStatusCode.NO_CONTENT.getStatusCode(), response.getStatusCode());
assertEquals("return=minimal", response.getHeader(HeaderName.preferenceApplied).iterator().next());
assertEquals("return=minimal", response.getHeader(HttpHeader.PREFERENCE_APPLIED).iterator().next());
final String cookie = response.getHeader(HttpHeader.SET_COOKIE).iterator().next();
final ODataEntityRequest<ClientEntity> entityRequest = client.getRetrieveRequestFactory()

View File

@ -33,7 +33,6 @@ import java.util.Iterator;
import org.apache.commons.io.IOUtils;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.communication.ODataClientErrorException;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest;
import org.apache.olingo.client.api.communication.request.cud.ODataPropertyUpdateRequest;
import org.apache.olingo.client.api.communication.request.cud.ODataValueUpdateRequest;
@ -380,7 +379,7 @@ public class PrimitiveComplexITCase extends AbstractBaseTestITCase {
final ODataValueUpdateResponse response = request.execute();
assertEquals(HttpStatusCode.NO_CONTENT.getStatusCode(), response.getStatusCode());
assertEquals("return=minimal", response.getHeader(HeaderName.preferenceApplied).iterator().next());
assertEquals("return=minimal", response.getHeader(HttpHeader.PREFERENCE_APPLIED).iterator().next());
}
@Test

View File

@ -25,13 +25,13 @@ import java.net.URI;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.communication.ODataClientErrorException;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
import org.apache.olingo.client.api.domain.ClientEntity;
import org.apache.olingo.client.api.domain.ClientEntitySet;
import org.apache.olingo.client.core.ODataClientFactory;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.commons.api.http.HttpStatusCode;
import org.apache.olingo.fit.AbstractBaseTestITCase;
import org.apache.olingo.fit.tecsvc.TecSvcConst;
@ -268,7 +268,7 @@ public class SystemQueryOptionITCase extends AbstractBaseTestITCase {
request.setPrefer(getClient().newPreferences().maxPageSize(7));
final ODataRetrieveResponse<ClientEntitySet> response = request.execute();
assertEquals("odata.maxpagesize=7", response.getHeader(HeaderName.preferenceApplied).iterator().next());
assertEquals("odata.maxpagesize=7", response.getHeader(HttpHeader.PREFERENCE_APPLIED).iterator().next());
assertEquals(SERVICE_URI + '/' + ES_SERVER_SIDE_PAGING + "?%24skiptoken=1%2A" + 7,
response.getBody().getNext().toASCIIString());
}

View File

@ -23,7 +23,6 @@ import static org.junit.Assert.assertEquals;
import java.net.URI;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.request.batch.BatchManager;
import org.apache.olingo.client.api.communication.request.batch.ODataBatchRequest;
import org.apache.olingo.client.api.communication.request.batch.ODataChangeset;
@ -40,6 +39,7 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.junit.Test;
public class AuthBatchTestITCase extends AbstractTestITCase {
@ -71,7 +71,7 @@ public class AuthBatchTestITCase extends AbstractTestITCase {
final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(baseURL);
request.setAccept(ACCEPT.toContentTypeString());
request.addCustomHeader("User-Agent", "Apache Olingo OData Client");
request.addCustomHeader(HeaderName.acceptCharset, "UTF-8");
request.addCustomHeader(HttpHeader.ACCEPT_CHARSET, "UTF-8");
final BatchManager streamManager = request.payloadManager();

View File

@ -35,7 +35,6 @@ import java.util.concurrent.TimeUnit;
import org.apache.http.HttpResponse;
import org.apache.olingo.client.api.ODataBatchConstants;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.request.AsyncBatchRequestWrapper;
import org.apache.olingo.client.api.communication.request.ODataPayloadManager;
import org.apache.olingo.client.api.communication.request.batch.BatchManager;
@ -68,6 +67,7 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.junit.Test;
public class BatchTestITCase extends AbstractTestITCase {
@ -570,7 +570,7 @@ public class BatchTestITCase extends AbstractTestITCase {
assertEquals(202, res.getStatusCode());
assertEquals("Accepted", res.getStatusMessage());
final Collection<String> newMonitorLocation = res.getHeader(HeaderName.location);
final Collection<String> newMonitorLocation = res.getHeader(HttpHeader.LOCATION);
if (newMonitorLocation != null && !newMonitorLocation.isEmpty()) {
responseWrapper.forceNextMonitorCheck(URI.create(newMonitorLocation.iterator().next()));
// .... now you can start again with isDone() and getODataResponse().

View File

@ -28,7 +28,6 @@ import java.net.URI;
import java.util.Calendar;
import java.util.TimeZone;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.request.AsyncRequestWrapper;
import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest;
import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
@ -55,6 +54,7 @@ import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.junit.Test;
/**
@ -75,8 +75,7 @@ public class ConformanceTestITCase extends AbstractTestITCase {
final ODataEntityRequest<ClientEntity> req =
client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
assertEquals("4.0", req.getHeader("OData-MaxVersion"));
assertEquals("4.0", req.getHeader(HeaderName.odataMaxVersion.toString()));
assertEquals("4.0", req.getHeader(HttpHeader.ODATA_MAX_VERSION));
assertNotNull(req.execute().getBody());
}
@ -121,16 +120,12 @@ public class ConformanceTestITCase extends AbstractTestITCase {
req.setFormat(ODataFormat.JSON_FULL_METADATA);
// check for OData-Version
assertEquals("4.0", req.getHeader("OData-Version"));
assertEquals("4.0", req.getHeader(HeaderName.odataVersion.toString()));
assertEquals("4.0", req.getHeader(HttpHeader.ODATA_VERSION));
// check for Content-Type
assertEquals(
ODataFormat.JSON_FULL_METADATA.getContentType().toContentTypeString(),
req.getHeader("Content-Type"));
assertEquals(
ODataFormat.JSON_FULL_METADATA.getContentType().toContentTypeString(),
req.getHeader(HeaderName.contentType.toString()));
req.getHeader(HttpHeader.CONTENT_TYPE));
assertEquals(
ODataFormat.JSON_FULL_METADATA.getContentType().toContentTypeString(),
req.getContentType());
@ -158,8 +153,7 @@ public class ConformanceTestITCase extends AbstractTestITCase {
final ODataEntityRequest<ClientEntity> req =
client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
assertEquals("4.0", req.getHeader("OData-MaxVersion"));
assertEquals("4.0", req.getHeader(HeaderName.odataMaxVersion.toString()));
assertEquals("4.0", req.getHeader(HttpHeader.ODATA_MAX_VERSION));
final ODataRetrieveResponse<ClientEntity> res = req.execute();
final ClientEntity entity = res.getBody();
@ -411,7 +405,6 @@ public class ConformanceTestITCase extends AbstractTestITCase {
req.setFormat(ODataFormat.JSON);
assertEquals("application/json;odata.metadata=minimal", req.getHeader("Accept"));
assertEquals("application/json;odata.metadata=minimal", req.getHeader(HeaderName.accept.toString()));
assertEquals("application/json;odata.metadata=minimal", req.getAccept());
final ODataRetrieveResponse<ClientEntity> res = req.execute();

View File

@ -32,7 +32,6 @@ import java.util.UUID;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
import org.apache.olingo.client.api.communication.request.cud.UpdateType;
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
@ -53,6 +52,7 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.junit.Test;
public class MediaEntityTestITCase extends AbstractTestITCase {
@ -108,7 +108,7 @@ public class MediaEntityTestITCase extends AbstractTestITCase {
final ODataMediaEntityCreateResponse<ClientEntity> createRes = streamManager.getResponse();
assertEquals(201, createRes.getStatusCode());
final Collection<String> location = createRes.getHeader(HeaderName.location);
final Collection<String> location = createRes.getHeader(HttpHeader.LOCATION);
assertNotNull(location);
final URI createdLocation = URI.create(location.iterator().next());

View File

@ -1,194 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.olingo.client.api.communication.header;
/**
* Major OData request/response header names.
*/
public enum HeaderName {
/**
* The OData protocol uses the Accept request-header field, as specified in [RFC2616].
*/
accept("Accept"),
/**
* As specified in [RFC2616], the client MAY specify the set of accepted character sets with the Accept-Charset
* header.
*/
acceptCharset("Accept-Charset"),
/**
* As specified in [RFC2616], the client MAY specify the set of accepted natural languages with the Accept-Language
* header.
*/
acceptLanguage("Accept-Language"),
/**
* The Content-Type header is used as specified in [RFC2616].
* <br/>
* OData request/response supports the following types:
* <ul>
* <li>application/atom+xml</li>
* <li>application/atom+xml;type=entry</li>
* <li>application/atom+xml;type=feed</li>
* <li>application/json; odata.metadata=full</li>
* <li>application/json; odata.metadata=minimal</li>
* <li>application/json; odata.metadata=none</li>
* <li>application/json</li>
* <li>application/xml</li>
* <li>text/plain</li>
* <li>text/xml</li>
* <li>octet/stream</li>
* <li>multipart/mixed</li>
* </ul>
*/
contentType("Content-Type"),
/**
* This header is a custom HTTP header defined for protocol versioning purposes. This header MAY be present on any
* request or response message.
*/
odataVersion("OData-Version"),
/**
* A response to a create operation that returns 204 No Content MUST include an OData-EntityId response header. The
* value of the header is the entity-id of the entity that was acted on by the request. The syntax of the
* OData-EntityId preference is specified in [OData-ABNF].
*/
odataEntityId("OData-EntityId"),
/**
* An ETag (entity tag) is an HTTP response header returned by an HTTP/1.1 compliant web server used to determine
* change in content of a resource at a given URL. The value of the header is an opaque string representing the state
* of the resource at the time the response was generated.
*/
etag("ETag"),
/**
* The If-Match request-header field is used with a method to make it conditional. As specified in [RFC2616], "the
* purpose of this feature is to allow efficient updates of cached information with a minimum amount of transaction
* overhead. It is also used, on updating requests, to prevent inadvertent modification of the wrong version of a
* resource".
*/
ifMatch("If-Match"),
/**
* The If-None-Match request header is used with a method to make it conditional. As specified in [RFC2616], "The
* purpose of this feature is to allow efficient updates of cached information with a minimum amount of transaction
* overhead. It is also used to prevent a method (for example, PUT) from inadvertently modifying an existing resource
* when the client believes that the resource does not exist."
*/
ifNoneMatch("If-None-Match"),
/**
* Clients SHOULD specify an OData-MaxVersion request header.
* <br />
* If specified the service MUST generate a response with an OData-Version less than or equal to the specified
* OData-MaxVersion.
* <br />
* If OData-MaxVersion is not specified, then the service SHOULD interpret the request as having an OData-MaxVersion
* equal to the maximum version supported by the service.
*/
odataMaxVersion("OData-MaxVersion"),
/**
* The OData-Isolation header specifies the isolation of the current request from external changes. The only supported
* value for this header is snapshot.
* <br />
* If the service doesnt support OData-Isolation:snapshot and this header was specified on the request, the service
* MUST NOT process the request and MUST respond with 412 Precondition Failed.
* <br />
* Snapshot isolation guarantees that all data returned for a request, including multiple requests within a batch or
* results retrieved across multiple pages, will be consistent as of a single point in time. Only data modifications
* made within the request (for example, by a data modification request within the same batch) are visible. The effect
* is as if the request generates a "snapshot" of the committed data as it existed at the start of the request.
* <br />
* The OData-Isolation header may be specified on a single or batch request. If it is specified on a batch then the
* value is applied to all statements within the batch.
* <br />
* Next links returned within a snapshot return results within the same snapshot as the initial request; the client is
* not required to repeat the header on each individual page request.
* <br />
* The OData-Isolation header has no effect on links other than the next link. Navigation links, read links, and edit
* links return the current version of the data.
* <br />
* A service returns 410 Gone or 404 Not Found if a consumer tries to follow a next link referring to a snapshot that
* is no longer available.
* <br />
* The syntax of the OData-Isolation header is specified in [OData-ABNF].
* <br />
* A service MAY specify the support for OData-Isolation:snapshot using an annotation with term
* Capabilities.IsolationSupport, see [OData-VocCap].
*/
odataIsolation("OData-Isolation"),
/**
* A Prefer header is included in a request to state the clients preferred, but not required, server behavior (that
* is, a hint to the server). The Prefer header MAY be included on any request type (within a standalone or batch
* request), and a server MAY honor the header for HTTP POST, PUT, PATCH, and MERGE requests. A Prefer header with a
* value of return-content MUST NOT be specified on a DELETE request, a batch request as a whole, or a PUT request
* to update a named stream.
*/
prefer("Prefer"),
/**
* When a Prefer header value is successfully honored by the server, it MAY include a Preference-Applied response
* header that states which preference values were honored by the server.
*/
preferenceApplied("Preference-Applied"),
/**
* Location header is used to specify the URL of an entity modified through a Data Modification request, or the
* request URL to check on the status of an asynchronous operation as described in
* <code>202 Accepted</code>.
*/
location("Location"),
/**
* A service must include a
* <code>Retry-After</code> header in a
* <code>202 Accepted</code>.
*/
retryAfter("Retry-After"),
/**
* This header is a custom HTTP request header.
* <br/>
* It is possible to instruct network intermediaries (proxies, firewalls, and so on) inspecting traffic at the
* application protocol layer (for example, HTTP) to block requests that contain certain HTTP verbs. In practice, GET
* and POST verbs are rarely blocked (traditional web pages rely heavily on these HTTP methods), while, for a variety
* of reasons (such as security vulnerabilities in prior protocols), other HTTP methods (PUT, DELETE, and so on) are
* at times blocked by intermediaries. Additionally, some existing HTTP libraries do not allow creation of requests
* using verbs other than GET or POST. Therefore, an alternative way of specifying request types which use verbs other
* than GET and POST is needed to ensure that this document works well in a wide range of environments.
* <br/>
* To address this need, the X-HTTP-Method header can be added to a POST request that signals that the server MUST
* process the request not as a POST, but as if the HTTP verb specified as the value of the header was used as the
* method on the HTTP request's request line, as specified in [RFC2616] section 5.1. This technique is often referred
* to as "verb tunneling".
* <br/>
* This header is only valid when on POST requests.
*/
xHttpMethod("X-HTTP-METHOD"),
//TODO: Delete
dataServiceUrlConventions("DataServiceUrlConventions");
private final String headerName;
private HeaderName(final String headerName) {
this.headerName = headerName;
}
@Override
public String toString() {
return headerName;
}
}

View File

@ -28,16 +28,6 @@ import java.util.Collection;
*/
public interface ODataHeaders {
/**
* Gets the value of the header identified by the given name.
* <br/>
* Please note that header name is case-insensitive.
*
* @param name name of the header to be retrieved.
* @return header value.
*/
String getHeader(final HeaderName name);
/**
* Gets the value of the header identified by the given name.
* <br/>
@ -66,15 +56,6 @@ public interface ODataHeaders {
*/
ODataHeaders setHeader(String name, String value);
/**
* Add the specified header.
*
* @param name header key.
* @param value header value.
* @return the current updated header instance.
*/
ODataHeaders setHeader(HeaderName name, String value);
/**
* Removes the header identified by the given name.
* <br/>
@ -83,8 +64,6 @@ public interface ODataHeaders {
* @param name name of the header to be retrieved.
* @return header name (if found).
*/
String removeHeader(HeaderName name);
String removeHeader(String name);
}

View File

@ -28,7 +28,7 @@ public class ODataPreferences {
/**
* <code>Prefer</code> header, return content.
*
* @see HeaderName#prefer
* @see org.apache.olingo.commons.api.http.HttpHeader#PREFER
*/
public String returnContent() {
return PreferenceNames.returnContent.toString();
@ -37,14 +37,16 @@ public class ODataPreferences {
/**
* <code>Prefer</code> header, return no content.
*
* @see HeaderName#prefer
* @see org.apache.olingo.commons.api.http.HttpHeader#PREFER
*/
public String returnNoContent() {
return PreferenceNames.returnNoContent.toString();
}
/**
* @see HeaderName#dataServiceUrlConventions
* Gets the value of the non-standard preference that the URL should follow the convention
* that keys are formatted as separate segments.
* @see org.apache.olingo.commons.api.http.HttpHeader#PREFER
*/
public String keyAsSegment() {
return PreferenceNames.keyAsSegment.toString();
@ -64,7 +66,7 @@ public class ODataPreferences {
* <br/><br/>
* Supported by OData version 4.0 only.
*
* @see HeaderName#prefer
* @see org.apache.olingo.commons.api.http.HttpHeader#PREFER
* @return preference.
*/
public String allowEntityReferences() {
@ -127,7 +129,7 @@ public class ODataPreferences {
* <br/><br/>
* Supported by OData version 4.0 only.
*
* @see HeaderName#prefer
* @see org.apache.olingo.commons.api.http.HttpHeader#PREFER
* @return preference.
*/
public String callback(final String url) {
@ -148,7 +150,7 @@ public class ODataPreferences {
* <br/><br/>
* Supported by OData version 4.0 only.
*
* @see HeaderName#prefer
* @see org.apache.olingo.commons.api.http.HttpHeader#PREFER
* @return preference.
*/
public String continueOnError() {
@ -195,7 +197,7 @@ public class ODataPreferences {
* <br/><br/>
* Supported by OData version 4.0 only.
*
* @see HeaderName#prefer
* @see org.apache.olingo.commons.api.http.HttpHeader#PREFER
* @return preference.
*/
public String includeAnnotations(final String value) {
@ -228,7 +230,7 @@ public class ODataPreferences {
* <br/><br/>
* Supported by OData version 4.0 only.
*
* @see HeaderName#prefer
* @see org.apache.olingo.commons.api.http.HttpHeader#PREFER
* @return preference.
*/
public String maxPageSize(final int size) {
@ -253,7 +255,7 @@ public class ODataPreferences {
* <br/><br/>
* Supported by OData version 4.0 only.
*
* @see HeaderName#prefer
* @see org.apache.olingo.commons.api.http.HttpHeader#PREFER
* @return preference.
*/
public String trackChanges() {
@ -288,7 +290,7 @@ public class ODataPreferences {
* <br/><br/>
* Supported by OData version 4.0 only.
*
* @see HeaderName#prefer
* @see org.apache.olingo.commons.api.http.HttpHeader#PREFER
* @return preference.
*/
public String respondAsync() {
@ -308,7 +310,7 @@ public class ODataPreferences {
* <br/><br/>
* Supported by OData version 4.0 only.
*
* @see HeaderName#prefer
* @see org.apache.olingo.commons.api.http.HttpHeader#PREFER
* @return preference.
*/
public String wait(final int value) {
@ -338,7 +340,7 @@ public class ODataPreferences {
* <br/><br/>
* Supported by OData version 4.0 only.
*
* @see HeaderName#prefer
* @see org.apache.olingo.commons.api.http.HttpHeader#PREFER
* @return preference.
*/
public String returnMinimal() {
@ -368,7 +370,7 @@ public class ODataPreferences {
* <br/><br/>
* Supported by OData version 4.0 only.
*
* @see HeaderName#prefer
* @see org.apache.olingo.commons.api.http.HttpHeader#PREFER
* @return preference.
*/
public String returnRepresentation() {

View File

@ -22,7 +22,6 @@ import java.io.InputStream;
import java.net.URI;
import java.util.Collection;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.commons.api.http.HttpMethod;
/**
@ -75,7 +74,7 @@ public interface ODataRequest {
*
* @param value header value.
* @return current object
* @see org.apache.olingo.client.api.communication.header.HeaderName#accept
* @see org.apache.olingo.commons.api.http.HttpHeader#ACCEPT
*/
ODataRequest setAccept(final String value);
@ -83,7 +82,7 @@ public interface ODataRequest {
* Gets <tt>Accept</tt> OData request header.
*
* @return header value.
* @see org.apache.olingo.client.api.communication.header.HeaderName#accept
* @see org.apache.olingo.commons.api.http.HttpHeader#ACCEPT
*/
String getAccept();
@ -92,7 +91,7 @@ public interface ODataRequest {
*
* @param value header value.
* @return current object
* @see org.apache.olingo.client.api.communication.header.HeaderName#ifMatch
* @see org.apache.olingo.commons.api.http.HttpHeader#IF_MATCH
*/
ODataRequest setIfMatch(final String value);
@ -100,7 +99,7 @@ public interface ODataRequest {
* Gets <tt>If-Match</tt> OData request header.
*
* @return header value.
* @see org.apache.olingo.client.api.communication.header.HeaderName#ifMatch
* @see org.apache.olingo.commons.api.http.HttpHeader#IF_MATCH
*/
String getIfMatch();
@ -109,7 +108,7 @@ public interface ODataRequest {
*
* @param value header value.
* @return current object
* @see org.apache.olingo.client.api.communication.header.HeaderName#ifNoneMatch
* @see org.apache.olingo.commons.api.http.HttpHeader#IF_NONE_MATCH
*/
ODataRequest setIfNoneMatch(final String value);
@ -117,7 +116,7 @@ public interface ODataRequest {
* Gets <tt>If-None-Match</tt> OData request header.
*
* @return header value.
* @see org.apache.olingo.client.api.communication.header.HeaderName#ifNoneMatch
* @see org.apache.olingo.commons.api.http.HttpHeader#IF_NONE_MATCH
*/
String getIfNoneMatch();
@ -126,7 +125,7 @@ public interface ODataRequest {
*
* @param value header value.
* @return current object
* @see org.apache.olingo.client.api.communication.header.HeaderName#prefer
* @see org.apache.olingo.commons.api.http.HttpHeader#PREFER
*/
ODataRequest setPrefer(final String value);
@ -134,7 +133,7 @@ public interface ODataRequest {
* Gets <tt>Prefer</tt> OData request header.
*
* @return header value.
* @see org.apache.olingo.client.api.communication.header.HeaderName#prefer
* @see org.apache.olingo.commons.api.http.HttpHeader#PREFER
*/
String getPrefer();
@ -143,7 +142,7 @@ public interface ODataRequest {
*
* @param value header value.
* @return current object
* @see org.apache.olingo.client.api.communication.header.HeaderName#contentType
* @see org.apache.olingo.commons.api.http.HttpHeader#CONTENT_TYPE
*/
ODataRequest setContentType(final String value);
@ -151,7 +150,7 @@ public interface ODataRequest {
* Gets <tt>contentType</tt> OData request header.
*
* @return header value.
* @see org.apache.olingo.client.api.communication.header.HeaderName#contentType
* @see org.apache.olingo.commons.api.http.HttpHeader#CONTENT_TYPE
*/
String getContentType();
@ -160,7 +159,7 @@ public interface ODataRequest {
*
* @param value header value.
* @return current object
* @see org.apache.olingo.client.api.communication.header.HeaderName#xHttpMethod
* @see org.apache.olingo.commons.api.http.HttpHeader#X_HTTP_METHOD
*/
ODataRequest setXHTTPMethod(final String value);
@ -173,16 +172,6 @@ public interface ODataRequest {
*/
ODataRequest addCustomHeader(final String name, final String value);
/**
* Adds a custom OData request header. The method fails in case of the header name is not supported by the current
* working version.
*
* @param name header name.
* @param value header value.
* @return current object
*/
ODataRequest addCustomHeader(final HeaderName name, final String value);
/**
* Gets byte array representation of the full request header.
*

View File

@ -23,7 +23,6 @@ import java.util.Collection;
import java.util.Map;
import org.apache.http.HttpResponse;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.request.batch.ODataBatchLineIterator;
/**
@ -46,14 +45,6 @@ public interface ODataResponse {
*/
Collection<String> getHeader(final String name);
/**
* Gets header value of the given header.
*
* @param name header to be retrieved.
* @return response header value.
*/
Collection<String> getHeader(final HeaderName name);
/**
* Gets 'ETag' header value.
*

View File

@ -20,7 +20,6 @@ package org.apache.olingo.client.core;
import org.apache.olingo.client.api.Configuration;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.header.ODataHeaders;
import org.apache.olingo.client.api.communication.header.ODataPreferences;
import org.apache.olingo.client.api.communication.request.AsyncRequestFactory;
@ -28,6 +27,7 @@ import org.apache.olingo.client.api.communication.request.batch.BatchRequestFact
import org.apache.olingo.client.api.communication.request.cud.CUDRequestFactory;
import org.apache.olingo.client.api.communication.request.invoke.InvokeRequestFactory;
import org.apache.olingo.client.api.communication.request.retrieve.RetrieveRequestFactory;
import org.apache.olingo.client.api.domain.ClientObjectFactory;
import org.apache.olingo.client.api.serialization.ClientODataDeserializer;
import org.apache.olingo.client.api.serialization.ODataBinder;
import org.apache.olingo.client.api.serialization.ODataReader;
@ -42,6 +42,7 @@ import org.apache.olingo.client.core.communication.request.batch.BatchRequestFac
import org.apache.olingo.client.core.communication.request.cud.CUDRequestFactoryImpl;
import org.apache.olingo.client.core.communication.request.invoke.InvokeRequestFactoryImpl;
import org.apache.olingo.client.core.communication.request.retrieve.RetrieveRequestFactoryImpl;
import org.apache.olingo.client.core.domain.ClientObjectFactoryImpl;
import org.apache.olingo.client.core.serialization.AtomSerializer;
import org.apache.olingo.client.core.serialization.ClientODataDeserializerImpl;
import org.apache.olingo.client.core.serialization.JsonSerializer;
@ -50,10 +51,9 @@ import org.apache.olingo.client.core.serialization.ODataReaderImpl;
import org.apache.olingo.client.core.serialization.ODataWriterImpl;
import org.apache.olingo.client.core.uri.FilterFactoryImpl;
import org.apache.olingo.client.core.uri.URIBuilderImpl;
import org.apache.olingo.client.api.domain.ClientObjectFactory;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.client.core.domain.ClientObjectFactoryImpl;
import org.apache.olingo.commons.api.http.HttpHeader;
public class ODataClientImpl implements ODataClient {
@ -104,8 +104,8 @@ public class ODataClientImpl implements ODataClient {
@Override
public ODataHeaders newVersionHeaders() {
final ODataHeadersImpl odataHeaders = new ODataHeadersImpl();
odataHeaders.setHeader(HeaderName.odataMaxVersion, ODataServiceVersion.V40.toString());
odataHeaders.setHeader(HeaderName.odataVersion, ODataServiceVersion.V40.toString());
odataHeaders.setHeader(HttpHeader.ODATA_MAX_VERSION, ODataServiceVersion.V40.toString());
odataHeaders.setHeader(HttpHeader.ODATA_VERSION, ODataServiceVersion.V40.toString());
return odataHeaders;
}

View File

@ -22,7 +22,6 @@ import java.util.Collection;
import java.util.Map;
import java.util.TreeMap;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.header.ODataHeaders;
public class ODataHeadersImpl implements ODataHeaders {
@ -38,27 +37,11 @@ public class ODataHeadersImpl implements ODataHeaders {
return this;
}
@Override
public ODataHeaders setHeader(final HeaderName name, final String value) {
headers.put(name.toString(), value);
return this;
}
@Override
public String getHeader(final HeaderName name) {
return headers.get(name.toString());
}
@Override
public String getHeader(final String name) {
return headers.get(name);
}
@Override
public String removeHeader(final HeaderName name) {
return headers.remove(name.toString());
}
@Override
public String removeHeader(final String name) {
return headers.remove(name);

View File

@ -34,7 +34,6 @@ import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DecompressingHttpClient;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.header.ODataHeaders;
import org.apache.olingo.client.api.communication.request.ODataRequest;
import org.apache.olingo.client.api.communication.request.ODataStreamer;
@ -42,6 +41,7 @@ import org.apache.olingo.client.api.communication.response.ODataResponse;
import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.commons.api.ODataRuntimeException;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.commons.api.http.HttpMethod;
/**
@ -128,37 +128,37 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD
@Override
public ODataRequest setAccept(final String value) {
odataHeaders.setHeader(HeaderName.accept, value);
odataHeaders.setHeader(HttpHeader.ACCEPT, value);
return this;
}
@Override
public ODataRequest setIfMatch(final String value) {
odataHeaders.setHeader(HeaderName.ifMatch, value);
odataHeaders.setHeader(HttpHeader.IF_MATCH, value);
return this;
}
@Override
public ODataRequest setIfNoneMatch(final String value) {
odataHeaders.setHeader(HeaderName.ifNoneMatch, value);
odataHeaders.setHeader(HttpHeader.IF_NONE_MATCH, value);
return this;
}
@Override
public ODataRequest setPrefer(final String value) {
odataHeaders.setHeader(HeaderName.prefer, value);
odataHeaders.setHeader(HttpHeader.PREFER, value);
return this;
}
@Override
public ODataRequest setXHTTPMethod(final String value) {
odataHeaders.setHeader(HeaderName.xHttpMethod, value);
odataHeaders.setHeader(HttpHeader.X_HTTP_METHOD, value);
return this;
}
@Override
public ODataRequest setContentType(final String value) {
odataHeaders.setHeader(HeaderName.contentType, value);
odataHeaders.setHeader(HttpHeader.CONTENT_TYPE, value);
return this;
}
@ -168,41 +168,35 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD
return this;
}
@Override
public ODataRequest addCustomHeader(final HeaderName name, final String value) {
odataHeaders.setHeader(name, value);
return this;
}
@Override
public String getAccept() {
final String acceptHead = odataHeaders.getHeader(HeaderName.accept);
return StringUtils.isBlank(acceptHead)
? getDefaultFormat().getContentType().toContentTypeString()
: acceptHead;
final String acceptHead = odataHeaders.getHeader(HttpHeader.ACCEPT);
return StringUtils.isBlank(acceptHead) ?
getDefaultFormat().getContentType().toContentTypeString() :
acceptHead;
}
@Override
public String getIfMatch() {
return odataHeaders.getHeader(HeaderName.ifMatch);
return odataHeaders.getHeader(HttpHeader.IF_MATCH);
}
@Override
public String getIfNoneMatch() {
return odataHeaders.getHeader(HeaderName.ifNoneMatch);
return odataHeaders.getHeader(HttpHeader.IF_NONE_MATCH);
}
@Override
public String getPrefer() {
return odataHeaders.getHeader(HeaderName.prefer);
return odataHeaders.getHeader(HttpHeader.PREFER);
}
@Override
public String getContentType() {
final String contentTypeHead = odataHeaders.getHeader(HeaderName.contentType);
return StringUtils.isBlank(contentTypeHead)
? getDefaultFormat().getContentType().toContentTypeString()
: contentTypeHead;
final String contentTypeHead = odataHeaders.getHeader(HttpHeader.CONTENT_TYPE);
return StringUtils.isBlank(contentTypeHead) ?
getDefaultFormat().getContentType().toContentTypeString() :
contentTypeHead;
}
@Override
@ -231,10 +225,10 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD
baos.write(ODataStreamer.CRLF);
// Set Content-Type and Accept headers with default values, if not yet set
if (StringUtils.isBlank(odataHeaders.getHeader(HeaderName.contentType))) {
if (StringUtils.isBlank(odataHeaders.getHeader(HttpHeader.CONTENT_TYPE))) {
setContentType(getContentType());
}
if (StringUtils.isBlank(odataHeaders.getHeader(HeaderName.accept))) {
if (StringUtils.isBlank(odataHeaders.getHeader(HttpHeader.ACCEPT))) {
setAccept(getAccept());
}
@ -277,18 +271,16 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD
checkRequest(odataClient, request);
// Set Content-Type and Accept headers with default values, if not yet set
if (StringUtils.isBlank(odataHeaders.getHeader(HeaderName.contentType))) {
if (StringUtils.isBlank(odataHeaders.getHeader(HttpHeader.CONTENT_TYPE))) {
setContentType(getContentType());
}
if (StringUtils.isBlank(odataHeaders.getHeader(HeaderName.accept))) {
if (StringUtils.isBlank(odataHeaders.getHeader(HttpHeader.ACCEPT))) {
setAccept(getAccept());
}
// Add header for KeyAsSegment management
if (odataClient.getConfiguration().isKeyAsSegment()) {
addCustomHeader(
HeaderName.dataServiceUrlConventions.toString(),
odataClient.newPreferences().keyAsSegment());
addCustomHeader("DataServiceUrlConventions", odataClient.newPreferences().keyAsSegment());
}
// Add all available headers

View File

@ -23,7 +23,6 @@ import java.util.Collection;
import org.apache.commons.io.IOUtils;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.header.ODataPreferences;
import org.apache.olingo.client.api.communication.request.AsyncBatchRequestWrapper;
import org.apache.olingo.client.api.communication.request.ODataBatchableRequest;
@ -32,6 +31,7 @@ import org.apache.olingo.client.api.communication.request.batch.ODataBatchReques
import org.apache.olingo.client.api.communication.request.batch.ODataChangeset;
import org.apache.olingo.client.api.communication.response.AsyncResponseWrapper;
import org.apache.olingo.client.api.communication.response.ODataBatchResponse;
import org.apache.olingo.commons.api.http.HttpHeader;
public class AsyncBatchRequestWrapperImpl extends AsyncRequestWrapperImpl<ODataBatchResponse>
implements AsyncBatchRequestWrapper {
@ -91,19 +91,19 @@ public class AsyncBatchRequestWrapperImpl extends AsyncRequestWrapperImpl<ODataB
}
private void retrieveMonitorDetails(final ODataBatchResponse res) {
Collection<String> headers = res.getHeader(HeaderName.location.toString());
Collection<String> headers = res.getHeader(HttpHeader.LOCATION);
if (headers == null || headers.isEmpty()) {
throw new AsyncRequestException("Invalid async request response. Monitor URL not found");
} else {
this.location = URI.create(headers.iterator().next());
}
headers = res.getHeader(HeaderName.retryAfter.toString());
headers = res.getHeader(HttpHeader.RETRY_AFTER);
if (headers != null && !headers.isEmpty()) {
this.retryAfter = Integer.parseInt(headers.iterator().next());
}
headers = res.getHeader(HeaderName.preferenceApplied.toString());
headers = res.getHeader(HttpHeader.PREFERENCE_APPLIED);
if (headers != null && !headers.isEmpty()) {
for (String header : headers) {
if (header.equalsIgnoreCase(new ODataPreferences().respondAsync())) {

View File

@ -32,7 +32,6 @@ import org.apache.http.impl.client.DecompressingHttpClient;
import org.apache.http.util.EntityUtils;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.communication.ODataClientErrorException;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.header.ODataPreferences;
import org.apache.olingo.client.api.communication.request.AsyncRequestWrapper;
import org.apache.olingo.client.api.communication.request.ODataRequest;
@ -41,7 +40,9 @@ import org.apache.olingo.client.api.communication.response.AsyncResponseWrapper;
import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
import org.apache.olingo.client.api.communication.response.ODataResponse;
import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.commons.api.http.HttpMethod;
import org.apache.olingo.commons.api.http.HttpStatusCode;
public class AsyncRequestWrapperImpl<R extends ODataResponse> extends AbstractRequest
implements AsyncRequestWrapper<R> {
@ -75,7 +76,7 @@ public class AsyncRequestWrapperImpl<R extends ODataResponse> extends AbstractRe
this.odataRequest.setAccept(this.odataRequest.getAccept());
this.odataRequest.setContentType(this.odataRequest.getContentType());
extendHeader(HeaderName.prefer.toString(), new ODataPreferences().respondAsync());
extendHeader(HttpHeader.PREFER, new ODataPreferences().respondAsync());
this.odataClient = odataClient;
final HttpMethod method = odataRequest.getMethod();
@ -94,14 +95,13 @@ public class AsyncRequestWrapperImpl<R extends ODataResponse> extends AbstractRe
@Override
public final AsyncRequestWrapper<R> wait(final int waitInSeconds) {
extendHeader(HeaderName.prefer.toString(), new ODataPreferences().wait(waitInSeconds));
extendHeader(HttpHeader.PREFER, new ODataPreferences().wait(waitInSeconds));
return this;
}
@Override
public final AsyncRequestWrapper<R> callback(URI url) {
extendHeader(HeaderName.prefer.toString(),
new ODataPreferences().callback(url.toASCIIString()));
extendHeader(HttpHeader.PREFER, new ODataPreferences().callback(url.toASCIIString()));
return this;
}
@ -184,9 +184,9 @@ public class AsyncRequestWrapperImpl<R extends ODataResponse> extends AbstractRe
for (int i = 0; response == null && i < MAX_RETRY; i++) {
res = checkMonitor(location);
if (res.getStatusLine().getStatusCode() == 202) {
if (res.getStatusLine().getStatusCode() == HttpStatusCode.ACCEPTED.getStatusCode()) {
final Header[] headers = res.getHeaders(HeaderName.retryAfter.toString());
final Header[] headers = res.getHeaders(HttpHeader.RETRY_AFTER);
if (ArrayUtils.isNotEmpty(headers)) {
this.retryAfter = Integer.parseInt(headers[0].getValue());
}
@ -211,27 +211,18 @@ public class AsyncRequestWrapperImpl<R extends ODataResponse> extends AbstractRe
return response;
}
/**
* {@inheritDoc}
*/
@Override
public ODataDeleteResponse delete() {
final ODataDeleteRequest deleteRequest = odataClient.getCUDRequestFactory().getDeleteRequest(location);
return deleteRequest.execute();
}
/**
* {@inheritDoc}
*/
@Override
public AsyncResponseWrapper<ODataDeleteResponse> asyncDelete() {
return odataClient.getAsyncRequestFactory().<ODataDeleteResponse>getAsyncRequestWrapper(
odataClient.getCUDRequestFactory().getDeleteRequest(location)).execute();
}
/**
* {@inheritDoc}
*/
@Override
public AsyncResponseWrapper<R> forceNextMonitorCheck(final URI uri) {
this.location = uri;
@ -255,7 +246,7 @@ public class AsyncRequestWrapperImpl<R extends ODataResponse> extends AbstractRe
}
private void retrieveMonitorDetails(final HttpResponse res) {
Header[] headers = res.getHeaders(HeaderName.location.toString());
Header[] headers = res.getHeaders(HttpHeader.LOCATION);
if (ArrayUtils.isNotEmpty(headers)) {
this.location = URI.create(headers[0].getValue());
} else {
@ -263,12 +254,12 @@ public class AsyncRequestWrapperImpl<R extends ODataResponse> extends AbstractRe
"Invalid async request response. Monitor URL '" + headers[0].getValue() + "'");
}
headers = res.getHeaders(HeaderName.retryAfter.toString());
headers = res.getHeaders(HttpHeader.RETRY_AFTER);
if (ArrayUtils.isNotEmpty(headers)) {
this.retryAfter = Integer.parseInt(headers[0].getValue());
}
headers = res.getHeaders(HeaderName.preferenceApplied.toString());
headers = res.getHeaders(HttpHeader.PREFERENCE_APPLIED);
if (ArrayUtils.isNotEmpty(headers)) {
for (Header header : headers) {
if (header.getValue().equalsIgnoreCase(new ODataPreferences().respondAsync())) {

View File

@ -26,7 +26,6 @@ import java.util.concurrent.TimeUnit;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.header.ODataPreferences;
import org.apache.olingo.client.api.communication.request.ODataBatchableRequest;
import org.apache.olingo.client.api.communication.request.batch.BatchManager;
@ -68,7 +67,7 @@ public class ODataBatchRequestImpl
@Override
protected HttpResponse doExecute() {
if (odataClient.getConfiguration().isContinueOnError()) {
addCustomHeader(HeaderName.prefer, new ODataPreferences().continueOnError());
setPrefer(new ODataPreferences().continueOnError());
}
return super.doExecute();

View File

@ -34,11 +34,11 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.io.LineIterator;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.ODataBatchConstants;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.request.ODataStreamer;
import org.apache.olingo.client.api.communication.request.batch.ODataBatchLineIterator;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -48,12 +48,11 @@ import org.slf4j.LoggerFactory;
public class ODataBatchUtilities {
public static enum BatchItemType {
NONE,
CHANGESET,
RETRIEVE
}
/**
* Logger.
*/
@ -300,8 +299,9 @@ public class ODataBatchUtilities {
final BatchItemType nextItemType;
final String contentType = headers.containsKey(HeaderName.contentType.toString())
? headers.get(HeaderName.contentType.toString()).toString() : StringUtils.EMPTY;
final String contentType = headers.containsKey(HttpHeader.CONTENT_TYPE) ?
headers.get(HttpHeader.CONTENT_TYPE).toString() :
StringUtils.EMPTY;
if (contentType.contains(ContentType.MULTIPART_MIXED.toContentTypeString())) {
nextItemType = BatchItemType.CHANGESET;

View File

@ -20,12 +20,12 @@ package org.apache.olingo.client.core.communication.request.batch;
import java.util.UUID;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.request.ODataBatchableRequest;
import org.apache.olingo.client.api.communication.request.batch.ODataBatchRequest;
import org.apache.olingo.client.api.communication.request.batch.ODataChangeset;
import org.apache.olingo.client.core.communication.request.AbstractODataRequest;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.commons.api.http.HttpMethod;
/**
@ -99,7 +99,7 @@ public class ODataChangesetImpl extends AbstractODataBatchRequestItem
}
if (!hasStreamedSomething) {
stream((HeaderName.contentType.toString() + ": "
stream((HttpHeader.CONTENT_TYPE + ": "
+ ContentType.MULTIPART_MIXED + ";boundary=" + boundary).getBytes());
newLine();

View File

@ -23,7 +23,6 @@ import java.util.Collection;
import org.apache.http.client.HttpClient;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.request.retrieve.EdmMetadataRequest;
import org.apache.olingo.client.api.communication.request.retrieve.XMLMetadataRequest;
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
@ -112,11 +111,6 @@ class EdmMetadataRequestImpl extends AbstractMetadataRequestImpl<Edm> implements
return xmlMetadataResponse.getHeader(name);
}
@Override
public Collection<String> getHeader(final HeaderName name) {
return xmlMetadataResponse.getHeader(name);
}
public XMLMetadata getXMLMetadata() {
if (metadata == null) {
try {

View File

@ -35,7 +35,6 @@ import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.request.ODataStreamer;
import org.apache.olingo.client.api.communication.request.batch.ODataBatchLineIterator;
import org.apache.olingo.client.api.communication.response.ODataResponse;
@ -45,6 +44,7 @@ import org.apache.olingo.client.core.communication.request.batch.ODataBatchLineI
import org.apache.olingo.client.core.communication.request.batch.ODataBatchUtilities;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.ODataRuntimeException;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -112,76 +112,46 @@ public abstract class AbstractODataResponse implements ODataResponse {
}
}
/**
* {@inheritDoc}
*/
@Override
public Collection<String> getHeaderNames() {
return headers.keySet();
}
/**
* {@inheritDoc}
*/
@Override
public Collection<String> getHeader(final String name) {
return headers.get(name);
}
/**
* {@inheritDoc}
*/
@Override
public Collection<String> getHeader(final HeaderName name) {
return headers.get(name.toString());
}
/**
* {@inheritDoc}
*/
@Override
public String getETag() {
final Collection<String> etag = getHeader(HeaderName.etag);
return etag == null || etag.isEmpty()
? null
: etag.iterator().next();
final Collection<String> etag = getHeader(HttpHeader.ETAG);
return etag == null || etag.isEmpty() ? null : etag.iterator().next();
}
/**
* {@inheritDoc}
*/
@Override
public String getContentType() {
final Collection<String> contentTypes = getHeader(HeaderName.contentType);
return contentTypes == null || contentTypes.isEmpty()
? null
: contentTypes.iterator().next();
final Collection<String> contentTypes = getHeader(HttpHeader.CONTENT_TYPE);
return contentTypes == null || contentTypes.isEmpty() ? null : contentTypes.iterator().next();
}
/**
* {@inheritDoc}
*/
@Override
public int getStatusCode() {
return statusCode;
}
/**
* {@inheritDoc}
*/
@Override
public String getStatusMessage() {
return statusMessage;
}
/**
* {@inheritDoc}
*/
@Override
public final ODataResponse initFromHttpResponse(final HttpResponse res) {
try {
this.payload = res.getEntity() == null ? null : res.getEntity().getContent();
} catch (Exception e) {
} catch (final IllegalStateException e) {
LOG.error("Error retrieving payload", e);
throw new ODataRuntimeException(e);
} catch (final IOException e) {
LOG.error("Error retrieving payload", e);
throw new ODataRuntimeException(e);
}
@ -205,9 +175,6 @@ public abstract class AbstractODataResponse implements ODataResponse {
return this;
}
/**
* {@inheritDoc}
*/
@Override
public ODataResponse initFromBatch(
final Map.Entry<Integer, String> responseLine,
@ -229,9 +196,6 @@ public abstract class AbstractODataResponse implements ODataResponse {
return this;
}
/**
* {@inheritDoc}
*/
@Override
public ODataResponse initFromEnclosedPart(final InputStream part) {
try {
@ -275,9 +239,6 @@ public abstract class AbstractODataResponse implements ODataResponse {
}
}
/**
* {@inheritDoc }
*/
@Override
public void close() {
odataClient.getConfiguration().getHttpClientFactory().close(httpClient);
@ -287,9 +248,6 @@ public abstract class AbstractODataResponse implements ODataResponse {
}
}
/**
* {@inheritDoc}
*/
@Override
public InputStream getRawResponse() {
if (HttpStatus.SC_NO_CONTENT == getStatusCode()) {

View File

@ -26,7 +26,6 @@ import java.util.Map;
import java.util.NoSuchElementException;
import org.apache.commons.io.IOUtils;
import org.apache.olingo.client.api.communication.header.HeaderName;
import org.apache.olingo.client.api.communication.request.batch.ODataBatchLineIterator;
import org.apache.olingo.client.api.communication.request.batch.ODataBatchResponseItem;
import org.apache.olingo.client.api.communication.response.ODataBatchResponse;
@ -34,6 +33,7 @@ import org.apache.olingo.client.core.communication.request.batch.ODataBatchLineI
import org.apache.olingo.client.core.communication.request.batch.ODataBatchUtilities;
import org.apache.olingo.client.core.communication.request.batch.ODataChangesetResponseItem;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -96,7 +96,7 @@ public class ODataBatchResponseManager implements Iterator<ODataBatchResponseIte
// search for boundary
batchBoundary = ODataBatchUtilities.getBoundaryFromHeader(
res.getHeader(HeaderName.contentType));
res.getHeader(HttpHeader.CONTENT_TYPE));
LOG.debug("Retrieved batch response bondary '{}'", batchBoundary);
} catch (IOException e) {
LOG.error("Error parsing batch response", e);
@ -104,17 +104,11 @@ public class ODataBatchResponseManager implements Iterator<ODataBatchResponseIte
}
}
/**
* {@inheritDoc }
*/
@Override
public boolean hasNext() {
return (current == null || continueOnError || !current.isBreaking()) && expectedItemsIterator.hasNext();
}
/**
* {@inheritDoc }
*/
@Override
public ODataBatchResponseItem next() {
if (current != null) {
@ -138,7 +132,7 @@ public class ODataBatchResponseManager implements Iterator<ODataBatchResponseIte
current.initFromBatch(
batchLineIterator,
ODataBatchUtilities.getBoundaryFromHeader(nextItemHeaders.get(HeaderName.contentType.toString())));
ODataBatchUtilities.getBoundaryFromHeader(nextItemHeaders.get(HttpHeader.CONTENT_TYPE)));
break;
case RETRIEVE: