olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sklev...@apache.org
Subject [1/4] git commit: Fix for (authenticated) batch repeatable request
Date Mon, 26 May 2014 10:09:45 GMT
Repository: olingo-odata4
Updated Branches:
  refs/heads/olingo-266-tecsvc 7dc44812c -> 4cb3b32af


Fix for (authenticated) batch repeatable request


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/5b5ff8ea
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/5b5ff8ea
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/5b5ff8ea

Branch: refs/heads/olingo-266-tecsvc
Commit: 5b5ff8ea2302df9437e6fb54ee374ca41f6ba914
Parents: 696c586
Author: fmartelli <fabio.martelli@gmail.com>
Authored: Fri May 23 14:25:08 2014 +0200
Committer: fmartelli <fabio.martelli@gmail.com>
Committed: Fri May 23 14:25:08 2014 +0200

----------------------------------------------------------------------
 .../ext/proxy/EntityContainerFactory.java       |   2 +-
 .../EntityContainerInvocationHandler.java       |   5 +-
 .../org/apache/olingo/fit/AbstractServices.java |   3 +-
 .../olingo/fit/proxy/v4/AbstractTestITCase.java |   3 +-
 .../proxy/v4/AuthEntityCreateTestITCase.java    |   4 +-
 .../proxy/v4/AuthEntityRetrieveTestITCase.java  |   4 +-
 .../fit/proxy/v4/EntityCreateTestITCase.java    |  10 +-
 .../fit/proxy/v4/EntityRetrieveTestITCase.java  |   8 +-
 .../fit/proxy/v4/KeyAsSegmentTestITCase.java    |  27 +++--
 .../v4/UnauthorizedEntityCreateTestITCase.java  |  57 +++++++++
 .../olingo/fit/v4/AuthBatchTestITCase.java      | 118 +++++++++++++++++++
 .../olingo/fit/v4/ErrorResponseTestITCase.java  |   6 +-
 .../ODataClientErrorException.java              |   4 +-
 .../communication/request/AbstractRequest.java  |  22 +++-
 .../streamed/AbstractODataStreamedRequest.java  |  30 +++--
 .../apache/olingo/client/core/uri/URIUtils.java |  17 +--
 16 files changed, 260 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b5ff8ea/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java
b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java
index e7bad01..b2ce911 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java
@@ -37,7 +37,7 @@ public final class EntityContainerFactory<C extends CommonEdmEnabledODataClient<
   private static final Map<String, EntityContainerFactory<?>> FACTORY_PER_SERVICEROOT
=
           new ConcurrentHashMap<String, EntityContainerFactory<?>>();
 
-  private static final Map<Class<?>, Object> ENTITY_CONTAINERS = new ConcurrentHashMap<Class<?>,
Object>();
+  private final Map<Class<?>, Object> ENTITY_CONTAINERS = new ConcurrentHashMap<Class<?>,
Object>();
 
   @SuppressWarnings("unchecked")
   private static <C extends CommonEdmEnabledODataClient<?>> EntityContainerFactory<C>
getInstance(final C client) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b5ff8ea/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
index 3bbeae3..5f9433b 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
@@ -32,8 +32,6 @@ public final class EntityContainerInvocationHandler extends AbstractInvocationHa
 
   private static final long serialVersionUID = 7379006755693410764L;
 
-  private final EntityContainerFactory<?> factory;
-
   protected final String namespace;
 
   private final String name;
@@ -56,8 +54,7 @@ public final class EntityContainerInvocationHandler extends AbstractInvocationHa
       throw new IllegalArgumentException(
               ref.getName() + " is not annotated as @" + EntityContainer.class.getSimpleName());
     }
-
-    this.factory = factory;
+    
     this.name = ((EntityContainer) annotation).name();
     this.defaultEC = ((EntityContainer) annotation).isDefaultEntityContainer();
     this.namespace = ((EntityContainer) annotation).namespace();

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b5ff8ea/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
index e8c0be5..7fd0b58 100644
--- a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
+++ b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
@@ -199,6 +199,7 @@ public abstract class AbstractServices {
   @Consumes(ContentType.MULTIPART_MIXED)
   @Produces(ContentType.APPLICATION_OCTET_STREAM + ";boundary=" + BOUNDARY)
   public Response batch(
+          @HeaderParam("Authorization") @DefaultValue(StringUtils.EMPTY) String authorization,
           @HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
           final @Multipart MultipartBody attachment) {
     try {
@@ -294,7 +295,7 @@ public abstract class AbstractServices {
     if (url == null) {
       res = null;
     } else {
-      final WebClient client = WebClient.create(url);
+      final WebClient client = WebClient.create(url, "odatajclient", "odatajclient", null);
       client.headers(headers);
 
       if ("DELETE".equals(method)) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b5ff8ea/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AbstractTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AbstractTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AbstractTestITCase.java
index 9365e44..931fcf4 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AbstractTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AbstractTestITCase.java
@@ -89,7 +89,8 @@ public abstract class AbstractTestITCase {
     return customer;
   }
 
-  protected void createAndDeleteOrder(final InMemoryEntities container) {
+  protected void createAndDeleteOrder(
+          final InMemoryEntities container, final EntityContainerFactory<EdmEnabledODataClient>
containerFactory) {
     final Order order = container.getOrders().newOrder();
     order.setOrderID(105);
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b5ff8ea/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityCreateTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityCreateTestITCase.java
b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityCreateTestITCase.java
index 678e714..f447b9f 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityCreateTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityCreateTestITCase.java
@@ -23,6 +23,7 @@ import org.apache.olingo.commons.api.format.ContentType;
 import org.apache.olingo.ext.proxy.EntityContainerFactory;
 
 import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
+import static org.apache.olingo.fit.proxy.v4.AbstractTestITCase.testAuthServiceRootURL;
 import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.InMemoryEntities;
 
 public class AuthEntityCreateTestITCase extends EntityCreateTestITCase {
@@ -32,7 +33,7 @@ public class AuthEntityCreateTestITCase extends EntityCreateTestITCase {
   private InMemoryEntities ime;
 
   @Override
-  public EntityContainerFactory<EdmEnabledODataClient> getContainerFactory() {
+  protected EntityContainerFactory<EdmEnabledODataClient> getContainerFactory() {
     if (ecf == null) {
       ecf = EntityContainerFactory.getV4(testAuthServiceRootURL);
       ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
@@ -49,4 +50,5 @@ public class AuthEntityCreateTestITCase extends EntityCreateTestITCase {
     }
     return ime;
   }
+  
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b5ff8ea/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java
b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java
index c5391d0..818d3b7 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java
@@ -29,9 +29,7 @@ public class AuthEntityRetrieveTestITCase extends EntityRetrieveTestITCase
{
 
   @Override
   protected InMemoryEntities getContainer() {
-    final EntityContainerFactory<EdmEnabledODataClient> ecf =
-            EntityContainerFactory.getV4(testAuthServiceRootURL);
-    ecf.getClient().getConfiguration().setKeyAsSegment(true);
+    final EntityContainerFactory<EdmEnabledODataClient> ecf = EntityContainerFactory.getV4(testAuthServiceRootURL);
     ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
     ecf.getClient().getConfiguration().
             setHttpClientFactory(new BasicAuthHttpClientFactory("odatajclient", "odatajclient"));

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b5ff8ea/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityCreateTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityCreateTestITCase.java
b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityCreateTestITCase.java
index faea864..3dadd6a 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityCreateTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityCreateTestITCase.java
@@ -56,7 +56,7 @@ import org.junit.Test;
  */
 public class EntityCreateTestITCase extends AbstractTestITCase {
 
-  public EntityContainerFactory<EdmEnabledODataClient> getContainerFactory() {
+  protected EntityContainerFactory<EdmEnabledODataClient> getContainerFactory() {
     return containerFactory;
   }
 
@@ -66,7 +66,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
 
   @Test
   public void createAndDelete() {
-    createAndDeleteOrder(getContainer());
+    createAndDeleteOrder(getContainer(), getContainerFactory());
   }
 
   @Test
@@ -137,7 +137,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
 
     getContainer().flush();
 
-    Customer actual = readCustomer(container, id);
+    Customer actual = readCustomer(getContainer(), id);
     assertEquals(homeAddress.getCity(), actual.getHomeAddress().getCity());
     assertEquals(1, actual.getOrders().size());
     assertEquals(8, actual.getOrders().iterator().next().getOrderID(), 0);
@@ -201,7 +201,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
     assertEquals(id, order.getOrderID());
     assertEquals(id, customer.getPersonID());
 
-    Customer actual = readCustomer(container, id);
+    Customer actual = readCustomer(getContainer(), id);
     assertEquals(homeAddress.getCity(), actual.getHomeAddress().getCity());
     assertEquals(1, actual.getOrders().size());
     assertEquals(id, actual.getOrders().iterator().next().getOrderID());
@@ -216,7 +216,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase {
     order = getContainer().getOrders().get(id);
     assertNull(order);
 
-    actual = readCustomer(container, id);
+    actual = readCustomer(getContainer(), id);
     assertTrue(actual.getOrders().isEmpty());
 
     getContainer().getCustomers().delete(actual.getPersonID());

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b5ff8ea/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityRetrieveTestITCase.java
b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityRetrieveTestITCase.java
index 7d79a60..6504fa9 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityRetrieveTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityRetrieveTestITCase.java
@@ -68,7 +68,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
 
   @Test
   public void get() {
-    readCustomer(container, 1);
+    readCustomer(getContainer(), 1);
   }
 
   @Test
@@ -120,14 +120,14 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
 
   @Test
   public void withInlineEntry() {
-    final Customer customer = readCustomer(container, 1);
+    final Customer customer = readCustomer(getContainer(), 1);
     final Company company = customer.getCompany();
     assertEquals(0, company.getCompanyID(), 0);
   }
 
   @Test
   public void withInlineFeed() {
-    final Customer customer = readCustomer(container, 1);
+    final Customer customer = readCustomer(getContainer(), 1);
     final OrderCollection orders = customer.getOrders();
     assertEquals(1, orders.size());
     assertEquals(8, orders.iterator().next().getOrderID(), 0);
@@ -165,7 +165,7 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
 
   @Test
   public void contained() {
-    final PaymentInstrument instrument = container.getAccounts().get(101).getMyPaymentInstruments().get(101901);
+    final PaymentInstrument instrument = getContainer().getAccounts().get(101).getMyPaymentInstruments().get(101901);
     assertNotNull(instrument);
     assertEquals(101901, instrument.getPaymentInstrumentID(), 0);
     assertNotNull(instrument.getCreatedDate());

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b5ff8ea/fit/src/test/java/org/apache/olingo/fit/proxy/v4/KeyAsSegmentTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/KeyAsSegmentTestITCase.java
b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/KeyAsSegmentTestITCase.java
index a992133..54c0390 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/KeyAsSegmentTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/KeyAsSegmentTestITCase.java
@@ -30,12 +30,24 @@ import org.junit.Test;
 
 public class KeyAsSegmentTestITCase extends AbstractTestITCase {
 
-  private InMemoryEntities getContainer() {
-    final EntityContainerFactory<EdmEnabledODataClient> ecf = 
-            EntityContainerFactory.getV4(testKeyAsSegmentServiceRootURL);
-    ecf.getClient().getConfiguration().setKeyAsSegment(true);
-    ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
-    return ecf.getEntityContainer(InMemoryEntities.class);
+  private EntityContainerFactory<EdmEnabledODataClient> ecf;
+
+  private InMemoryEntities ime;
+
+  protected EntityContainerFactory<EdmEnabledODataClient> getContainerFactory() {
+    if (ecf == null) {
+      ecf = EntityContainerFactory.getV4(testKeyAsSegmentServiceRootURL);
+      ecf.getClient().getConfiguration().setKeyAsSegment(true);
+      ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
+    }
+    return ecf;
+  }
+
+  protected InMemoryEntities getContainer() {
+    if (ime == null) {
+      ime = getContainerFactory().getEntityContainer(InMemoryEntities.class);
+    }
+    return ime;
   }
 
   @Test
@@ -45,7 +57,7 @@ public class KeyAsSegmentTestITCase extends AbstractTestITCase {
 
   @Test
   public void createAndDelete() {
-    createAndDeleteOrder(getContainer());
+    createAndDeleteOrder(getContainer(), getContainerFactory());
   }
 
   @Test
@@ -58,5 +70,4 @@ public class KeyAsSegmentTestITCase extends AbstractTestITCase {
     person = getContainer().getPeople().get(5);
     assertEquals("middleN", person.getMiddleName());
   }
-
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b5ff8ea/fit/src/test/java/org/apache/olingo/fit/proxy/v4/UnauthorizedEntityCreateTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/UnauthorizedEntityCreateTestITCase.java
b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/UnauthorizedEntityCreateTestITCase.java
new file mode 100644
index 0000000..188a491
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/UnauthorizedEntityCreateTestITCase.java
@@ -0,0 +1,57 @@
+/*
+ * 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.fit.proxy.v4;
+
+import org.apache.olingo.client.api.http.HttpClientException;
+import org.apache.olingo.client.core.http.BasicAuthHttpClientFactory;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.ext.proxy.EntityContainerFactory;
+
+import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
+import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.InMemoryEntities;
+import org.junit.Test;
+
+public class UnauthorizedEntityCreateTestITCase extends AbstractTestITCase {
+
+  private EntityContainerFactory<EdmEnabledODataClient> ecf;
+
+  private InMemoryEntities ime;
+
+  public EntityContainerFactory<EdmEnabledODataClient> getContainerFactory() {
+    if (ecf == null) {
+      ecf = EntityContainerFactory.getV4(testAuthServiceRootURL);
+      ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
+      ecf.getClient().getConfiguration().
+              setHttpClientFactory(new BasicAuthHttpClientFactory("not_auth", "not_auth"));
+    }
+    return ecf;
+  }
+
+  @Test(expected = HttpClientException.class)
+  public void unauthorizedCreate() {
+    createAndDeleteOrder(getContainer(), getContainerFactory());
+  }
+
+  protected InMemoryEntities getContainer() {
+    if (ime == null) {
+      ime = getContainerFactory().getEntityContainer(InMemoryEntities.class);
+    }
+    return ime;
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b5ff8ea/fit/src/test/java/org/apache/olingo/fit/v4/AuthBatchTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/AuthBatchTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/AuthBatchTestITCase.java
new file mode 100644
index 0000000..2b3faea
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/AuthBatchTestITCase.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2014 The Apache Software Foundation.
+ *
+ * Licensed 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.fit.v4;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import java.net.URI;
+import org.apache.olingo.client.api.communication.header.HeaderName;
+
+import org.apache.olingo.client.api.communication.request.batch.BatchManager;
+import org.apache.olingo.client.api.communication.request.batch.ODataChangeset;
+import org.apache.olingo.client.api.communication.request.batch.v4.ODataBatchRequest;
+import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
+import org.apache.olingo.client.api.communication.request.cud.v4.UpdateType;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
+import org.apache.olingo.client.api.communication.response.ODataBatchResponse;
+import org.apache.olingo.client.api.http.HttpClientException;
+import org.apache.olingo.client.api.uri.v4.URIBuilder;
+import org.apache.olingo.client.api.v4.ODataClient;
+import org.apache.olingo.client.core.ODataClientFactory;
+import org.apache.olingo.client.core.http.BasicAuthHttpClientFactory;
+import org.apache.olingo.commons.api.domain.v4.ODataEntity;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+
+public class AuthBatchTestITCase extends AbstractTestITCase {
+
+  private final static String ACCEPT = ContentType.APPLICATION_OCTET_STREAM;
+
+  @Test
+  public void clean() throws EdmPrimitiveTypeException {
+    final ODataClient authclient = ODataClientFactory.getV4();
+    batchRequest(authclient, testStaticServiceRootURL);
+  }
+
+  @Test
+  public void authorized() throws EdmPrimitiveTypeException {
+    final ODataClient authclient = ODataClientFactory.getV4();
+    authclient.getConfiguration().setHttpClientFactory(new BasicAuthHttpClientFactory("odatajclient",
"odatajclient"));
+    batchRequest(authclient, testAuthServiceRootURL);
+  }
+
+  @Test(expected = HttpClientException.class)
+  public void unauthorized() throws EdmPrimitiveTypeException {
+    final ODataClient unauthclient = ODataClientFactory.getV4();
+    unauthclient.getConfiguration().setHttpClientFactory(new BasicAuthHttpClientFactory("not_auth",
"not_auth"));
+    batchRequest(unauthclient, testAuthServiceRootURL);
+  }
+
+  @SuppressWarnings({"unchecked"})
+  private void batchRequest(final ODataClient client, final String baseURL) throws EdmPrimitiveTypeException
{
+    // create your request
+    final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(baseURL);
+    request.setAccept(ACCEPT);
+    request.addCustomHeader("User-Agent", "Microsoft ADO.NET Data Client xxx");
+    request.addCustomHeader(HeaderName.acceptCharset, "UTF-8");
+
+    final BatchManager streamManager = request.payloadManager();
+
+    // -------------------------------------------
+    // Add retrieve item
+    // -------------------------------------------
+    // prepare URI
+    URIBuilder targetURI = client.newURIBuilder(baseURL);
+    targetURI.appendEntitySetSegment("Customers").appendKeySegment(1);
+
+    // create new request
+    ODataEntityRequest<ODataEntity> queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
+    queryReq.setFormat(ODataPubFormat.JSON);
+
+    streamManager.addRequest(queryReq);
+    // -------------------------------------------
+
+    // -------------------------------------------
+    // Add changeset item
+    // -------------------------------------------
+    final ODataChangeset changeset = streamManager.addChangeset();
+
+    // Update Customer into the changeset
+    targetURI = client.newURIBuilder(baseURL).appendEntitySetSegment("Customers").appendKeySegment(1);
+    final URI editLink = targetURI.build();
+
+    final ODataEntity patch = client.getObjectFactory().newEntity(
+            new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Customer"));
+    patch.setEditLink(editLink);
+
+    patch.getProperties().add(client.getObjectFactory().newPrimitiveProperty(
+            "LastName",
+            client.getObjectFactory().newPrimitiveValueBuilder().buildString("new last name")));
+
+    final ODataEntityUpdateRequest<ODataEntity> changeReq =
+            client.getCUDRequestFactory().getEntityUpdateRequest(UpdateType.PATCH, patch);
+    changeReq.setFormat(ODataPubFormat.JSON_FULL_METADATA);
+
+    changeset.addRequest(changeReq);
+    // -------------------------------------------
+
+    final ODataBatchResponse response = streamManager.getResponse();
+    assertEquals(200, response.getStatusCode());
+    assertEquals("OK", response.getStatusMessage());
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b5ff8ea/fit/src/test/java/org/apache/olingo/fit/v4/ErrorResponseTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/ErrorResponseTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/ErrorResponseTestITCase.java
index 902e731..a48bb49 100644
--- a/fit/src/test/java/org/apache/olingo/fit/v4/ErrorResponseTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/ErrorResponseTestITCase.java
@@ -39,16 +39,14 @@ public class ErrorResponseTestITCase extends AbstractTestITCase {
             appendEntitySetSegment("Customers").appendKeySegment(32).
             build();
 
-    final ODataEntityRequest<ODataEntity> req = getClient().getRetrieveRequestFactory().getEntityRequest(readURI);
     try {
-      final ODataEntity read = read(ODataPubFormat.JSON, readURI);
-
+      read(ODataPubFormat.JSON, readURI);
       fail("should have got exception");
     } catch (Exception ex) {
       final ODataError err = ((ODataClientErrorException) ex).getODataError();
 
       // verify details
-      final ODataErrorDetail detail = (ODataErrorDetail) err.getDetails().get(0);
+      final ODataErrorDetail detail = err.getDetails().get(0);
       assertEquals("Code should be correct", "301", detail.getCode());
       assertEquals("Target should be correct", "$search", detail.getTarget());
       assertEquals("Message should be correct", "$search query option not supported", detail.getMessage());

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b5ff8ea/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataClientErrorException.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataClientErrorException.java
b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataClientErrorException.java
index 6dc2f07..9284d42 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataClientErrorException.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataClientErrorException.java
@@ -54,7 +54,9 @@ public class ODataClientErrorException extends RuntimeException {
    * @param error OData error to be wrapped.
    */
   public ODataClientErrorException(final StatusLine statusLine, final ODataError error) {
-    super((StringUtils.isBlank(error.getCode()) ? StringUtils.EMPTY : "(" + error.getCode()
+ ") ")
+    super(error == null
+            ? statusLine.toString()
+            : (StringUtils.isBlank(error.getCode()) ? StringUtils.EMPTY : "(" + error.getCode()
+ ") ")
             + error.getMessage() + " [" + statusLine.toString() + "]");
 
     this.statusLine = statusLine;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b5ff8ea/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractRequest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractRequest.java
b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractRequest.java
index 1023618..0632c42 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractRequest.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractRequest.java
@@ -16,6 +16,8 @@
 package org.apache.olingo.client.core.communication.request;
 
 import java.io.IOException;
+import java.io.InputStream;
+import org.apache.http.Header;
 
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
@@ -24,6 +26,7 @@ import org.apache.olingo.client.api.CommonEdmEnabledODataClient;
 import org.apache.olingo.client.api.CommonODataClient;
 import org.apache.olingo.client.api.communication.ODataClientErrorException;
 import org.apache.olingo.client.api.communication.ODataServerErrorException;
+import org.apache.olingo.client.api.communication.header.HeaderName;
 import org.apache.olingo.client.api.http.HttpClientException;
 import org.apache.olingo.commons.api.domain.ODataError;
 import org.apache.olingo.commons.core.data.JSONODataErrorImpl;
@@ -57,12 +60,12 @@ public abstract class AbstractRequest {
     // If using and Edm enabled client, checks that the cached service root matches the request
URI
     if (odataClient instanceof CommonEdmEnabledODataClient
             && !request.getURI().toASCIIString().startsWith(
-                    ((CommonEdmEnabledODataClient) odataClient).getServiceRoot())) {
+            ((CommonEdmEnabledODataClient) odataClient).getServiceRoot())) {
 
       throw new IllegalArgumentException(
               String.format("The current request URI %s does not match the configured service
root %s",
-                      request.getURI().toASCIIString(),
-                      ((CommonEdmEnabledODataClient) odataClient).getServiceRoot()));
+              request.getURI().toASCIIString(),
+              ((CommonEdmEnabledODataClient) odataClient).getServiceRoot()));
     }
   }
 
@@ -75,7 +78,18 @@ public abstract class AbstractRequest {
         if (httpEntity == null) {
           throw new ODataClientErrorException(response.getStatusLine());
         } else {
-          final boolean isXML = !accept.contains("json");
+          boolean isXML;
+          if (!accept.contains("json") && !accept.contains("xml")) {
+            isXML = true;
+            for (Header header : response.getHeaders(HeaderName.contentType.toString()))
{
+              if (header.getValue() != null && header.getValue().contains("json"))
{
+                isXML = false;
+              }
+            }
+          } else {
+            isXML = !accept.contains("json");
+          }
+
           ODataError error;
           try {
             error = odataClient.getReader().readError(httpEntity.getContent(), isXML);

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b5ff8ea/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/AbstractODataStreamedRequest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/AbstractODataStreamedRequest.java
b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/AbstractODataStreamedRequest.java
index 3d5c0a2..4f3abe9 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/AbstractODataStreamedRequest.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/AbstractODataStreamedRequest.java
@@ -91,15 +91,27 @@ public abstract class AbstractODataStreamedRequest<V extends ODataResponse,
T ex
   public T payloadManager() {
     payloadManager = getPayloadManager();
 
-    ((HttpEntityEnclosingRequestBase) request).setEntity(
-            URIUtils.buildInputStreamEntity(odataClient, payloadManager.getBody()));
-
-    futureWrapper.setWrapped(odataClient.getConfiguration().getExecutor().submit(new Callable<HttpResponse>()
{
-      @Override
-      public HttpResponse call() throws Exception {
-        return doExecute();
-      }
-    }));
+    if (URIUtils.shouldUseRepeatableHttpBodyEntry(odataClient)) {
+      futureWrapper.setWrapped(odataClient.getConfiguration().getExecutor().submit(new Callable<HttpResponse>()
{
+        @Override
+        public HttpResponse call() throws Exception {
+          ((HttpEntityEnclosingRequestBase) request).setEntity(
+                  URIUtils.buildInputStreamEntity(odataClient, payloadManager.getBody()));
+
+          return doExecute();
+        }
+      }));
+    } else {
+      ((HttpEntityEnclosingRequestBase) request).setEntity(
+              URIUtils.buildInputStreamEntity(odataClient, payloadManager.getBody()));
+
+      futureWrapper.setWrapped(odataClient.getConfiguration().getExecutor().submit(new Callable<HttpResponse>()
{
+        @Override
+        public HttpResponse call() throws Exception {
+          return doExecute();
+        }
+      }));
+    }
 
     // returns the stream manager object
     return (T) payloadManager;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b5ff8ea/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java
b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java
index c97e6fd..53ece5f 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java
@@ -373,7 +373,7 @@ public final class URIUtils {
     return value;
   }
 
-  private static boolean shouldUseRepeatableHttpBodyEntry(final CommonODataClient<?>
client) {
+  public static boolean shouldUseRepeatableHttpBodyEntry(final CommonODataClient<?>
client) {
     // returns true for authentication request in case of http401 which needs retry so requires
being repeatable.
     HttpClientFactory httpclientFactory = client.getConfiguration().getHttpClientFactory();
     if (httpclientFactory instanceof BasicAuthHttpClientFactory) {
@@ -391,24 +391,13 @@ public final class URIUtils {
   public static HttpEntity buildInputStreamEntity(final CommonODataClient<?> client,
final InputStream input) {
     HttpEntity entity;
 
-    // --------------------------
-    // Check just required by batch requests since their ansynchronous entity specification
mechanism
-    // --------------------------
-    boolean contentAvailable;
-    try {
-      contentAvailable = input.available() > 0;
-    } catch (IOException ex) {
-      contentAvailable = false;
-    }
-    // --------------------------
-
-    boolean repeatableRequired = shouldUseRepeatableHttpBodyEntry(client);
-    if (!contentAvailable || !repeatableRequired) {
+    if (!shouldUseRepeatableHttpBodyEntry(client)) {
       entity = new InputStreamEntity(input, -1);
     } else {
       byte[] bytes = new byte[0];
       try {
         bytes = IOUtils.toByteArray(input);
+        IOUtils.closeQuietly(input);
       } catch (IOException e) {
         LOG.error("While reading input for not chunked encoding", e);
       }


Mime
View raw message