Several Android enhancements
This commit is contained in:
parent
4e61f1093d
commit
c3a709309e
|
@ -39,7 +39,12 @@
|
|||
<groupId>org.apache.olingo</groupId>
|
||||
<artifactId>olingo-client-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<optional>true</optional>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.android</groupId>
|
||||
<artifactId>android</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -65,7 +70,6 @@
|
|||
<include>org.apache.commons:commons-lang3</include>
|
||||
<include>org.slf4j:slf4j-api</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-databind</include>
|
||||
<include>com.fasterxml.jackson.core:jackson-annotations</include>
|
||||
|
|
|
@ -16,11 +16,28 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.client.core.android.http;
|
||||
|
||||
package org.apache.olingo.client.api.v4;
|
||||
import android.net.http.AndroidHttpClient;
|
||||
import java.net.URI;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.olingo.client.api.http.HttpMethod;
|
||||
import org.apache.olingo.client.core.http.AbstractHttpClientFactory;
|
||||
|
||||
import org.apache.olingo.client.api.CommonConfiguration;
|
||||
public class AndroidHttpClientFactory extends AbstractHttpClientFactory {
|
||||
|
||||
private static final long serialVersionUID = -5224104561624556177L;
|
||||
|
||||
@Override
|
||||
public HttpClient create(final HttpMethod method, final URI uri) {
|
||||
return AndroidHttpClient.newInstance(USER_AGENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(final HttpClient httpClient) {
|
||||
if (httpClient instanceof AndroidHttpClient) {
|
||||
((AndroidHttpClient) httpClient).close();
|
||||
}
|
||||
}
|
||||
|
||||
public interface Configuration extends CommonConfiguration {
|
||||
|
||||
}
|
|
@ -39,12 +39,37 @@
|
|||
<groupId>org.apache.olingo</groupId>
|
||||
<artifactId>olingo-client-proxy</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<optional>true</optional>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.android</groupId>
|
||||
<artifactId>android</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<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>
|
||||
<groupId>org.sonatype.plugins</groupId>
|
||||
<artifactId>jarjar-maven-plugin</artifactId>
|
||||
|
@ -67,7 +92,6 @@
|
|||
<include>org.apache.commons:commons-lang3</include>
|
||||
<include>org.slf4j:slf4j-api</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-databind</include>
|
||||
<include>com.fasterxml.jackson.core:jackson-annotations</include>
|
||||
|
|
|
@ -23,13 +23,13 @@ import java.util.concurrent.ExecutionException;
|
|||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import org.apache.olingo.client.api.CommonConfiguration;
|
||||
import org.apache.olingo.client.api.Configuration;
|
||||
|
||||
public abstract class AsyncCall<V> implements Future<V> {
|
||||
|
||||
private final Future<V> future;
|
||||
|
||||
public AsyncCall(final CommonConfiguration configuration) {
|
||||
public AsyncCall(final Configuration configuration) {
|
||||
this.future = configuration.getExecutor().submit(new Callable<V>() {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -54,8 +54,8 @@ public class TransactionalPersistenceManagerImpl extends AbstractPersistenceMana
|
|||
protected void doFlush(final PersistenceChanges changes, final TransactionItems items) {
|
||||
final CommonODataBatchRequest request =
|
||||
factory.getClient().getBatchRequestFactory().getBatchRequest(factory.getClient().getServiceRoot());
|
||||
String accept = factory.getClient().getConfiguration().getDefaultBatchAcceptFormat().toContentTypeString();
|
||||
((ODataRequest) request).setAccept(accept);
|
||||
((ODataRequest) request).setAccept(
|
||||
factory.getClient().getConfiguration().getDefaultBatchAcceptFormat().toContentTypeString());
|
||||
|
||||
final BatchManager streamManager = (BatchManager) ((ODataStreamedRequest) request).payloadManager();
|
||||
|
||||
|
@ -105,5 +105,6 @@ public class TransactionalPersistenceManagerImpl extends AbstractPersistenceMana
|
|||
}
|
||||
}
|
||||
}
|
||||
response.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,6 @@ import java.util.regex.Pattern;
|
|||
|
||||
import javax.ws.rs.NotFoundException;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
|
@ -51,7 +51,7 @@ import org.junit.Test;
|
|||
public class ErrorTestITCase extends AbstractTestITCase {
|
||||
|
||||
private class ErrorGeneratingRequest
|
||||
extends AbstractODataBasicRequest<ODataEntityCreateResponse<ODataEntity>> {
|
||||
extends AbstractODataBasicRequest<ODataEntityCreateResponse<ODataEntity>> {
|
||||
|
||||
public ErrorGeneratingRequest(final HttpMethod method, final URI uri) {
|
||||
super(client, method, uri);
|
||||
|
@ -75,16 +75,13 @@ public class ErrorTestITCase extends AbstractTestITCase {
|
|||
|
||||
private class ErrorResponseImpl extends AbstractODataResponse implements ODataEntityCreateResponse<ODataEntity> {
|
||||
|
||||
private final ODataClient odataClient;
|
||||
|
||||
public ErrorResponseImpl(final ODataClient odataClient, final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
this.odataClient = odataClient;
|
||||
super(odataClient, client, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataEntity getBody() {
|
||||
return odataClient.getObjectFactory().newEntity(new FullQualifiedName("Invalid.Invalid"));
|
||||
return ((ODataClient) odataClient).getObjectFactory().newEntity(new FullQualifiedName("Invalid.Invalid"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -146,9 +143,9 @@ public class ErrorTestITCase extends AbstractTestITCase {
|
|||
|
||||
private void instreamError(final ODataFormat format) {
|
||||
final URIBuilder builder = client.newURIBuilder(testStaticServiceRootURL).
|
||||
appendOperationCallSegment("InStreamErrorGetCustomer");
|
||||
appendOperationCallSegment("InStreamErrorGetCustomer");
|
||||
final ODataInvokeRequest<ODataEntitySet> req =
|
||||
client.getInvokeRequestFactory().getFunctionInvokeRequest(builder.build(), ODataEntitySet.class);
|
||||
client.getInvokeRequestFactory().getFunctionInvokeRequest(builder.build(), ODataEntitySet.class);
|
||||
req.setFormat(format);
|
||||
|
||||
final ODataInvokeResponse<ODataEntitySet> res = req.execute();
|
||||
|
|
|
@ -47,7 +47,7 @@ public interface CommonODataClient<UT extends CommonUpdateType> {
|
|||
|
||||
ODataHeaders newVersionHeaders();
|
||||
|
||||
CommonConfiguration getConfiguration();
|
||||
Configuration getConfiguration();
|
||||
|
||||
ODataPreferences newPreferences();
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.apache.olingo.commons.api.format.ODataFormat;
|
|||
/**
|
||||
* Configuration wrapper.
|
||||
*/
|
||||
public interface CommonConfiguration {
|
||||
public interface Configuration {
|
||||
|
||||
/**
|
||||
* Gets the configured default <tt>Accept</tt> header value format for a batch request.
|
|
@ -50,11 +50,11 @@ public interface ODataBatchResponseItem extends Iterator<ODataResponse> {
|
|||
boolean isChangeset();
|
||||
|
||||
/**
|
||||
* Checks if the current item is a braking item like as error item or asynchronous response part.
|
||||
* Checks if the current item is a breaking item like as error item or asynchronous response part.
|
||||
*
|
||||
* @return 'TRUE' if breaking; 'FALSE' otherwise.
|
||||
*/
|
||||
boolean isBreakingitem();
|
||||
boolean isBreaking();
|
||||
|
||||
/**
|
||||
* Closes the current batch responses item including all wrapped OData responses.
|
||||
|
|
|
@ -26,5 +26,7 @@ import org.apache.http.client.HttpClient;
|
|||
*/
|
||||
public interface HttpClientFactory {
|
||||
|
||||
HttpClient createHttpClient(HttpMethod method, URI uri);
|
||||
HttpClient create(HttpMethod method, URI uri);
|
||||
|
||||
void close(HttpClient httpClient);
|
||||
}
|
||||
|
|
|
@ -26,5 +26,5 @@ import org.apache.http.client.methods.HttpUriRequest;
|
|||
*/
|
||||
public interface HttpUriRequestFactory {
|
||||
|
||||
HttpUriRequest createHttpUriRequest(HttpMethod method, URI uri);
|
||||
HttpUriRequest create(HttpMethod method, URI uri);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.apache.olingo.client.api.v3;
|
||||
|
||||
import org.apache.olingo.client.api.CommonConfiguration;
|
||||
import org.apache.olingo.client.api.CommonODataClient;
|
||||
import org.apache.olingo.client.api.communication.request.batch.v3.BatchRequestFactory;
|
||||
import org.apache.olingo.client.api.communication.request.cud.v3.CUDRequestFactory;
|
||||
|
@ -34,9 +33,6 @@ import org.apache.olingo.commons.api.format.ODataFormat;
|
|||
|
||||
public interface ODataClient extends CommonODataClient<UpdateType> {
|
||||
|
||||
@Override
|
||||
CommonConfiguration getConfiguration();
|
||||
|
||||
@Override
|
||||
ODataDeserializer getDeserializer(ODataFormat format);
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.apache.olingo.client.api.v4;
|
||||
|
||||
import org.apache.olingo.client.api.CommonConfiguration;
|
||||
import org.apache.olingo.client.api.CommonODataClient;
|
||||
import org.apache.olingo.client.api.communication.request.batch.v4.BatchRequestFactory;
|
||||
import org.apache.olingo.client.api.communication.request.cud.v4.CUDRequestFactory;
|
||||
|
@ -36,9 +35,6 @@ import org.apache.olingo.commons.api.format.ODataFormat;
|
|||
|
||||
public interface ODataClient extends CommonODataClient<UpdateType> {
|
||||
|
||||
@Override
|
||||
CommonConfiguration getConfiguration();
|
||||
|
||||
@Override
|
||||
ODataDeserializer getDeserializer(ODataFormat format);
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.apache.olingo.client.core;
|
||||
|
||||
import org.apache.olingo.client.api.CommonODataClient;
|
||||
import org.apache.olingo.client.api.Configuration;
|
||||
import org.apache.olingo.client.api.communication.header.ODataPreferences;
|
||||
import org.apache.olingo.client.api.communication.request.cud.CommonUpdateType;
|
||||
import org.apache.olingo.client.api.serialization.ODataWriter;
|
||||
|
@ -26,8 +27,15 @@ import org.apache.olingo.client.core.serialization.ODataWriterImpl;
|
|||
|
||||
public abstract class AbstractODataClient<UT extends CommonUpdateType> implements CommonODataClient<UT> {
|
||||
|
||||
protected final Configuration configuration = new ConfigurationImpl();
|
||||
|
||||
private final ODataWriter writer = new ODataWriterImpl(this);
|
||||
|
||||
@Override
|
||||
public Configuration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataPreferences newPreferences() {
|
||||
return new ODataPreferences(getServiceVersion());
|
||||
|
|
|
@ -23,7 +23,7 @@ import java.util.Map;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.apache.olingo.client.api.CommonConfiguration;
|
||||
import org.apache.olingo.client.api.Configuration;
|
||||
import org.apache.olingo.client.api.http.HttpClientFactory;
|
||||
import org.apache.olingo.client.api.http.HttpUriRequestFactory;
|
||||
import org.apache.olingo.client.core.http.DefaultHttpClientFactory;
|
||||
|
@ -31,7 +31,7 @@ import org.apache.olingo.client.core.http.DefaultHttpUriRequestFactory;
|
|||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
|
||||
public class Configuration implements CommonConfiguration {
|
||||
public class ConfigurationImpl implements Configuration {
|
||||
|
||||
private static final String DEFAULT_PUB_FORMAT = "pubFormat";
|
||||
|
||||
|
@ -48,7 +48,7 @@ public class Configuration implements CommonConfiguration {
|
|||
private static final String USE_XHTTP_METHOD = "useHTTPMethod";
|
||||
|
||||
private static final String KEY_AS_SEGMENT = "keyAsSegment";
|
||||
|
||||
|
||||
private static final String ADDRESS_DERIVED_TYPE = "addressDerivedType";
|
||||
|
||||
private static final String USE_OPERATION_FQN_IN_URL = "useOperationFqnInUrl";
|
||||
|
@ -198,7 +198,7 @@ public class Configuration implements CommonConfiguration {
|
|||
public void setAddressingDerivedTypes(final boolean value) {
|
||||
setProperty(ADDRESS_DERIVED_TYPE, value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isUseUrlOperationFQN() {
|
||||
return (Boolean) getProperty(USE_OPERATION_FQN_IN_URL, true);
|
||||
|
@ -208,7 +208,7 @@ public class Configuration implements CommonConfiguration {
|
|||
public void setUseUrlOperationFQN(final boolean value) {
|
||||
setProperty(USE_OPERATION_FQN_IN_URL, value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ExecutorService getExecutor() {
|
||||
return executor;
|
|
@ -20,7 +20,6 @@ package org.apache.olingo.client.core;
|
|||
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
|
||||
|
||||
public final class ODataClientFactory {
|
||||
|
||||
public static org.apache.olingo.client.api.v3.ODataClient getV3() {
|
||||
|
|
|
@ -84,12 +84,13 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD
|
|||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param odataClient client instance getting this request
|
||||
* @param method HTTP request method. If configured X-HTTP-METHOD header will be used.
|
||||
* @param uri OData request URI.
|
||||
* @param odataClient client instance getting this request
|
||||
* @param method HTTP request method. If configured X-HTTP-METHOD header will be used.
|
||||
* @param uri OData request URI.
|
||||
*/
|
||||
protected AbstractODataRequest(final CommonODataClient<?> odataClient, final HttpMethod method, final URI uri) {
|
||||
|
||||
super();
|
||||
|
||||
this.odataClient = odataClient;
|
||||
this.method = method;
|
||||
|
||||
|
@ -99,15 +100,13 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD
|
|||
// target uri
|
||||
this.uri = uri;
|
||||
|
||||
HttpClient _httpClient = odataClient.getConfiguration().getHttpClientFactory().
|
||||
createHttpClient(this.method, this.uri);
|
||||
HttpClient _httpClient = odataClient.getConfiguration().getHttpClientFactory().create(this.method, this.uri);
|
||||
if (odataClient.getConfiguration().isGzipCompression()) {
|
||||
_httpClient = new DecompressingHttpClient(_httpClient);
|
||||
}
|
||||
this.httpClient = _httpClient;
|
||||
|
||||
this.request = odataClient.getConfiguration().getHttpUriRequestFactory().
|
||||
createHttpUriRequest(this.method, this.uri);
|
||||
this.request = odataClient.getConfiguration().getHttpUriRequestFactory().create(this.method, this.uri);
|
||||
}
|
||||
|
||||
public abstract ODataFormat getDefaultFormat();
|
||||
|
@ -184,9 +183,9 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD
|
|||
@Override
|
||||
public String getAccept() {
|
||||
final String acceptHead = odataHeaders.getHeader(HeaderName.accept);
|
||||
return StringUtils.isBlank(acceptHead) ?
|
||||
getDefaultFormat().getContentType(odataClient.getServiceVersion()).toContentTypeString() :
|
||||
acceptHead;
|
||||
return StringUtils.isBlank(acceptHead)
|
||||
? getDefaultFormat().getContentType(odataClient.getServiceVersion()).toContentTypeString()
|
||||
: acceptHead;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -207,9 +206,9 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD
|
|||
@Override
|
||||
public String getContentType() {
|
||||
final String contentTypeHead = odataHeaders.getHeader(HeaderName.contentType);
|
||||
return StringUtils.isBlank(contentTypeHead) ?
|
||||
getDefaultFormat().getContentType(odataClient.getServiceVersion()).toContentTypeString() :
|
||||
contentTypeHead;
|
||||
return StringUtils.isBlank(contentTypeHead)
|
||||
? getDefaultFormat().getContentType(odataClient.getServiceVersion()).toContentTypeString()
|
||||
: contentTypeHead;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -326,21 +325,21 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD
|
|||
|
||||
/**
|
||||
* Gets an empty response that can be initialized by a stream.
|
||||
* <p>
|
||||
* <br/>
|
||||
* 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.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <V extends ODataResponse> V getResponseTemplate() {
|
||||
|
||||
for (Class<?> clazz : this.getClass().getDeclaredClasses()) {
|
||||
if (ODataResponse.class.isAssignableFrom(clazz)) {
|
||||
try {
|
||||
final Constructor<?> constructor = clazz.getDeclaredConstructor(this.getClass());
|
||||
final Constructor<?> constructor = clazz.getDeclaredConstructor(
|
||||
this.getClass(), CommonODataClient.class, HttpClient.class, HttpResponse.class);
|
||||
constructor.setAccessible(true);
|
||||
return (V) constructor.newInstance(this);
|
||||
return (V) constructor.newInstance(this, odataClient, httpClient, null);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error retrieving response class template instance", e);
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ public abstract class AbstractODataBatchResponseItem implements ODataBatchRespon
|
|||
*/
|
||||
protected ODataResponse current;
|
||||
|
||||
protected boolean breakingitem = false;
|
||||
protected boolean breaking = false;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -143,15 +143,15 @@ public abstract class AbstractODataBatchResponseItem implements ODataBatchRespon
|
|||
expectedItemsIterator = responses.values().iterator();
|
||||
}
|
||||
|
||||
return !breakingitem && expectedItemsIterator.hasNext();
|
||||
return !breaking && expectedItemsIterator.hasNext();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc }
|
||||
*/
|
||||
@Override
|
||||
public boolean isBreakingitem() {
|
||||
return breakingitem;
|
||||
public boolean isBreaking() {
|
||||
return breaking;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -63,7 +63,7 @@ public class ODataChangesetResponseItem extends AbstractODataBatchResponseItem {
|
|||
}
|
||||
|
||||
if (unexpected) {
|
||||
breakingitem = true;
|
||||
breaking = true;
|
||||
return nextUnexpected();
|
||||
} else {
|
||||
return nextExpected();
|
||||
|
@ -107,7 +107,7 @@ public class ODataChangesetResponseItem extends AbstractODataBatchResponseItem {
|
|||
|
||||
if (current.getStatusCode() >= 400) {
|
||||
// found error ....
|
||||
breakingitem = true;
|
||||
breaking = true;
|
||||
}
|
||||
|
||||
return current;
|
||||
|
|
|
@ -27,8 +27,7 @@ import org.apache.olingo.client.core.communication.request.AbstractODataRequest;
|
|||
/**
|
||||
* Retrieve request wrapper for the corresponding batch item.
|
||||
*/
|
||||
public class ODataSingleRequestImpl extends AbstractODataBatchRequestItem
|
||||
implements ODataSingleRequest {
|
||||
public class ODataSingleRequestImpl extends AbstractODataBatchRequestItem implements ODataSingleRequest {
|
||||
|
||||
private final ODataSingleResponseItem expectedResItem;
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ import java.util.Collection;
|
|||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import org.apache.olingo.client.api.communication.response.ODataResponse;
|
||||
import static org.apache.olingo.client.core.communication.request.batch.AbstractODataBatchResponseItem.LOG;
|
||||
import org.apache.olingo.client.core.communication.response.batch.ODataBatchErrorResponse;
|
||||
import org.apache.olingo.client.core.communication.response.v4.AsyncResponseImpl;
|
||||
|
||||
|
@ -62,11 +61,11 @@ public class ODataSingleResponseItem extends AbstractODataBatchResponseItem {
|
|||
if (responseLine.getKey() == 202) {
|
||||
// generate async response
|
||||
current = new AsyncResponseImpl(responseLine, headers, batchLineIterator, boundary);
|
||||
breakingitem = true;
|
||||
breaking = true;
|
||||
} else if (responseLine.getKey() >= 400) {
|
||||
// generate error response
|
||||
current = new ODataBatchErrorResponse(responseLine, headers, batchLineIterator, boundary);
|
||||
breakingitem = true;
|
||||
breaking = true;
|
||||
} else {
|
||||
if (!hasNext()) {
|
||||
throw new NoSuchElementException("No item found");
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Iterator;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.olingo.client.api.CommonODataClient;
|
||||
import org.apache.olingo.client.api.communication.request.ODataBatchableRequest;
|
||||
import org.apache.olingo.client.api.communication.request.ODataStreamedRequest;
|
||||
import org.apache.olingo.client.api.communication.request.batch.BatchManager;
|
||||
|
@ -89,7 +90,7 @@ public class ODataBatchRequestImpl
|
|||
|
||||
@Override
|
||||
protected ODataBatchResponse getResponseInstance(final long timeout, final TimeUnit unit) {
|
||||
return new ODataBatchResponseImpl(httpClient, getHttpResponse(timeout, unit));
|
||||
return new ODataBatchResponseImpl(odataClient, httpClient, getHttpResponse(timeout, unit));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -107,14 +108,10 @@ public class ODataBatchRequestImpl
|
|||
*/
|
||||
protected class ODataBatchResponseImpl extends AbstractODataResponse implements ODataBatchResponse {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
protected ODataBatchResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
protected ODataBatchResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -125,4 +122,4 @@ public class ODataBatchRequestImpl
|
|||
return new ODataBatchResponseManager(this, expectedResItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Iterator;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.olingo.client.api.CommonODataClient;
|
||||
import org.apache.olingo.client.api.communication.header.HeaderName;
|
||||
import org.apache.olingo.client.api.communication.header.ODataPreferences;
|
||||
import org.apache.olingo.client.api.communication.request.ODataBatchableRequest;
|
||||
|
@ -95,7 +96,7 @@ public class ODataBatchRequestImpl
|
|||
|
||||
@Override
|
||||
protected ODataBatchResponse getResponseInstance(final long timeout, final TimeUnit unit) {
|
||||
return new ODataBatchResponseImpl(httpClient, getHttpResponse(timeout, unit));
|
||||
return new ODataBatchResponseImpl(odataClient, httpClient, getHttpResponse(timeout, unit));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -110,17 +111,10 @@ public class ODataBatchRequestImpl
|
|||
*/
|
||||
protected class ODataBatchResponseImpl extends AbstractODataResponse implements ODataBatchResponse {
|
||||
|
||||
private ODataBatchResponseImpl() {
|
||||
}
|
||||
protected ODataBatchResponseImpl(
|
||||
final CommonODataClient<?> odataClient, final HttpClient httpClient, final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
protected ODataBatchResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -131,4 +125,4 @@ public class ODataBatchRequestImpl
|
|||
return new ODataBatchResponseManager(this, expectedResItems, continueOnError);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,15 +35,8 @@ import org.apache.olingo.commons.api.format.ODataFormat;
|
|||
* This class implements an OData delete request.
|
||||
*/
|
||||
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) {
|
||||
super(odataClient, method, uri);
|
||||
}
|
||||
|
@ -63,7 +56,7 @@ public class ODataDeleteRequestImpl extends AbstractODataBasicRequest<ODataDelet
|
|||
|
||||
@Override
|
||||
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 {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataDeleteResponseImpl() {
|
||||
}
|
||||
private ODataDeleteResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
private ODataDeleteResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ public class ODataEntityCreateRequestImpl<E extends CommonODataEntity>
|
|||
((HttpPost) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input));
|
||||
|
||||
try {
|
||||
return new ODataEntityCreateResponseImpl(httpClient, doExecute());
|
||||
return new ODataEntityCreateResponseImpl(odataClient, httpClient, doExecute());
|
||||
} finally {
|
||||
IOUtils.closeQuietly(input);
|
||||
}
|
||||
|
@ -98,23 +98,10 @@ public class ODataEntityCreateRequestImpl<E extends CommonODataEntity>
|
|||
|
||||
private E entity = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataEntityCreateResponseImpl() {
|
||||
super();
|
||||
}
|
||||
private ODataEntityCreateResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
private ODataEntityCreateResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -125,9 +112,9 @@ public class ODataEntityCreateRequestImpl<E extends CommonODataEntity>
|
|||
public E getBody() {
|
||||
if (entity == null) {
|
||||
try {
|
||||
final ResWrap<Entity> resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept()))
|
||||
.toEntity(getRawResponse());
|
||||
|
||||
final ResWrap<Entity> resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept())).
|
||||
toEntity(getRawResponse());
|
||||
|
||||
entity = (E) odataClient.getBinder().getODataEntity(resource);
|
||||
} catch (final ODataDeserializerException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
|
|
|
@ -45,8 +45,8 @@ import org.apache.olingo.commons.api.serialization.ODataSerializerException;
|
|||
* @param <E> concrete ODataEntity implementation
|
||||
*/
|
||||
public class ODataEntityUpdateRequestImpl<E extends CommonODataEntity>
|
||||
extends AbstractODataBasicRequest<ODataEntityUpdateResponse<E>>
|
||||
implements ODataEntityUpdateRequest<E> {
|
||||
extends AbstractODataBasicRequest<ODataEntityUpdateResponse<E>>
|
||||
implements ODataEntityUpdateRequest<E> {
|
||||
|
||||
/**
|
||||
* Changes to be applied.
|
||||
|
@ -62,7 +62,7 @@ public class ODataEntityUpdateRequestImpl<E extends CommonODataEntity>
|
|||
* @param changes changes to be applied.
|
||||
*/
|
||||
public ODataEntityUpdateRequestImpl(final CommonODataClient<?> odataClient,
|
||||
final HttpMethod method, final URI uri, final E changes) {
|
||||
final HttpMethod method, final URI uri, final E changes) {
|
||||
|
||||
super(odataClient, method, uri);
|
||||
this.changes = changes;
|
||||
|
@ -73,18 +73,6 @@ public class ODataEntityUpdateRequestImpl<E extends CommonODataEntity>
|
|||
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
|
||||
protected InputStream getPayload() {
|
||||
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.
|
||||
*/
|
||||
|
@ -104,21 +104,10 @@ public class ODataEntityUpdateRequestImpl<E extends CommonODataEntity>
|
|||
*/
|
||||
private E entity = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataEntityUpdateResponseImpl() {}
|
||||
private ODataEntityUpdateResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
private ODataEntityUpdateResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -126,8 +115,8 @@ public class ODataEntityUpdateRequestImpl<E extends CommonODataEntity>
|
|||
public E getBody() {
|
||||
if (entity == null) {
|
||||
try {
|
||||
final ResWrap<Entity> resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept()))
|
||||
.toEntity(getRawResponse());
|
||||
final ResWrap<Entity> resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept())).
|
||||
toEntity(getRawResponse());
|
||||
|
||||
entity = (E) odataClient.getBinder().getODataEntity(resource);
|
||||
} catch (final ODataDeserializerException e) {
|
||||
|
|
|
@ -43,7 +43,7 @@ import org.apache.olingo.commons.api.serialization.ODataSerializerException;
|
|||
* This class implements an OData update entity property request.
|
||||
*/
|
||||
public class ODataPropertyUpdateRequestImpl extends AbstractODataBasicRequest<ODataPropertyUpdateResponse>
|
||||
implements ODataPropertyUpdateRequest {
|
||||
implements ODataPropertyUpdateRequest {
|
||||
|
||||
/**
|
||||
* Value to be created.
|
||||
|
@ -77,7 +77,7 @@ public class ODataPropertyUpdateRequestImpl extends AbstractODataBasicRequest<OD
|
|||
((HttpEntityEnclosingRequestBase) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input));
|
||||
|
||||
try {
|
||||
return new ODataPropertyUpdateResponseImpl(httpClient, doExecute());
|
||||
return new ODataPropertyUpdateResponseImpl(odataClient, httpClient, doExecute());
|
||||
} finally {
|
||||
IOUtils.closeQuietly(input);
|
||||
}
|
||||
|
@ -99,30 +99,18 @@ public class ODataPropertyUpdateRequestImpl extends AbstractODataBasicRequest<OD
|
|||
|
||||
private CommonODataProperty property = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataPropertyUpdateResponseImpl() {
|
||||
}
|
||||
private ODataPropertyUpdateResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
private ODataPropertyUpdateResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonODataProperty getBody() {
|
||||
if (property == null) {
|
||||
try {
|
||||
final ResWrap<Property> resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept()))
|
||||
.toProperty(getRawResponse());
|
||||
final ResWrap<Property> resource = odataClient.getDeserializer(ODataFormat.fromString(getAccept())).
|
||||
toProperty(getRawResponse());
|
||||
|
||||
property = odataClient.getBinder().getODataProperty(resource);
|
||||
} catch (final ODataDeserializerException e) {
|
||||
|
|
|
@ -41,7 +41,7 @@ import org.apache.olingo.commons.api.format.ODataFormat;
|
|||
* This class implements an OData update entity property value request.
|
||||
*/
|
||||
public class ODataValueUpdateRequestImpl extends AbstractODataBasicRequest<ODataValueUpdateResponse>
|
||||
implements ODataValueUpdateRequest {
|
||||
implements ODataValueUpdateRequest {
|
||||
|
||||
/**
|
||||
* Value to be created.
|
||||
|
@ -75,7 +75,7 @@ public class ODataValueUpdateRequestImpl extends AbstractODataBasicRequest<OData
|
|||
((HttpEntityEnclosingRequestBase) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input));
|
||||
|
||||
try {
|
||||
return new ODataValueUpdateResponseImpl(httpClient, doExecute());
|
||||
return new ODataValueUpdateResponseImpl(odataClient, httpClient, doExecute());
|
||||
} finally {
|
||||
IOUtils.closeQuietly(input);
|
||||
}
|
||||
|
@ -96,23 +96,10 @@ public class ODataValueUpdateRequestImpl extends AbstractODataBasicRequest<OData
|
|||
|
||||
private ODataPrimitiveValue value = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataValueUpdateResponseImpl() {
|
||||
super();
|
||||
}
|
||||
private ODataValueUpdateResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
private ODataValueUpdateResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -123,7 +110,7 @@ public class ODataValueUpdateRequestImpl extends AbstractODataBasicRequest<OData
|
|||
try {
|
||||
value = odataClient.getObjectFactory().newPrimitiveValueBuilder().
|
||||
setType(format == ODataFormat.TEXT_PLAIN
|
||||
? EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream).
|
||||
? EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream).
|
||||
setValue(getRawResponse()).
|
||||
build();
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -71,7 +71,7 @@ public class ODataLinkCreateRequestImpl extends AbstractODataBasicRequest<ODataL
|
|||
((HttpPost) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input));
|
||||
|
||||
try {
|
||||
return new ODataLinkCreateResponseImpl(httpClient, doExecute());
|
||||
return new ODataLinkCreateResponseImpl(odataClient, httpClient, doExecute());
|
||||
} finally {
|
||||
IOUtils.closeQuietly(input);
|
||||
}
|
||||
|
@ -91,22 +91,10 @@ public class ODataLinkCreateRequestImpl extends AbstractODataBasicRequest<ODataL
|
|||
*/
|
||||
private class ODataLinkCreateResponseImpl extends AbstractODataResponse implements ODataLinkOperationResponse {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataLinkCreateResponseImpl() {
|
||||
}
|
||||
private ODataLinkCreateResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
private ODataLinkCreateResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ import org.apache.olingo.commons.api.serialization.ODataSerializerException;
|
|||
* This class implements an update link OData request.
|
||||
*/
|
||||
public class ODataLinkUpdateRequestImpl extends AbstractODataBasicRequest<ODataLinkOperationResponse>
|
||||
implements ODataLinkUpdateRequest {
|
||||
implements ODataLinkUpdateRequest {
|
||||
|
||||
/**
|
||||
* Entity to be linked.
|
||||
|
@ -73,7 +73,7 @@ public class ODataLinkUpdateRequestImpl extends AbstractODataBasicRequest<ODataL
|
|||
((HttpEntityEnclosingRequestBase) request).setEntity(URIUtils.buildInputStreamEntity(odataClient, input));
|
||||
|
||||
try {
|
||||
return new ODataLinkUpdateResponseImpl(httpClient, doExecute());
|
||||
return new ODataLinkUpdateResponseImpl(odataClient, httpClient, doExecute());
|
||||
} finally {
|
||||
IOUtils.closeQuietly(input);
|
||||
}
|
||||
|
@ -93,14 +93,10 @@ public class ODataLinkUpdateRequestImpl extends AbstractODataBasicRequest<ODataL
|
|||
*/
|
||||
public class ODataLinkUpdateResponseImpl extends AbstractODataResponse implements ODataLinkOperationResponse {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
public ODataLinkUpdateResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
public ODataLinkUpdateResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -171,7 +171,7 @@ public abstract class AbstractODataInvokeRequest<T extends ODataInvokeResult>
|
|||
}
|
||||
|
||||
try {
|
||||
return new ODataInvokeResponseImpl(httpClient, doExecute());
|
||||
return new ODataInvokeResponseImpl(odataClient, httpClient, doExecute());
|
||||
} finally {
|
||||
IOUtils.closeQuietly(input);
|
||||
}
|
||||
|
@ -184,23 +184,10 @@ public abstract class AbstractODataInvokeRequest<T extends ODataInvokeResult>
|
|||
|
||||
private T invokeResult = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataInvokeResponseImpl() {
|
||||
super();
|
||||
}
|
||||
private ODataInvokeResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
private ODataInvokeResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -213,19 +200,19 @@ public abstract class AbstractODataInvokeRequest<T extends ODataInvokeResult>
|
|||
if (ODataNoContent.class.isAssignableFrom(reference)) {
|
||||
invokeResult = reference.cast(new ODataNoContent());
|
||||
} else {
|
||||
// avoid getContent() twice:IllegalStateException: Content has been consumed
|
||||
InputStream responseStream = this.payload == null ? res.getEntity().getContent() : this.payload;
|
||||
if (CommonODataEntitySet.class.isAssignableFrom(reference)) {
|
||||
invokeResult = reference.cast(odataClient.getReader().readEntitySet(responseStream,
|
||||
ODataFormat.fromString(getContentType())));
|
||||
} else if (CommonODataEntity.class.isAssignableFrom(reference)) {
|
||||
invokeResult = reference.cast(odataClient.getReader().readEntity(responseStream,
|
||||
ODataFormat.fromString(getContentType())));
|
||||
} else if (CommonODataProperty.class.isAssignableFrom(reference)) {
|
||||
invokeResult = reference.cast(odataClient.getReader().readProperty(responseStream,
|
||||
ODataFormat.fromString(getContentType())));
|
||||
}
|
||||
}
|
||||
// avoid getContent() twice:IllegalStateException: Content has been consumed
|
||||
final InputStream responseStream = this.payload == null ? res.getEntity().getContent() : this.payload;
|
||||
if (CommonODataEntitySet.class.isAssignableFrom(reference)) {
|
||||
invokeResult = reference.cast(odataClient.getReader().readEntitySet(responseStream,
|
||||
ODataFormat.fromString(getContentType())));
|
||||
} else if (CommonODataEntity.class.isAssignableFrom(reference)) {
|
||||
invokeResult = reference.cast(odataClient.getReader().readEntity(responseStream,
|
||||
ODataFormat.fromString(getContentType())));
|
||||
} else if (CommonODataProperty.class.isAssignableFrom(reference)) {
|
||||
invokeResult = reference.cast(odataClient.getReader().readProperty(responseStream,
|
||||
ODataFormat.fromString(getContentType())));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new HttpClientException(e);
|
||||
} catch (final ODataDeserializerException e) {
|
||||
|
|
|
@ -19,17 +19,17 @@
|
|||
package org.apache.olingo.client.core.communication.request.retrieve;
|
||||
|
||||
import java.net.URI;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.olingo.client.api.CommonODataClient;
|
||||
import org.apache.olingo.client.api.communication.request.ODataRequest;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
|
||||
public abstract class AbstractMetadataRequestImpl<V> extends AbstractODataRetrieveRequest<V> {
|
||||
|
||||
public AbstractMetadataRequestImpl(final CommonODataClient<?> odataClient, final URI query) {
|
||||
super(odataClient, query);
|
||||
super.setAccept(ContentType.APPLICATION_XML.getMimeType());
|
||||
super.setContentType(ContentType.APPLICATION_XML.getMimeType());
|
||||
super.setAccept(ContentType.APPLICATION_XML.toContentTypeString());
|
||||
super.setContentType(ContentType.APPLICATION_XML.toContentTypeString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.olingo.client.core.communication.request.retrieve;
|
|||
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.olingo.client.api.CommonODataClient;
|
||||
|
@ -64,23 +63,10 @@ public abstract class AbstractODataRetrieveRequest<T>
|
|||
protected abstract class AbstractODataRetrieveResponse
|
||||
extends AbstractODataResponse implements ODataRetrieveResponse<T> {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
protected AbstractODataRetrieveResponse() {
|
||||
super();
|
||||
}
|
||||
protected AbstractODataRetrieveResponse(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
protected AbstractODataRetrieveResponse(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -49,11 +49,12 @@ class EdmMetadataRequestImpl extends AbstractMetadataRequestImpl<Edm> implements
|
|||
final ODataRetrieveResponse<Map<String, Schema>> xmlMetadataResponse =
|
||||
odataClient.getRetrieveRequestFactory().getXMLMetadataRequest(serviceRoot).execute();
|
||||
|
||||
return new AbstractODataRetrieveResponse() {
|
||||
return new AbstractODataRetrieveResponse(odataClient, httpClient, null) {
|
||||
private Edm metadata = null;
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
super.close();
|
||||
xmlMetadataResponse.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ public class ODataEntityRequestImpl<E extends CommonODataEntity>
|
|||
|
||||
@Override
|
||||
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;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <br/>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataEntityResponseImpl() {
|
||||
super();
|
||||
}
|
||||
private ODataEntityResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
private ODataEntityResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -88,11 +75,11 @@ public class ODataEntityRequestImpl<E extends CommonODataEntity>
|
|||
public E getBody() {
|
||||
if (entity == null) {
|
||||
try {
|
||||
final ResWrap<Entity> resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType()))
|
||||
.toEntity(getRawResponse());
|
||||
final ResWrap<Entity> resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType())).
|
||||
toEntity(getRawResponse());
|
||||
|
||||
entity = (E) odataClient.getBinder().getODataEntity(resource);
|
||||
} catch (final ODataDeserializerException e) {
|
||||
} catch (ODataDeserializerException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
} finally {
|
||||
this.close();
|
||||
|
|
|
@ -57,7 +57,7 @@ public class ODataEntitySetIteratorRequestImpl<ES extends CommonODataEntitySet,
|
|||
@Override
|
||||
public ODataRetrieveResponse<ODataEntitySetIterator<ES, E>> execute() {
|
||||
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 {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
private ODataEntitySetIteratorResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
private ODataEntitySetIteratorResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -59,7 +59,7 @@ public class ODataEntitySetRequestImpl<ES extends CommonODataEntitySet>
|
|||
@Override
|
||||
public ODataRetrieveResponse<ES> execute() {
|
||||
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 {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataEntitySetResponseImpl() {
|
||||
super();
|
||||
}
|
||||
private ODataEntitySetResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
private ODataEntitySetResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -91,8 +78,8 @@ public class ODataEntitySetRequestImpl<ES extends CommonODataEntitySet>
|
|||
public ES getBody() {
|
||||
if (entitySet == null) {
|
||||
try {
|
||||
final ResWrap<EntitySet> resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType()))
|
||||
.toEntitySet(getRawResponse());
|
||||
final ResWrap<EntitySet> resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType())).
|
||||
toEntitySet(getRawResponse());
|
||||
|
||||
entitySet = (ES) odataClient.getBinder().getODataEntitySet(resource);
|
||||
} catch (final ODataDeserializerException e) {
|
||||
|
|
|
@ -61,7 +61,7 @@ public class ODataMediaRequestImpl extends AbstractODataRetrieveRequest<InputStr
|
|||
@Override
|
||||
public ODataRetrieveResponse<InputStream> execute() {
|
||||
final HttpResponse res = doExecute();
|
||||
return new ODataMediaResponseImpl(httpClient, res);
|
||||
return new ODataMediaResponseImpl(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,23 +71,10 @@ public class ODataMediaRequestImpl extends AbstractODataRetrieveRequest<InputStr
|
|||
|
||||
private InputStream input = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataMediaResponseImpl() {
|
||||
super();
|
||||
}
|
||||
private ODataMediaResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
private ODataMediaResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.apache.olingo.commons.api.serialization.ODataDeserializerException;
|
|||
* This class implements an OData entity property query request.
|
||||
*/
|
||||
public class ODataPropertyRequestImpl<T extends CommonODataProperty>
|
||||
extends AbstractODataRetrieveRequest<T> implements ODataPropertyRequest<T> {
|
||||
extends AbstractODataRetrieveRequest<T> implements ODataPropertyRequest<T> {
|
||||
|
||||
/**
|
||||
* Private constructor.
|
||||
|
@ -57,29 +57,17 @@ public class ODataPropertyRequestImpl<T extends CommonODataProperty>
|
|||
@Override
|
||||
public ODataRetrieveResponse<T> execute() {
|
||||
final HttpResponse res = doExecute();
|
||||
return new ODataPropertyResponseImpl(httpClient, res);
|
||||
return new ODataPropertyResponseImpl(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
protected class ODataPropertyResponseImpl extends AbstractODataRetrieveResponse {
|
||||
|
||||
private T property = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataPropertyResponseImpl() {
|
||||
}
|
||||
private ODataPropertyResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
private ODataPropertyResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -88,7 +76,7 @@ public class ODataPropertyRequestImpl<T extends CommonODataProperty>
|
|||
if (property == null) {
|
||||
try {
|
||||
final ResWrap<Property> resource = odataClient.getDeserializer(ODataFormat.fromString(getContentType()))
|
||||
.toProperty(res.getEntity().getContent());
|
||||
.toProperty(res.getEntity().getContent());
|
||||
|
||||
property = (T) odataClient.getBinder().getODataProperty(resource);
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -63,29 +63,17 @@ public class ODataRawRequestImpl extends AbstractODataRequest implements ODataRa
|
|||
|
||||
@Override
|
||||
public ODataRawResponse execute() {
|
||||
return new ODataRawResponseImpl(httpClient, doExecute());
|
||||
return new ODataRawResponseImpl(odataClient, httpClient, doExecute());
|
||||
}
|
||||
|
||||
private class ODataRawResponseImpl extends AbstractODataResponse implements ODataRawResponse {
|
||||
|
||||
private byte[] obj = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <br/>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataRawResponseImpl() {
|
||||
}
|
||||
private ODataRawResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
private ODataRawResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -101,8 +89,7 @@ public class ODataRawRequestImpl extends AbstractODataRequest implements ODataRa
|
|||
}
|
||||
|
||||
try {
|
||||
return odataClient.getReader().
|
||||
read(new ByteArrayInputStream(obj), getContentType(), reference);
|
||||
return odataClient.getReader().read(new ByteArrayInputStream(obj), getContentType(), reference);
|
||||
} catch (final ODataDeserializerException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.apache.olingo.commons.api.serialization.ODataDeserializerException;
|
|||
* This class implements an OData service document request.
|
||||
*/
|
||||
public class ODataServiceDocumentRequestImpl extends AbstractODataRetrieveRequest<ODataServiceDocument>
|
||||
implements ODataServiceDocumentRequest {
|
||||
implements ODataServiceDocumentRequest {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -55,7 +55,7 @@ public class ODataServiceDocumentRequestImpl extends AbstractODataRetrieveReques
|
|||
@Override
|
||||
public ODataRetrieveResponse<ODataServiceDocument> execute() {
|
||||
final HttpResponse res = doExecute();
|
||||
return new ODataServiceResponseImpl(httpClient, res);
|
||||
return new ODataServiceResponseImpl(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,30 +65,18 @@ public class ODataServiceDocumentRequestImpl extends AbstractODataRetrieveReques
|
|||
|
||||
private ODataServiceDocument serviceDocument = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataServiceResponseImpl() {}
|
||||
private ODataServiceResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
private ODataServiceResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataServiceDocument getBody() {
|
||||
if (serviceDocument == null) {
|
||||
try {
|
||||
final ResWrap<ServiceDocument> resource =
|
||||
odataClient.getDeserializer(ODataFormat.fromString(getContentType()))
|
||||
.toServiceDocument(getRawResponse());
|
||||
final ResWrap<ServiceDocument> resource = odataClient.
|
||||
getDeserializer(ODataFormat.fromString(getContentType())).toServiceDocument(getRawResponse());
|
||||
|
||||
serviceDocument = odataClient.getBinder().getODataServiceDocument(resource.getPayload());
|
||||
} catch (final ODataDeserializerException e) {
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.apache.olingo.commons.api.format.ODataFormat;
|
|||
* This class implements an OData entity property value query request.
|
||||
*/
|
||||
public class ODataValueRequestImpl extends AbstractODataRetrieveRequest<ODataPrimitiveValue>
|
||||
implements ODataValueRequest {
|
||||
implements ODataValueRequest {
|
||||
|
||||
/**
|
||||
* Private constructor.
|
||||
|
@ -55,7 +55,7 @@ public class ODataValueRequestImpl extends AbstractODataRetrieveRequest<ODataPri
|
|||
@Override
|
||||
public ODataRetrieveResponse<ODataPrimitiveValue> execute() {
|
||||
final HttpResponse res = doExecute();
|
||||
return new ODataValueResponseImpl(httpClient, res);
|
||||
return new ODataValueResponseImpl(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,23 +65,10 @@ public class ODataValueRequestImpl extends AbstractODataRetrieveRequest<ODataPri
|
|||
|
||||
private ODataPrimitiveValue value = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataValueResponseImpl() {
|
||||
super();
|
||||
}
|
||||
private ODataValueResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
private ODataValueResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -91,8 +78,8 @@ public class ODataValueRequestImpl extends AbstractODataRetrieveRequest<ODataPri
|
|||
|
||||
try {
|
||||
value = odataClient.getObjectFactory().newPrimitiveValueBuilder().
|
||||
setType(format == ODataFormat.TEXT_PLAIN ?
|
||||
EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream).
|
||||
setType(format == ODataFormat.TEXT_PLAIN
|
||||
? EdmPrimitiveTypeKind.String : EdmPrimitiveTypeKind.Stream).
|
||||
setValue(IOUtils.toString(getRawResponse())).build();
|
||||
} catch (Exception e) {
|
||||
throw new HttpClientException(e);
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.net.URI;
|
|||
|
||||
import org.apache.http.HttpResponse;
|
||||
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.communication.request.retrieve.v3.ODataLinkCollectionRequest;
|
||||
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
||||
|
@ -36,7 +37,7 @@ import org.apache.olingo.client.core.communication.request.retrieve.AbstractODat
|
|||
* This class implements an OData link query request.
|
||||
*/
|
||||
public class ODataLinkCollectionRequestImpl extends AbstractODataRetrieveRequest<ODataLinkCollection>
|
||||
implements ODataLinkCollectionRequest {
|
||||
implements ODataLinkCollectionRequest {
|
||||
|
||||
/**
|
||||
* Private constructor.
|
||||
|
@ -47,7 +48,7 @@ public class ODataLinkCollectionRequestImpl extends AbstractODataRetrieveRequest
|
|||
*/
|
||||
ODataLinkCollectionRequestImpl(final ODataClient odataClient, final URI targetURI, final String linkName) {
|
||||
super(odataClient,
|
||||
odataClient.newURIBuilder(targetURI.toASCIIString()).appendLinksSegment(linkName).build());
|
||||
odataClient.newURIBuilder(targetURI.toASCIIString()).appendLinksSegment(linkName).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,29 +58,17 @@ public class ODataLinkCollectionRequestImpl extends AbstractODataRetrieveRequest
|
|||
|
||||
@Override
|
||||
public ODataRetrieveResponse<ODataLinkCollection> execute() {
|
||||
return new ODataLinkCollectionResponseImpl(httpClient, doExecute());
|
||||
return new ODataLinkCollectionResponseImpl(odataClient, httpClient, doExecute());
|
||||
}
|
||||
|
||||
protected class ODataLinkCollectionResponseImpl extends AbstractODataRetrieveResponse {
|
||||
|
||||
private ODataLinkCollection links = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataLinkCollectionResponseImpl() {
|
||||
}
|
||||
private ODataLinkCollectionResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
private ODataLinkCollectionResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.Map;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.olingo.client.api.CommonODataClient;
|
||||
import org.apache.olingo.client.api.communication.request.retrieve.XMLMetadataRequest;
|
||||
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
||||
import org.apache.olingo.client.api.edm.xml.Schema;
|
||||
|
@ -42,30 +43,17 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl<Map<Stri
|
|||
|
||||
@Override
|
||||
public ODataRetrieveResponse<Map<String, Schema>> execute() {
|
||||
return new XMLMetadataResponseImpl(httpClient, doExecute());
|
||||
return new XMLMetadataResponseImpl(odataClient, httpClient, doExecute());
|
||||
}
|
||||
|
||||
public class XMLMetadataResponseImpl extends AbstractODataRetrieveResponse {
|
||||
|
||||
private Map<String, Schema> schemas;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <br/>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private XMLMetadataResponseImpl() {
|
||||
super();
|
||||
}
|
||||
private XMLMetadataResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
private XMLMetadataResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -73,8 +61,7 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl<Map<Stri
|
|||
if (schemas == null) {
|
||||
schemas = new HashMap<String, Schema>();
|
||||
try {
|
||||
final XMLMetadata metadata = odataClient.getDeserializer(ODataFormat.XML)
|
||||
.toMetadata(getRawResponse());
|
||||
final XMLMetadata metadata = odataClient.getDeserializer(ODataFormat.XML).toMetadata(getRawResponse());
|
||||
for (Schema schema : metadata.getSchemas()) {
|
||||
schemas.put(schema.getNamespace(), schema);
|
||||
if (StringUtils.isNotBlank(schema.getAlias())) {
|
||||
|
|
|
@ -36,7 +36,7 @@ import org.apache.olingo.commons.api.format.ODataFormat;
|
|||
import org.apache.olingo.commons.api.serialization.ODataDeserializerException;
|
||||
|
||||
public class ODataDeltaRequestImpl extends AbstractODataRetrieveRequest<ODataDelta>
|
||||
implements ODataDeltaRequest {
|
||||
implements ODataDeltaRequest {
|
||||
|
||||
public ODataDeltaRequestImpl(final CommonODataClient<?> odataClient, final URI query) {
|
||||
super(odataClient, query);
|
||||
|
@ -50,30 +50,26 @@ public class ODataDeltaRequestImpl extends AbstractODataRetrieveRequest<ODataDel
|
|||
@Override
|
||||
public ODataRetrieveResponse<ODataDelta> execute() {
|
||||
final HttpResponse res = doExecute();
|
||||
return new ODataDeltaResponseImpl(httpClient, res);
|
||||
return new ODataDeltaResponseImpl(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
protected class ODataDeltaResponseImpl extends AbstractODataRetrieveResponse {
|
||||
|
||||
private ODataDelta delta = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
private ODataDeltaResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
private ODataDeltaResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ODataDelta getBody() {
|
||||
if (delta == null) {
|
||||
try {
|
||||
final ResWrap<Delta> resource = ((ODataClient) odataClient)
|
||||
.getDeserializer(ODataFormat.fromString(getContentType()))
|
||||
.toDelta(res.getEntity().getContent());
|
||||
final ResWrap<Delta> resource = ((ODataClient) odataClient).
|
||||
getDeserializer(ODataFormat.fromString(getContentType())).
|
||||
toDelta(res.getEntity().getContent());
|
||||
|
||||
delta = ((ODataClient) odataClient).getBinder().getODataDelta(resource);
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -24,6 +24,8 @@ import java.util.Map;
|
|||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.olingo.client.api.CommonODataClient;
|
||||
import org.apache.olingo.client.api.communication.request.retrieve.XMLMetadataRequest;
|
||||
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
||||
import org.apache.olingo.client.api.edm.xml.Schema;
|
||||
|
@ -51,7 +53,8 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl<Map<Stri
|
|||
final SingleXMLMetadatRequestImpl rootReq = new SingleXMLMetadatRequestImpl((ODataClient) odataClient, uri);
|
||||
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();
|
||||
for (Schema schema : rootMetadata.getSchemas()) {
|
||||
|
@ -137,7 +140,7 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl<Map<Stri
|
|||
@Override
|
||||
public ODataRetrieveResponse<XMLMetadata> execute() {
|
||||
httpResponse = doExecute();
|
||||
return new AbstractODataRetrieveResponse(httpClient, httpResponse) {
|
||||
return new AbstractODataRetrieveResponse(odataClient, httpClient, httpResponse) {
|
||||
|
||||
@Override
|
||||
public XMLMetadata getBody() {
|
||||
|
@ -155,8 +158,10 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl<Map<Stri
|
|||
|
||||
private final Map<String, Schema> schemas = new HashMap<String, Schema>();
|
||||
|
||||
private XMLMetadataResponseImpl(final HttpResponse res) {
|
||||
super();
|
||||
private XMLMetadataResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
super(odataClient, httpClient, null);
|
||||
|
||||
statusCode = res.getStatusLine().getStatusCode();
|
||||
statusMessage = res.getStatusLine().getReasonPhrase();
|
||||
|
@ -164,11 +169,6 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl<Map<Stri
|
|||
hasBeenInitialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
// just do nothing, this is a placeholder response
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Schema> getBody() {
|
||||
return schemas;
|
||||
|
|
|
@ -28,7 +28,6 @@ import org.apache.commons.io.IOUtils;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.olingo.client.api.CommonODataClient;
|
||||
import org.apache.olingo.client.api.ODataBatchConstants;
|
||||
import org.apache.olingo.client.api.communication.request.ODataPayloadManager;
|
||||
|
@ -40,6 +39,7 @@ import org.apache.olingo.client.api.http.HttpMethod;
|
|||
import org.apache.olingo.client.core.communication.request.AbstractODataRequest;
|
||||
import org.apache.olingo.client.core.communication.request.Wrapper;
|
||||
import org.apache.olingo.client.core.uri.URIUtils;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
|
||||
/**
|
||||
|
@ -73,8 +73,8 @@ public abstract class AbstractODataStreamedRequest<V extends ODataResponse, T ex
|
|||
final HttpMethod method, final URI uri) {
|
||||
|
||||
super(odataClient, method, uri);
|
||||
setAccept(ContentType.APPLICATION_OCTET_STREAM.getMimeType());
|
||||
setContentType(ContentType.APPLICATION_OCTET_STREAM.getMimeType());
|
||||
setAccept(ContentType.APPLICATION_OCTET_STREAM.toContentTypeString());
|
||||
setContentType(ContentType.APPLICATION_OCTET_STREAM.toContentTypeString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -87,7 +87,7 @@ public class ODataMediaEntityCreateRequestImpl<E extends CommonODataEntity>
|
|||
@Override
|
||||
protected ODataMediaEntityCreateResponse<E> getResponse(final long timeout, final TimeUnit unit) {
|
||||
finalizeBody();
|
||||
return new ODataMediaEntityCreateResponseImpl(httpClient, getHttpResponse(timeout, unit));
|
||||
return new ODataMediaEntityCreateResponseImpl(odataClient, httpClient, getHttpResponse(timeout, unit));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,22 +99,10 @@ public class ODataMediaEntityCreateRequestImpl<E extends CommonODataEntity>
|
|||
|
||||
private E entity = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataMediaEntityCreateResponseImpl() {
|
||||
}
|
||||
private ODataMediaEntityCreateResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
private ODataMediaEntityCreateResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -122,8 +110,7 @@ public class ODataMediaEntityCreateRequestImpl<E extends CommonODataEntity>
|
|||
public E getBody() {
|
||||
if (entity == null) {
|
||||
try {
|
||||
final ResWrap<Entity> resource = odataClient.getDeserializer(getFormat())
|
||||
.toEntity(getRawResponse());
|
||||
final ResWrap<Entity> resource = odataClient.getDeserializer(getFormat()).toEntity(getRawResponse());
|
||||
|
||||
entity = (E) odataClient.getBinder().getODataEntity(resource);
|
||||
} catch (final ODataDeserializerException e) {
|
||||
|
|
|
@ -88,7 +88,7 @@ public class ODataMediaEntityUpdateRequestImpl<E extends CommonODataEntity>
|
|||
@Override
|
||||
protected ODataMediaEntityUpdateResponse<E> getResponse(final long timeout, final TimeUnit unit) {
|
||||
finalizeBody();
|
||||
return new ODataMediaEntityUpdateResponseImpl(httpClient, getHttpResponse(timeout, unit));
|
||||
return new ODataMediaEntityUpdateResponseImpl(odataClient, httpClient, getHttpResponse(timeout, unit));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,23 +100,10 @@ public class ODataMediaEntityUpdateRequestImpl<E extends CommonODataEntity>
|
|||
|
||||
private E entity = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <br/>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataMediaEntityUpdateResponseImpl() {
|
||||
super();
|
||||
}
|
||||
private ODataMediaEntityUpdateResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
private ODataMediaEntityUpdateResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -85,7 +85,7 @@ public class ODataStreamUpdateRequestImpl
|
|||
@Override
|
||||
protected ODataStreamUpdateResponse getResponse(final long timeout, final TimeUnit unit) {
|
||||
finalizeBody();
|
||||
return new ODataStreamUpdateResponseImpl(httpClient, getHttpResponse(timeout, unit));
|
||||
return new ODataStreamUpdateResponseImpl(odataClient, httpClient, getHttpResponse(timeout, unit));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,22 +96,10 @@ public class ODataStreamUpdateRequestImpl
|
|||
|
||||
private InputStream input = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
private ODataStreamUpdateResponseImpl() {
|
||||
}
|
||||
private ODataStreamUpdateResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
private ODataStreamUpdateResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -85,13 +85,13 @@ public class AsyncRequestWrapperImpl<R extends ODataResponse> extends AbstractRe
|
|||
// target uri
|
||||
this.uri = odataRequest.getURI();
|
||||
|
||||
HttpClient _httpClient = odataClient.getConfiguration().getHttpClientFactory().createHttpClient(method, this.uri);
|
||||
HttpClient _httpClient = odataClient.getConfiguration().getHttpClientFactory().create(method, this.uri);
|
||||
if (odataClient.getConfiguration().isGzipCompression()) {
|
||||
_httpClient = new DecompressingHttpClient(_httpClient);
|
||||
}
|
||||
this.httpClient = _httpClient;
|
||||
|
||||
this.request = odataClient.getConfiguration().getHttpUriRequestFactory().createHttpUriRequest(method, this.uri);
|
||||
this.request = odataClient.getConfiguration().getHttpUriRequestFactory().create(method, this.uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -292,7 +292,7 @@ public class AsyncRequestWrapperImpl<R extends ODataResponse> extends AbstractRe
|
|||
}
|
||||
|
||||
final HttpUriRequest monitor = odataClient.getConfiguration().getHttpUriRequestFactory().
|
||||
createHttpUriRequest(HttpMethod.GET, location);
|
||||
create(HttpMethod.GET, location);
|
||||
|
||||
return executeHttpRequest(httpClient, monitor);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.apache.http.Header;
|
|||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.olingo.client.api.CommonODataClient;
|
||||
import org.apache.olingo.client.api.communication.header.HeaderName;
|
||||
import org.apache.olingo.client.api.communication.request.ODataStreamer;
|
||||
import org.apache.olingo.client.api.communication.request.batch.ODataBatchLineIterator;
|
||||
|
@ -55,10 +56,12 @@ public abstract class AbstractODataResponse implements ODataResponse {
|
|||
*/
|
||||
protected static final Logger LOG = LoggerFactory.getLogger(ODataResponse.class);
|
||||
|
||||
protected final CommonODataClient<?> odataClient;
|
||||
|
||||
/**
|
||||
* HTTP client.
|
||||
*/
|
||||
protected final HttpClient client;
|
||||
protected final HttpClient httpClient;
|
||||
|
||||
/**
|
||||
* HTTP response.
|
||||
|
@ -96,21 +99,11 @@ public abstract class AbstractODataResponse implements ODataResponse {
|
|||
*/
|
||||
protected ODataBatchController batchInfo = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public AbstractODataResponse() {
|
||||
this(null, null);
|
||||
}
|
||||
public AbstractODataResponse(
|
||||
final CommonODataClient<?> odataClient, final HttpClient httpclient, final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
public AbstractODataResponse(final HttpClient client, final HttpResponse res) {
|
||||
this.client = client;
|
||||
this.odataClient = odataClient;
|
||||
this.httpClient = httpclient;
|
||||
this.res = res;
|
||||
if (res != null) {
|
||||
initFromHttpResponse(res);
|
||||
|
@ -285,11 +278,7 @@ public abstract class AbstractODataResponse implements ODataResponse {
|
|||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
if (client == null) {
|
||||
IOUtils.closeQuietly(payload);
|
||||
} else {
|
||||
this.client.getConnectionManager().shutdown();
|
||||
}
|
||||
odataClient.getConfiguration().getHttpClientFactory().close(httpClient);
|
||||
|
||||
if (batchInfo != null) {
|
||||
batchInfo.setValidBatch(false);
|
||||
|
|
|
@ -24,21 +24,15 @@ import org.apache.olingo.client.api.communication.request.batch.ODataBatchLineIt
|
|||
import org.apache.olingo.client.core.communication.request.batch.ODataBatchController;
|
||||
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
|
||||
|
||||
/**
|
||||
* Abstract representation of an OData response.
|
||||
*/
|
||||
public class ODataBatchErrorResponse extends AbstractODataResponse {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public ODataBatchErrorResponse(
|
||||
final Map.Entry<Integer, String> responseLine,
|
||||
final Map<String, Collection<String>> headers,
|
||||
final ODataBatchLineIterator batchLineIterator,
|
||||
final String boundary) {
|
||||
|
||||
super();
|
||||
super(null, null, null);
|
||||
|
||||
if (hasBeenInitialized) {
|
||||
throw new IllegalStateException("Request already initialized");
|
||||
|
|
|
@ -77,6 +77,7 @@ public class ODataBatchResponseManager implements Iterator<ODataBatchResponseIte
|
|||
public ODataBatchResponseManager(
|
||||
final ODataBatchResponse res,
|
||||
final List<ODataBatchResponseItem> expectedItems) {
|
||||
|
||||
this(res, expectedItems, false);
|
||||
}
|
||||
|
||||
|
@ -84,6 +85,7 @@ public class ODataBatchResponseManager implements Iterator<ODataBatchResponseIte
|
|||
final ODataBatchResponse res,
|
||||
final List<ODataBatchResponseItem> expectedItems,
|
||||
final boolean continueOnError) {
|
||||
|
||||
this.continueOnError = continueOnError;
|
||||
|
||||
try {
|
||||
|
@ -106,7 +108,7 @@ public class ODataBatchResponseManager implements Iterator<ODataBatchResponseIte
|
|||
*/
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return (current == null || continueOnError || !current.isBreakingitem()) && expectedItemsIterator.hasNext();
|
||||
return (current == null || continueOnError || !current.isBreaking()) && expectedItemsIterator.hasNext();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.Collection;
|
|||
import java.util.Map;
|
||||
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.batch.ODataBatchLineIterator;
|
||||
import org.apache.olingo.client.api.communication.response.v4.AsyncResponse;
|
||||
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 {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* <p>
|
||||
* Just to create response templates to be initialized from batch.
|
||||
*/
|
||||
public AsyncResponseImpl() {
|
||||
super();
|
||||
}
|
||||
public AsyncResponseImpl(final CommonODataClient<?> odataClient, final HttpClient httpClient,
|
||||
final HttpResponse res) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param client HTTP client.
|
||||
* @param res HTTP response.
|
||||
*/
|
||||
public AsyncResponseImpl(final HttpClient client, final HttpResponse res) {
|
||||
super(client, res);
|
||||
super(odataClient, httpClient, res);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,7 +47,8 @@ public class AsyncResponseImpl extends AbstractODataResponse implements AsyncRes
|
|||
final Map<String, Collection<String>> headers,
|
||||
final ODataBatchLineIterator batchLineIterator,
|
||||
final String boundary) {
|
||||
super();
|
||||
|
||||
super(null, null, null);
|
||||
|
||||
if (hasBeenInitialized) {
|
||||
throw new IllegalStateException("Request already initialized");
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -42,8 +42,8 @@ public class BasicAuthHttpClientFactory extends DefaultHttpClientFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
public DefaultHttpClient createHttpClient(final HttpMethod method, final URI uri) {
|
||||
final DefaultHttpClient httpclient = super.createHttpClient(method, uri);
|
||||
public DefaultHttpClient create(final HttpMethod method, final URI uri) {
|
||||
final DefaultHttpClient httpclient = super.create(method, uri);
|
||||
|
||||
httpclient.getCredentialsProvider().setCredentials(
|
||||
new AuthScope(uri.getHost(), uri.getPort()),
|
||||
|
|
|
@ -18,51 +18,29 @@
|
|||
*/
|
||||
package org.apache.olingo.client.core.http;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.params.CoreProtocolPNames;
|
||||
import org.apache.olingo.client.api.http.HttpClientFactory;
|
||||
import org.apache.olingo.client.api.http.HttpMethod;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Default implementation returning HttpClients with default parameters.
|
||||
*/
|
||||
public class DefaultHttpClientFactory implements HttpClientFactory, Serializable {
|
||||
public class DefaultHttpClientFactory extends AbstractHttpClientFactory {
|
||||
|
||||
private static final long serialVersionUID = -2461355444507227332L;
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DefaultHttpClientFactory.class);
|
||||
|
||||
private static final String USER_AGENT;
|
||||
|
||||
static {
|
||||
final StringBuilder userAgent = new StringBuilder("Apache-Olingo");
|
||||
|
||||
final InputStream input = DefaultHttpClientFactory.class.getResourceAsStream("/client.properties");
|
||||
try {
|
||||
final Properties prop = new Properties();
|
||||
prop.load(input);
|
||||
userAgent.append('/').append(prop.getProperty("version"));
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Could not get Apache Olingo version", e);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(input);
|
||||
}
|
||||
|
||||
USER_AGENT = userAgent.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultHttpClient createHttpClient(final HttpMethod method, final URI uri) {
|
||||
public DefaultHttpClient create(final HttpMethod method, final URI uri) {
|
||||
final DefaultHttpClient client = new DefaultHttpClient();
|
||||
client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT);
|
||||
return client;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(final HttpClient httpClient) {
|
||||
httpClient.getConnectionManager().shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.apache.olingo.client.api.http.HttpUriRequestFactory;
|
|||
public class DefaultHttpUriRequestFactory implements HttpUriRequestFactory {
|
||||
|
||||
@Override
|
||||
public HttpUriRequest createHttpUriRequest(final HttpMethod method, final URI uri) {
|
||||
public HttpUriRequest create(final HttpMethod method, final URI uri) {
|
||||
HttpUriRequest result;
|
||||
|
||||
switch (method) {
|
||||
|
|
|
@ -58,8 +58,8 @@ public class NTLMAuthHttpClientFactory extends DefaultHttpClientFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
public DefaultHttpClient createHttpClient(final HttpMethod method, final URI uri) {
|
||||
final DefaultHttpClient httpclient = super.createHttpClient(method, uri);
|
||||
public DefaultHttpClient create(final HttpMethod method, final URI uri) {
|
||||
final DefaultHttpClient httpclient = super.create(method, uri);
|
||||
|
||||
final CredentialsProvider credsProvider = new BasicCredentialsProvider();
|
||||
credsProvider.setCredentials(AuthScope.ANY,
|
||||
|
|
|
@ -68,9 +68,9 @@ public class ProxyWrapperHttpClientFactory implements HttpClientFactory {
|
|||
}
|
||||
|
||||
@Override
|
||||
public HttpClient createHttpClient(final HttpMethod method, final URI uri) {
|
||||
public HttpClient create(final HttpMethod method, final URI uri) {
|
||||
// Use wrapped factory to obtain an httpclient instance for given method and uri
|
||||
final DefaultHttpClient httpclient = (DefaultHttpClient) wrapped.createHttpClient(method, uri);
|
||||
final DefaultHttpClient httpclient = (DefaultHttpClient) wrapped.create(method, uri);
|
||||
|
||||
final HttpHost proxyHost = new HttpHost(proxy.getHost(), proxy.getPort());
|
||||
|
||||
|
@ -87,4 +87,9 @@ public class ProxyWrapperHttpClientFactory implements HttpClientFactory {
|
|||
return httpclient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(final HttpClient httpClient) {
|
||||
wrapped.close(httpClient);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.olingo.client.core.uri;
|
|||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
|
@ -32,7 +31,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.utils.URLEncodedUtils;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.olingo.client.api.CommonConfiguration;
|
||||
import org.apache.olingo.client.api.Configuration;
|
||||
import org.apache.olingo.client.api.uri.CommonURIBuilder;
|
||||
import org.apache.olingo.client.api.uri.QueryOption;
|
||||
import org.apache.olingo.client.api.uri.SegmentType;
|
||||
|
@ -72,7 +71,7 @@ public abstract class AbstractURIBuilder<UB extends CommonURIBuilder<?>> impleme
|
|||
|
||||
private final ODataServiceVersion version;
|
||||
|
||||
private final CommonConfiguration configuration;
|
||||
private final Configuration configuration;
|
||||
|
||||
protected final List<Segment> segments = new ArrayList<Segment>();
|
||||
|
||||
|
@ -93,7 +92,7 @@ public abstract class AbstractURIBuilder<UB extends CommonURIBuilder<?>> impleme
|
|||
* service.
|
||||
*/
|
||||
protected AbstractURIBuilder(
|
||||
final ODataServiceVersion version, final CommonConfiguration configuration, final String serviceRoot) {
|
||||
final ODataServiceVersion version, final Configuration configuration, final String serviceRoot) {
|
||||
|
||||
this.version = version;
|
||||
this.configuration = configuration;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
package org.apache.olingo.client.core.uri.v3;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.olingo.client.api.CommonConfiguration;
|
||||
import org.apache.olingo.client.api.Configuration;
|
||||
import org.apache.olingo.client.api.uri.QueryOption;
|
||||
import org.apache.olingo.client.api.uri.SegmentType;
|
||||
import org.apache.olingo.client.api.uri.v3.URIBuilder;
|
||||
|
@ -29,7 +29,7 @@ import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
|||
public class URIBuilderImpl extends AbstractURIBuilder<URIBuilder> implements URIBuilder {
|
||||
|
||||
public URIBuilderImpl(
|
||||
final ODataServiceVersion version, final CommonConfiguration configuration, final String serviceRoot) {
|
||||
final ODataServiceVersion version, final Configuration configuration, final String serviceRoot) {
|
||||
super(version, configuration, serviceRoot);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ import java.util.Map;
|
|||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.olingo.client.api.CommonConfiguration;
|
||||
import org.apache.olingo.client.api.Configuration;
|
||||
import org.apache.olingo.client.api.uri.QueryOption;
|
||||
import org.apache.olingo.client.api.uri.SegmentType;
|
||||
import org.apache.olingo.client.api.uri.v4.URIBuilder;
|
||||
|
@ -35,7 +35,7 @@ import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
|||
public class URIBuilderImpl extends AbstractURIBuilder<URIBuilder> implements URIBuilder {
|
||||
|
||||
public URIBuilderImpl(
|
||||
final ODataServiceVersion version, final CommonConfiguration configuration, final String serviceRoot) {
|
||||
final ODataServiceVersion version, final Configuration configuration, final String serviceRoot) {
|
||||
super(version, configuration, serviceRoot);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.apache.olingo.client.core.v3;
|
||||
|
||||
import org.apache.olingo.client.api.CommonConfiguration;
|
||||
import org.apache.olingo.client.api.communication.header.HeaderName;
|
||||
import org.apache.olingo.client.api.communication.header.ODataHeaders;
|
||||
import org.apache.olingo.client.api.communication.request.batch.v3.BatchRequestFactory;
|
||||
|
@ -33,7 +32,6 @@ import org.apache.olingo.client.api.uri.v3.FilterFactory;
|
|||
import org.apache.olingo.client.api.uri.v3.URIBuilder;
|
||||
import org.apache.olingo.client.api.v3.ODataClient;
|
||||
import org.apache.olingo.client.core.AbstractODataClient;
|
||||
import org.apache.olingo.client.core.Configuration;
|
||||
import org.apache.olingo.client.core.communication.header.ODataHeadersImpl;
|
||||
import org.apache.olingo.client.core.communication.request.batch.v3.BatchRequestFactoryImpl;
|
||||
import org.apache.olingo.client.core.communication.request.cud.v3.CUDRequestFactoryImpl;
|
||||
|
@ -54,8 +52,6 @@ import org.apache.olingo.commons.core.serialization.JsonSerializer;
|
|||
|
||||
public class ODataClientImpl extends AbstractODataClient<UpdateType> implements ODataClient {
|
||||
|
||||
protected final Configuration configuration = new Configuration();
|
||||
|
||||
private final FilterFactory filterFactory = new FilterFactoryImpl(getServiceVersion());
|
||||
|
||||
private final ODataReader reader = new ODataReaderImpl(this);
|
||||
|
@ -86,11 +82,6 @@ public class ODataClientImpl extends AbstractODataClient<UpdateType> implements
|
|||
return odataHeaders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonConfiguration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URIBuilder newURIBuilder(final String serviceRoot) {
|
||||
return new URIBuilderImpl(getServiceVersion(), configuration, serviceRoot);
|
||||
|
@ -108,8 +99,8 @@ public class ODataClientImpl extends AbstractODataClient<UpdateType> implements
|
|||
|
||||
@Override
|
||||
public ODataSerializer getSerializer(final ODataFormat format) {
|
||||
return format == ODataFormat.ATOM || format == ODataFormat.XML ?
|
||||
new AtomSerializer(getServiceVersion()) : new JsonSerializer(getServiceVersion(), false);
|
||||
return format == ODataFormat.ATOM || format == ODataFormat.XML
|
||||
? new AtomSerializer(getServiceVersion()) : new JsonSerializer(getServiceVersion(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.apache.olingo.client.api.uri.v4.SearchFactory;
|
|||
import org.apache.olingo.client.api.uri.v4.URIBuilder;
|
||||
import org.apache.olingo.client.api.v4.ODataClient;
|
||||
import org.apache.olingo.client.core.AbstractODataClient;
|
||||
import org.apache.olingo.client.core.Configuration;
|
||||
import org.apache.olingo.client.core.communication.header.ODataHeadersImpl;
|
||||
import org.apache.olingo.client.core.communication.request.batch.v4.BatchRequestFactoryImpl;
|
||||
import org.apache.olingo.client.core.communication.request.cud.v4.CUDRequestFactoryImpl;
|
||||
|
@ -56,8 +55,6 @@ import org.apache.olingo.commons.core.serialization.JsonSerializer;
|
|||
|
||||
public class ODataClientImpl extends AbstractODataClient<UpdateType> implements ODataClient {
|
||||
|
||||
protected final Configuration configuration = new Configuration();
|
||||
|
||||
private final FilterFactory filterFactory = new FilterFactoryImpl(getServiceVersion());
|
||||
|
||||
private final SearchFactory searchFactory = new SearchFactoryImpl();
|
||||
|
@ -91,11 +88,6 @@ public class ODataClientImpl extends AbstractODataClient<UpdateType> implements
|
|||
return odataHeaders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Configuration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URIBuilder newURIBuilder(final String serviceRoot) {
|
||||
return new URIBuilderImpl(getServiceVersion(), getConfiguration(), serviceRoot);
|
||||
|
@ -118,8 +110,8 @@ public class ODataClientImpl extends AbstractODataClient<UpdateType> implements
|
|||
|
||||
@Override
|
||||
public ODataSerializer getSerializer(final ODataFormat format) {
|
||||
return format == ODataFormat.ATOM || format == ODataFormat.XML ?
|
||||
new AtomSerializer(getServiceVersion()) : new JsonSerializer(getServiceVersion(), false);
|
||||
return format == ODataFormat.ATOM || format == ODataFormat.XML
|
||||
? new AtomSerializer(getServiceVersion()) : new JsonSerializer(getServiceVersion(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
/*******************************************************************************
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
******************************************************************************/
|
||||
*/
|
||||
package org.apache.olingo.commons.api.format;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -30,7 +30,7 @@ import java.util.TreeMap;
|
|||
|
||||
/**
|
||||
* Internally used {@link ContentType} for OData library.
|
||||
*
|
||||
*
|
||||
* For more details on format and content of a {@link ContentType} see
|
||||
* <em>Media Type</em> format as defined in
|
||||
* <a href="http://www.ietf.org/rfc/rfc7231.txt">RFC 7231</a>, chapter 3.1.1.1.
|
||||
|
@ -40,35 +40,52 @@ import java.util.TreeMap;
|
|||
* subtype = token
|
||||
* OWS = *( SP / HTAB ) ; optional whitespace
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* 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_ATOM_XML = create("application/atom+xml");
|
||||
|
||||
public static final ContentType APPLICATION_ATOM_XML_ENTRY = create(APPLICATION_ATOM_XML, "type=entry");
|
||||
|
||||
public static final ContentType APPLICATION_ATOM_XML_FEED = create(APPLICATION_ATOM_XML, "type=feed");
|
||||
|
||||
public static final ContentType APPLICATION_ATOM_SVC = create("application/atomsvc+xml");
|
||||
|
||||
public static final ContentType APPLICATION_JSON = create("application/json");
|
||||
|
||||
public static final ContentType APPLICATION_OCTET_STREAM = create("application/octet-stream");
|
||||
|
||||
public static final ContentType TEXT_PLAIN = create("text/plain");
|
||||
|
||||
public static final ContentType MULTIPART_MIXED = create("multipart/mixed");
|
||||
|
||||
public static final ContentType APPLICATION_XHTML_XML = create("application/xhtml+xml");
|
||||
|
||||
public static final ContentType APPLICATION_SVG_XML = create("application/svg+xml");
|
||||
|
||||
public static final ContentType APPLICATION_FORM_URLENCODED = create("application/x-www-form-urlencoded");
|
||||
|
||||
public static final ContentType MULTIPART_FORM_DATA = create("multipart/form-data");
|
||||
|
||||
public static final ContentType TEXT_XML = create("text/xml");
|
||||
|
||||
public static final ContentType TEXT_HTML = create("text/html");
|
||||
|
||||
public static final String PARAMETER_CHARSET_UTF8 = "charset=utf-8";
|
||||
|
||||
private final String type;
|
||||
|
||||
private final String subtype;
|
||||
|
||||
private final Map<String, String> parameters;
|
||||
|
||||
/**
|
||||
* Creates a content type from type, subtype, and parameters.
|
||||
*
|
||||
* @param type
|
||||
* @param subtype
|
||||
* @param parameters
|
||||
|
@ -105,6 +122,7 @@ public class ContentType {
|
|||
|
||||
/**
|
||||
* Validates if given <code>format</code> is parseable and can be used as input for {@link #create(String)} method.
|
||||
*
|
||||
* @param format to be validated string
|
||||
* @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
|
||||
*
|
||||
* @param format for example "application/json"
|
||||
* @param parameters for example "a=b", "c=d"
|
||||
* @return a new <code>ContentType</code> object
|
||||
|
@ -126,7 +145,7 @@ public class ContentType {
|
|||
ContentType ct = parse(format);
|
||||
|
||||
for (String p : parameters) {
|
||||
String[] keyvalue = p.split("=");
|
||||
final String[] keyvalue = p.split("=");
|
||||
ct.parameters.put(keyvalue[0], keyvalue[1]);
|
||||
}
|
||||
|
||||
|
@ -135,7 +154,8 @@ public class ContentType {
|
|||
|
||||
/**
|
||||
* Creates a content type from format and key-value pairs for parameters
|
||||
* @param format for example "application/json"
|
||||
*
|
||||
* @param contentType for example "application/json"
|
||||
* @param parameters for example "a=b", "c=d"
|
||||
* @return a new <code>ContentType</code> object
|
||||
*/
|
||||
|
@ -151,8 +171,9 @@ public class ContentType {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link ContentType} based on given input string (<code>format</code>).
|
||||
* Supported format is <code>Media Type</code> format as defined in RFC 7231, chapter 3.1.1.1.
|
||||
* Creates a {@link ContentType} based on given input string (<code>format</code>). Supported format is
|
||||
* <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
|
||||
* @return a new <code>ContentType</code> object
|
||||
* @throws IllegalArgumentException if input string is not parseable
|
||||
|
@ -161,8 +182,8 @@ public class ContentType {
|
|||
if (format == null) {
|
||||
throw new IllegalArgumentException("Parameter format MUST NOT be NULL.");
|
||||
}
|
||||
List<String> typeSubtype = new ArrayList<String>();
|
||||
Map<String, String> parameters = new HashMap<String, String>();
|
||||
final List<String> typeSubtype = new ArrayList<String>();
|
||||
final Map<String, String> parameters = new HashMap<String, String>();
|
||||
parse(format, typeSubtype, parameters);
|
||||
return new ContentType(typeSubtype.get(0), typeSubtype.get(1), parameters);
|
||||
}
|
||||
|
@ -170,9 +191,9 @@ public class ContentType {
|
|||
/**
|
||||
* Parses the given input string (<code>format</code>) and returns created {@link ContentType} if input was valid or
|
||||
* return <code>NULL</code> if input was not parseable.
|
||||
*
|
||||
*
|
||||
* For the definition of the supported format see {@link #create(String)}.
|
||||
*
|
||||
*
|
||||
* @param format a string in format as defined in RFC 7231, chapter 3.1.1.1
|
||||
* @return a new <code>ContentType</code> object
|
||||
*/
|
||||
|
@ -184,14 +205,13 @@ public class ContentType {
|
|||
}
|
||||
}
|
||||
|
||||
private static void
|
||||
parse(final String format, final List<String> typeSubtype, final Map<String, String> parameters) {
|
||||
private static void parse(final String format, final List<String> typeSubtype, final Map<String, String> parameters) {
|
||||
final String[] typesAndParameters = format.split(TypeUtil.PARAMETER_SEPARATOR, 2);
|
||||
final String types = typesAndParameters[0];
|
||||
final String params = (typesAndParameters.length > 1 ? typesAndParameters[1] : null);
|
||||
|
||||
if (types.contains(TypeUtil.TYPE_SUBTYPE_SEPARATOR)) {
|
||||
String[] tokens = types.split(TypeUtil.TYPE_SUBTYPE_SEPARATOR);
|
||||
final String[] tokens = types.split(TypeUtil.TYPE_SUBTYPE_SEPARATOR);
|
||||
if (tokens.length == 2) {
|
||||
if (tokens[0] == null || tokens[0].isEmpty()) {
|
||||
throw new IllegalArgumentException("No type found in format '" + format + "'.");
|
||||
|
@ -203,11 +223,11 @@ public class ContentType {
|
|||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"Too many '" + TypeUtil.TYPE_SUBTYPE_SEPARATOR + "' in format '" + format + "'.");
|
||||
"Too many '" + TypeUtil.TYPE_SUBTYPE_SEPARATOR + "' in format '" + format + "'.");
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("No separator '" + TypeUtil.TYPE_SUBTYPE_SEPARATOR
|
||||
+ "' was found in format '" + format + "'.");
|
||||
+ "' was found in format '" + format + "'.");
|
||||
}
|
||||
|
||||
TypeUtil.parseParameters(params, parameters);
|
||||
|
@ -222,7 +242,7 @@ public class ContentType {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return parameters of this {@link ContentType} as unmodifiable map.
|
||||
*/
|
||||
public Map<String, String> getParameters() {
|
||||
|
@ -241,13 +261,13 @@ public class ContentType {
|
|||
* <li>if <code>type</code> and/or <code>subtype</code> is set to "*" (in such a case the <code>parameters</code> are
|
||||
* ignored).</li>
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
* @return <code>true</code> if both instances are equal (see definition above), otherwise <code>false</code>.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
// NULL validation is done in method 'isEqualWithoutParameters(obj)'
|
||||
Boolean compatible = isEqualWithoutParameters(obj);
|
||||
final Boolean compatible = isEqualWithoutParameters(obj);
|
||||
|
||||
if (compatible == null) {
|
||||
ContentType other = (ContentType) obj;
|
||||
|
@ -258,11 +278,11 @@ public class ContentType {
|
|||
return false;
|
||||
}
|
||||
} else if (parameters.size() == other.parameters.size()) {
|
||||
Iterator<Entry<String, String>> entries = parameters.entrySet().iterator();
|
||||
Iterator<Entry<String, String>> otherEntries = other.parameters.entrySet().iterator();
|
||||
final Iterator<Entry<String, String>> entries = parameters.entrySet().iterator();
|
||||
final Iterator<Entry<String, String>> otherEntries = other.parameters.entrySet().iterator();
|
||||
while (entries.hasNext()) {
|
||||
Entry<String, String> e = entries.next();
|
||||
Entry<String, String> oe = otherEntries.next();
|
||||
final Entry<String, String> e = entries.next();
|
||||
final Entry<String, String> oe = otherEntries.next();
|
||||
|
||||
if (!areEqual(e.getKey(), oe.getKey())) {
|
||||
return false;
|
||||
|
@ -289,7 +309,7 @@ public class ContentType {
|
|||
* </ul>
|
||||
* The set <code>parameters</code> are <b>always</b> ignored (for compare with parameters see {@link #equals(Object)}
|
||||
* ).
|
||||
*
|
||||
*
|
||||
* @return <code>true</code> if both instances are equal (see definition above), otherwise <code>false</code>.
|
||||
*/
|
||||
public boolean isCompatible(final ContentType obj) {
|
||||
|
@ -301,13 +321,12 @@ public class ContentType {
|
|||
}
|
||||
|
||||
/**
|
||||
* Check equal without parameters.
|
||||
* It is possible that no decision about <code>equal/none equal</code> can be determined a <code>NULL</code> is
|
||||
* returned.
|
||||
*
|
||||
* Check equal without parameters. It is possible that no decision about <code>equal/none equal</code> can be
|
||||
* determined a <code>NULL</code> is returned.
|
||||
*
|
||||
* @param obj to checked object
|
||||
* @return <code>true</code> if both instances are equal (see definition above), otherwise <code>false</code>
|
||||
* or <code>NULL</code> if no decision about <code>equal/none equal</code> could be determined.
|
||||
* @return <code>true</code> if both instances are equal (see definition above), otherwise <code>false</code> or
|
||||
* <code>NULL</code> if no decision about <code>equal/none equal</code> could be determined.
|
||||
*/
|
||||
private Boolean isEqualWithoutParameters(final Object obj) {
|
||||
// basic checks
|
||||
|
@ -346,7 +365,7 @@ public class ContentType {
|
|||
|
||||
/**
|
||||
* Check whether both string are equal ignoring the case of the strings.
|
||||
*
|
||||
*
|
||||
* @param first first string
|
||||
* @param second second string
|
||||
* @return <code>true</code> if both strings are equal (by ignoring the case), otherwise <code>false</code> is
|
||||
|
@ -357,12 +376,13 @@ public class ContentType {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get {@link ContentType} as string as defined in RFC 7231
|
||||
* (http://www.ietf.org/rfc/rfc7231.txt, chapter 3.1.1.1: Media Type)
|
||||
* Get {@link ContentType} as string as defined in RFC 7231 (http://www.ietf.org/rfc/rfc7231.txt, chapter 3.1.1.1:
|
||||
* Media Type)
|
||||
*
|
||||
* @return string representation of <code>ContentType</code> object
|
||||
*/
|
||||
public String toContentTypeString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append(type).append(TypeUtil.TYPE_SUBTYPE_SEPARATOR).append(subtype);
|
||||
|
||||
|
|
23
pom.xml
23
pom.xml
|
@ -84,6 +84,8 @@
|
|||
|
||||
<antlr.version>4.1</antlr.version>
|
||||
|
||||
<android.platform.version>4.1.1.4</android.platform.version>
|
||||
|
||||
<sl4j.version>1.7.7</sl4j.version>
|
||||
|
||||
<log.directory>${project.build.directory}/log</log.directory>
|
||||
|
@ -165,6 +167,13 @@
|
|||
<version>0.9.9</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.android</groupId>
|
||||
<artifactId>android</artifactId>
|
||||
<version>${android.platform.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
|
@ -248,9 +257,9 @@
|
|||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.keyboardsamurais.maven</groupId>
|
||||
<artifactId>maven-timestamp-plugin</artifactId>
|
||||
<version>1.0</version>
|
||||
<groupId>com.keyboardsamurais.maven</groupId>
|
||||
<artifactId>maven-timestamp-plugin</artifactId>
|
||||
<version>1.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.rat</groupId>
|
||||
|
@ -344,11 +353,17 @@
|
|||
</delimiters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>1.8</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.sonatype.plugins</groupId>
|
||||
<artifactId>jarjar-maven-plugin</artifactId>
|
||||
<version>1.8</version>
|
||||
<version>1.9</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
|
|
Loading…
Reference in New Issue