From c3a709309e19af8fc12807d71283d7ef624117d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= <--global> Date: Sat, 12 Jul 2014 17:34:21 +0200 Subject: [PATCH] Several Android enhancements --- ext/client-core-android/pom.xml | 8 +- .../http/AndroidHttpClientFactory.java | 25 ++++- ext/client-proxy-android/pom.xml | 28 ++++- .../olingo/ext/proxy/api/AsyncCall.java | 4 +- .../TransactionalPersistenceManagerImpl.java | 5 +- .../olingo/fit/utils/AbstractUtilities.java | 1 - .../apache/olingo/fit/v3/ErrorTestITCase.java | 13 +-- .../olingo/client/api/CommonODataClient.java | 2 +- ...nConfiguration.java => Configuration.java} | 2 +- .../request/batch/ODataBatchResponseItem.java | 4 +- .../client/api/http/HttpClientFactory.java | 4 +- .../api/http/HttpUriRequestFactory.java | 2 +- .../olingo/client/api/v3/ODataClient.java | 4 - .../olingo/client/api/v4/ODataClient.java | 4 - .../client/core/AbstractODataClient.java | 8 ++ ...figuration.java => ConfigurationImpl.java} | 10 +- .../client/core/ODataClientFactory.java | 1 - .../request/AbstractODataRequest.java | 37 +++--- .../batch/AbstractODataBatchResponseItem.java | 8 +- .../batch/ODataChangesetResponseItem.java | 4 +- .../request/batch/ODataSingleRequestImpl.java | 3 +- .../batch/ODataSingleResponseItem.java | 5 +- .../batch/v3/ODataBatchRequestImpl.java | 17 ++- .../batch/v4/ODataBatchRequestImpl.java | 18 +-- .../request/cud/ODataDeleteRequestImpl.java | 29 +---- .../cud/ODataEntityCreateRequestImpl.java | 27 ++--- .../cud/ODataEntityUpdateRequestImpl.java | 51 ++++----- .../cud/ODataPropertyUpdateRequestImpl.java | 26 ++--- .../cud/ODataValueUpdateRequestImpl.java | 25 +---- .../cud/v3/ODataLinkCreateRequestImpl.java | 20 +--- .../cud/v3/ODataLinkUpdateRequestImpl.java | 16 +-- .../invoke/AbstractODataInvokeRequest.java | 47 +++----- .../retrieve/AbstractMetadataRequestImpl.java | 6 +- .../AbstractODataRetrieveRequest.java | 20 +--- .../retrieve/EdmMetadataRequestImpl.java | 3 +- .../retrieve/ODataEntityRequestImpl.java | 27 ++--- .../ODataEntitySetIteratorRequestImpl.java | 14 +-- .../retrieve/ODataEntitySetRequestImpl.java | 25 +---- .../retrieve/ODataMediaRequestImpl.java | 21 +--- .../retrieve/ODataPropertyRequestImpl.java | 24 +--- .../request/retrieve/ODataRawRequestImpl.java | 23 +--- .../ODataServiceDocumentRequestImpl.java | 26 ++--- .../retrieve/ODataValueRequestImpl.java | 27 ++--- .../v3/ODataLinkCollectionRequestImpl.java | 25 ++--- .../retrieve/v3/XMLMetadataRequestImpl.java | 25 +---- .../retrieve/v4/ODataDeltaRequestImpl.java | 22 ++-- .../retrieve/v4/XMLMetadataRequestImpl.java | 18 +-- .../AbstractODataStreamedRequest.java | 6 +- .../ODataMediaEntityCreateRequestImpl.java | 23 +--- .../ODataMediaEntityUpdateRequestImpl.java | 21 +--- .../ODataStreamUpdateRequestImpl.java | 20 +--- .../request/v4/AsyncRequestWrapperImpl.java | 6 +- .../response/AbstractODataResponse.java | 29 ++--- .../batch/ODataBatchErrorResponse.java | 8 +- .../batch/ODataBatchResponseManager.java | 4 +- .../response/v4/AsyncResponseImpl.java | 23 +--- .../core/http/AbstractHttpClientFactory.java | 50 +++++++++ .../core/http/BasicAuthHttpClientFactory.java | 4 +- .../core/http/DefaultHttpClientFactory.java | 40 ++----- .../http/DefaultHttpUriRequestFactory.java | 2 +- .../core/http/NTLMAuthHttpClientFactory.java | 4 +- .../http/ProxyWrapperHttpClientFactory.java | 9 +- .../client/core/uri/AbstractURIBuilder.java | 7 +- .../client/core/uri/v3/URIBuilderImpl.java | 4 +- .../client/core/uri/v4/URIBuilderImpl.java | 4 +- .../client/core/v3/ODataClientImpl.java | 13 +-- .../client/core/v4/ODataClientImpl.java | 12 +- .../commons/api/format/ContentType.java | 106 +++++++++++------- pom.xml | 23 +++- 69 files changed, 484 insertions(+), 698 deletions(-) rename lib/client-api/src/main/java/org/apache/olingo/client/api/v4/Configuration.java => ext/client-core-android/src/main/java/org/apache/olingo/client/core/android/http/AndroidHttpClientFactory.java (51%) rename lib/client-api/src/main/java/org/apache/olingo/client/api/{CommonConfiguration.java => Configuration.java} (99%) rename lib/client-core/src/main/java/org/apache/olingo/client/core/{Configuration.java => ConfigurationImpl.java} (98%) create mode 100644 lib/client-core/src/main/java/org/apache/olingo/client/core/http/AbstractHttpClientFactory.java diff --git a/ext/client-core-android/pom.xml b/ext/client-core-android/pom.xml index 7599970f0..ed94bbfc0 100644 --- a/ext/client-core-android/pom.xml +++ b/ext/client-core-android/pom.xml @@ -39,7 +39,12 @@ org.apache.olingo olingo-client-core ${project.version} - true + provided + + + + com.google.android + android @@ -65,7 +70,6 @@ org.apache.commons:commons-lang3 org.slf4j:slf4j-api commons-io:commons-io - org.apache.httpcomponents:httpcore com.fasterxml.jackson.core:jackson-core com.fasterxml.jackson.core:jackson-databind com.fasterxml.jackson.core:jackson-annotations diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/v4/Configuration.java b/ext/client-core-android/src/main/java/org/apache/olingo/client/core/android/http/AndroidHttpClientFactory.java similarity index 51% rename from lib/client-api/src/main/java/org/apache/olingo/client/api/v4/Configuration.java rename to ext/client-core-android/src/main/java/org/apache/olingo/client/core/android/http/AndroidHttpClientFactory.java index f7daa911f..4baa0c233 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/v4/Configuration.java +++ b/ext/client-core-android/src/main/java/org/apache/olingo/client/core/android/http/AndroidHttpClientFactory.java @@ -16,11 +16,28 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.olingo.client.core.android.http; -package org.apache.olingo.client.api.v4; +import android.net.http.AndroidHttpClient; +import java.net.URI; +import org.apache.http.client.HttpClient; +import org.apache.olingo.client.api.http.HttpMethod; +import org.apache.olingo.client.core.http.AbstractHttpClientFactory; -import org.apache.olingo.client.api.CommonConfiguration; +public class AndroidHttpClientFactory extends AbstractHttpClientFactory { + + private static final long serialVersionUID = -5224104561624556177L; + + @Override + public HttpClient create(final HttpMethod method, final URI uri) { + return AndroidHttpClient.newInstance(USER_AGENT); + } + + @Override + public void close(final HttpClient httpClient) { + if (httpClient instanceof AndroidHttpClient) { + ((AndroidHttpClient) httpClient).close(); + } + } -public interface Configuration extends CommonConfiguration { - } diff --git a/ext/client-proxy-android/pom.xml b/ext/client-proxy-android/pom.xml index ecfdc534e..f48cbc150 100644 --- a/ext/client-proxy-android/pom.xml +++ b/ext/client-proxy-android/pom.xml @@ -39,12 +39,37 @@ org.apache.olingo olingo-client-proxy ${project.version} - true + provided + + + com.google.android + android + + + org.codehaus.mojo + build-helper-maven-plugin + true + + + add-client-core-proxy-source + generate-sources + + add-source + + + + ${basedir}/../client-core-android/src/main/java + + + + + + org.sonatype.plugins jarjar-maven-plugin @@ -67,7 +92,6 @@ org.apache.commons:commons-lang3 org.slf4j:slf4j-api commons-io:commons-io - org.apache.httpcomponents:httpcore com.fasterxml.jackson.core:jackson-core com.fasterxml.jackson.core:jackson-databind com.fasterxml.jackson.core:jackson-annotations diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AsyncCall.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AsyncCall.java index e3eea9e5e..eb05a4e8e 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AsyncCall.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AsyncCall.java @@ -23,13 +23,13 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import org.apache.olingo.client.api.CommonConfiguration; +import org.apache.olingo.client.api.Configuration; public abstract class AsyncCall implements Future { private final Future future; - public AsyncCall(final CommonConfiguration configuration) { + public AsyncCall(final Configuration configuration) { this.future = configuration.getExecutor().submit(new Callable() { @Override diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java index 1165830f8..952285a8c 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java @@ -54,8 +54,8 @@ public class TransactionalPersistenceManagerImpl extends AbstractPersistenceMana protected void doFlush(final PersistenceChanges changes, final TransactionItems items) { final CommonODataBatchRequest request = factory.getClient().getBatchRequestFactory().getBatchRequest(factory.getClient().getServiceRoot()); - String accept = factory.getClient().getConfiguration().getDefaultBatchAcceptFormat().toContentTypeString(); - ((ODataRequest) request).setAccept(accept); + ((ODataRequest) request).setAccept( + factory.getClient().getConfiguration().getDefaultBatchAcceptFormat().toContentTypeString()); final BatchManager streamManager = (BatchManager) ((ODataStreamedRequest) request).payloadManager(); @@ -105,5 +105,6 @@ public class TransactionalPersistenceManagerImpl extends AbstractPersistenceMana } } } + response.close(); } } diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java index d2e6d1faf..55d6733a4 100644 --- a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java +++ b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java @@ -38,7 +38,6 @@ import java.util.regex.Pattern; import javax.ws.rs.NotFoundException; import javax.ws.rs.core.Response; -import javax.xml.stream.XMLStreamException; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/ErrorTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/ErrorTestITCase.java index 2d22d23d4..c394608c3 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v3/ErrorTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v3/ErrorTestITCase.java @@ -51,7 +51,7 @@ import org.junit.Test; public class ErrorTestITCase extends AbstractTestITCase { private class ErrorGeneratingRequest - extends AbstractODataBasicRequest> { + extends AbstractODataBasicRequest> { public ErrorGeneratingRequest(final HttpMethod method, final URI uri) { super(client, method, uri); @@ -75,16 +75,13 @@ public class ErrorTestITCase extends AbstractTestITCase { private class ErrorResponseImpl extends AbstractODataResponse implements ODataEntityCreateResponse { - private final ODataClient odataClient; - public ErrorResponseImpl(final ODataClient odataClient, final HttpClient client, final HttpResponse res) { - super(client, res); - this.odataClient = odataClient; + super(odataClient, client, res); } @Override public ODataEntity getBody() { - return odataClient.getObjectFactory().newEntity(new FullQualifiedName("Invalid.Invalid")); + return ((ODataClient) odataClient).getObjectFactory().newEntity(new FullQualifiedName("Invalid.Invalid")); } } } @@ -146,9 +143,9 @@ public class ErrorTestITCase extends AbstractTestITCase { private void instreamError(final ODataFormat format) { final URIBuilder builder = client.newURIBuilder(testStaticServiceRootURL). - appendOperationCallSegment("InStreamErrorGetCustomer"); + appendOperationCallSegment("InStreamErrorGetCustomer"); final ODataInvokeRequest req = - client.getInvokeRequestFactory().getFunctionInvokeRequest(builder.build(), ODataEntitySet.class); + client.getInvokeRequestFactory().getFunctionInvokeRequest(builder.build(), ODataEntitySet.class); req.setFormat(format); final ODataInvokeResponse res = req.execute(); diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonODataClient.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonODataClient.java index 136f07a5c..336fa6fb9 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonODataClient.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonODataClient.java @@ -47,7 +47,7 @@ public interface CommonODataClient { ODataHeaders newVersionHeaders(); - CommonConfiguration getConfiguration(); + Configuration getConfiguration(); ODataPreferences newPreferences(); diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonConfiguration.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/Configuration.java similarity index 99% rename from lib/client-api/src/main/java/org/apache/olingo/client/api/CommonConfiguration.java rename to lib/client-api/src/main/java/org/apache/olingo/client/api/Configuration.java index b2fb01766..e1bf90788 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/CommonConfiguration.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/Configuration.java @@ -28,7 +28,7 @@ import org.apache.olingo.commons.api.format.ODataFormat; /** * Configuration wrapper. */ -public interface CommonConfiguration { +public interface Configuration { /** * Gets the configured default Accept header value format for a batch request. diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/batch/ODataBatchResponseItem.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/batch/ODataBatchResponseItem.java index 388250492..2c829e9e4 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/batch/ODataBatchResponseItem.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/batch/ODataBatchResponseItem.java @@ -50,11 +50,11 @@ public interface ODataBatchResponseItem extends Iterator { boolean isChangeset(); /** - * Checks if the current item is a braking item like as error item or asynchronous response part. + * Checks if the current item is a breaking item like as error item or asynchronous response part. * * @return 'TRUE' if breaking; 'FALSE' otherwise. */ - boolean isBreakingitem(); + boolean isBreaking(); /** * Closes the current batch responses item including all wrapped OData responses. diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/http/HttpClientFactory.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/http/HttpClientFactory.java index 367ef0179..b7711818f 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/http/HttpClientFactory.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/http/HttpClientFactory.java @@ -26,5 +26,7 @@ import org.apache.http.client.HttpClient; */ public interface HttpClientFactory { - HttpClient createHttpClient(HttpMethod method, URI uri); + HttpClient create(HttpMethod method, URI uri); + + void close(HttpClient httpClient); } diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/http/HttpUriRequestFactory.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/http/HttpUriRequestFactory.java index 1687045c8..18b89bd31 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/http/HttpUriRequestFactory.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/http/HttpUriRequestFactory.java @@ -26,5 +26,5 @@ import org.apache.http.client.methods.HttpUriRequest; */ public interface HttpUriRequestFactory { - HttpUriRequest createHttpUriRequest(HttpMethod method, URI uri); + HttpUriRequest create(HttpMethod method, URI uri); } diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/v3/ODataClient.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/v3/ODataClient.java index 71d5ffdc7..4e8acb136 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/v3/ODataClient.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/v3/ODataClient.java @@ -18,7 +18,6 @@ */ package org.apache.olingo.client.api.v3; -import org.apache.olingo.client.api.CommonConfiguration; import org.apache.olingo.client.api.CommonODataClient; import org.apache.olingo.client.api.communication.request.batch.v3.BatchRequestFactory; import org.apache.olingo.client.api.communication.request.cud.v3.CUDRequestFactory; @@ -34,9 +33,6 @@ import org.apache.olingo.commons.api.format.ODataFormat; public interface ODataClient extends CommonODataClient { - @Override - CommonConfiguration getConfiguration(); - @Override ODataDeserializer getDeserializer(ODataFormat format); diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/v4/ODataClient.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/v4/ODataClient.java index ee1fe97f6..2c9ba9086 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/v4/ODataClient.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/v4/ODataClient.java @@ -18,7 +18,6 @@ */ package org.apache.olingo.client.api.v4; -import org.apache.olingo.client.api.CommonConfiguration; import org.apache.olingo.client.api.CommonODataClient; import org.apache.olingo.client.api.communication.request.batch.v4.BatchRequestFactory; import org.apache.olingo.client.api.communication.request.cud.v4.CUDRequestFactory; @@ -36,9 +35,6 @@ import org.apache.olingo.commons.api.format.ODataFormat; public interface ODataClient extends CommonODataClient { - @Override - CommonConfiguration getConfiguration(); - @Override ODataDeserializer getDeserializer(ODataFormat format); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/AbstractODataClient.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/AbstractODataClient.java index 2f6e860d2..5f04a4bc6 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/AbstractODataClient.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/AbstractODataClient.java @@ -19,6 +19,7 @@ package org.apache.olingo.client.core; import org.apache.olingo.client.api.CommonODataClient; +import org.apache.olingo.client.api.Configuration; import org.apache.olingo.client.api.communication.header.ODataPreferences; import org.apache.olingo.client.api.communication.request.cud.CommonUpdateType; import org.apache.olingo.client.api.serialization.ODataWriter; @@ -26,8 +27,15 @@ import org.apache.olingo.client.core.serialization.ODataWriterImpl; public abstract class AbstractODataClient implements CommonODataClient { + protected final Configuration configuration = new ConfigurationImpl(); + private final ODataWriter writer = new ODataWriterImpl(this); + @Override + public Configuration getConfiguration() { + return configuration; + } + @Override public ODataPreferences newPreferences() { return new ODataPreferences(getServiceVersion()); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/Configuration.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/ConfigurationImpl.java similarity index 98% rename from lib/client-core/src/main/java/org/apache/olingo/client/core/Configuration.java rename to lib/client-core/src/main/java/org/apache/olingo/client/core/ConfigurationImpl.java index 5b8f36b3f..ca8884562 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/Configuration.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/ConfigurationImpl.java @@ -23,7 +23,7 @@ import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import org.apache.olingo.client.api.CommonConfiguration; +import org.apache.olingo.client.api.Configuration; import org.apache.olingo.client.api.http.HttpClientFactory; import org.apache.olingo.client.api.http.HttpUriRequestFactory; import org.apache.olingo.client.core.http.DefaultHttpClientFactory; @@ -31,7 +31,7 @@ import org.apache.olingo.client.core.http.DefaultHttpUriRequestFactory; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.format.ODataFormat; -public class Configuration implements CommonConfiguration { +public class ConfigurationImpl implements Configuration { private static final String DEFAULT_PUB_FORMAT = "pubFormat"; @@ -48,7 +48,7 @@ public class Configuration implements CommonConfiguration { private static final String USE_XHTTP_METHOD = "useHTTPMethod"; private static final String KEY_AS_SEGMENT = "keyAsSegment"; - + private static final String ADDRESS_DERIVED_TYPE = "addressDerivedType"; private static final String USE_OPERATION_FQN_IN_URL = "useOperationFqnInUrl"; @@ -198,7 +198,7 @@ public class Configuration implements CommonConfiguration { public void setAddressingDerivedTypes(final boolean value) { setProperty(ADDRESS_DERIVED_TYPE, value); } - + @Override public boolean isUseUrlOperationFQN() { return (Boolean) getProperty(USE_OPERATION_FQN_IN_URL, true); @@ -208,7 +208,7 @@ public class Configuration implements CommonConfiguration { public void setUseUrlOperationFQN(final boolean value) { setProperty(USE_OPERATION_FQN_IN_URL, value); } - + @Override public ExecutorService getExecutor() { return executor; diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientFactory.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientFactory.java index fd462ff32..ecefb369c 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientFactory.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/ODataClientFactory.java @@ -20,7 +20,6 @@ package org.apache.olingo.client.core; import org.apache.olingo.commons.api.format.ODataFormat; - public final class ODataClientFactory { public static org.apache.olingo.client.api.v3.ODataClient getV3() { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java index 58412fc7e..ee3f74f2c 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java @@ -84,12 +84,13 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD /** * Constructor. * - * @param odataClient client instance getting this request - * @param method HTTP request method. If configured X-HTTP-METHOD header will be used. - * @param uri OData request URI. + * @param odataClient client instance getting this request + * @param method HTTP request method. If configured X-HTTP-METHOD header will be used. + * @param uri OData request URI. */ protected AbstractODataRequest(final CommonODataClient odataClient, final HttpMethod method, final URI uri) { - + super(); + this.odataClient = odataClient; this.method = method; @@ -99,15 +100,13 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD // target uri this.uri = uri; - HttpClient _httpClient = odataClient.getConfiguration().getHttpClientFactory(). - createHttpClient(this.method, this.uri); + HttpClient _httpClient = odataClient.getConfiguration().getHttpClientFactory().create(this.method, this.uri); if (odataClient.getConfiguration().isGzipCompression()) { _httpClient = new DecompressingHttpClient(_httpClient); } this.httpClient = _httpClient; - this.request = odataClient.getConfiguration().getHttpUriRequestFactory(). - createHttpUriRequest(this.method, this.uri); + this.request = odataClient.getConfiguration().getHttpUriRequestFactory().create(this.method, this.uri); } public abstract ODataFormat getDefaultFormat(); @@ -184,9 +183,9 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD @Override public String getAccept() { final String acceptHead = odataHeaders.getHeader(HeaderName.accept); - return StringUtils.isBlank(acceptHead) ? - getDefaultFormat().getContentType(odataClient.getServiceVersion()).toContentTypeString() : - acceptHead; + return StringUtils.isBlank(acceptHead) + ? getDefaultFormat().getContentType(odataClient.getServiceVersion()).toContentTypeString() + : acceptHead; } @Override @@ -207,9 +206,9 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD @Override public String getContentType() { final String contentTypeHead = odataHeaders.getHeader(HeaderName.contentType); - return StringUtils.isBlank(contentTypeHead) ? - getDefaultFormat().getContentType(odataClient.getServiceVersion()).toContentTypeString() : - contentTypeHead; + return StringUtils.isBlank(contentTypeHead) + ? getDefaultFormat().getContentType(odataClient.getServiceVersion()).toContentTypeString() + : contentTypeHead; } @Override @@ -326,21 +325,21 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD /** * Gets an empty response that can be initialized by a stream. - *

+ *
* This method has to be used to build response items about a batch request. * - * @param ODataResppnse type. + * @param ODataResponse type. * @return empty OData response instance. */ @SuppressWarnings("unchecked") public V getResponseTemplate() { - for (Class clazz : this.getClass().getDeclaredClasses()) { if (ODataResponse.class.isAssignableFrom(clazz)) { try { - final Constructor constructor = clazz.getDeclaredConstructor(this.getClass()); + final Constructor constructor = clazz.getDeclaredConstructor( + this.getClass(), CommonODataClient.class, HttpClient.class, HttpResponse.class); constructor.setAccessible(true); - return (V) constructor.newInstance(this); + return (V) constructor.newInstance(this, odataClient, httpClient, null); } catch (Exception e) { LOG.error("Error retrieving response class template instance", e); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/AbstractODataBatchResponseItem.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/AbstractODataBatchResponseItem.java index a21e0aa61..0deaf4368 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/AbstractODataBatchResponseItem.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/AbstractODataBatchResponseItem.java @@ -72,7 +72,7 @@ public abstract class AbstractODataBatchResponseItem implements ODataBatchRespon */ protected ODataResponse current; - protected boolean breakingitem = false; + protected boolean breaking = false; /** * Constructor. @@ -143,15 +143,15 @@ public abstract class AbstractODataBatchResponseItem implements ODataBatchRespon expectedItemsIterator = responses.values().iterator(); } - return !breakingitem && expectedItemsIterator.hasNext(); + return !breaking && expectedItemsIterator.hasNext(); } /** * {@inheritDoc } */ @Override - public boolean isBreakingitem() { - return breakingitem; + public boolean isBreaking() { + return breaking; } /** diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataChangesetResponseItem.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataChangesetResponseItem.java index 51f3a48a3..0128894bc 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataChangesetResponseItem.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataChangesetResponseItem.java @@ -63,7 +63,7 @@ public class ODataChangesetResponseItem extends AbstractODataBatchResponseItem { } if (unexpected) { - breakingitem = true; + breaking = true; return nextUnexpected(); } else { return nextExpected(); @@ -107,7 +107,7 @@ public class ODataChangesetResponseItem extends AbstractODataBatchResponseItem { if (current.getStatusCode() >= 400) { // found error .... - breakingitem = true; + breaking = true; } return current; diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataSingleRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataSingleRequestImpl.java index 8b915fed9..c69213735 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataSingleRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataSingleRequestImpl.java @@ -27,8 +27,7 @@ import org.apache.olingo.client.core.communication.request.AbstractODataRequest; /** * Retrieve request wrapper for the corresponding batch item. */ -public class ODataSingleRequestImpl extends AbstractODataBatchRequestItem - implements ODataSingleRequest { +public class ODataSingleRequestImpl extends AbstractODataBatchRequestItem implements ODataSingleRequest { private final ODataSingleResponseItem expectedResItem; diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataSingleResponseItem.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataSingleResponseItem.java index 12e50f38c..cd53ede9d 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataSingleResponseItem.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/ODataSingleResponseItem.java @@ -22,7 +22,6 @@ import java.util.Collection; import java.util.Map; import java.util.NoSuchElementException; import org.apache.olingo.client.api.communication.response.ODataResponse; -import static org.apache.olingo.client.core.communication.request.batch.AbstractODataBatchResponseItem.LOG; import org.apache.olingo.client.core.communication.response.batch.ODataBatchErrorResponse; import org.apache.olingo.client.core.communication.response.v4.AsyncResponseImpl; @@ -62,11 +61,11 @@ public class ODataSingleResponseItem extends AbstractODataBatchResponseItem { if (responseLine.getKey() == 202) { // generate async response current = new AsyncResponseImpl(responseLine, headers, batchLineIterator, boundary); - breakingitem = true; + breaking = true; } else if (responseLine.getKey() >= 400) { // generate error response current = new ODataBatchErrorResponse(responseLine, headers, batchLineIterator, boundary); - breakingitem = true; + breaking = true; } else { if (!hasNext()) { throw new NoSuchElementException("No item found"); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/v3/ODataBatchRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/v3/ODataBatchRequestImpl.java index 93821daff..8863161ac 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/v3/ODataBatchRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/v3/ODataBatchRequestImpl.java @@ -24,6 +24,7 @@ import java.util.Iterator; import java.util.concurrent.TimeUnit; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; +import org.apache.olingo.client.api.CommonODataClient; import org.apache.olingo.client.api.communication.request.ODataBatchableRequest; import org.apache.olingo.client.api.communication.request.ODataStreamedRequest; import org.apache.olingo.client.api.communication.request.batch.BatchManager; @@ -89,7 +90,7 @@ public class ODataBatchRequestImpl @Override protected ODataBatchResponse getResponseInstance(final long timeout, final TimeUnit unit) { - return new ODataBatchResponseImpl(httpClient, getHttpResponse(timeout, unit)); + return new ODataBatchResponseImpl(odataClient, httpClient, getHttpResponse(timeout, unit)); } @Override @@ -107,14 +108,10 @@ public class ODataBatchRequestImpl */ protected class ODataBatchResponseImpl extends AbstractODataResponse implements ODataBatchResponse { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - protected ODataBatchResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + protected ODataBatchResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { + + super(odataClient, httpClient, res); } /** @@ -125,4 +122,4 @@ public class ODataBatchRequestImpl return new ODataBatchResponseManager(this, expectedResItems); } } -} \ No newline at end of file +} diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/v4/ODataBatchRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/v4/ODataBatchRequestImpl.java index 8fea8ce81..f7dc70797 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/v4/ODataBatchRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/batch/v4/ODataBatchRequestImpl.java @@ -24,6 +24,7 @@ import java.util.Iterator; import java.util.concurrent.TimeUnit; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; +import org.apache.olingo.client.api.CommonODataClient; 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; @@ -95,7 +96,7 @@ public class ODataBatchRequestImpl @Override protected ODataBatchResponse getResponseInstance(final long timeout, final TimeUnit unit) { - return new ODataBatchResponseImpl(httpClient, getHttpResponse(timeout, unit)); + return new ODataBatchResponseImpl(odataClient, httpClient, getHttpResponse(timeout, unit)); } @Override @@ -110,17 +111,10 @@ public class ODataBatchRequestImpl */ protected class ODataBatchResponseImpl extends AbstractODataResponse implements ODataBatchResponse { - private ODataBatchResponseImpl() { - } + protected ODataBatchResponseImpl( + final CommonODataClient odataClient, final HttpClient httpClient, final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - protected ODataBatchResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); } /** @@ -131,4 +125,4 @@ public class ODataBatchRequestImpl return new ODataBatchResponseManager(this, expectedResItems, continueOnError); } } -} \ No newline at end of file +} diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataDeleteRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataDeleteRequestImpl.java index 174f73980..c9b2594fb 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataDeleteRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataDeleteRequestImpl.java @@ -35,15 +35,8 @@ import org.apache.olingo.commons.api.format.ODataFormat; * This class implements an OData delete request. */ public class ODataDeleteRequestImpl extends AbstractODataBasicRequest - implements ODataDeleteRequest { + implements ODataDeleteRequest { - /** - * Constructor. - * - * @param odataClient client instance getting this request - * @param method HTTP method to be used - * @param uri URI of the entity to be deleted. - */ ODataDeleteRequestImpl(final CommonODataClient odataClient, final HttpMethod method, final URI uri) { super(odataClient, method, uri); } @@ -63,7 +56,7 @@ public class ODataDeleteRequestImpl extends AbstractODataBasicRequest - * Just to create response templates to be initialized from batch. - */ - private ODataDeleteResponseImpl() { - } + private ODataDeleteResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - private ODataDeleteResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); this.close(); } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityCreateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityCreateRequestImpl.java index e09236c6d..de514bf60 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityCreateRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityCreateRequestImpl.java @@ -85,7 +85,7 @@ public class ODataEntityCreateRequestImpl ((HttpPost) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input)); try { - return new ODataEntityCreateResponseImpl(httpClient, doExecute()); + return new ODataEntityCreateResponseImpl(odataClient, httpClient, doExecute()); } finally { IOUtils.closeQuietly(input); } @@ -98,23 +98,10 @@ public class ODataEntityCreateRequestImpl private E entity = null; - /** - * Constructor. - *

- * Just to create response templates to be initialized from batch. - */ - private ODataEntityCreateResponseImpl() { - super(); - } + private ODataEntityCreateResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - private ODataEntityCreateResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); } /** @@ -125,9 +112,9 @@ public class ODataEntityCreateRequestImpl public E getBody() { if (entity == null) { try { - final ResWrap resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept())) - .toEntity(getRawResponse()); - + final ResWrap resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept())). + toEntity(getRawResponse()); + entity = (E) odataClient.getBinder().getODataEntity(resource); } catch (final ODataDeserializerException e) { throw new IllegalArgumentException(e); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java index 6acbd2aa4..55f8d87af 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java @@ -45,8 +45,8 @@ import org.apache.olingo.commons.api.serialization.ODataSerializerException; * @param concrete ODataEntity implementation */ public class ODataEntityUpdateRequestImpl - extends AbstractODataBasicRequest> - implements ODataEntityUpdateRequest { + extends AbstractODataBasicRequest> + implements ODataEntityUpdateRequest { /** * Changes to be applied. @@ -62,7 +62,7 @@ public class ODataEntityUpdateRequestImpl * @param changes changes to be applied. */ public ODataEntityUpdateRequestImpl(final CommonODataClient odataClient, - final HttpMethod method, final URI uri, final E changes) { + final HttpMethod method, final URI uri, final E changes) { super(odataClient, method, uri); this.changes = changes; @@ -73,18 +73,6 @@ public class ODataEntityUpdateRequestImpl return odataClient.getConfiguration().getDefaultPubFormat(); } - @Override - public ODataEntityUpdateResponse execute() { - final InputStream input = getPayload(); - ((HttpEntityEnclosingRequestBase) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input)); - - try { - return new ODataEntityUpdateResponseImpl(httpClient, doExecute()); - } finally { - IOUtils.closeQuietly(input); - } - } - @Override protected InputStream getPayload() { try { @@ -94,6 +82,18 @@ public class ODataEntityUpdateRequestImpl } } + @Override + public ODataEntityUpdateResponse execute() { + final InputStream input = getPayload(); + ((HttpEntityEnclosingRequestBase) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input)); + + try { + return new ODataEntityUpdateResponseImpl(odataClient, httpClient, doExecute()); + } finally { + IOUtils.closeQuietly(input); + } + } + /** * Response class about an ODataEntityUpdateRequest. */ @@ -104,21 +104,10 @@ public class ODataEntityUpdateRequestImpl */ private E entity = null; - /** - * Constructor. - *

- * Just to create response templates to be initialized from batch. - */ - private ODataEntityUpdateResponseImpl() {} + private ODataEntityUpdateResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - private ODataEntityUpdateResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); } @Override @@ -126,8 +115,8 @@ public class ODataEntityUpdateRequestImpl public E getBody() { if (entity == null) { try { - final ResWrap resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept())) - .toEntity(getRawResponse()); + final ResWrap resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept())). + toEntity(getRawResponse()); entity = (E) odataClient.getBinder().getODataEntity(resource); } catch (final ODataDeserializerException e) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java index 738912837..f65cb9485 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java @@ -43,7 +43,7 @@ import org.apache.olingo.commons.api.serialization.ODataSerializerException; * This class implements an OData update entity property request. */ public class ODataPropertyUpdateRequestImpl extends AbstractODataBasicRequest - implements ODataPropertyUpdateRequest { + implements ODataPropertyUpdateRequest { /** * Value to be created. @@ -77,7 +77,7 @@ public class ODataPropertyUpdateRequestImpl extends AbstractODataBasicRequest - * Just to create response templates to be initialized from batch. - */ - private ODataPropertyUpdateResponseImpl() { - } + private ODataPropertyUpdateResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - private ODataPropertyUpdateResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); } @Override public CommonODataProperty getBody() { if (property == null) { try { - final ResWrap resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept())) - .toProperty(getRawResponse()); + final ResWrap resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept())). + toProperty(getRawResponse()); property = odataClient.getBinder().getODataProperty(resource); } catch (final ODataDeserializerException e) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataValueUpdateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataValueUpdateRequestImpl.java index b229052b2..e1ec593cd 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataValueUpdateRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataValueUpdateRequestImpl.java @@ -41,7 +41,7 @@ import org.apache.olingo.commons.api.format.ODataFormat; * This class implements an OData update entity property value request. */ public class ODataValueUpdateRequestImpl extends AbstractODataBasicRequest - implements ODataValueUpdateRequest { + implements ODataValueUpdateRequest { /** * Value to be created. @@ -75,7 +75,7 @@ public class ODataValueUpdateRequestImpl extends AbstractODataBasicRequest - * Just to create response templates to be initialized from batch. - */ - private ODataValueUpdateResponseImpl() { - super(); - } + private ODataValueUpdateResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - private ODataValueUpdateResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); } @Override @@ -123,7 +110,7 @@ public class ODataValueUpdateRequestImpl extends AbstractODataBasicRequest - * Just to create response templates to be initialized from batch. - */ - private ODataLinkCreateResponseImpl() { - } + private ODataLinkCreateResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - private ODataLinkCreateResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); } } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/v3/ODataLinkUpdateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/v3/ODataLinkUpdateRequestImpl.java index aa00574ec..8d4464987 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/v3/ODataLinkUpdateRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/v3/ODataLinkUpdateRequestImpl.java @@ -40,7 +40,7 @@ import org.apache.olingo.commons.api.serialization.ODataSerializerException; * This class implements an update link OData request. */ public class ODataLinkUpdateRequestImpl extends AbstractODataBasicRequest - implements ODataLinkUpdateRequest { + implements ODataLinkUpdateRequest { /** * Entity to be linked. @@ -73,7 +73,7 @@ public class ODataLinkUpdateRequestImpl extends AbstractODataBasicRequest odataClient, final HttpClient httpClient, + final HttpResponse res) { + + super(odataClient, httpClient, res); } } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java index 5546778d6..27f40754a 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java @@ -171,7 +171,7 @@ public abstract class AbstractODataInvokeRequest } try { - return new ODataInvokeResponseImpl(httpClient, doExecute()); + return new ODataInvokeResponseImpl(odataClient, httpClient, doExecute()); } finally { IOUtils.closeQuietly(input); } @@ -184,23 +184,10 @@ public abstract class AbstractODataInvokeRequest private T invokeResult = null; - /** - * Constructor. - *

- * Just to create response templates to be initialized from batch. - */ - private ODataInvokeResponseImpl() { - super(); - } + private ODataInvokeResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - private ODataInvokeResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); } /** @@ -213,19 +200,19 @@ public abstract class AbstractODataInvokeRequest if (ODataNoContent.class.isAssignableFrom(reference)) { invokeResult = reference.cast(new ODataNoContent()); } else { - // avoid getContent() twice:IllegalStateException: Content has been consumed - InputStream responseStream = this.payload == null ? res.getEntity().getContent() : this.payload; - if (CommonODataEntitySet.class.isAssignableFrom(reference)) { - invokeResult = reference.cast(odataClient.getReader().readEntitySet(responseStream, - ODataFormat.fromString(getContentType()))); - } else if (CommonODataEntity.class.isAssignableFrom(reference)) { - invokeResult = reference.cast(odataClient.getReader().readEntity(responseStream, - ODataFormat.fromString(getContentType()))); - } else if (CommonODataProperty.class.isAssignableFrom(reference)) { - invokeResult = reference.cast(odataClient.getReader().readProperty(responseStream, - ODataFormat.fromString(getContentType()))); - } - } + // avoid getContent() twice:IllegalStateException: Content has been consumed + final InputStream responseStream = this.payload == null ? res.getEntity().getContent() : this.payload; + if (CommonODataEntitySet.class.isAssignableFrom(reference)) { + invokeResult = reference.cast(odataClient.getReader().readEntitySet(responseStream, + ODataFormat.fromString(getContentType()))); + } else if (CommonODataEntity.class.isAssignableFrom(reference)) { + invokeResult = reference.cast(odataClient.getReader().readEntity(responseStream, + ODataFormat.fromString(getContentType()))); + } else if (CommonODataProperty.class.isAssignableFrom(reference)) { + invokeResult = reference.cast(odataClient.getReader().readProperty(responseStream, + ODataFormat.fromString(getContentType()))); + } + } } catch (IOException e) { throw new HttpClientException(e); } catch (final ODataDeserializerException e) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractMetadataRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractMetadataRequestImpl.java index e84beb98d..537e00ca1 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractMetadataRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractMetadataRequestImpl.java @@ -19,17 +19,17 @@ package org.apache.olingo.client.core.communication.request.retrieve; import java.net.URI; -import org.apache.http.entity.ContentType; import org.apache.olingo.client.api.CommonODataClient; import org.apache.olingo.client.api.communication.request.ODataRequest; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.format.ODataFormat; public abstract class AbstractMetadataRequestImpl extends AbstractODataRetrieveRequest { public AbstractMetadataRequestImpl(final CommonODataClient odataClient, final URI query) { super(odataClient, query); - super.setAccept(ContentType.APPLICATION_XML.getMimeType()); - super.setContentType(ContentType.APPLICATION_XML.getMimeType()); + super.setAccept(ContentType.APPLICATION_XML.toContentTypeString()); + super.setContentType(ContentType.APPLICATION_XML.toContentTypeString()); } @Override diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractODataRetrieveRequest.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractODataRetrieveRequest.java index c42832c2d..9c4cf2e10 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractODataRetrieveRequest.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractODataRetrieveRequest.java @@ -20,7 +20,6 @@ package org.apache.olingo.client.core.communication.request.retrieve; import java.io.InputStream; import java.net.URI; - import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.olingo.client.api.CommonODataClient; @@ -64,23 +63,10 @@ public abstract class AbstractODataRetrieveRequest protected abstract class AbstractODataRetrieveResponse extends AbstractODataResponse implements ODataRetrieveResponse { - /** - * Constructor. - *

- * Just to create response templates to be initialized from batch. - */ - protected AbstractODataRetrieveResponse() { - super(); - } + protected AbstractODataRetrieveResponse(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - protected AbstractODataRetrieveResponse(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); } @Override diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/EdmMetadataRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/EdmMetadataRequestImpl.java index 64486fff5..c902eacd4 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/EdmMetadataRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/EdmMetadataRequestImpl.java @@ -49,11 +49,12 @@ class EdmMetadataRequestImpl extends AbstractMetadataRequestImpl implements final ODataRetrieveResponse> xmlMetadataResponse = odataClient.getRetrieveRequestFactory().getXMLMetadataRequest(serviceRoot).execute(); - return new AbstractODataRetrieveResponse() { + return new AbstractODataRetrieveResponse(odataClient, httpClient, null) { private Edm metadata = null; @Override public void close() { + super.close(); xmlMetadataResponse.close(); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java index 427e5b315..1b8526684 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java @@ -54,7 +54,7 @@ public class ODataEntityRequestImpl @Override public ODataRetrieveResponse execute() { - return new ODataEntityResponseImpl(httpClient, doExecute()); + return new ODataEntityResponseImpl(odataClient, httpClient, doExecute()); } /** @@ -64,23 +64,10 @@ public class ODataEntityRequestImpl private E entity = null; - /** - * Constructor. - *
- * Just to create response templates to be initialized from batch. - */ - private ODataEntityResponseImpl() { - super(); - } + private ODataEntityResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - private ODataEntityResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); } @Override @@ -88,11 +75,11 @@ public class ODataEntityRequestImpl public E getBody() { if (entity == null) { try { - final ResWrap resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType())) - .toEntity(getRawResponse()); + final ResWrap resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType())). + toEntity(getRawResponse()); entity = (E) odataClient.getBinder().getODataEntity(resource); - } catch (final ODataDeserializerException e) { + } catch (ODataDeserializerException e) { throw new IllegalArgumentException(e); } finally { this.close(); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetIteratorRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetIteratorRequestImpl.java index 5cf1377fe..de4c11dcc 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetIteratorRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetIteratorRequestImpl.java @@ -57,7 +57,7 @@ public class ODataEntitySetIteratorRequestImpl> execute() { final HttpResponse res = doExecute(); - return new ODataEntitySetIteratorResponseImpl(httpClient, res); + return new ODataEntitySetIteratorResponseImpl(odataClient, httpClient, res); } /** @@ -65,14 +65,10 @@ public class ODataEntitySetIteratorRequestImpl odataClient, final HttpClient httpClient, + final HttpResponse res) { + + super(odataClient, httpClient, res); } @Override diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java index c5605764f..f39d113d1 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java @@ -59,7 +59,7 @@ public class ODataEntitySetRequestImpl @Override public ODataRetrieveResponse execute() { final HttpResponse res = doExecute(); - return new ODataEntitySetResponseImpl(httpClient, res); + return new ODataEntitySetResponseImpl(odataClient, httpClient, res); } /** @@ -67,23 +67,10 @@ public class ODataEntitySetRequestImpl */ protected class ODataEntitySetResponseImpl extends AbstractODataRetrieveResponse { - /** - * Constructor. - *

- * Just to create response templates to be initialized from batch. - */ - private ODataEntitySetResponseImpl() { - super(); - } + private ODataEntitySetResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - private ODataEntitySetResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); } @Override @@ -91,8 +78,8 @@ public class ODataEntitySetRequestImpl public ES getBody() { if (entitySet == null) { try { - final ResWrap resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType())) - .toEntitySet(getRawResponse()); + final ResWrap resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType())). + toEntitySet(getRawResponse()); entitySet = (ES) odataClient.getBinder().getODataEntitySet(resource); } catch (final ODataDeserializerException e) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataMediaRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataMediaRequestImpl.java index ad2263e6c..c24f80a7b 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataMediaRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataMediaRequestImpl.java @@ -61,7 +61,7 @@ public class ODataMediaRequestImpl extends AbstractODataRetrieveRequest execute() { final HttpResponse res = doExecute(); - return new ODataMediaResponseImpl(httpClient, res); + return new ODataMediaResponseImpl(odataClient, httpClient, res); } /** @@ -71,23 +71,10 @@ public class ODataMediaRequestImpl extends AbstractODataRetrieveRequest - * Just to create response templates to be initialized from batch. - */ - private ODataMediaResponseImpl() { - super(); - } + private ODataMediaResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - private ODataMediaResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); } /** diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataPropertyRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataPropertyRequestImpl.java index f13da7d5f..25a9ca6a4 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataPropertyRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataPropertyRequestImpl.java @@ -37,7 +37,7 @@ import org.apache.olingo.commons.api.serialization.ODataDeserializerException; * This class implements an OData entity property query request. */ public class ODataPropertyRequestImpl - extends AbstractODataRetrieveRequest implements ODataPropertyRequest { + extends AbstractODataRetrieveRequest implements ODataPropertyRequest { /** * Private constructor. @@ -57,29 +57,17 @@ public class ODataPropertyRequestImpl @Override public ODataRetrieveResponse execute() { final HttpResponse res = doExecute(); - return new ODataPropertyResponseImpl(httpClient, res); + return new ODataPropertyResponseImpl(odataClient, httpClient, res); } protected class ODataPropertyResponseImpl extends AbstractODataRetrieveResponse { private T property = null; - /** - * Constructor. - *

- * Just to create response templates to be initialized from batch. - */ - private ODataPropertyResponseImpl() { - } + private ODataPropertyResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - private ODataPropertyResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); } @Override @@ -88,7 +76,7 @@ public class ODataPropertyRequestImpl if (property == null) { try { final ResWrap resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType())) - .toProperty(res.getEntity().getContent()); + .toProperty(res.getEntity().getContent()); property = (T) odataClient.getBinder().getODataProperty(resource); } catch (IOException e) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataRawRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataRawRequestImpl.java index e005c8ba9..35cf07309 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataRawRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataRawRequestImpl.java @@ -63,29 +63,17 @@ public class ODataRawRequestImpl extends AbstractODataRequest implements ODataRa @Override public ODataRawResponse execute() { - return new ODataRawResponseImpl(httpClient, doExecute()); + return new ODataRawResponseImpl(odataClient, httpClient, doExecute()); } private class ODataRawResponseImpl extends AbstractODataResponse implements ODataRawResponse { private byte[] obj = null; - /** - * Constructor. - *
- * Just to create response templates to be initialized from batch. - */ - private ODataRawResponseImpl() { - } + private ODataRawResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - private ODataRawResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); } @Override @@ -101,8 +89,7 @@ public class ODataRawRequestImpl extends AbstractODataRequest implements ODataRa } try { - return odataClient.getReader(). - read(new ByteArrayInputStream(obj), getContentType(), reference); + return odataClient.getReader().read(new ByteArrayInputStream(obj), getContentType(), reference); } catch (final ODataDeserializerException e) { throw new IllegalArgumentException(e); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java index d252c6e6f..21dabf9be 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java @@ -35,7 +35,7 @@ import org.apache.olingo.commons.api.serialization.ODataDeserializerException; * This class implements an OData service document request. */ public class ODataServiceDocumentRequestImpl extends AbstractODataRetrieveRequest - implements ODataServiceDocumentRequest { + implements ODataServiceDocumentRequest { /** * Constructor. @@ -55,7 +55,7 @@ public class ODataServiceDocumentRequestImpl extends AbstractODataRetrieveReques @Override public ODataRetrieveResponse execute() { final HttpResponse res = doExecute(); - return new ODataServiceResponseImpl(httpClient, res); + return new ODataServiceResponseImpl(odataClient, httpClient, res); } /** @@ -65,30 +65,18 @@ public class ODataServiceDocumentRequestImpl extends AbstractODataRetrieveReques private ODataServiceDocument serviceDocument = null; - /** - * Constructor. - *

- * Just to create response templates to be initialized from batch. - */ - private ODataServiceResponseImpl() {} + private ODataServiceResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - private ODataServiceResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); } @Override public ODataServiceDocument getBody() { if (serviceDocument == null) { try { - final ResWrap resource = - odataClient.getDeserializer(ODataFormat.fromString(getContentType())) - .toServiceDocument(getRawResponse()); + final ResWrap resource = odataClient. + getDeserializer(ODataFormat.fromString(getContentType())).toServiceDocument(getRawResponse()); serviceDocument = odataClient.getBinder().getODataServiceDocument(resource.getPayload()); } catch (final ODataDeserializerException e) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataValueRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataValueRequestImpl.java index 95cf01643..f417e5d4c 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataValueRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataValueRequestImpl.java @@ -35,7 +35,7 @@ import org.apache.olingo.commons.api.format.ODataFormat; * This class implements an OData entity property value query request. */ public class ODataValueRequestImpl extends AbstractODataRetrieveRequest - implements ODataValueRequest { + implements ODataValueRequest { /** * Private constructor. @@ -55,7 +55,7 @@ public class ODataValueRequestImpl extends AbstractODataRetrieveRequest execute() { final HttpResponse res = doExecute(); - return new ODataValueResponseImpl(httpClient, res); + return new ODataValueResponseImpl(odataClient, httpClient, res); } /** @@ -65,23 +65,10 @@ public class ODataValueRequestImpl extends AbstractODataRetrieveRequest - * Just to create response templates to be initialized from batch. - */ - private ODataValueResponseImpl() { - super(); - } + private ODataValueResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - private ODataValueResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); } @Override @@ -91,8 +78,8 @@ public class ODataValueRequestImpl extends AbstractODataRetrieveRequest - implements ODataLinkCollectionRequest { + implements ODataLinkCollectionRequest { /** * Private constructor. @@ -47,7 +48,7 @@ public class ODataLinkCollectionRequestImpl extends AbstractODataRetrieveRequest */ ODataLinkCollectionRequestImpl(final ODataClient odataClient, final URI targetURI, final String linkName) { super(odataClient, - odataClient.newURIBuilder(targetURI.toASCIIString()).appendLinksSegment(linkName).build()); + odataClient.newURIBuilder(targetURI.toASCIIString()).appendLinksSegment(linkName).build()); } @Override @@ -57,29 +58,17 @@ public class ODataLinkCollectionRequestImpl extends AbstractODataRetrieveRequest @Override public ODataRetrieveResponse execute() { - return new ODataLinkCollectionResponseImpl(httpClient, doExecute()); + return new ODataLinkCollectionResponseImpl(odataClient, httpClient, doExecute()); } protected class ODataLinkCollectionResponseImpl extends AbstractODataRetrieveResponse { private ODataLinkCollection links = null; - /** - * Constructor. - *

- * Just to create response templates to be initialized from batch. - */ - private ODataLinkCollectionResponseImpl() { - } + private ODataLinkCollectionResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - private ODataLinkCollectionResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); } @Override diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/XMLMetadataRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/XMLMetadataRequestImpl.java index 1304b84e4..2b0cd1817 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/XMLMetadataRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/XMLMetadataRequestImpl.java @@ -25,6 +25,7 @@ import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; +import org.apache.olingo.client.api.CommonODataClient; import org.apache.olingo.client.api.communication.request.retrieve.XMLMetadataRequest; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; import org.apache.olingo.client.api.edm.xml.Schema; @@ -42,30 +43,17 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl> execute() { - return new XMLMetadataResponseImpl(httpClient, doExecute()); + return new XMLMetadataResponseImpl(odataClient, httpClient, doExecute()); } public class XMLMetadataResponseImpl extends AbstractODataRetrieveResponse { private Map schemas; - /** - * Constructor. - *
- * Just to create response templates to be initialized from batch. - */ - private XMLMetadataResponseImpl() { - super(); - } + private XMLMetadataResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - private XMLMetadataResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); } @Override @@ -73,8 +61,7 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl(); try { - final XMLMetadata metadata = odataClient.getDeserializer(ODataFormat.XML) - .toMetadata(getRawResponse()); + final XMLMetadata metadata = odataClient.getDeserializer(ODataFormat.XML).toMetadata(getRawResponse()); for (Schema schema : metadata.getSchemas()) { schemas.put(schema.getNamespace(), schema); if (StringUtils.isNotBlank(schema.getAlias())) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/ODataDeltaRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/ODataDeltaRequestImpl.java index bd32c9e77..dbcfd4a71 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/ODataDeltaRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/ODataDeltaRequestImpl.java @@ -36,7 +36,7 @@ import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.serialization.ODataDeserializerException; public class ODataDeltaRequestImpl extends AbstractODataRetrieveRequest - implements ODataDeltaRequest { + implements ODataDeltaRequest { public ODataDeltaRequestImpl(final CommonODataClient odataClient, final URI query) { super(odataClient, query); @@ -50,30 +50,26 @@ public class ODataDeltaRequestImpl extends AbstractODataRetrieveRequest execute() { final HttpResponse res = doExecute(); - return new ODataDeltaResponseImpl(httpClient, res); + return new ODataDeltaResponseImpl(odataClient, httpClient, res); } protected class ODataDeltaResponseImpl extends AbstractODataRetrieveResponse { private ODataDelta delta = null; - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - private ODataDeltaResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + private ODataDeltaResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { + + super(odataClient, httpClient, res); } @Override public ODataDelta getBody() { if (delta == null) { try { - final ResWrap resource = ((ODataClient) odataClient) - .getDeserializer(ODataFormat.fromString(getContentType())) - .toDelta(res.getEntity().getContent()); + final ResWrap resource = ((ODataClient) odataClient). + getDeserializer(ODataFormat.fromString(getContentType())). + toDelta(res.getEntity().getContent()); delta = ((ODataClient) odataClient).getBinder().getODataDelta(resource); } catch (IOException e) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/XMLMetadataRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/XMLMetadataRequestImpl.java index 814306cf9..e489c99f7 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/XMLMetadataRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/XMLMetadataRequestImpl.java @@ -24,6 +24,8 @@ import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.olingo.client.api.CommonODataClient; import org.apache.olingo.client.api.communication.request.retrieve.XMLMetadataRequest; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; import org.apache.olingo.client.api.edm.xml.Schema; @@ -51,7 +53,8 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl rootRes = rootReq.execute(); - final XMLMetadataResponseImpl response = new XMLMetadataResponseImpl(rootReq.getHttpResponse()); + final XMLMetadataResponseImpl response = + new XMLMetadataResponseImpl(odataClient, httpClient, rootReq.getHttpResponse()); final XMLMetadata rootMetadata = rootRes.getBody(); for (Schema schema : rootMetadata.getSchemas()) { @@ -137,7 +140,7 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl execute() { httpResponse = doExecute(); - return new AbstractODataRetrieveResponse(httpClient, httpResponse) { + return new AbstractODataRetrieveResponse(odataClient, httpClient, httpResponse) { @Override public XMLMetadata getBody() { @@ -155,8 +158,10 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl schemas = new HashMap(); - private XMLMetadataResponseImpl(final HttpResponse res) { - super(); + private XMLMetadataResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { + + super(odataClient, httpClient, null); statusCode = res.getStatusLine().getStatusCode(); statusMessage = res.getStatusLine().getReasonPhrase(); @@ -164,11 +169,6 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl getBody() { return schemas; diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/AbstractODataStreamedRequest.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/AbstractODataStreamedRequest.java index 0f6a18891..d55c27843 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/AbstractODataStreamedRequest.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/AbstractODataStreamedRequest.java @@ -28,7 +28,6 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; -import org.apache.http.entity.ContentType; import org.apache.olingo.client.api.CommonODataClient; import org.apache.olingo.client.api.ODataBatchConstants; import org.apache.olingo.client.api.communication.request.ODataPayloadManager; @@ -40,6 +39,7 @@ import org.apache.olingo.client.api.http.HttpMethod; import org.apache.olingo.client.core.communication.request.AbstractODataRequest; import org.apache.olingo.client.core.communication.request.Wrapper; import org.apache.olingo.client.core.uri.URIUtils; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.format.ODataFormat; /** @@ -73,8 +73,8 @@ public abstract class AbstractODataStreamedRequest @Override protected ODataMediaEntityCreateResponse getResponse(final long timeout, final TimeUnit unit) { finalizeBody(); - return new ODataMediaEntityCreateResponseImpl(httpClient, getHttpResponse(timeout, unit)); + return new ODataMediaEntityCreateResponseImpl(odataClient, httpClient, getHttpResponse(timeout, unit)); } } @@ -99,22 +99,10 @@ public class ODataMediaEntityCreateRequestImpl private E entity = null; - /** - * Constructor. - *

- * Just to create response templates to be initialized from batch. - */ - private ODataMediaEntityCreateResponseImpl() { - } + private ODataMediaEntityCreateResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - private ODataMediaEntityCreateResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); } @Override @@ -122,8 +110,7 @@ public class ODataMediaEntityCreateRequestImpl public E getBody() { if (entity == null) { try { - final ResWrap resource = odataClient.getDeserializer(getFormat()) - .toEntity(getRawResponse()); + final ResWrap resource = odataClient.getDeserializer(getFormat()).toEntity(getRawResponse()); entity = (E) odataClient.getBinder().getODataEntity(resource); } catch (final ODataDeserializerException e) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java index 154d69943..2290d68a0 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java @@ -88,7 +88,7 @@ public class ODataMediaEntityUpdateRequestImpl @Override protected ODataMediaEntityUpdateResponse getResponse(final long timeout, final TimeUnit unit) { finalizeBody(); - return new ODataMediaEntityUpdateResponseImpl(httpClient, getHttpResponse(timeout, unit)); + return new ODataMediaEntityUpdateResponseImpl(odataClient, httpClient, getHttpResponse(timeout, unit)); } } @@ -100,23 +100,10 @@ public class ODataMediaEntityUpdateRequestImpl private E entity = null; - /** - * Constructor. - *
- * Just to create response templates to be initialized from batch. - */ - private ODataMediaEntityUpdateResponseImpl() { - super(); - } + private ODataMediaEntityUpdateResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - private ODataMediaEntityUpdateResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); } @Override diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataStreamUpdateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataStreamUpdateRequestImpl.java index 216c5214c..c9dcf5e84 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataStreamUpdateRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataStreamUpdateRequestImpl.java @@ -85,7 +85,7 @@ public class ODataStreamUpdateRequestImpl @Override protected ODataStreamUpdateResponse getResponse(final long timeout, final TimeUnit unit) { finalizeBody(); - return new ODataStreamUpdateResponseImpl(httpClient, getHttpResponse(timeout, unit)); + return new ODataStreamUpdateResponseImpl(odataClient, httpClient, getHttpResponse(timeout, unit)); } } @@ -96,22 +96,10 @@ public class ODataStreamUpdateRequestImpl private InputStream input = null; - /** - * Constructor. - *

- * Just to create response templates to be initialized from batch. - */ - private ODataStreamUpdateResponseImpl() { - } + private ODataStreamUpdateResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - private ODataStreamUpdateResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); } /** diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/v4/AsyncRequestWrapperImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/v4/AsyncRequestWrapperImpl.java index 2ec51e098..98866986c 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/v4/AsyncRequestWrapperImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/v4/AsyncRequestWrapperImpl.java @@ -85,13 +85,13 @@ public class AsyncRequestWrapperImpl extends AbstractRe // target uri this.uri = odataRequest.getURI(); - HttpClient _httpClient = odataClient.getConfiguration().getHttpClientFactory().createHttpClient(method, this.uri); + HttpClient _httpClient = odataClient.getConfiguration().getHttpClientFactory().create(method, this.uri); if (odataClient.getConfiguration().isGzipCompression()) { _httpClient = new DecompressingHttpClient(_httpClient); } this.httpClient = _httpClient; - this.request = odataClient.getConfiguration().getHttpUriRequestFactory().createHttpUriRequest(method, this.uri); + this.request = odataClient.getConfiguration().getHttpUriRequestFactory().create(method, this.uri); } @Override @@ -292,7 +292,7 @@ public class AsyncRequestWrapperImpl extends AbstractRe } final HttpUriRequest monitor = odataClient.getConfiguration().getHttpUriRequestFactory(). - createHttpUriRequest(HttpMethod.GET, location); + create(HttpMethod.GET, location); return executeHttpRequest(httpClient, monitor); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/AbstractODataResponse.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/AbstractODataResponse.java index 3bac01840..3127608d3 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/AbstractODataResponse.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/AbstractODataResponse.java @@ -33,6 +33,7 @@ import org.apache.http.Header; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.client.HttpClient; +import org.apache.olingo.client.api.CommonODataClient; 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; @@ -55,10 +56,12 @@ public abstract class AbstractODataResponse implements ODataResponse { */ protected static final Logger LOG = LoggerFactory.getLogger(ODataResponse.class); + protected final CommonODataClient odataClient; + /** * HTTP client. */ - protected final HttpClient client; + protected final HttpClient httpClient; /** * HTTP response. @@ -96,21 +99,11 @@ public abstract class AbstractODataResponse implements ODataResponse { */ protected ODataBatchController batchInfo = null; - /** - * Constructor. - */ - public AbstractODataResponse() { - this(null, null); - } + public AbstractODataResponse( + final CommonODataClient odataClient, final HttpClient httpclient, final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - public AbstractODataResponse(final HttpClient client, final HttpResponse res) { - this.client = client; + this.odataClient = odataClient; + this.httpClient = httpclient; this.res = res; if (res != null) { initFromHttpResponse(res); @@ -285,11 +278,7 @@ public abstract class AbstractODataResponse implements ODataResponse { */ @Override public void close() { - if (client == null) { - IOUtils.closeQuietly(payload); - } else { - this.client.getConnectionManager().shutdown(); - } + odataClient.getConfiguration().getHttpClientFactory().close(httpClient); if (batchInfo != null) { batchInfo.setValidBatch(false); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/batch/ODataBatchErrorResponse.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/batch/ODataBatchErrorResponse.java index fa41b8226..6305aad57 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/batch/ODataBatchErrorResponse.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/batch/ODataBatchErrorResponse.java @@ -24,21 +24,15 @@ import org.apache.olingo.client.api.communication.request.batch.ODataBatchLineIt import org.apache.olingo.client.core.communication.request.batch.ODataBatchController; import org.apache.olingo.client.core.communication.response.AbstractODataResponse; -/** - * Abstract representation of an OData response. - */ public class ODataBatchErrorResponse extends AbstractODataResponse { - /** - * Constructor. - */ public ODataBatchErrorResponse( final Map.Entry responseLine, final Map> headers, final ODataBatchLineIterator batchLineIterator, final String boundary) { - super(); + super(null, null, null); if (hasBeenInitialized) { throw new IllegalStateException("Request already initialized"); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/batch/ODataBatchResponseManager.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/batch/ODataBatchResponseManager.java index 9db555ed1..5f522478e 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/batch/ODataBatchResponseManager.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/batch/ODataBatchResponseManager.java @@ -77,6 +77,7 @@ public class ODataBatchResponseManager implements Iterator expectedItems) { + this(res, expectedItems, false); } @@ -84,6 +85,7 @@ public class ODataBatchResponseManager implements Iterator expectedItems, final boolean continueOnError) { + this.continueOnError = continueOnError; try { @@ -106,7 +108,7 @@ public class ODataBatchResponseManager implements Iterator - * Just to create response templates to be initialized from batch. - */ - public AsyncResponseImpl() { - super(); - } + public AsyncResponseImpl(final CommonODataClient odataClient, final HttpClient httpClient, + final HttpResponse res) { - /** - * Constructor. - * - * @param client HTTP client. - * @param res HTTP response. - */ - public AsyncResponseImpl(final HttpClient client, final HttpResponse res) { - super(client, res); + super(odataClient, httpClient, res); } /** @@ -59,7 +47,8 @@ public class AsyncResponseImpl extends AbstractODataResponse implements AsyncRes final Map> headers, final ODataBatchLineIterator batchLineIterator, final String boundary) { - super(); + + super(null, null, null); if (hasBeenInitialized) { throw new IllegalStateException("Request already initialized"); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/http/AbstractHttpClientFactory.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/http/AbstractHttpClientFactory.java new file mode 100644 index 000000000..271dcc68b --- /dev/null +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/http/AbstractHttpClientFactory.java @@ -0,0 +1,50 @@ +/* + * 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.core.http; + +import java.io.InputStream; +import java.util.Properties; +import org.apache.commons.io.IOUtils; +import org.apache.olingo.client.api.http.HttpClientFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class AbstractHttpClientFactory implements HttpClientFactory { + + private static final Logger LOG = LoggerFactory.getLogger(AbstractHttpClientFactory.class); + + protected static final String USER_AGENT; + + static { + final StringBuilder userAgent = new StringBuilder("Apache-Olingo"); + + final InputStream input = AbstractHttpClientFactory.class.getResourceAsStream("/client.properties"); + try { + final Properties prop = new Properties(); + prop.load(input); + userAgent.append('/').append(prop.getProperty("version")); + } catch (Exception e) { + LOG.warn("Could not get Apache Olingo version", e); + } finally { + IOUtils.closeQuietly(input); + } + + USER_AGENT = userAgent.toString(); + } +} diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/http/BasicAuthHttpClientFactory.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/http/BasicAuthHttpClientFactory.java index 0f60a3195..b9cd98084 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/http/BasicAuthHttpClientFactory.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/http/BasicAuthHttpClientFactory.java @@ -42,8 +42,8 @@ public class BasicAuthHttpClientFactory extends DefaultHttpClientFactory { } @Override - public DefaultHttpClient createHttpClient(final HttpMethod method, final URI uri) { - final DefaultHttpClient httpclient = super.createHttpClient(method, uri); + public DefaultHttpClient create(final HttpMethod method, final URI uri) { + final DefaultHttpClient httpclient = super.create(method, uri); httpclient.getCredentialsProvider().setCredentials( new AuthScope(uri.getHost(), uri.getPort()), diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/http/DefaultHttpClientFactory.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/http/DefaultHttpClientFactory.java index 6c5cd4912..fd64c2f8f 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/http/DefaultHttpClientFactory.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/http/DefaultHttpClientFactory.java @@ -18,51 +18,29 @@ */ package org.apache.olingo.client.core.http; -import java.io.InputStream; -import java.io.Serializable; import java.net.URI; -import java.util.Properties; -import org.apache.commons.io.IOUtils; - +import org.apache.http.client.HttpClient; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.params.CoreProtocolPNames; -import org.apache.olingo.client.api.http.HttpClientFactory; import org.apache.olingo.client.api.http.HttpMethod; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Default implementation returning HttpClients with default parameters. */ -public class DefaultHttpClientFactory implements HttpClientFactory, Serializable { +public class DefaultHttpClientFactory extends AbstractHttpClientFactory { private static final long serialVersionUID = -2461355444507227332L; - private static final Logger LOG = LoggerFactory.getLogger(DefaultHttpClientFactory.class); - - private static final String USER_AGENT; - - static { - final StringBuilder userAgent = new StringBuilder("Apache-Olingo"); - - final InputStream input = DefaultHttpClientFactory.class.getResourceAsStream("/client.properties"); - try { - final Properties prop = new Properties(); - prop.load(input); - userAgent.append('/').append(prop.getProperty("version")); - } catch (Exception e) { - LOG.warn("Could not get Apache Olingo version", e); - } finally { - IOUtils.closeQuietly(input); - } - - USER_AGENT = userAgent.toString(); - } - @Override - public DefaultHttpClient createHttpClient(final HttpMethod method, final URI uri) { + public DefaultHttpClient create(final HttpMethod method, final URI uri) { final DefaultHttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT); return client; } + + @Override + public void close(final HttpClient httpClient) { + httpClient.getConnectionManager().shutdown(); + } + } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/http/DefaultHttpUriRequestFactory.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/http/DefaultHttpUriRequestFactory.java index aaa17c087..c336b22f6 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/http/DefaultHttpUriRequestFactory.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/http/DefaultHttpUriRequestFactory.java @@ -34,7 +34,7 @@ import org.apache.olingo.client.api.http.HttpUriRequestFactory; public class DefaultHttpUriRequestFactory implements HttpUriRequestFactory { @Override - public HttpUriRequest createHttpUriRequest(final HttpMethod method, final URI uri) { + public HttpUriRequest create(final HttpMethod method, final URI uri) { HttpUriRequest result; switch (method) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/http/NTLMAuthHttpClientFactory.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/http/NTLMAuthHttpClientFactory.java index 5f2578bea..c776bf934 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/http/NTLMAuthHttpClientFactory.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/http/NTLMAuthHttpClientFactory.java @@ -58,8 +58,8 @@ public class NTLMAuthHttpClientFactory extends DefaultHttpClientFactory { } @Override - public DefaultHttpClient createHttpClient(final HttpMethod method, final URI uri) { - final DefaultHttpClient httpclient = super.createHttpClient(method, uri); + public DefaultHttpClient create(final HttpMethod method, final URI uri) { + final DefaultHttpClient httpclient = super.create(method, uri); final CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/http/ProxyWrapperHttpClientFactory.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/http/ProxyWrapperHttpClientFactory.java index 29b6fe43e..2ce0b3d82 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/http/ProxyWrapperHttpClientFactory.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/http/ProxyWrapperHttpClientFactory.java @@ -68,9 +68,9 @@ public class ProxyWrapperHttpClientFactory implements HttpClientFactory { } @Override - public HttpClient createHttpClient(final HttpMethod method, final URI uri) { + public HttpClient create(final HttpMethod method, final URI uri) { // Use wrapped factory to obtain an httpclient instance for given method and uri - final DefaultHttpClient httpclient = (DefaultHttpClient) wrapped.createHttpClient(method, uri); + final DefaultHttpClient httpclient = (DefaultHttpClient) wrapped.create(method, uri); final HttpHost proxyHost = new HttpHost(proxy.getHost(), proxy.getPort()); @@ -87,4 +87,9 @@ public class ProxyWrapperHttpClientFactory implements HttpClientFactory { return httpclient; } + @Override + public void close(final HttpClient httpClient) { + wrapped.close(httpClient); + } + } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/AbstractURIBuilder.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/AbstractURIBuilder.java index 7a7c63018..d8c0de6d0 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/AbstractURIBuilder.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/AbstractURIBuilder.java @@ -20,7 +20,6 @@ package org.apache.olingo.client.core.uri; import java.io.UnsupportedEncodingException; import java.net.URI; -import java.net.URISyntaxException; import java.net.URLDecoder; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -32,7 +31,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.http.NameValuePair; import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.message.BasicNameValuePair; -import org.apache.olingo.client.api.CommonConfiguration; +import org.apache.olingo.client.api.Configuration; import org.apache.olingo.client.api.uri.CommonURIBuilder; import org.apache.olingo.client.api.uri.QueryOption; import org.apache.olingo.client.api.uri.SegmentType; @@ -72,7 +71,7 @@ public abstract class AbstractURIBuilder> impleme private final ODataServiceVersion version; - private final CommonConfiguration configuration; + private final Configuration configuration; protected final List segments = new ArrayList(); @@ -93,7 +92,7 @@ public abstract class AbstractURIBuilder> impleme * service. */ protected AbstractURIBuilder( - final ODataServiceVersion version, final CommonConfiguration configuration, final String serviceRoot) { + final ODataServiceVersion version, final Configuration configuration, final String serviceRoot) { this.version = version; this.configuration = configuration; diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/v3/URIBuilderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/v3/URIBuilderImpl.java index 1d231672e..7f351b2bd 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/v3/URIBuilderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/v3/URIBuilderImpl.java @@ -19,7 +19,7 @@ package org.apache.olingo.client.core.uri.v3; import org.apache.commons.lang3.StringUtils; -import org.apache.olingo.client.api.CommonConfiguration; +import org.apache.olingo.client.api.Configuration; import org.apache.olingo.client.api.uri.QueryOption; import org.apache.olingo.client.api.uri.SegmentType; import org.apache.olingo.client.api.uri.v3.URIBuilder; @@ -29,7 +29,7 @@ import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; public class URIBuilderImpl extends AbstractURIBuilder implements URIBuilder { public URIBuilderImpl( - final ODataServiceVersion version, final CommonConfiguration configuration, final String serviceRoot) { + final ODataServiceVersion version, final Configuration configuration, final String serviceRoot) { super(version, configuration, serviceRoot); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/v4/URIBuilderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/v4/URIBuilderImpl.java index f5ab420cd..e5a156c32 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/v4/URIBuilderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/v4/URIBuilderImpl.java @@ -23,7 +23,7 @@ import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; -import org.apache.olingo.client.api.CommonConfiguration; +import org.apache.olingo.client.api.Configuration; import org.apache.olingo.client.api.uri.QueryOption; import org.apache.olingo.client.api.uri.SegmentType; import org.apache.olingo.client.api.uri.v4.URIBuilder; @@ -35,7 +35,7 @@ import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; public class URIBuilderImpl extends AbstractURIBuilder implements URIBuilder { public URIBuilderImpl( - final ODataServiceVersion version, final CommonConfiguration configuration, final String serviceRoot) { + final ODataServiceVersion version, final Configuration configuration, final String serviceRoot) { super(version, configuration, serviceRoot); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/ODataClientImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/ODataClientImpl.java index ec8cd3399..caaf423ec 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/ODataClientImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/ODataClientImpl.java @@ -18,7 +18,6 @@ */ package org.apache.olingo.client.core.v3; -import org.apache.olingo.client.api.CommonConfiguration; 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.batch.v3.BatchRequestFactory; @@ -33,7 +32,6 @@ import org.apache.olingo.client.api.uri.v3.FilterFactory; import org.apache.olingo.client.api.uri.v3.URIBuilder; import org.apache.olingo.client.api.v3.ODataClient; import org.apache.olingo.client.core.AbstractODataClient; -import org.apache.olingo.client.core.Configuration; import org.apache.olingo.client.core.communication.header.ODataHeadersImpl; import org.apache.olingo.client.core.communication.request.batch.v3.BatchRequestFactoryImpl; import org.apache.olingo.client.core.communication.request.cud.v3.CUDRequestFactoryImpl; @@ -54,8 +52,6 @@ import org.apache.olingo.commons.core.serialization.JsonSerializer; public class ODataClientImpl extends AbstractODataClient implements ODataClient { - protected final Configuration configuration = new Configuration(); - private final FilterFactory filterFactory = new FilterFactoryImpl(getServiceVersion()); private final ODataReader reader = new ODataReaderImpl(this); @@ -86,11 +82,6 @@ public class ODataClientImpl extends AbstractODataClient implements return odataHeaders; } - @Override - public CommonConfiguration getConfiguration() { - return configuration; - } - @Override public URIBuilder newURIBuilder(final String serviceRoot) { return new URIBuilderImpl(getServiceVersion(), configuration, serviceRoot); @@ -108,8 +99,8 @@ public class ODataClientImpl extends AbstractODataClient implements @Override public ODataSerializer getSerializer(final ODataFormat format) { - return format == ODataFormat.ATOM || format == ODataFormat.XML ? - new AtomSerializer(getServiceVersion()) : new JsonSerializer(getServiceVersion(), false); + return format == ODataFormat.ATOM || format == ODataFormat.XML + ? new AtomSerializer(getServiceVersion()) : new JsonSerializer(getServiceVersion(), false); } @Override diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/ODataClientImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/ODataClientImpl.java index dec4e841f..c1a4f1df7 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/ODataClientImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/ODataClientImpl.java @@ -34,7 +34,6 @@ import org.apache.olingo.client.api.uri.v4.SearchFactory; import org.apache.olingo.client.api.uri.v4.URIBuilder; import org.apache.olingo.client.api.v4.ODataClient; import org.apache.olingo.client.core.AbstractODataClient; -import org.apache.olingo.client.core.Configuration; import org.apache.olingo.client.core.communication.header.ODataHeadersImpl; import org.apache.olingo.client.core.communication.request.batch.v4.BatchRequestFactoryImpl; import org.apache.olingo.client.core.communication.request.cud.v4.CUDRequestFactoryImpl; @@ -56,8 +55,6 @@ import org.apache.olingo.commons.core.serialization.JsonSerializer; public class ODataClientImpl extends AbstractODataClient implements ODataClient { - protected final Configuration configuration = new Configuration(); - private final FilterFactory filterFactory = new FilterFactoryImpl(getServiceVersion()); private final SearchFactory searchFactory = new SearchFactoryImpl(); @@ -91,11 +88,6 @@ public class ODataClientImpl extends AbstractODataClient implements return odataHeaders; } - @Override - public Configuration getConfiguration() { - return configuration; - } - @Override public URIBuilder newURIBuilder(final String serviceRoot) { return new URIBuilderImpl(getServiceVersion(), getConfiguration(), serviceRoot); @@ -118,8 +110,8 @@ public class ODataClientImpl extends AbstractODataClient implements @Override public ODataSerializer getSerializer(final ODataFormat format) { - return format == ODataFormat.ATOM || format == ODataFormat.XML ? - new AtomSerializer(getServiceVersion()) : new JsonSerializer(getServiceVersion(), false); + return format == ODataFormat.ATOM || format == ODataFormat.XML + ? new AtomSerializer(getServiceVersion()) : new JsonSerializer(getServiceVersion(), false); } @Override diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java index 648a0064b..5fa44ce67 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java @@ -1,21 +1,21 @@ -/******************************************************************************* +/* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * 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 - * + * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. - ******************************************************************************/ + */ package org.apache.olingo.commons.api.format; import java.util.ArrayList; @@ -30,7 +30,7 @@ import java.util.TreeMap; /** * Internally used {@link ContentType} for OData library. - * + * * For more details on format and content of a {@link ContentType} see * Media Type format as defined in * RFC 7231, chapter 3.1.1.1. @@ -40,35 +40,52 @@ import java.util.TreeMap; * subtype = token * OWS = *( SP / HTAB ) ; optional whitespace * - * + * * Once created a {@link ContentType} is IMMUTABLE. */ -public class ContentType { +public final class ContentType { public static final ContentType APPLICATION_XML = create("application/xml"); + public static final ContentType APPLICATION_ATOM_XML = create("application/atom+xml"); + public static final ContentType APPLICATION_ATOM_XML_ENTRY = create(APPLICATION_ATOM_XML, "type=entry"); + public static final ContentType APPLICATION_ATOM_XML_FEED = create(APPLICATION_ATOM_XML, "type=feed"); + public static final ContentType APPLICATION_ATOM_SVC = create("application/atomsvc+xml"); + public static final ContentType APPLICATION_JSON = create("application/json"); + public static final ContentType APPLICATION_OCTET_STREAM = create("application/octet-stream"); + public static final ContentType TEXT_PLAIN = create("text/plain"); + public static final ContentType MULTIPART_MIXED = create("multipart/mixed"); + public static final ContentType APPLICATION_XHTML_XML = create("application/xhtml+xml"); + public static final ContentType APPLICATION_SVG_XML = create("application/svg+xml"); + public static final ContentType APPLICATION_FORM_URLENCODED = create("application/x-www-form-urlencoded"); + public static final ContentType MULTIPART_FORM_DATA = create("multipart/form-data"); + public static final ContentType TEXT_XML = create("text/xml"); + public static final ContentType TEXT_HTML = create("text/html"); public static final String PARAMETER_CHARSET_UTF8 = "charset=utf-8"; private final String type; + private final String subtype; + private final Map parameters; /** * Creates a content type from type, subtype, and parameters. + * * @param type * @param subtype * @param parameters @@ -105,6 +122,7 @@ public class ContentType { /** * Validates if given format is parseable and can be used as input for {@link #create(String)} method. + * * @param format to be validated string * @return true if format is parseable otherwise false */ @@ -118,6 +136,7 @@ public class ContentType { /** * Creates a content type from format and key-value pairs for parameters + * * @param format for example "application/json" * @param parameters for example "a=b", "c=d" * @return a new ContentType object @@ -126,7 +145,7 @@ public class ContentType { ContentType ct = parse(format); for (String p : parameters) { - String[] keyvalue = p.split("="); + final String[] keyvalue = p.split("="); ct.parameters.put(keyvalue[0], keyvalue[1]); } @@ -135,7 +154,8 @@ public class ContentType { /** * Creates a content type from format and key-value pairs for parameters - * @param format for example "application/json" + * + * @param contentType for example "application/json" * @param parameters for example "a=b", "c=d" * @return a new ContentType object */ @@ -151,8 +171,9 @@ public class ContentType { } /** - * Creates a {@link ContentType} based on given input string (format). - * Supported format is Media Type format as defined in RFC 7231, chapter 3.1.1.1. + * Creates a {@link ContentType} based on given input string (format). Supported format is + * Media Type format as defined in RFC 7231, chapter 3.1.1.1. + * * @param format a string in format as defined in RFC 7231, chapter 3.1.1.1 * @return a new ContentType object * @throws IllegalArgumentException if input string is not parseable @@ -161,8 +182,8 @@ public class ContentType { if (format == null) { throw new IllegalArgumentException("Parameter format MUST NOT be NULL."); } - List typeSubtype = new ArrayList(); - Map parameters = new HashMap(); + final List typeSubtype = new ArrayList(); + final Map parameters = new HashMap(); parse(format, typeSubtype, parameters); return new ContentType(typeSubtype.get(0), typeSubtype.get(1), parameters); } @@ -170,9 +191,9 @@ public class ContentType { /** * Parses the given input string (format) and returns created {@link ContentType} if input was valid or * return NULL if input was not parseable. - * + * * For the definition of the supported format see {@link #create(String)}. - * + * * @param format a string in format as defined in RFC 7231, chapter 3.1.1.1 * @return a new ContentType object */ @@ -184,14 +205,13 @@ public class ContentType { } } - private static void - parse(final String format, final List typeSubtype, final Map parameters) { + private static void parse(final String format, final List typeSubtype, final Map parameters) { final String[] typesAndParameters = format.split(TypeUtil.PARAMETER_SEPARATOR, 2); final String types = typesAndParameters[0]; final String params = (typesAndParameters.length > 1 ? typesAndParameters[1] : null); if (types.contains(TypeUtil.TYPE_SUBTYPE_SEPARATOR)) { - String[] tokens = types.split(TypeUtil.TYPE_SUBTYPE_SEPARATOR); + final String[] tokens = types.split(TypeUtil.TYPE_SUBTYPE_SEPARATOR); if (tokens.length == 2) { if (tokens[0] == null || tokens[0].isEmpty()) { throw new IllegalArgumentException("No type found in format '" + format + "'."); @@ -203,11 +223,11 @@ public class ContentType { } } else { throw new IllegalArgumentException( - "Too many '" + TypeUtil.TYPE_SUBTYPE_SEPARATOR + "' in format '" + format + "'."); + "Too many '" + TypeUtil.TYPE_SUBTYPE_SEPARATOR + "' in format '" + format + "'."); } } else { throw new IllegalArgumentException("No separator '" + TypeUtil.TYPE_SUBTYPE_SEPARATOR - + "' was found in format '" + format + "'."); + + "' was found in format '" + format + "'."); } TypeUtil.parseParameters(params, parameters); @@ -222,7 +242,7 @@ public class ContentType { } /** - * + * * @return parameters of this {@link ContentType} as unmodifiable map. */ public Map getParameters() { @@ -241,13 +261,13 @@ public class ContentType { *

  • if type and/or subtype is set to "*" (in such a case the parameters are * ignored).
  • * - * + * * @return true if both instances are equal (see definition above), otherwise false. */ @Override public boolean equals(final Object obj) { // NULL validation is done in method 'isEqualWithoutParameters(obj)' - Boolean compatible = isEqualWithoutParameters(obj); + final Boolean compatible = isEqualWithoutParameters(obj); if (compatible == null) { ContentType other = (ContentType) obj; @@ -258,11 +278,11 @@ public class ContentType { return false; } } else if (parameters.size() == other.parameters.size()) { - Iterator> entries = parameters.entrySet().iterator(); - Iterator> otherEntries = other.parameters.entrySet().iterator(); + final Iterator> entries = parameters.entrySet().iterator(); + final Iterator> otherEntries = other.parameters.entrySet().iterator(); while (entries.hasNext()) { - Entry e = entries.next(); - Entry oe = otherEntries.next(); + final Entry e = entries.next(); + final Entry oe = otherEntries.next(); if (!areEqual(e.getKey(), oe.getKey())) { return false; @@ -289,7 +309,7 @@ public class ContentType { * * The set parameters are always ignored (for compare with parameters see {@link #equals(Object)} * ). - * + * * @return true if both instances are equal (see definition above), otherwise false. */ public boolean isCompatible(final ContentType obj) { @@ -301,13 +321,12 @@ public class ContentType { } /** - * Check equal without parameters. - * It is possible that no decision about equal/none equal can be determined a NULL is - * returned. - * + * Check equal without parameters. It is possible that no decision about equal/none equal can be + * determined a NULL is returned. + * * @param obj to checked object - * @return true if both instances are equal (see definition above), otherwise false - * or NULL if no decision about equal/none equal could be determined. + * @return true if both instances are equal (see definition above), otherwise false or + * NULL if no decision about equal/none equal could be determined. */ private Boolean isEqualWithoutParameters(final Object obj) { // basic checks @@ -346,7 +365,7 @@ public class ContentType { /** * Check whether both string are equal ignoring the case of the strings. - * + * * @param first first string * @param second second string * @return true if both strings are equal (by ignoring the case), otherwise false is @@ -357,12 +376,13 @@ public class ContentType { } /** - * Get {@link ContentType} as string as defined in RFC 7231 - * (http://www.ietf.org/rfc/rfc7231.txt, chapter 3.1.1.1: Media Type) + * Get {@link ContentType} as string as defined in RFC 7231 (http://www.ietf.org/rfc/rfc7231.txt, chapter 3.1.1.1: + * Media Type) + * * @return string representation of ContentType object */ public String toContentTypeString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append(type).append(TypeUtil.TYPE_SUBTYPE_SEPARATOR).append(subtype); diff --git a/pom.xml b/pom.xml index 447aaa8ca..213a050a5 100644 --- a/pom.xml +++ b/pom.xml @@ -84,6 +84,8 @@ 4.1 + 4.1.1.4 + 1.7.7 ${project.build.directory}/log @@ -165,6 +167,13 @@ 0.9.9 + + com.google.android + android + ${android.platform.version} + provided + + org.slf4j slf4j-api @@ -248,9 +257,9 @@ - com.keyboardsamurais.maven - maven-timestamp-plugin - 1.0 + com.keyboardsamurais.maven + maven-timestamp-plugin + 1.0 org.apache.rat @@ -344,11 +353,17 @@ + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + org.sonatype.plugins jarjar-maven-plugin - 1.8 + 1.9