mirror of
https://github.com/apache/olingo-odata4.git
synced 2025-03-06 08:39:14 +00:00
[OLINGO-472] Client refactoring
Signed-off-by: Christian Amend <chrisam@apache.org>
This commit is contained in:
parent
ace57fd586
commit
2318ffad20
@ -25,6 +25,7 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
@ -42,7 +43,6 @@ import org.apache.olingo.client.api.communication.response.ODataBatchResponse;
|
||||
import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
|
||||
import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
|
||||
import org.apache.olingo.client.api.communication.response.ODataResponse;
|
||||
import org.apache.olingo.client.api.uri.UriFormat;
|
||||
import org.apache.olingo.client.api.uri.v4.URIBuilder;
|
||||
import org.apache.olingo.client.core.communication.request.batch.ODataChangesetResponseItem;
|
||||
import org.apache.olingo.client.core.uri.URIUtils;
|
||||
@ -66,7 +66,6 @@ public class BatchClientITCase extends AbstractTestITCase {
|
||||
@Before
|
||||
public void setup() {
|
||||
client.getConfiguration().setContinueOnError(false);
|
||||
client.getConfiguration().setBatchUriFormat(UriFormat.RELATIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -86,14 +85,14 @@ public class BatchClientITCase extends AbstractTestITCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBatchRequest() {
|
||||
public void getBatchRequestWithRelativeUris() throws URISyntaxException {
|
||||
final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(SERVICE_URI);
|
||||
request.setAccept(ACCEPT);
|
||||
|
||||
final BatchManager payload = request.payloadManager();
|
||||
|
||||
// create new request
|
||||
appendGetRequest(payload, "ESAllPrim", 32767);
|
||||
appendGetRequest(payload, "ESAllPrim", 32767, true);
|
||||
|
||||
// Fetch result
|
||||
final ODataBatchResponse response = payload.getResponse();
|
||||
@ -118,15 +117,47 @@ public class BatchClientITCase extends AbstractTestITCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorWithoutContinueOnErrorPreferHeader() {
|
||||
public void getBatchRequest() throws URISyntaxException {
|
||||
final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(SERVICE_URI);
|
||||
request.setAccept(ACCEPT);
|
||||
|
||||
final BatchManager payload = request.payloadManager();
|
||||
|
||||
appendGetRequest(payload, "ESAllPrim", 32767); // Without error
|
||||
appendGetRequest(payload, "ESAllPrim", 42); // Error ( Key does not exist )
|
||||
appendGetRequest(payload, "ESAllPrim", 0); // Without error
|
||||
// create new request
|
||||
appendGetRequest(payload, "ESAllPrim", 32767, false);
|
||||
|
||||
// Fetch result
|
||||
final ODataBatchResponse response = payload.getResponse();
|
||||
|
||||
assertEquals(202, response.getStatusCode());
|
||||
assertEquals("Accepted", response.getStatusMessage());
|
||||
|
||||
final Iterator<ODataBatchResponseItem> iter = response.getBody();
|
||||
assertTrue(iter.hasNext());
|
||||
|
||||
ODataBatchResponseItem item = iter.next();
|
||||
assertFalse(item.isChangeset());
|
||||
|
||||
ODataResponse oDataResonse = item.next();
|
||||
assertNotNull(oDataResonse);
|
||||
assertEquals(HttpStatusCode.OK.getStatusCode(), oDataResonse.getStatusCode());
|
||||
assertEquals(1, oDataResonse.getHeader("OData-Version").size());
|
||||
assertEquals("4.0", oDataResonse.getHeader("OData-Version").toArray()[0]);
|
||||
assertEquals(1, oDataResonse.getHeader("Content-Length").size());
|
||||
assertEquals("538", oDataResonse.getHeader("Content-Length").toArray()[0]);
|
||||
assertEquals("application/json;odata.metadata=minimal", oDataResonse.getContentType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorWithoutContinueOnErrorPreferHeader() throws URISyntaxException {
|
||||
final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(SERVICE_URI);
|
||||
request.setAccept(ACCEPT);
|
||||
|
||||
final BatchManager payload = request.payloadManager();
|
||||
|
||||
appendGetRequest(payload, "ESAllPrim", 32767, false); // Without error
|
||||
appendGetRequest(payload, "ESAllPrim", 42, false); // Error ( Key does not exist )
|
||||
appendGetRequest(payload, "ESAllPrim", 0, false); // Without error
|
||||
|
||||
// Fetch result
|
||||
final ODataBatchResponse response = payload.getResponse();
|
||||
@ -162,16 +193,16 @@ public class BatchClientITCase extends AbstractTestITCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorWithContinueOnErrorPreferHeader() {
|
||||
public void testErrorWithContinueOnErrorPreferHeader() throws URISyntaxException {
|
||||
client.getConfiguration().setContinueOnError(true);
|
||||
final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(SERVICE_URI);
|
||||
request.setAccept(ACCEPT);
|
||||
|
||||
final BatchManager payload = request.payloadManager();
|
||||
|
||||
appendGetRequest(payload, "ESAllPrim", 32767); // Without error
|
||||
appendGetRequest(payload, "ESAllPrim", 42); // Error ( Key does not exist )
|
||||
appendGetRequest(payload, "ESAllPrim", 0); // Without error
|
||||
appendGetRequest(payload, "ESAllPrim", 32767, false); // Without error
|
||||
appendGetRequest(payload, "ESAllPrim", 42, false); // Error ( Key does not exist )
|
||||
appendGetRequest(payload, "ESAllPrim", 0, false); // Without error
|
||||
|
||||
// Fetch result
|
||||
final ODataBatchResponse response = payload.getResponse();
|
||||
@ -317,10 +348,10 @@ public class BatchClientITCase extends AbstractTestITCase {
|
||||
return entity;
|
||||
}
|
||||
|
||||
//TODO If write support is implemented, remove ignore tag
|
||||
// TODO If write support is implemented, remove ignore tag
|
||||
@Test
|
||||
@Ignore("Not implemented")
|
||||
public void changesetBatchRequest() {
|
||||
public void changesetBatchRequest() throws URISyntaxException {
|
||||
final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(SERVICE_URI);
|
||||
request.setAccept(ACCEPT);
|
||||
|
||||
@ -328,7 +359,7 @@ public class BatchClientITCase extends AbstractTestITCase {
|
||||
// -----------------------------
|
||||
// - Append get request
|
||||
// -----------------------------
|
||||
appendGetRequest(payload, "ESAllPrim", 32767); // Without error
|
||||
appendGetRequest(payload, "ESAllPrim", 32767, false); // Without error
|
||||
|
||||
// -----------------------------
|
||||
// - Append change set
|
||||
@ -397,7 +428,7 @@ public class BatchClientITCase extends AbstractTestITCase {
|
||||
// -----------------------------
|
||||
// - Append get request
|
||||
// -----------------------------
|
||||
appendGetRequest(payload, "ESAllPrim", 32767); // Without error
|
||||
appendGetRequest(payload, "ESAllPrim", 32767, false); // Without error
|
||||
|
||||
// -----------------------------
|
||||
// - Fetch result
|
||||
@ -446,11 +477,13 @@ public class BatchClientITCase extends AbstractTestITCase {
|
||||
assertFalse(item.isChangeset());
|
||||
}
|
||||
|
||||
private void appendGetRequest(final BatchManager manager, final String segment, final Object key) {
|
||||
URIBuilder targetURI = client.newBatchURIBuilder(SERVICE_URI);
|
||||
private void appendGetRequest(final BatchManager manager, final String segment, final Object key, boolean isRelative)
|
||||
throws URISyntaxException {
|
||||
final URIBuilder targetURI = client.newURIBuilder(SERVICE_URI);
|
||||
targetURI.appendEntitySetSegment(segment).appendKeySegment(key);
|
||||
|
||||
ODataEntityRequest<ODataEntity> queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
|
||||
final URI uri = (isRelative) ? new URI(SERVICE_URI).relativize(targetURI.build()) : targetURI.build();
|
||||
|
||||
ODataEntityRequest<ODataEntity> queryReq = client.getRetrieveRequestFactory().getEntityRequest(uri);
|
||||
queryReq.setFormat(ODataFormat.JSON);
|
||||
manager.addRequest(queryReq);
|
||||
}
|
||||
|
@ -53,8 +53,6 @@ public interface CommonODataClient<UT extends CommonUpdateType> {
|
||||
|
||||
CommonURIBuilder<?> newURIBuilder(String serviceRoot);
|
||||
|
||||
CommonURIBuilder<?> newBatchURIBuilder(String serviceRoot);
|
||||
|
||||
CommonFilterFactory getFilterFactory();
|
||||
|
||||
ODataSerializer getSerializer(ODataFormat format);
|
||||
|
@ -22,7 +22,6 @@ import java.util.concurrent.ExecutorService;
|
||||
|
||||
import org.apache.olingo.client.api.http.HttpClientFactory;
|
||||
import org.apache.olingo.client.api.http.HttpUriRequestFactory;
|
||||
import org.apache.olingo.client.api.uri.UriFormat;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
|
||||
@ -270,18 +269,4 @@ public interface Configuration {
|
||||
* @param executorService new executor services.
|
||||
*/
|
||||
void setExecutor(ExecutorService executorService);
|
||||
|
||||
/**
|
||||
* Returns the current URI format
|
||||
*
|
||||
* @return current URI format
|
||||
*/
|
||||
UriFormat getUriFormat();
|
||||
|
||||
/**
|
||||
* Sets the current URI format
|
||||
*
|
||||
* @param format new URI format
|
||||
*/
|
||||
void setBatchUriFormat(UriFormat format);
|
||||
}
|
||||
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.client.api.uri;
|
||||
|
||||
/**
|
||||
* Determines if absolute or relative URIs are used
|
||||
*/
|
||||
public enum UriFormat {
|
||||
/**
|
||||
* Relative URI
|
||||
*
|
||||
* Example People(1)
|
||||
*/
|
||||
RELATIVE,
|
||||
|
||||
/**
|
||||
* Absolute URI
|
||||
*
|
||||
* Example https://host:1234/path/service/People(1)
|
||||
*/
|
||||
ABSOLUTE;
|
||||
}
|
@ -45,9 +45,6 @@ public interface ODataClient extends CommonODataClient<UpdateType> {
|
||||
@Override
|
||||
URIBuilder newURIBuilder(String serviceRoot);
|
||||
|
||||
@Override
|
||||
URIBuilder newBatchURIBuilder(String serviceRoot);
|
||||
|
||||
@Override
|
||||
FilterFactory getFilterFactory();
|
||||
|
||||
|
@ -47,9 +47,6 @@ public interface ODataClient extends CommonODataClient<UpdateType> {
|
||||
@Override
|
||||
URIBuilder newURIBuilder(String serviceRoot);
|
||||
|
||||
@Override
|
||||
URIBuilder newBatchURIBuilder(String serviceRoot);
|
||||
|
||||
@Override
|
||||
FilterFactory getFilterFactory();
|
||||
|
||||
|
@ -26,7 +26,6 @@ import java.util.concurrent.Executors;
|
||||
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.api.uri.UriFormat;
|
||||
import org.apache.olingo.client.core.http.DefaultHttpClientFactory;
|
||||
import org.apache.olingo.client.core.http.DefaultHttpUriRequestFactory;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
@ -60,8 +59,6 @@ public class ConfigurationImpl implements Configuration {
|
||||
|
||||
private static final String CONTINUE_ON_ERROR = "continueOnError";
|
||||
|
||||
private static final String BATCH_URI_FORMAT = "batchUriFormat";
|
||||
|
||||
private final Map<String, Object> CONF = new HashMap<String, Object>();
|
||||
|
||||
private transient ExecutorService executor = Executors.newFixedThreadPool(10);
|
||||
@ -233,14 +230,4 @@ public class ConfigurationImpl implements Configuration {
|
||||
public void setExecutor(final ExecutorService executorService) {
|
||||
executor = executorService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UriFormat getUriFormat() {
|
||||
return (UriFormat) getProperty(BATCH_URI_FORMAT, UriFormat.ABSOLUTE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBatchUriFormat(UriFormat format) {
|
||||
setProperty(BATCH_URI_FORMAT, format);
|
||||
}
|
||||
}
|
||||
|
@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.client.core.uri.v3;
|
||||
|
||||
import org.apache.olingo.client.api.Configuration;
|
||||
import org.apache.olingo.client.api.uri.UriFormat;
|
||||
import org.apache.olingo.client.api.uri.v3.URIBuilder;
|
||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||
|
||||
public class BatchURIBuilderImpl extends URIBuilderImpl implements URIBuilder {
|
||||
|
||||
public BatchURIBuilderImpl(ODataServiceVersion version, Configuration configuration, String serviceRoot) {
|
||||
super(version, configuration, serviceRoot);
|
||||
|
||||
if (configuration.getUriFormat() == UriFormat.RELATIVE && segments.size() >= 0) {
|
||||
segments.remove(0);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.client.core.uri.v4;
|
||||
|
||||
import org.apache.olingo.client.api.Configuration;
|
||||
import org.apache.olingo.client.api.uri.UriFormat;
|
||||
import org.apache.olingo.client.api.uri.v4.URIBuilder;
|
||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||
|
||||
public class BatchURIBuilderImpl extends URIBuilderImpl implements URIBuilder {
|
||||
|
||||
public BatchURIBuilderImpl(ODataServiceVersion version, Configuration configuration, String serviceRoot) {
|
||||
super(version, configuration, serviceRoot);
|
||||
|
||||
if(configuration.getUriFormat() == UriFormat.RELATIVE && segments.size() >= 0) {
|
||||
segments.remove(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -40,7 +40,6 @@ import org.apache.olingo.client.core.communication.request.retrieve.v3.RetrieveR
|
||||
import org.apache.olingo.client.core.serialization.v3.ODataBinderImpl;
|
||||
import org.apache.olingo.client.core.serialization.v3.ODataDeserializerImpl;
|
||||
import org.apache.olingo.client.core.serialization.v3.ODataReaderImpl;
|
||||
import org.apache.olingo.client.core.uri.v3.BatchURIBuilderImpl;
|
||||
import org.apache.olingo.client.core.uri.v3.FilterFactoryImpl;
|
||||
import org.apache.olingo.client.core.uri.v3.URIBuilderImpl;
|
||||
import org.apache.olingo.commons.api.domain.v3.ODataObjectFactory;
|
||||
@ -88,11 +87,6 @@ public class ODataClientImpl extends AbstractODataClient<UpdateType> implements
|
||||
return new URIBuilderImpl(getServiceVersion(), configuration, serviceRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URIBuilder newBatchURIBuilder(String serviceRoot) {
|
||||
return new BatchURIBuilderImpl(getServiceVersion(), getConfiguration(), serviceRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilterFactory getFilterFactory() {
|
||||
return filterFactory;
|
||||
|
@ -43,7 +43,6 @@ import org.apache.olingo.client.core.communication.request.v4.AsyncRequestFactor
|
||||
import org.apache.olingo.client.core.serialization.v4.ODataBinderImpl;
|
||||
import org.apache.olingo.client.core.serialization.v4.ODataDeserializerImpl;
|
||||
import org.apache.olingo.client.core.serialization.v4.ODataReaderImpl;
|
||||
import org.apache.olingo.client.core.uri.v4.BatchURIBuilderImpl;
|
||||
import org.apache.olingo.client.core.uri.v4.FilterFactoryImpl;
|
||||
import org.apache.olingo.client.core.uri.v4.URIBuilderImpl;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataObjectFactory;
|
||||
@ -94,11 +93,6 @@ public class ODataClientImpl extends AbstractODataClient<UpdateType> implements
|
||||
return new URIBuilderImpl(getServiceVersion(), getConfiguration(), serviceRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URIBuilder newBatchURIBuilder(String serviceRoot) {
|
||||
return new BatchURIBuilderImpl(getServiceVersion(), getConfiguration(), serviceRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilterFactory getFilterFactory() {
|
||||
return filterFactory;
|
||||
|
Loading…
x
Reference in New Issue
Block a user