Several Android enhancements

This commit is contained in:
Francesco Chicchiriccò 2014-07-12 17:34:21 +02:00
parent 4e61f1093d
commit c3a709309e
69 changed files with 484 additions and 698 deletions

View File

@ -39,7 +39,12 @@
<groupId>org.apache.olingo</groupId> <groupId>org.apache.olingo</groupId>
<artifactId>olingo-client-core</artifactId> <artifactId>olingo-client-core</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<optional>true</optional> <scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
@ -65,7 +70,6 @@
<include>org.apache.commons:commons-lang3</include> <include>org.apache.commons:commons-lang3</include>
<include>org.slf4j:slf4j-api</include> <include>org.slf4j:slf4j-api</include>
<include>commons-io:commons-io</include> <include>commons-io:commons-io</include>
<include>org.apache.httpcomponents:httpcore</include>
<include>com.fasterxml.jackson.core:jackson-core</include> <include>com.fasterxml.jackson.core:jackson-core</include>
<include>com.fasterxml.jackson.core:jackson-databind</include> <include>com.fasterxml.jackson.core:jackson-databind</include>
<include>com.fasterxml.jackson.core:jackson-annotations</include> <include>com.fasterxml.jackson.core:jackson-annotations</include>

View File

@ -16,11 +16,28 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * 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 {
public interface Configuration extends CommonConfiguration { 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();
}
}
} }

View File

@ -39,12 +39,37 @@
<groupId>org.apache.olingo</groupId> <groupId>org.apache.olingo</groupId>
<artifactId>olingo-client-proxy</artifactId> <artifactId>olingo-client-proxy</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<optional>true</optional> <scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<inherited>true</inherited>
<executions>
<execution>
<id>add-client-core-proxy-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/../client-core-android/src/main/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin> <plugin>
<groupId>org.sonatype.plugins</groupId> <groupId>org.sonatype.plugins</groupId>
<artifactId>jarjar-maven-plugin</artifactId> <artifactId>jarjar-maven-plugin</artifactId>
@ -67,7 +92,6 @@
<include>org.apache.commons:commons-lang3</include> <include>org.apache.commons:commons-lang3</include>
<include>org.slf4j:slf4j-api</include> <include>org.slf4j:slf4j-api</include>
<include>commons-io:commons-io</include> <include>commons-io:commons-io</include>
<include>org.apache.httpcomponents:httpcore</include>
<include>com.fasterxml.jackson.core:jackson-core</include> <include>com.fasterxml.jackson.core:jackson-core</include>
<include>com.fasterxml.jackson.core:jackson-databind</include> <include>com.fasterxml.jackson.core:jackson-databind</include>
<include>com.fasterxml.jackson.core:jackson-annotations</include> <include>com.fasterxml.jackson.core:jackson-annotations</include>

View File

@ -23,13 +23,13 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import org.apache.olingo.client.api.CommonConfiguration; import org.apache.olingo.client.api.Configuration;
public abstract class AsyncCall<V> implements Future<V> { public abstract class AsyncCall<V> implements Future<V> {
private final Future<V> future; private final Future<V> future;
public AsyncCall(final CommonConfiguration configuration) { public AsyncCall(final Configuration configuration) {
this.future = configuration.getExecutor().submit(new Callable<V>() { this.future = configuration.getExecutor().submit(new Callable<V>() {
@Override @Override

View File

@ -54,8 +54,8 @@ public class TransactionalPersistenceManagerImpl extends AbstractPersistenceMana
protected void doFlush(final PersistenceChanges changes, final TransactionItems items) { protected void doFlush(final PersistenceChanges changes, final TransactionItems items) {
final CommonODataBatchRequest request = final CommonODataBatchRequest request =
factory.getClient().getBatchRequestFactory().getBatchRequest(factory.getClient().getServiceRoot()); factory.getClient().getBatchRequestFactory().getBatchRequest(factory.getClient().getServiceRoot());
String accept = factory.getClient().getConfiguration().getDefaultBatchAcceptFormat().toContentTypeString(); ((ODataRequest) request).setAccept(
((ODataRequest) request).setAccept(accept); factory.getClient().getConfiguration().getDefaultBatchAcceptFormat().toContentTypeString());
final BatchManager streamManager = (BatchManager) ((ODataStreamedRequest) request).payloadManager(); final BatchManager streamManager = (BatchManager) ((ODataStreamedRequest) request).payloadManager();
@ -105,5 +105,6 @@ public class TransactionalPersistenceManagerImpl extends AbstractPersistenceMana
} }
} }
} }
response.close();
} }
} }

View File

@ -38,7 +38,6 @@ import java.util.regex.Pattern;
import javax.ws.rs.NotFoundException; import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.xml.stream.XMLStreamException;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;

View File

@ -75,16 +75,13 @@ public class ErrorTestITCase extends AbstractTestITCase {
private class ErrorResponseImpl extends AbstractODataResponse implements ODataEntityCreateResponse<ODataEntity> { private class ErrorResponseImpl extends AbstractODataResponse implements ODataEntityCreateResponse<ODataEntity> {
private final ODataClient odataClient;
public ErrorResponseImpl(final ODataClient odataClient, final HttpClient client, final HttpResponse res) { public ErrorResponseImpl(final ODataClient odataClient, final HttpClient client, final HttpResponse res) {
super(client, res); super(odataClient, client, res);
this.odataClient = odataClient;
} }
@Override @Override
public ODataEntity getBody() { public ODataEntity getBody() {
return odataClient.getObjectFactory().newEntity(new FullQualifiedName("Invalid.Invalid")); return ((ODataClient) odataClient).getObjectFactory().newEntity(new FullQualifiedName("Invalid.Invalid"));
} }
} }
} }

View File

@ -47,7 +47,7 @@ public interface CommonODataClient<UT extends CommonUpdateType> {
ODataHeaders newVersionHeaders(); ODataHeaders newVersionHeaders();
CommonConfiguration getConfiguration(); Configuration getConfiguration();
ODataPreferences newPreferences(); ODataPreferences newPreferences();

View File

@ -28,7 +28,7 @@ import org.apache.olingo.commons.api.format.ODataFormat;
/** /**
* Configuration wrapper. * Configuration wrapper.
*/ */
public interface CommonConfiguration { public interface Configuration {
/** /**
* Gets the configured default <tt>Accept</tt> header value format for a batch request. * Gets the configured default <tt>Accept</tt> header value format for a batch request.

View File

@ -50,11 +50,11 @@ public interface ODataBatchResponseItem extends Iterator<ODataResponse> {
boolean isChangeset(); 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. * @return 'TRUE' if breaking; 'FALSE' otherwise.
*/ */
boolean isBreakingitem(); boolean isBreaking();
/** /**
* Closes the current batch responses item including all wrapped OData responses. * Closes the current batch responses item including all wrapped OData responses.

View File

@ -26,5 +26,7 @@ import org.apache.http.client.HttpClient;
*/ */
public interface HttpClientFactory { public interface HttpClientFactory {
HttpClient createHttpClient(HttpMethod method, URI uri); HttpClient create(HttpMethod method, URI uri);
void close(HttpClient httpClient);
} }

View File

@ -26,5 +26,5 @@ import org.apache.http.client.methods.HttpUriRequest;
*/ */
public interface HttpUriRequestFactory { public interface HttpUriRequestFactory {
HttpUriRequest createHttpUriRequest(HttpMethod method, URI uri); HttpUriRequest create(HttpMethod method, URI uri);
} }

View File

@ -18,7 +18,6 @@
*/ */
package org.apache.olingo.client.api.v3; 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.CommonODataClient;
import org.apache.olingo.client.api.communication.request.batch.v3.BatchRequestFactory; import org.apache.olingo.client.api.communication.request.batch.v3.BatchRequestFactory;
import org.apache.olingo.client.api.communication.request.cud.v3.CUDRequestFactory; 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<UpdateType> { public interface ODataClient extends CommonODataClient<UpdateType> {
@Override
CommonConfiguration getConfiguration();
@Override @Override
ODataDeserializer getDeserializer(ODataFormat format); ODataDeserializer getDeserializer(ODataFormat format);

View File

@ -18,7 +18,6 @@
*/ */
package org.apache.olingo.client.api.v4; 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.CommonODataClient;
import org.apache.olingo.client.api.communication.request.batch.v4.BatchRequestFactory; import org.apache.olingo.client.api.communication.request.batch.v4.BatchRequestFactory;
import org.apache.olingo.client.api.communication.request.cud.v4.CUDRequestFactory; 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<UpdateType> { public interface ODataClient extends CommonODataClient<UpdateType> {
@Override
CommonConfiguration getConfiguration();
@Override @Override
ODataDeserializer getDeserializer(ODataFormat format); ODataDeserializer getDeserializer(ODataFormat format);

View File

@ -19,6 +19,7 @@
package org.apache.olingo.client.core; package org.apache.olingo.client.core;
import org.apache.olingo.client.api.CommonODataClient; 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.header.ODataPreferences;
import org.apache.olingo.client.api.communication.request.cud.CommonUpdateType; import org.apache.olingo.client.api.communication.request.cud.CommonUpdateType;
import org.apache.olingo.client.api.serialization.ODataWriter; import org.apache.olingo.client.api.serialization.ODataWriter;
@ -26,8 +27,15 @@ import org.apache.olingo.client.core.serialization.ODataWriterImpl;
public abstract class AbstractODataClient<UT extends CommonUpdateType> implements CommonODataClient<UT> { public abstract class AbstractODataClient<UT extends CommonUpdateType> implements CommonODataClient<UT> {
protected final Configuration configuration = new ConfigurationImpl();
private final ODataWriter writer = new ODataWriterImpl(this); private final ODataWriter writer = new ODataWriterImpl(this);
@Override
public Configuration getConfiguration() {
return configuration;
}
@Override @Override
public ODataPreferences newPreferences() { public ODataPreferences newPreferences() {
return new ODataPreferences(getServiceVersion()); return new ODataPreferences(getServiceVersion());

View File

@ -23,7 +23,7 @@ import java.util.Map;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; 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.HttpClientFactory;
import org.apache.olingo.client.api.http.HttpUriRequestFactory; import org.apache.olingo.client.api.http.HttpUriRequestFactory;
import org.apache.olingo.client.core.http.DefaultHttpClientFactory; 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.ContentType;
import org.apache.olingo.commons.api.format.ODataFormat; 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"; private static final String DEFAULT_PUB_FORMAT = "pubFormat";

View File

@ -20,7 +20,6 @@ package org.apache.olingo.client.core;
import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.format.ODataFormat;
public final class ODataClientFactory { public final class ODataClientFactory {
public static org.apache.olingo.client.api.v3.ODataClient getV3() { public static org.apache.olingo.client.api.v3.ODataClient getV3() {

View File

@ -89,6 +89,7 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD
* @param uri OData request URI. * @param uri OData request URI.
*/ */
protected AbstractODataRequest(final CommonODataClient<?> odataClient, final HttpMethod method, final URI uri) { protected AbstractODataRequest(final CommonODataClient<?> odataClient, final HttpMethod method, final URI uri) {
super();
this.odataClient = odataClient; this.odataClient = odataClient;
this.method = method; this.method = method;
@ -99,15 +100,13 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD
// target uri // target uri
this.uri = uri; this.uri = uri;
HttpClient _httpClient = odataClient.getConfiguration().getHttpClientFactory(). HttpClient _httpClient = odataClient.getConfiguration().getHttpClientFactory().create(this.method, this.uri);
createHttpClient(this.method, this.uri);
if (odataClient.getConfiguration().isGzipCompression()) { if (odataClient.getConfiguration().isGzipCompression()) {
_httpClient = new DecompressingHttpClient(_httpClient); _httpClient = new DecompressingHttpClient(_httpClient);
} }
this.httpClient = _httpClient; this.httpClient = _httpClient;
this.request = odataClient.getConfiguration().getHttpUriRequestFactory(). this.request = odataClient.getConfiguration().getHttpUriRequestFactory().create(this.method, this.uri);
createHttpUriRequest(this.method, this.uri);
} }
public abstract ODataFormat getDefaultFormat(); public abstract ODataFormat getDefaultFormat();
@ -184,9 +183,9 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD
@Override @Override
public String getAccept() { public String getAccept() {
final String acceptHead = odataHeaders.getHeader(HeaderName.accept); final String acceptHead = odataHeaders.getHeader(HeaderName.accept);
return StringUtils.isBlank(acceptHead) ? return StringUtils.isBlank(acceptHead)
getDefaultFormat().getContentType(odataClient.getServiceVersion()).toContentTypeString() : ? getDefaultFormat().getContentType(odataClient.getServiceVersion()).toContentTypeString()
acceptHead; : acceptHead;
} }
@Override @Override
@ -207,9 +206,9 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD
@Override @Override
public String getContentType() { public String getContentType() {
final String contentTypeHead = odataHeaders.getHeader(HeaderName.contentType); final String contentTypeHead = odataHeaders.getHeader(HeaderName.contentType);
return StringUtils.isBlank(contentTypeHead) ? return StringUtils.isBlank(contentTypeHead)
getDefaultFormat().getContentType(odataClient.getServiceVersion()).toContentTypeString() : ? getDefaultFormat().getContentType(odataClient.getServiceVersion()).toContentTypeString()
contentTypeHead; : contentTypeHead;
} }
@Override @Override
@ -326,21 +325,21 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD
/** /**
* Gets an empty response that can be initialized by a stream. * Gets an empty response that can be initialized by a stream.
* <p> * <br/>
* This method has to be used to build response items about a batch request. * This method has to be used to build response items about a batch request.
* *
* @param <V> ODataResppnse type. * @param <V> ODataResponse type.
* @return empty OData response instance. * @return empty OData response instance.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <V extends ODataResponse> V getResponseTemplate() { public <V extends ODataResponse> V getResponseTemplate() {
for (Class<?> clazz : this.getClass().getDeclaredClasses()) { for (Class<?> clazz : this.getClass().getDeclaredClasses()) {
if (ODataResponse.class.isAssignableFrom(clazz)) { if (ODataResponse.class.isAssignableFrom(clazz)) {
try { try {
final Constructor<?> constructor = clazz.getDeclaredConstructor(this.getClass()); final Constructor<?> constructor = clazz.getDeclaredConstructor(
this.getClass(), CommonODataClient.class, HttpClient.class, HttpResponse.class);
constructor.setAccessible(true); constructor.setAccessible(true);
return (V) constructor.newInstance(this); return (V) constructor.newInstance(this, odataClient, httpClient, null);
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error retrieving response class template instance", e); LOG.error("Error retrieving response class template instance", e);
} }

View File

@ -72,7 +72,7 @@ public abstract class AbstractODataBatchResponseItem implements ODataBatchRespon
*/ */
protected ODataResponse current; protected ODataResponse current;
protected boolean breakingitem = false; protected boolean breaking = false;
/** /**
* Constructor. * Constructor.
@ -143,15 +143,15 @@ public abstract class AbstractODataBatchResponseItem implements ODataBatchRespon
expectedItemsIterator = responses.values().iterator(); expectedItemsIterator = responses.values().iterator();
} }
return !breakingitem && expectedItemsIterator.hasNext(); return !breaking && expectedItemsIterator.hasNext();
} }
/** /**
* {@inheritDoc } * {@inheritDoc }
*/ */
@Override @Override
public boolean isBreakingitem() { public boolean isBreaking() {
return breakingitem; return breaking;
} }
/** /**

View File

@ -63,7 +63,7 @@ public class ODataChangesetResponseItem extends AbstractODataBatchResponseItem {
} }
if (unexpected) { if (unexpected) {
breakingitem = true; breaking = true;
return nextUnexpected(); return nextUnexpected();
} else { } else {
return nextExpected(); return nextExpected();
@ -107,7 +107,7 @@ public class ODataChangesetResponseItem extends AbstractODataBatchResponseItem {
if (current.getStatusCode() >= 400) { if (current.getStatusCode() >= 400) {
// found error .... // found error ....
breakingitem = true; breaking = true;
} }
return current; return current;

View File

@ -27,8 +27,7 @@ import org.apache.olingo.client.core.communication.request.AbstractODataRequest;
/** /**
* Retrieve request wrapper for the corresponding batch item. * Retrieve request wrapper for the corresponding batch item.
*/ */
public class ODataSingleRequestImpl extends AbstractODataBatchRequestItem public class ODataSingleRequestImpl extends AbstractODataBatchRequestItem implements ODataSingleRequest {
implements ODataSingleRequest {
private final ODataSingleResponseItem expectedResItem; private final ODataSingleResponseItem expectedResItem;

View File

@ -22,7 +22,6 @@ import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import org.apache.olingo.client.api.communication.response.ODataResponse; 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.batch.ODataBatchErrorResponse;
import org.apache.olingo.client.core.communication.response.v4.AsyncResponseImpl; import org.apache.olingo.client.core.communication.response.v4.AsyncResponseImpl;
@ -62,11 +61,11 @@ public class ODataSingleResponseItem extends AbstractODataBatchResponseItem {
if (responseLine.getKey() == 202) { if (responseLine.getKey() == 202) {
// generate async response // generate async response
current = new AsyncResponseImpl(responseLine, headers, batchLineIterator, boundary); current = new AsyncResponseImpl(responseLine, headers, batchLineIterator, boundary);
breakingitem = true; breaking = true;
} else if (responseLine.getKey() >= 400) { } else if (responseLine.getKey() >= 400) {
// generate error response // generate error response
current = new ODataBatchErrorResponse(responseLine, headers, batchLineIterator, boundary); current = new ODataBatchErrorResponse(responseLine, headers, batchLineIterator, boundary);
breakingitem = true; breaking = true;
} else { } else {
if (!hasNext()) { if (!hasNext()) {
throw new NoSuchElementException("No item found"); throw new NoSuchElementException("No item found");

View File

@ -24,6 +24,7 @@ import java.util.Iterator;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient; 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.ODataBatchableRequest;
import org.apache.olingo.client.api.communication.request.ODataStreamedRequest; import org.apache.olingo.client.api.communication.request.ODataStreamedRequest;
import org.apache.olingo.client.api.communication.request.batch.BatchManager; import org.apache.olingo.client.api.communication.request.batch.BatchManager;
@ -89,7 +90,7 @@ public class ODataBatchRequestImpl
@Override @Override
protected ODataBatchResponse getResponseInstance(final long timeout, final TimeUnit unit) { 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 @Override
@ -107,14 +108,10 @@ public class ODataBatchRequestImpl
*/ */
protected class ODataBatchResponseImpl extends AbstractODataResponse implements ODataBatchResponse { protected class ODataBatchResponseImpl extends AbstractODataResponse implements ODataBatchResponse {
/** protected ODataBatchResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
*
* @param client HTTP client. super(odataClient, httpClient, res);
* @param res HTTP response.
*/
protected ODataBatchResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
/** /**

View File

@ -24,6 +24,7 @@ import java.util.Iterator;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient; 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.HeaderName;
import org.apache.olingo.client.api.communication.header.ODataPreferences; import org.apache.olingo.client.api.communication.header.ODataPreferences;
import org.apache.olingo.client.api.communication.request.ODataBatchableRequest; import org.apache.olingo.client.api.communication.request.ODataBatchableRequest;
@ -95,7 +96,7 @@ public class ODataBatchRequestImpl
@Override @Override
protected ODataBatchResponse getResponseInstance(final long timeout, final TimeUnit unit) { 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 @Override
@ -110,17 +111,10 @@ public class ODataBatchRequestImpl
*/ */
protected class ODataBatchResponseImpl extends AbstractODataResponse implements ODataBatchResponse { protected class ODataBatchResponseImpl extends AbstractODataResponse implements ODataBatchResponse {
private ODataBatchResponseImpl() { protected ODataBatchResponseImpl(
} final CommonODataClient<?> odataClient, final HttpClient httpClient, final HttpResponse res) {
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
protected ODataBatchResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
/** /**

View File

@ -37,13 +37,6 @@ import org.apache.olingo.commons.api.format.ODataFormat;
public class ODataDeleteRequestImpl extends AbstractODataBasicRequest<ODataDeleteResponse> public class ODataDeleteRequestImpl extends AbstractODataBasicRequest<ODataDeleteResponse>
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) { ODataDeleteRequestImpl(final CommonODataClient<?> odataClient, final HttpMethod method, final URI uri) {
super(odataClient, method, uri); super(odataClient, method, uri);
} }
@ -63,7 +56,7 @@ public class ODataDeleteRequestImpl extends AbstractODataBasicRequest<ODataDelet
@Override @Override
public ODataDeleteResponse execute() { public ODataDeleteResponse execute() {
return new ODataDeleteResponseImpl(httpClient, doExecute()); return new ODataDeleteResponseImpl(odataClient, httpClient, doExecute());
} }
/** /**
@ -71,22 +64,10 @@ public class ODataDeleteRequestImpl extends AbstractODataBasicRequest<ODataDelet
*/ */
private class ODataDeleteResponseImpl extends AbstractODataResponse implements ODataDeleteResponse { private class ODataDeleteResponseImpl extends AbstractODataResponse implements ODataDeleteResponse {
/** private ODataDeleteResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataDeleteResponseImpl() {
}
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataDeleteResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
this.close(); this.close();
} }
} }

View File

@ -85,7 +85,7 @@ public class ODataEntityCreateRequestImpl<E extends CommonODataEntity>
((HttpPost) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input)); ((HttpPost) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input));
try { try {
return new ODataEntityCreateResponseImpl(httpClient, doExecute()); return new ODataEntityCreateResponseImpl(odataClient, httpClient, doExecute());
} finally { } finally {
IOUtils.closeQuietly(input); IOUtils.closeQuietly(input);
} }
@ -98,23 +98,10 @@ public class ODataEntityCreateRequestImpl<E extends CommonODataEntity>
private E entity = null; private E entity = null;
/** private ODataEntityCreateResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataEntityCreateResponseImpl() {
super();
}
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataEntityCreateResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
/** /**
@ -125,8 +112,8 @@ public class ODataEntityCreateRequestImpl<E extends CommonODataEntity>
public E getBody() { public E getBody() {
if (entity == null) { if (entity == null) {
try { try {
final ResWrap<Entity> resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept())) final ResWrap<Entity> resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept())).
.toEntity(getRawResponse()); toEntity(getRawResponse());
entity = (E) odataClient.getBinder().getODataEntity(resource); entity = (E) odataClient.getBinder().getODataEntity(resource);
} catch (final ODataDeserializerException e) { } catch (final ODataDeserializerException e) {

View File

@ -73,18 +73,6 @@ public class ODataEntityUpdateRequestImpl<E extends CommonODataEntity>
return odataClient.getConfiguration().getDefaultPubFormat(); return odataClient.getConfiguration().getDefaultPubFormat();
} }
@Override
public ODataEntityUpdateResponse<E> execute() {
final InputStream input = getPayload();
((HttpEntityEnclosingRequestBase) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input));
try {
return new ODataEntityUpdateResponseImpl(httpClient, doExecute());
} finally {
IOUtils.closeQuietly(input);
}
}
@Override @Override
protected InputStream getPayload() { protected InputStream getPayload() {
try { try {
@ -94,6 +82,18 @@ public class ODataEntityUpdateRequestImpl<E extends CommonODataEntity>
} }
} }
@Override
public ODataEntityUpdateResponse<E> 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. * Response class about an ODataEntityUpdateRequest.
*/ */
@ -104,21 +104,10 @@ public class ODataEntityUpdateRequestImpl<E extends CommonODataEntity>
*/ */
private E entity = null; private E entity = null;
/** private ODataEntityUpdateResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataEntityUpdateResponseImpl() {}
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataEntityUpdateResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
@Override @Override
@ -126,8 +115,8 @@ public class ODataEntityUpdateRequestImpl<E extends CommonODataEntity>
public E getBody() { public E getBody() {
if (entity == null) { if (entity == null) {
try { try {
final ResWrap<Entity> resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept())) final ResWrap<Entity> resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept())).
.toEntity(getRawResponse()); toEntity(getRawResponse());
entity = (E) odataClient.getBinder().getODataEntity(resource); entity = (E) odataClient.getBinder().getODataEntity(resource);
} catch (final ODataDeserializerException e) { } catch (final ODataDeserializerException e) {

View File

@ -77,7 +77,7 @@ public class ODataPropertyUpdateRequestImpl extends AbstractODataBasicRequest<OD
((HttpEntityEnclosingRequestBase) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input)); ((HttpEntityEnclosingRequestBase) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input));
try { try {
return new ODataPropertyUpdateResponseImpl(httpClient, doExecute()); return new ODataPropertyUpdateResponseImpl(odataClient, httpClient, doExecute());
} finally { } finally {
IOUtils.closeQuietly(input); IOUtils.closeQuietly(input);
} }
@ -99,30 +99,18 @@ public class ODataPropertyUpdateRequestImpl extends AbstractODataBasicRequest<OD
private CommonODataProperty property = null; private CommonODataProperty property = null;
/** private ODataPropertyUpdateResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataPropertyUpdateResponseImpl() {
}
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataPropertyUpdateResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
@Override @Override
public CommonODataProperty getBody() { public CommonODataProperty getBody() {
if (property == null) { if (property == null) {
try { try {
final ResWrap<Property> resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept())) final ResWrap<Property> resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept())).
.toProperty(getRawResponse()); toProperty(getRawResponse());
property = odataClient.getBinder().getODataProperty(resource); property = odataClient.getBinder().getODataProperty(resource);
} catch (final ODataDeserializerException e) { } catch (final ODataDeserializerException e) {

View File

@ -75,7 +75,7 @@ public class ODataValueUpdateRequestImpl extends AbstractODataBasicRequest<OData
((HttpEntityEnclosingRequestBase) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input)); ((HttpEntityEnclosingRequestBase) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input));
try { try {
return new ODataValueUpdateResponseImpl(httpClient, doExecute()); return new ODataValueUpdateResponseImpl(odataClient, httpClient, doExecute());
} finally { } finally {
IOUtils.closeQuietly(input); IOUtils.closeQuietly(input);
} }
@ -96,23 +96,10 @@ public class ODataValueUpdateRequestImpl extends AbstractODataBasicRequest<OData
private ODataPrimitiveValue value = null; private ODataPrimitiveValue value = null;
/** private ODataValueUpdateResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataValueUpdateResponseImpl() {
super();
}
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataValueUpdateResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
@Override @Override

View File

@ -71,7 +71,7 @@ public class ODataLinkCreateRequestImpl extends AbstractODataBasicRequest<ODataL
((HttpPost) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input)); ((HttpPost) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input));
try { try {
return new ODataLinkCreateResponseImpl(httpClient, doExecute()); return new ODataLinkCreateResponseImpl(odataClient, httpClient, doExecute());
} finally { } finally {
IOUtils.closeQuietly(input); IOUtils.closeQuietly(input);
} }
@ -91,22 +91,10 @@ public class ODataLinkCreateRequestImpl extends AbstractODataBasicRequest<ODataL
*/ */
private class ODataLinkCreateResponseImpl extends AbstractODataResponse implements ODataLinkOperationResponse { private class ODataLinkCreateResponseImpl extends AbstractODataResponse implements ODataLinkOperationResponse {
/** private ODataLinkCreateResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataLinkCreateResponseImpl() {
}
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataLinkCreateResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
} }
} }

View File

@ -73,7 +73,7 @@ public class ODataLinkUpdateRequestImpl extends AbstractODataBasicRequest<ODataL
((HttpEntityEnclosingRequestBase) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input)); ((HttpEntityEnclosingRequestBase) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input));
try { try {
return new ODataLinkUpdateResponseImpl(httpClient, doExecute()); return new ODataLinkUpdateResponseImpl(odataClient, httpClient, doExecute());
} finally { } finally {
IOUtils.closeQuietly(input); IOUtils.closeQuietly(input);
} }
@ -93,14 +93,10 @@ public class ODataLinkUpdateRequestImpl extends AbstractODataBasicRequest<ODataL
*/ */
public class ODataLinkUpdateResponseImpl extends AbstractODataResponse implements ODataLinkOperationResponse { public class ODataLinkUpdateResponseImpl extends AbstractODataResponse implements ODataLinkOperationResponse {
/** public ODataLinkUpdateResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
*
* @param client HTTP client. super(odataClient, httpClient, res);
* @param res HTTP response.
*/
public ODataLinkUpdateResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
} }
} }

View File

@ -171,7 +171,7 @@ public abstract class AbstractODataInvokeRequest<T extends ODataInvokeResult>
} }
try { try {
return new ODataInvokeResponseImpl(httpClient, doExecute()); return new ODataInvokeResponseImpl(odataClient, httpClient, doExecute());
} finally { } finally {
IOUtils.closeQuietly(input); IOUtils.closeQuietly(input);
} }
@ -184,23 +184,10 @@ public abstract class AbstractODataInvokeRequest<T extends ODataInvokeResult>
private T invokeResult = null; private T invokeResult = null;
/** private ODataInvokeResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataInvokeResponseImpl() {
super();
}
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataInvokeResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
/** /**
@ -214,7 +201,7 @@ public abstract class AbstractODataInvokeRequest<T extends ODataInvokeResult>
invokeResult = reference.cast(new ODataNoContent()); invokeResult = reference.cast(new ODataNoContent());
} else { } else {
// avoid getContent() twice:IllegalStateException: Content has been consumed // avoid getContent() twice:IllegalStateException: Content has been consumed
InputStream responseStream = this.payload == null ? res.getEntity().getContent() : this.payload; final InputStream responseStream = this.payload == null ? res.getEntity().getContent() : this.payload;
if (CommonODataEntitySet.class.isAssignableFrom(reference)) { if (CommonODataEntitySet.class.isAssignableFrom(reference)) {
invokeResult = reference.cast(odataClient.getReader().readEntitySet(responseStream, invokeResult = reference.cast(odataClient.getReader().readEntitySet(responseStream,
ODataFormat.fromString(getContentType()))); ODataFormat.fromString(getContentType())));

View File

@ -19,17 +19,17 @@
package org.apache.olingo.client.core.communication.request.retrieve; package org.apache.olingo.client.core.communication.request.retrieve;
import java.net.URI; import java.net.URI;
import org.apache.http.entity.ContentType;
import org.apache.olingo.client.api.CommonODataClient; import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.ODataRequest; 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; import org.apache.olingo.commons.api.format.ODataFormat;
public abstract class AbstractMetadataRequestImpl<V> extends AbstractODataRetrieveRequest<V> { public abstract class AbstractMetadataRequestImpl<V> extends AbstractODataRetrieveRequest<V> {
public AbstractMetadataRequestImpl(final CommonODataClient<?> odataClient, final URI query) { public AbstractMetadataRequestImpl(final CommonODataClient<?> odataClient, final URI query) {
super(odataClient, query); super(odataClient, query);
super.setAccept(ContentType.APPLICATION_XML.getMimeType()); super.setAccept(ContentType.APPLICATION_XML.toContentTypeString());
super.setContentType(ContentType.APPLICATION_XML.getMimeType()); super.setContentType(ContentType.APPLICATION_XML.toContentTypeString());
} }
@Override @Override

View File

@ -20,7 +20,6 @@ package org.apache.olingo.client.core.communication.request.retrieve;
import java.io.InputStream; import java.io.InputStream;
import java.net.URI; import java.net.URI;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.apache.olingo.client.api.CommonODataClient; import org.apache.olingo.client.api.CommonODataClient;
@ -64,23 +63,10 @@ public abstract class AbstractODataRetrieveRequest<T>
protected abstract class AbstractODataRetrieveResponse protected abstract class AbstractODataRetrieveResponse
extends AbstractODataResponse implements ODataRetrieveResponse<T> { extends AbstractODataResponse implements ODataRetrieveResponse<T> {
/** protected AbstractODataRetrieveResponse(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
* <p>
* Just to create response templates to be initialized from batch.
*/
protected AbstractODataRetrieveResponse() {
super();
}
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
protected AbstractODataRetrieveResponse(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
@Override @Override

View File

@ -49,11 +49,12 @@ class EdmMetadataRequestImpl extends AbstractMetadataRequestImpl<Edm> implements
final ODataRetrieveResponse<Map<String, Schema>> xmlMetadataResponse = final ODataRetrieveResponse<Map<String, Schema>> xmlMetadataResponse =
odataClient.getRetrieveRequestFactory().getXMLMetadataRequest(serviceRoot).execute(); odataClient.getRetrieveRequestFactory().getXMLMetadataRequest(serviceRoot).execute();
return new AbstractODataRetrieveResponse() { return new AbstractODataRetrieveResponse(odataClient, httpClient, null) {
private Edm metadata = null; private Edm metadata = null;
@Override @Override
public void close() { public void close() {
super.close();
xmlMetadataResponse.close(); xmlMetadataResponse.close();
} }

View File

@ -54,7 +54,7 @@ public class ODataEntityRequestImpl<E extends CommonODataEntity>
@Override @Override
public ODataRetrieveResponse<E> execute() { public ODataRetrieveResponse<E> execute() {
return new ODataEntityResponseImpl(httpClient, doExecute()); return new ODataEntityResponseImpl(odataClient, httpClient, doExecute());
} }
/** /**
@ -64,23 +64,10 @@ public class ODataEntityRequestImpl<E extends CommonODataEntity>
private E entity = null; private E entity = null;
/** private ODataEntityResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
* <br/>
* Just to create response templates to be initialized from batch.
*/
private ODataEntityResponseImpl() {
super();
}
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataEntityResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
@Override @Override
@ -88,11 +75,11 @@ public class ODataEntityRequestImpl<E extends CommonODataEntity>
public E getBody() { public E getBody() {
if (entity == null) { if (entity == null) {
try { try {
final ResWrap<Entity> resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType())) final ResWrap<Entity> resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType())).
.toEntity(getRawResponse()); toEntity(getRawResponse());
entity = (E) odataClient.getBinder().getODataEntity(resource); entity = (E) odataClient.getBinder().getODataEntity(resource);
} catch (final ODataDeserializerException e) { } catch (ODataDeserializerException e) {
throw new IllegalArgumentException(e); throw new IllegalArgumentException(e);
} finally { } finally {
this.close(); this.close();

View File

@ -57,7 +57,7 @@ public class ODataEntitySetIteratorRequestImpl<ES extends CommonODataEntitySet,
@Override @Override
public ODataRetrieveResponse<ODataEntitySetIterator<ES, E>> execute() { public ODataRetrieveResponse<ODataEntitySetIterator<ES, E>> execute() {
final HttpResponse res = doExecute(); final HttpResponse res = doExecute();
return new ODataEntitySetIteratorResponseImpl(httpClient, res); return new ODataEntitySetIteratorResponseImpl(odataClient, httpClient, res);
} }
/** /**
@ -65,14 +65,10 @@ public class ODataEntitySetIteratorRequestImpl<ES extends CommonODataEntitySet,
*/ */
protected class ODataEntitySetIteratorResponseImpl extends AbstractODataRetrieveResponse { protected class ODataEntitySetIteratorResponseImpl extends AbstractODataRetrieveResponse {
/** private ODataEntitySetIteratorResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
*
* @param client HTTP client. super(odataClient, httpClient, res);
* @param res HTTP response.
*/
private ODataEntitySetIteratorResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
@Override @Override

View File

@ -59,7 +59,7 @@ public class ODataEntitySetRequestImpl<ES extends CommonODataEntitySet>
@Override @Override
public ODataRetrieveResponse<ES> execute() { public ODataRetrieveResponse<ES> execute() {
final HttpResponse res = doExecute(); final HttpResponse res = doExecute();
return new ODataEntitySetResponseImpl(httpClient, res); return new ODataEntitySetResponseImpl(odataClient, httpClient, res);
} }
/** /**
@ -67,23 +67,10 @@ public class ODataEntitySetRequestImpl<ES extends CommonODataEntitySet>
*/ */
protected class ODataEntitySetResponseImpl extends AbstractODataRetrieveResponse { protected class ODataEntitySetResponseImpl extends AbstractODataRetrieveResponse {
/** private ODataEntitySetResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataEntitySetResponseImpl() {
super();
}
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataEntitySetResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
@Override @Override
@ -91,8 +78,8 @@ public class ODataEntitySetRequestImpl<ES extends CommonODataEntitySet>
public ES getBody() { public ES getBody() {
if (entitySet == null) { if (entitySet == null) {
try { try {
final ResWrap<EntitySet> resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType())) final ResWrap<EntitySet> resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType())).
.toEntitySet(getRawResponse()); toEntitySet(getRawResponse());
entitySet = (ES) odataClient.getBinder().getODataEntitySet(resource); entitySet = (ES) odataClient.getBinder().getODataEntitySet(resource);
} catch (final ODataDeserializerException e) { } catch (final ODataDeserializerException e) {

View File

@ -61,7 +61,7 @@ public class ODataMediaRequestImpl extends AbstractODataRetrieveRequest<InputStr
@Override @Override
public ODataRetrieveResponse<InputStream> execute() { public ODataRetrieveResponse<InputStream> execute() {
final HttpResponse res = doExecute(); final HttpResponse res = doExecute();
return new ODataMediaResponseImpl(httpClient, res); return new ODataMediaResponseImpl(odataClient, httpClient, res);
} }
/** /**
@ -71,23 +71,10 @@ public class ODataMediaRequestImpl extends AbstractODataRetrieveRequest<InputStr
private InputStream input = null; private InputStream input = null;
/** private ODataMediaResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataMediaResponseImpl() {
super();
}
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataMediaResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
/** /**

View File

@ -57,29 +57,17 @@ public class ODataPropertyRequestImpl<T extends CommonODataProperty>
@Override @Override
public ODataRetrieveResponse<T> execute() { public ODataRetrieveResponse<T> execute() {
final HttpResponse res = doExecute(); final HttpResponse res = doExecute();
return new ODataPropertyResponseImpl(httpClient, res); return new ODataPropertyResponseImpl(odataClient, httpClient, res);
} }
protected class ODataPropertyResponseImpl extends AbstractODataRetrieveResponse { protected class ODataPropertyResponseImpl extends AbstractODataRetrieveResponse {
private T property = null; private T property = null;
/** private ODataPropertyResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataPropertyResponseImpl() {
}
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataPropertyResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
@Override @Override

View File

@ -63,29 +63,17 @@ public class ODataRawRequestImpl extends AbstractODataRequest implements ODataRa
@Override @Override
public ODataRawResponse execute() { public ODataRawResponse execute() {
return new ODataRawResponseImpl(httpClient, doExecute()); return new ODataRawResponseImpl(odataClient, httpClient, doExecute());
} }
private class ODataRawResponseImpl extends AbstractODataResponse implements ODataRawResponse { private class ODataRawResponseImpl extends AbstractODataResponse implements ODataRawResponse {
private byte[] obj = null; private byte[] obj = null;
/** private ODataRawResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
* <br/>
* Just to create response templates to be initialized from batch.
*/
private ODataRawResponseImpl() {
}
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataRawResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
@Override @Override
@ -101,8 +89,7 @@ public class ODataRawRequestImpl extends AbstractODataRequest implements ODataRa
} }
try { try {
return odataClient.getReader(). return odataClient.getReader().read(new ByteArrayInputStream(obj), getContentType(), reference);
read(new ByteArrayInputStream(obj), getContentType(), reference);
} catch (final ODataDeserializerException e) { } catch (final ODataDeserializerException e) {
throw new IllegalArgumentException(e); throw new IllegalArgumentException(e);
} }

View File

@ -55,7 +55,7 @@ public class ODataServiceDocumentRequestImpl extends AbstractODataRetrieveReques
@Override @Override
public ODataRetrieveResponse<ODataServiceDocument> execute() { public ODataRetrieveResponse<ODataServiceDocument> execute() {
final HttpResponse res = doExecute(); 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; private ODataServiceDocument serviceDocument = null;
/** private ODataServiceResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataServiceResponseImpl() {}
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataServiceResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
@Override @Override
public ODataServiceDocument getBody() { public ODataServiceDocument getBody() {
if (serviceDocument == null) { if (serviceDocument == null) {
try { try {
final ResWrap<ServiceDocument> resource = final ResWrap<ServiceDocument> resource = odataClient.
odataClient.getDeserializer(ODataFormat.fromString(getContentType())) getDeserializer(ODataFormat.fromString(getContentType())).toServiceDocument(getRawResponse());
.toServiceDocument(getRawResponse());
serviceDocument = odataClient.getBinder().getODataServiceDocument(resource.getPayload()); serviceDocument = odataClient.getBinder().getODataServiceDocument(resource.getPayload());
} catch (final ODataDeserializerException e) { } catch (final ODataDeserializerException e) {

View File

@ -55,7 +55,7 @@ public class ODataValueRequestImpl extends AbstractODataRetrieveRequest<ODataPri
@Override @Override
public ODataRetrieveResponse<ODataPrimitiveValue> execute() { public ODataRetrieveResponse<ODataPrimitiveValue> execute() {
final HttpResponse res = doExecute(); final HttpResponse res = doExecute();
return new ODataValueResponseImpl(httpClient, res); return new ODataValueResponseImpl(odataClient, httpClient, res);
} }
/** /**
@ -65,23 +65,10 @@ public class ODataValueRequestImpl extends AbstractODataRetrieveRequest<ODataPri
private ODataPrimitiveValue value = null; private ODataPrimitiveValue value = null;
/** private ODataValueResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataValueResponseImpl() {
super();
}
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataValueResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
@Override @Override
@ -91,8 +78,8 @@ public class ODataValueRequestImpl extends AbstractODataRetrieveRequest<ODataPri
try { try {
value = odataClient.getObjectFactory().newPrimitiveValueBuilder(). value = odataClient.getObjectFactory().newPrimitiveValueBuilder().
setType(format == ODataFormat.TEXT_PLAIN ? setType(format == ODataFormat.TEXT_PLAIN
EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream). ? EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream).
setValue(IOUtils.toString(getRawResponse())).build(); setValue(IOUtils.toString(getRawResponse())).build();
} catch (Exception e) { } catch (Exception e) {
throw new HttpClientException(e); throw new HttpClientException(e);

View File

@ -23,6 +23,7 @@ import java.net.URI;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.v3.ODataClient; import org.apache.olingo.client.api.v3.ODataClient;
import org.apache.olingo.client.api.communication.request.retrieve.v3.ODataLinkCollectionRequest; import org.apache.olingo.client.api.communication.request.retrieve.v3.ODataLinkCollectionRequest;
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
@ -57,29 +58,17 @@ public class ODataLinkCollectionRequestImpl extends AbstractODataRetrieveRequest
@Override @Override
public ODataRetrieveResponse<ODataLinkCollection> execute() { public ODataRetrieveResponse<ODataLinkCollection> execute() {
return new ODataLinkCollectionResponseImpl(httpClient, doExecute()); return new ODataLinkCollectionResponseImpl(odataClient, httpClient, doExecute());
} }
protected class ODataLinkCollectionResponseImpl extends AbstractODataRetrieveResponse { protected class ODataLinkCollectionResponseImpl extends AbstractODataRetrieveResponse {
private ODataLinkCollection links = null; private ODataLinkCollection links = null;
/** private ODataLinkCollectionResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataLinkCollectionResponseImpl() {
}
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataLinkCollectionResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
@Override @Override

View File

@ -25,6 +25,7 @@ import java.util.Map;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient; 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.request.retrieve.XMLMetadataRequest;
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
import org.apache.olingo.client.api.edm.xml.Schema; import org.apache.olingo.client.api.edm.xml.Schema;
@ -42,30 +43,17 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl<Map<Stri
@Override @Override
public ODataRetrieveResponse<Map<String, Schema>> execute() { public ODataRetrieveResponse<Map<String, Schema>> execute() {
return new XMLMetadataResponseImpl(httpClient, doExecute()); return new XMLMetadataResponseImpl(odataClient, httpClient, doExecute());
} }
public class XMLMetadataResponseImpl extends AbstractODataRetrieveResponse { public class XMLMetadataResponseImpl extends AbstractODataRetrieveResponse {
private Map<String, Schema> schemas; private Map<String, Schema> schemas;
/** private XMLMetadataResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
* <br/>
* Just to create response templates to be initialized from batch.
*/
private XMLMetadataResponseImpl() {
super();
}
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private XMLMetadataResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
@Override @Override
@ -73,8 +61,7 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl<Map<Stri
if (schemas == null) { if (schemas == null) {
schemas = new HashMap<String, Schema>(); schemas = new HashMap<String, Schema>();
try { try {
final XMLMetadata metadata = odataClient.getDeserializer(ODataFormat.XML) final XMLMetadata metadata = odataClient.getDeserializer(ODataFormat.XML).toMetadata(getRawResponse());
.toMetadata(getRawResponse());
for (Schema schema : metadata.getSchemas()) { for (Schema schema : metadata.getSchemas()) {
schemas.put(schema.getNamespace(), schema); schemas.put(schema.getNamespace(), schema);
if (StringUtils.isNotBlank(schema.getAlias())) { if (StringUtils.isNotBlank(schema.getAlias())) {

View File

@ -50,30 +50,26 @@ public class ODataDeltaRequestImpl extends AbstractODataRetrieveRequest<ODataDel
@Override @Override
public ODataRetrieveResponse<ODataDelta> execute() { public ODataRetrieveResponse<ODataDelta> execute() {
final HttpResponse res = doExecute(); final HttpResponse res = doExecute();
return new ODataDeltaResponseImpl(httpClient, res); return new ODataDeltaResponseImpl(odataClient, httpClient, res);
} }
protected class ODataDeltaResponseImpl extends AbstractODataRetrieveResponse { protected class ODataDeltaResponseImpl extends AbstractODataRetrieveResponse {
private ODataDelta delta = null; private ODataDelta delta = null;
/** private ODataDeltaResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
*
* @param client HTTP client. super(odataClient, httpClient, res);
* @param res HTTP response.
*/
private ODataDeltaResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
@Override @Override
public ODataDelta getBody() { public ODataDelta getBody() {
if (delta == null) { if (delta == null) {
try { try {
final ResWrap<Delta> resource = ((ODataClient) odataClient) final ResWrap<Delta> resource = ((ODataClient) odataClient).
.getDeserializer(ODataFormat.fromString(getContentType())) getDeserializer(ODataFormat.fromString(getContentType())).
.toDelta(res.getEntity().getContent()); toDelta(res.getEntity().getContent());
delta = ((ODataClient) odataClient).getBinder().getODataDelta(resource); delta = ((ODataClient) odataClient).getBinder().getODataDelta(resource);
} catch (IOException e) { } catch (IOException e) {

View File

@ -24,6 +24,8 @@ import java.util.Map;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse; 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.request.retrieve.XMLMetadataRequest;
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
import org.apache.olingo.client.api.edm.xml.Schema; import org.apache.olingo.client.api.edm.xml.Schema;
@ -51,7 +53,8 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl<Map<Stri
final SingleXMLMetadatRequestImpl rootReq = new SingleXMLMetadatRequestImpl((ODataClient) odataClient, uri); final SingleXMLMetadatRequestImpl rootReq = new SingleXMLMetadatRequestImpl((ODataClient) odataClient, uri);
final ODataRetrieveResponse<XMLMetadata> rootRes = rootReq.execute(); final ODataRetrieveResponse<XMLMetadata> rootRes = rootReq.execute();
final XMLMetadataResponseImpl response = new XMLMetadataResponseImpl(rootReq.getHttpResponse()); final XMLMetadataResponseImpl response =
new XMLMetadataResponseImpl(odataClient, httpClient, rootReq.getHttpResponse());
final XMLMetadata rootMetadata = rootRes.getBody(); final XMLMetadata rootMetadata = rootRes.getBody();
for (Schema schema : rootMetadata.getSchemas()) { for (Schema schema : rootMetadata.getSchemas()) {
@ -137,7 +140,7 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl<Map<Stri
@Override @Override
public ODataRetrieveResponse<XMLMetadata> execute() { public ODataRetrieveResponse<XMLMetadata> execute() {
httpResponse = doExecute(); httpResponse = doExecute();
return new AbstractODataRetrieveResponse(httpClient, httpResponse) { return new AbstractODataRetrieveResponse(odataClient, httpClient, httpResponse) {
@Override @Override
public XMLMetadata getBody() { public XMLMetadata getBody() {
@ -155,8 +158,10 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl<Map<Stri
private final Map<String, Schema> schemas = new HashMap<String, Schema>(); private final Map<String, Schema> schemas = new HashMap<String, Schema>();
private XMLMetadataResponseImpl(final HttpResponse res) { private XMLMetadataResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
super(); final HttpResponse res) {
super(odataClient, httpClient, null);
statusCode = res.getStatusLine().getStatusCode(); statusCode = res.getStatusLine().getStatusCode();
statusMessage = res.getStatusLine().getReasonPhrase(); statusMessage = res.getStatusLine().getReasonPhrase();
@ -164,11 +169,6 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl<Map<Stri
hasBeenInitialized = true; hasBeenInitialized = true;
} }
@Override
public void close() {
// just do nothing, this is a placeholder response
}
@Override @Override
public Map<String, Schema> getBody() { public Map<String, Schema> getBody() {
return schemas; return schemas;

View File

@ -28,7 +28,6 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; 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.CommonODataClient;
import org.apache.olingo.client.api.ODataBatchConstants; import org.apache.olingo.client.api.ODataBatchConstants;
import org.apache.olingo.client.api.communication.request.ODataPayloadManager; 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.AbstractODataRequest;
import org.apache.olingo.client.core.communication.request.Wrapper; import org.apache.olingo.client.core.communication.request.Wrapper;
import org.apache.olingo.client.core.uri.URIUtils; import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.commons.api.format.ODataFormat;
/** /**
@ -73,8 +73,8 @@ public abstract class AbstractODataStreamedRequest<V extends ODataResponse, T ex
final HttpMethod method, final URI uri) { final HttpMethod method, final URI uri) {
super(odataClient, method, uri); super(odataClient, method, uri);
setAccept(ContentType.APPLICATION_OCTET_STREAM.getMimeType()); setAccept(ContentType.APPLICATION_OCTET_STREAM.toContentTypeString());
setContentType(ContentType.APPLICATION_OCTET_STREAM.getMimeType()); setContentType(ContentType.APPLICATION_OCTET_STREAM.toContentTypeString());
} }
@Override @Override

View File

@ -87,7 +87,7 @@ public class ODataMediaEntityCreateRequestImpl<E extends CommonODataEntity>
@Override @Override
protected ODataMediaEntityCreateResponse<E> getResponse(final long timeout, final TimeUnit unit) { protected ODataMediaEntityCreateResponse<E> getResponse(final long timeout, final TimeUnit unit) {
finalizeBody(); finalizeBody();
return new ODataMediaEntityCreateResponseImpl(httpClient, getHttpResponse(timeout, unit)); return new ODataMediaEntityCreateResponseImpl(odataClient, httpClient, getHttpResponse(timeout, unit));
} }
} }
@ -99,22 +99,10 @@ public class ODataMediaEntityCreateRequestImpl<E extends CommonODataEntity>
private E entity = null; private E entity = null;
/** private ODataMediaEntityCreateResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataMediaEntityCreateResponseImpl() {
}
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataMediaEntityCreateResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
@Override @Override
@ -122,8 +110,7 @@ public class ODataMediaEntityCreateRequestImpl<E extends CommonODataEntity>
public E getBody() { public E getBody() {
if (entity == null) { if (entity == null) {
try { try {
final ResWrap<Entity> resource = odataClient.getDeserializer(getFormat()) final ResWrap<Entity> resource = odataClient.getDeserializer(getFormat()).toEntity(getRawResponse());
.toEntity(getRawResponse());
entity = (E) odataClient.getBinder().getODataEntity(resource); entity = (E) odataClient.getBinder().getODataEntity(resource);
} catch (final ODataDeserializerException e) { } catch (final ODataDeserializerException e) {

View File

@ -88,7 +88,7 @@ public class ODataMediaEntityUpdateRequestImpl<E extends CommonODataEntity>
@Override @Override
protected ODataMediaEntityUpdateResponse<E> getResponse(final long timeout, final TimeUnit unit) { protected ODataMediaEntityUpdateResponse<E> getResponse(final long timeout, final TimeUnit unit) {
finalizeBody(); finalizeBody();
return new ODataMediaEntityUpdateResponseImpl(httpClient, getHttpResponse(timeout, unit)); return new ODataMediaEntityUpdateResponseImpl(odataClient, httpClient, getHttpResponse(timeout, unit));
} }
} }
@ -100,23 +100,10 @@ public class ODataMediaEntityUpdateRequestImpl<E extends CommonODataEntity>
private E entity = null; private E entity = null;
/** private ODataMediaEntityUpdateResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
* <br/>
* Just to create response templates to be initialized from batch.
*/
private ODataMediaEntityUpdateResponseImpl() {
super();
}
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataMediaEntityUpdateResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
@Override @Override

View File

@ -85,7 +85,7 @@ public class ODataStreamUpdateRequestImpl
@Override @Override
protected ODataStreamUpdateResponse getResponse(final long timeout, final TimeUnit unit) { protected ODataStreamUpdateResponse getResponse(final long timeout, final TimeUnit unit) {
finalizeBody(); 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; private InputStream input = null;
/** private ODataStreamUpdateResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataStreamUpdateResponseImpl() {
}
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
private ODataStreamUpdateResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
/** /**

View File

@ -85,13 +85,13 @@ public class AsyncRequestWrapperImpl<R extends ODataResponse> extends AbstractRe
// target uri // target uri
this.uri = odataRequest.getURI(); 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()) { if (odataClient.getConfiguration().isGzipCompression()) {
_httpClient = new DecompressingHttpClient(_httpClient); _httpClient = new DecompressingHttpClient(_httpClient);
} }
this.httpClient = _httpClient; this.httpClient = _httpClient;
this.request = odataClient.getConfiguration().getHttpUriRequestFactory().createHttpUriRequest(method, this.uri); this.request = odataClient.getConfiguration().getHttpUriRequestFactory().create(method, this.uri);
} }
@Override @Override
@ -292,7 +292,7 @@ public class AsyncRequestWrapperImpl<R extends ODataResponse> extends AbstractRe
} }
final HttpUriRequest monitor = odataClient.getConfiguration().getHttpUriRequestFactory(). final HttpUriRequest monitor = odataClient.getConfiguration().getHttpUriRequestFactory().
createHttpUriRequest(HttpMethod.GET, location); create(HttpMethod.GET, location);
return executeHttpRequest(httpClient, monitor); return executeHttpRequest(httpClient, monitor);
} }

View File

@ -33,6 +33,7 @@ import org.apache.http.Header;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient; 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.HeaderName;
import org.apache.olingo.client.api.communication.request.ODataStreamer; import org.apache.olingo.client.api.communication.request.ODataStreamer;
import org.apache.olingo.client.api.communication.request.batch.ODataBatchLineIterator; import org.apache.olingo.client.api.communication.request.batch.ODataBatchLineIterator;
@ -55,10 +56,12 @@ public abstract class AbstractODataResponse implements ODataResponse {
*/ */
protected static final Logger LOG = LoggerFactory.getLogger(ODataResponse.class); protected static final Logger LOG = LoggerFactory.getLogger(ODataResponse.class);
protected final CommonODataClient<?> odataClient;
/** /**
* HTTP client. * HTTP client.
*/ */
protected final HttpClient client; protected final HttpClient httpClient;
/** /**
* HTTP response. * HTTP response.
@ -96,21 +99,11 @@ public abstract class AbstractODataResponse implements ODataResponse {
*/ */
protected ODataBatchController batchInfo = null; protected ODataBatchController batchInfo = null;
/** public AbstractODataResponse(
* Constructor. final CommonODataClient<?> odataClient, final HttpClient httpclient, final HttpResponse res) {
*/
public AbstractODataResponse() {
this(null, null);
}
/** this.odataClient = odataClient;
* Constructor. this.httpClient = httpclient;
*
* @param client HTTP client.
* @param res HTTP response.
*/
public AbstractODataResponse(final HttpClient client, final HttpResponse res) {
this.client = client;
this.res = res; this.res = res;
if (res != null) { if (res != null) {
initFromHttpResponse(res); initFromHttpResponse(res);
@ -285,11 +278,7 @@ public abstract class AbstractODataResponse implements ODataResponse {
*/ */
@Override @Override
public void close() { public void close() {
if (client == null) { odataClient.getConfiguration().getHttpClientFactory().close(httpClient);
IOUtils.closeQuietly(payload);
} else {
this.client.getConnectionManager().shutdown();
}
if (batchInfo != null) { if (batchInfo != null) {
batchInfo.setValidBatch(false); batchInfo.setValidBatch(false);

View File

@ -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.request.batch.ODataBatchController;
import org.apache.olingo.client.core.communication.response.AbstractODataResponse; import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
/**
* Abstract representation of an OData response.
*/
public class ODataBatchErrorResponse extends AbstractODataResponse { public class ODataBatchErrorResponse extends AbstractODataResponse {
/**
* Constructor.
*/
public ODataBatchErrorResponse( public ODataBatchErrorResponse(
final Map.Entry<Integer, String> responseLine, final Map.Entry<Integer, String> responseLine,
final Map<String, Collection<String>> headers, final Map<String, Collection<String>> headers,
final ODataBatchLineIterator batchLineIterator, final ODataBatchLineIterator batchLineIterator,
final String boundary) { final String boundary) {
super(); super(null, null, null);
if (hasBeenInitialized) { if (hasBeenInitialized) {
throw new IllegalStateException("Request already initialized"); throw new IllegalStateException("Request already initialized");

View File

@ -77,6 +77,7 @@ public class ODataBatchResponseManager implements Iterator<ODataBatchResponseIte
public ODataBatchResponseManager( public ODataBatchResponseManager(
final ODataBatchResponse res, final ODataBatchResponse res,
final List<ODataBatchResponseItem> expectedItems) { final List<ODataBatchResponseItem> expectedItems) {
this(res, expectedItems, false); this(res, expectedItems, false);
} }
@ -84,6 +85,7 @@ public class ODataBatchResponseManager implements Iterator<ODataBatchResponseIte
final ODataBatchResponse res, final ODataBatchResponse res,
final List<ODataBatchResponseItem> expectedItems, final List<ODataBatchResponseItem> expectedItems,
final boolean continueOnError) { final boolean continueOnError) {
this.continueOnError = continueOnError; this.continueOnError = continueOnError;
try { try {
@ -106,7 +108,7 @@ public class ODataBatchResponseManager implements Iterator<ODataBatchResponseIte
*/ */
@Override @Override
public boolean hasNext() { public boolean hasNext() {
return (current == null || continueOnError || !current.isBreakingitem()) && expectedItemsIterator.hasNext(); return (current == null || continueOnError || !current.isBreaking()) && expectedItemsIterator.hasNext();
} }
/** /**

View File

@ -22,6 +22,7 @@ import java.util.Collection;
import java.util.Map; import java.util.Map;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.batch.ODataBatchLineIterator; import org.apache.olingo.client.api.communication.request.batch.ODataBatchLineIterator;
import org.apache.olingo.client.api.communication.response.v4.AsyncResponse; import org.apache.olingo.client.api.communication.response.v4.AsyncResponse;
import org.apache.olingo.client.core.communication.request.batch.ODataBatchController; import org.apache.olingo.client.core.communication.request.batch.ODataBatchController;
@ -32,23 +33,10 @@ import org.apache.olingo.client.core.communication.response.AbstractODataRespons
*/ */
public class AsyncResponseImpl extends AbstractODataResponse implements AsyncResponse { public class AsyncResponseImpl extends AbstractODataResponse implements AsyncResponse {
/** public AsyncResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
* Constructor. final HttpResponse res) {
* <p>
* Just to create response templates to be initialized from batch.
*/
public AsyncResponseImpl() {
super();
}
/** super(odataClient, httpClient, res);
* Constructor.
*
* @param client HTTP client.
* @param res HTTP response.
*/
public AsyncResponseImpl(final HttpClient client, final HttpResponse res) {
super(client, res);
} }
/** /**
@ -59,7 +47,8 @@ public class AsyncResponseImpl extends AbstractODataResponse implements AsyncRes
final Map<String, Collection<String>> headers, final Map<String, Collection<String>> headers,
final ODataBatchLineIterator batchLineIterator, final ODataBatchLineIterator batchLineIterator,
final String boundary) { final String boundary) {
super();
super(null, null, null);
if (hasBeenInitialized) { if (hasBeenInitialized) {
throw new IllegalStateException("Request already initialized"); throw new IllegalStateException("Request already initialized");

View File

@ -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();
}
}

View File

@ -42,8 +42,8 @@ public class BasicAuthHttpClientFactory extends DefaultHttpClientFactory {
} }
@Override @Override
public DefaultHttpClient createHttpClient(final HttpMethod method, final URI uri) { public DefaultHttpClient create(final HttpMethod method, final URI uri) {
final DefaultHttpClient httpclient = super.createHttpClient(method, uri); final DefaultHttpClient httpclient = super.create(method, uri);
httpclient.getCredentialsProvider().setCredentials( httpclient.getCredentialsProvider().setCredentials(
new AuthScope(uri.getHost(), uri.getPort()), new AuthScope(uri.getHost(), uri.getPort()),

View File

@ -18,51 +18,29 @@
*/ */
package org.apache.olingo.client.core.http; package org.apache.olingo.client.core.http;
import java.io.InputStream;
import java.io.Serializable;
import java.net.URI; import java.net.URI;
import java.util.Properties; import org.apache.http.client.HttpClient;
import org.apache.commons.io.IOUtils;
import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames; import org.apache.http.params.CoreProtocolPNames;
import org.apache.olingo.client.api.http.HttpClientFactory;
import org.apache.olingo.client.api.http.HttpMethod; import org.apache.olingo.client.api.http.HttpMethod;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* Default implementation returning HttpClients with default parameters. * 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 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 @Override
public DefaultHttpClient createHttpClient(final HttpMethod method, final URI uri) { public DefaultHttpClient create(final HttpMethod method, final URI uri) {
final DefaultHttpClient client = new DefaultHttpClient(); final DefaultHttpClient client = new DefaultHttpClient();
client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT); client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT);
return client; return client;
} }
@Override
public void close(final HttpClient httpClient) {
httpClient.getConnectionManager().shutdown();
}
} }

View File

@ -34,7 +34,7 @@ import org.apache.olingo.client.api.http.HttpUriRequestFactory;
public class DefaultHttpUriRequestFactory implements HttpUriRequestFactory { public class DefaultHttpUriRequestFactory implements HttpUriRequestFactory {
@Override @Override
public HttpUriRequest createHttpUriRequest(final HttpMethod method, final URI uri) { public HttpUriRequest create(final HttpMethod method, final URI uri) {
HttpUriRequest result; HttpUriRequest result;
switch (method) { switch (method) {

View File

@ -58,8 +58,8 @@ public class NTLMAuthHttpClientFactory extends DefaultHttpClientFactory {
} }
@Override @Override
public DefaultHttpClient createHttpClient(final HttpMethod method, final URI uri) { public DefaultHttpClient create(final HttpMethod method, final URI uri) {
final DefaultHttpClient httpclient = super.createHttpClient(method, uri); final DefaultHttpClient httpclient = super.create(method, uri);
final CredentialsProvider credsProvider = new BasicCredentialsProvider(); final CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, credsProvider.setCredentials(AuthScope.ANY,

View File

@ -68,9 +68,9 @@ public class ProxyWrapperHttpClientFactory implements HttpClientFactory {
} }
@Override @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 // 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()); final HttpHost proxyHost = new HttpHost(proxy.getHost(), proxy.getPort());
@ -87,4 +87,9 @@ public class ProxyWrapperHttpClientFactory implements HttpClientFactory {
return httpclient; return httpclient;
} }
@Override
public void close(final HttpClient httpClient) {
wrapped.close(httpClient);
}
} }

View File

@ -20,7 +20,6 @@ package org.apache.olingo.client.core.uri;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -32,7 +31,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair; import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair; 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.CommonURIBuilder;
import org.apache.olingo.client.api.uri.QueryOption; import org.apache.olingo.client.api.uri.QueryOption;
import org.apache.olingo.client.api.uri.SegmentType; import org.apache.olingo.client.api.uri.SegmentType;
@ -72,7 +71,7 @@ public abstract class AbstractURIBuilder<UB extends CommonURIBuilder<?>> impleme
private final ODataServiceVersion version; private final ODataServiceVersion version;
private final CommonConfiguration configuration; private final Configuration configuration;
protected final List<Segment> segments = new ArrayList<Segment>(); protected final List<Segment> segments = new ArrayList<Segment>();
@ -93,7 +92,7 @@ public abstract class AbstractURIBuilder<UB extends CommonURIBuilder<?>> impleme
* service. * service.
*/ */
protected AbstractURIBuilder( protected AbstractURIBuilder(
final ODataServiceVersion version, final CommonConfiguration configuration, final String serviceRoot) { final ODataServiceVersion version, final Configuration configuration, final String serviceRoot) {
this.version = version; this.version = version;
this.configuration = configuration; this.configuration = configuration;

View File

@ -19,7 +19,7 @@
package org.apache.olingo.client.core.uri.v3; package org.apache.olingo.client.core.uri.v3;
import org.apache.commons.lang3.StringUtils; 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.QueryOption;
import org.apache.olingo.client.api.uri.SegmentType; import org.apache.olingo.client.api.uri.SegmentType;
import org.apache.olingo.client.api.uri.v3.URIBuilder; 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<URIBuilder> implements URIBuilder { public class URIBuilderImpl extends AbstractURIBuilder<URIBuilder> implements URIBuilder {
public URIBuilderImpl( public URIBuilderImpl(
final ODataServiceVersion version, final CommonConfiguration configuration, final String serviceRoot) { final ODataServiceVersion version, final Configuration configuration, final String serviceRoot) {
super(version, configuration, serviceRoot); super(version, configuration, serviceRoot);
} }

View File

@ -23,7 +23,7 @@ import java.util.Map;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair; 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.QueryOption;
import org.apache.olingo.client.api.uri.SegmentType; import org.apache.olingo.client.api.uri.SegmentType;
import org.apache.olingo.client.api.uri.v4.URIBuilder; 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<URIBuilder> implements URIBuilder { public class URIBuilderImpl extends AbstractURIBuilder<URIBuilder> implements URIBuilder {
public URIBuilderImpl( public URIBuilderImpl(
final ODataServiceVersion version, final CommonConfiguration configuration, final String serviceRoot) { final ODataServiceVersion version, final Configuration configuration, final String serviceRoot) {
super(version, configuration, serviceRoot); super(version, configuration, serviceRoot);
} }

View File

@ -18,7 +18,6 @@
*/ */
package org.apache.olingo.client.core.v3; 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.HeaderName;
import org.apache.olingo.client.api.communication.header.ODataHeaders; import org.apache.olingo.client.api.communication.header.ODataHeaders;
import org.apache.olingo.client.api.communication.request.batch.v3.BatchRequestFactory; 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.uri.v3.URIBuilder;
import org.apache.olingo.client.api.v3.ODataClient; import org.apache.olingo.client.api.v3.ODataClient;
import org.apache.olingo.client.core.AbstractODataClient; 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.header.ODataHeadersImpl;
import org.apache.olingo.client.core.communication.request.batch.v3.BatchRequestFactoryImpl; import org.apache.olingo.client.core.communication.request.batch.v3.BatchRequestFactoryImpl;
import org.apache.olingo.client.core.communication.request.cud.v3.CUDRequestFactoryImpl; 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<UpdateType> implements ODataClient { public class ODataClientImpl extends AbstractODataClient<UpdateType> implements ODataClient {
protected final Configuration configuration = new Configuration();
private final FilterFactory filterFactory = new FilterFactoryImpl(getServiceVersion()); private final FilterFactory filterFactory = new FilterFactoryImpl(getServiceVersion());
private final ODataReader reader = new ODataReaderImpl(this); private final ODataReader reader = new ODataReaderImpl(this);
@ -86,11 +82,6 @@ public class ODataClientImpl extends AbstractODataClient<UpdateType> implements
return odataHeaders; return odataHeaders;
} }
@Override
public CommonConfiguration getConfiguration() {
return configuration;
}
@Override @Override
public URIBuilder newURIBuilder(final String serviceRoot) { public URIBuilder newURIBuilder(final String serviceRoot) {
return new URIBuilderImpl(getServiceVersion(), configuration, serviceRoot); return new URIBuilderImpl(getServiceVersion(), configuration, serviceRoot);
@ -108,8 +99,8 @@ public class ODataClientImpl extends AbstractODataClient<UpdateType> implements
@Override @Override
public ODataSerializer getSerializer(final ODataFormat format) { public ODataSerializer getSerializer(final ODataFormat format) {
return format == ODataFormat.ATOM || format == ODataFormat.XML ? return format == ODataFormat.ATOM || format == ODataFormat.XML
new AtomSerializer(getServiceVersion()) : new JsonSerializer(getServiceVersion(), false); ? new AtomSerializer(getServiceVersion()) : new JsonSerializer(getServiceVersion(), false);
} }
@Override @Override

View File

@ -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.uri.v4.URIBuilder;
import org.apache.olingo.client.api.v4.ODataClient; import org.apache.olingo.client.api.v4.ODataClient;
import org.apache.olingo.client.core.AbstractODataClient; 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.header.ODataHeadersImpl;
import org.apache.olingo.client.core.communication.request.batch.v4.BatchRequestFactoryImpl; import org.apache.olingo.client.core.communication.request.batch.v4.BatchRequestFactoryImpl;
import org.apache.olingo.client.core.communication.request.cud.v4.CUDRequestFactoryImpl; 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<UpdateType> implements ODataClient { public class ODataClientImpl extends AbstractODataClient<UpdateType> implements ODataClient {
protected final Configuration configuration = new Configuration();
private final FilterFactory filterFactory = new FilterFactoryImpl(getServiceVersion()); private final FilterFactory filterFactory = new FilterFactoryImpl(getServiceVersion());
private final SearchFactory searchFactory = new SearchFactoryImpl(); private final SearchFactory searchFactory = new SearchFactoryImpl();
@ -91,11 +88,6 @@ public class ODataClientImpl extends AbstractODataClient<UpdateType> implements
return odataHeaders; return odataHeaders;
} }
@Override
public Configuration getConfiguration() {
return configuration;
}
@Override @Override
public URIBuilder newURIBuilder(final String serviceRoot) { public URIBuilder newURIBuilder(final String serviceRoot) {
return new URIBuilderImpl(getServiceVersion(), getConfiguration(), serviceRoot); return new URIBuilderImpl(getServiceVersion(), getConfiguration(), serviceRoot);
@ -118,8 +110,8 @@ public class ODataClientImpl extends AbstractODataClient<UpdateType> implements
@Override @Override
public ODataSerializer getSerializer(final ODataFormat format) { public ODataSerializer getSerializer(final ODataFormat format) {
return format == ODataFormat.ATOM || format == ODataFormat.XML ? return format == ODataFormat.ATOM || format == ODataFormat.XML
new AtomSerializer(getServiceVersion()) : new JsonSerializer(getServiceVersion(), false); ? new AtomSerializer(getServiceVersion()) : new JsonSerializer(getServiceVersion(), false);
} }
@Override @Override

View File

@ -1,4 +1,4 @@
/******************************************************************************* /*
* Licensed to the Apache Software Foundation (ASF) under one * 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 * distributed with this work for additional information
@ -15,7 +15,7 @@
* 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 * specific language governing permissions and limitations
* under the License. * under the License.
******************************************************************************/ */
package org.apache.olingo.commons.api.format; package org.apache.olingo.commons.api.format;
import java.util.ArrayList; import java.util.ArrayList;
@ -43,32 +43,49 @@ import java.util.TreeMap;
* *
* Once created a {@link ContentType} is <b>IMMUTABLE</b>. * Once created a {@link ContentType} is <b>IMMUTABLE</b>.
*/ */
public class ContentType { public final class ContentType {
public static final ContentType APPLICATION_XML = create("application/xml"); 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 = 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_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_XML_FEED = create(APPLICATION_ATOM_XML, "type=feed");
public static final ContentType APPLICATION_ATOM_SVC = create("application/atomsvc+xml"); 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_JSON = create("application/json");
public static final ContentType APPLICATION_OCTET_STREAM = create("application/octet-stream"); public static final ContentType APPLICATION_OCTET_STREAM = create("application/octet-stream");
public static final ContentType TEXT_PLAIN = create("text/plain"); public static final ContentType TEXT_PLAIN = create("text/plain");
public static final ContentType MULTIPART_MIXED = create("multipart/mixed"); 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_XHTML_XML = create("application/xhtml+xml");
public static final ContentType APPLICATION_SVG_XML = create("application/svg+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 APPLICATION_FORM_URLENCODED = create("application/x-www-form-urlencoded");
public static final ContentType MULTIPART_FORM_DATA = create("multipart/form-data"); 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_XML = create("text/xml");
public static final ContentType TEXT_HTML = create("text/html"); public static final ContentType TEXT_HTML = create("text/html");
public static final String PARAMETER_CHARSET_UTF8 = "charset=utf-8"; public static final String PARAMETER_CHARSET_UTF8 = "charset=utf-8";
private final String type; private final String type;
private final String subtype; private final String subtype;
private final Map<String, String> parameters; private final Map<String, String> parameters;
/** /**
* Creates a content type from type, subtype, and parameters. * Creates a content type from type, subtype, and parameters.
*
* @param type * @param type
* @param subtype * @param subtype
* @param parameters * @param parameters
@ -105,6 +122,7 @@ public class ContentType {
/** /**
* Validates if given <code>format</code> is parseable and can be used as input for {@link #create(String)} method. * Validates if given <code>format</code> is parseable and can be used as input for {@link #create(String)} method.
*
* @param format to be validated string * @param format to be validated string
* @return <code>true</code> if format is parseable otherwise <code>false</code> * @return <code>true</code> if format is parseable otherwise <code>false</code>
*/ */
@ -118,6 +136,7 @@ public class ContentType {
/** /**
* Creates a content type from format and key-value pairs for parameters * Creates a content type from format and key-value pairs for parameters
*
* @param format for example "application/json" * @param format for example "application/json"
* @param parameters for example "a=b", "c=d" * @param parameters for example "a=b", "c=d"
* @return a new <code>ContentType</code> object * @return a new <code>ContentType</code> object
@ -126,7 +145,7 @@ public class ContentType {
ContentType ct = parse(format); ContentType ct = parse(format);
for (String p : parameters) { for (String p : parameters) {
String[] keyvalue = p.split("="); final String[] keyvalue = p.split("=");
ct.parameters.put(keyvalue[0], keyvalue[1]); 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 * 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" * @param parameters for example "a=b", "c=d"
* @return a new <code>ContentType</code> object * @return a new <code>ContentType</code> object
*/ */
@ -151,8 +171,9 @@ public class ContentType {
} }
/** /**
* Creates a {@link ContentType} based on given input string (<code>format</code>). * Creates a {@link ContentType} based on given input string (<code>format</code>). Supported format is
* Supported format is <code>Media Type</code> format as defined in RFC 7231, chapter 3.1.1.1. * <code>Media Type</code> 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 * @param format a string in format as defined in RFC 7231, chapter 3.1.1.1
* @return a new <code>ContentType</code> object * @return a new <code>ContentType</code> object
* @throws IllegalArgumentException if input string is not parseable * @throws IllegalArgumentException if input string is not parseable
@ -161,8 +182,8 @@ public class ContentType {
if (format == null) { if (format == null) {
throw new IllegalArgumentException("Parameter format MUST NOT be NULL."); throw new IllegalArgumentException("Parameter format MUST NOT be NULL.");
} }
List<String> typeSubtype = new ArrayList<String>(); final List<String> typeSubtype = new ArrayList<String>();
Map<String, String> parameters = new HashMap<String, String>(); final Map<String, String> parameters = new HashMap<String, String>();
parse(format, typeSubtype, parameters); parse(format, typeSubtype, parameters);
return new ContentType(typeSubtype.get(0), typeSubtype.get(1), parameters); return new ContentType(typeSubtype.get(0), typeSubtype.get(1), parameters);
} }
@ -184,14 +205,13 @@ public class ContentType {
} }
} }
private static void private static void parse(final String format, final List<String> typeSubtype, final Map<String, String> parameters) {
parse(final String format, final List<String> typeSubtype, final Map<String, String> parameters) {
final String[] typesAndParameters = format.split(TypeUtil.PARAMETER_SEPARATOR, 2); final String[] typesAndParameters = format.split(TypeUtil.PARAMETER_SEPARATOR, 2);
final String types = typesAndParameters[0]; final String types = typesAndParameters[0];
final String params = (typesAndParameters.length > 1 ? typesAndParameters[1] : null); final String params = (typesAndParameters.length > 1 ? typesAndParameters[1] : null);
if (types.contains(TypeUtil.TYPE_SUBTYPE_SEPARATOR)) { 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.length == 2) {
if (tokens[0] == null || tokens[0].isEmpty()) { if (tokens[0] == null || tokens[0].isEmpty()) {
throw new IllegalArgumentException("No type found in format '" + format + "'."); throw new IllegalArgumentException("No type found in format '" + format + "'.");
@ -247,7 +267,7 @@ public class ContentType {
@Override @Override
public boolean equals(final Object obj) { public boolean equals(final Object obj) {
// NULL validation is done in method 'isEqualWithoutParameters(obj)' // NULL validation is done in method 'isEqualWithoutParameters(obj)'
Boolean compatible = isEqualWithoutParameters(obj); final Boolean compatible = isEqualWithoutParameters(obj);
if (compatible == null) { if (compatible == null) {
ContentType other = (ContentType) obj; ContentType other = (ContentType) obj;
@ -258,11 +278,11 @@ public class ContentType {
return false; return false;
} }
} else if (parameters.size() == other.parameters.size()) { } else if (parameters.size() == other.parameters.size()) {
Iterator<Entry<String, String>> entries = parameters.entrySet().iterator(); final Iterator<Entry<String, String>> entries = parameters.entrySet().iterator();
Iterator<Entry<String, String>> otherEntries = other.parameters.entrySet().iterator(); final Iterator<Entry<String, String>> otherEntries = other.parameters.entrySet().iterator();
while (entries.hasNext()) { while (entries.hasNext()) {
Entry<String, String> e = entries.next(); final Entry<String, String> e = entries.next();
Entry<String, String> oe = otherEntries.next(); final Entry<String, String> oe = otherEntries.next();
if (!areEqual(e.getKey(), oe.getKey())) { if (!areEqual(e.getKey(), oe.getKey())) {
return false; return false;
@ -301,13 +321,12 @@ public class ContentType {
} }
/** /**
* Check equal without parameters. * Check equal without parameters. It is possible that no decision about <code>equal/none equal</code> can be
* It is possible that no decision about <code>equal/none equal</code> can be determined a <code>NULL</code> is * determined a <code>NULL</code> is returned.
* returned.
* *
* @param obj to checked object * @param obj to checked object
* @return <code>true</code> if both instances are equal (see definition above), otherwise <code>false</code> * @return <code>true</code> if both instances are equal (see definition above), otherwise <code>false</code> or
* or <code>NULL</code> if no decision about <code>equal/none equal</code> could be determined. * <code>NULL</code> if no decision about <code>equal/none equal</code> could be determined.
*/ */
private Boolean isEqualWithoutParameters(final Object obj) { private Boolean isEqualWithoutParameters(final Object obj) {
// basic checks // basic checks
@ -357,12 +376,13 @@ public class ContentType {
} }
/** /**
* Get {@link ContentType} as string as defined in RFC 7231 * Get {@link ContentType} as string as defined in RFC 7231 (http://www.ietf.org/rfc/rfc7231.txt, chapter 3.1.1.1:
* (http://www.ietf.org/rfc/rfc7231.txt, chapter 3.1.1.1: Media Type) * Media Type)
*
* @return string representation of <code>ContentType</code> object * @return string representation of <code>ContentType</code> object
*/ */
public String toContentTypeString() { public String toContentTypeString() {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append(type).append(TypeUtil.TYPE_SUBTYPE_SEPARATOR).append(subtype); sb.append(type).append(TypeUtil.TYPE_SUBTYPE_SEPARATOR).append(subtype);

17
pom.xml
View File

@ -84,6 +84,8 @@
<antlr.version>4.1</antlr.version> <antlr.version>4.1</antlr.version>
<android.platform.version>4.1.1.4</android.platform.version>
<sl4j.version>1.7.7</sl4j.version> <sl4j.version>1.7.7</sl4j.version>
<log.directory>${project.build.directory}/log</log.directory> <log.directory>${project.build.directory}/log</log.directory>
@ -165,6 +167,13 @@
<version>0.9.9</version> <version>0.9.9</version>
</dependency> </dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${android.platform.version}</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
@ -345,10 +354,16 @@
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
</plugin>
<plugin> <plugin>
<groupId>org.sonatype.plugins</groupId> <groupId>org.sonatype.plugins</groupId>
<artifactId>jarjar-maven-plugin</artifactId> <artifactId>jarjar-maven-plugin</artifactId>
<version>1.8</version> <version>1.9</version>
</plugin> </plugin>
<plugin> <plugin>