Repository: olingo-odata2
Updated Branches:
  refs/heads/master 0689384db -> e6cdbf1f7


[OLINGO-926] absolute-path request URLs in batch

Signed-off-by: Christian Amend <[email protected]>


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

Branch: refs/heads/master
Commit: e6cdbf1f796f32dfdb08a596547764cdbe4ff96f
Parents: 0689384
Author: Klaus Straubinger <[email protected]>
Authored: Wed Sep 7 14:48:35 2016 +0200
Committer: Christian Amend <[email protected]>
Committed: Wed Sep 7 16:23:57 2016 +0200

----------------------------------------------------------------------
 .../apache/olingo/odata2/core/PathInfoImpl.java |   8 +-
 .../batch/v2/BatchRequestTransformator.java     |   1 +
 .../core/batch/v2/BatchTransformatorCommon.java |  41 ++--
 .../odata2/core/batch/BatchHandlerTest.java     |  45 ++--
 .../core/batch/BatchRequestParserTest.java      | 240 ++++++++++---------
 .../src/test/resources/batchLarge.batch         |  36 +--
 .../odata2/fit/client/ClientBatchTest.java      |  97 +++++---
 7 files changed, 254 insertions(+), 214 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/e6cdbf1f/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/PathInfoImpl.java
----------------------------------------------------------------------
diff --git 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/PathInfoImpl.java
 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/PathInfoImpl.java
index 85000cc..d3c2479 100644
--- 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/PathInfoImpl.java
+++ 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/PathInfoImpl.java
@@ -35,12 +35,12 @@ public class PathInfoImpl implements PathInfo {
   private URI serviceRoot;
   private URI requestUri;
 
-  public void setODataPathSegment(final List<PathSegment> odataPathSegement) {
-    odataPathSegment = odataPathSegement;
+  public void setODataPathSegment(final List<PathSegment> odataPathSegment) {
+    this.odataPathSegment = odataPathSegment;
   }
 
-  public void setPrecedingPathSegment(final List<PathSegment> 
precedingPathSegement) {
-    precedingPathSegment = precedingPathSegement;
+  public void setPrecedingPathSegment(final List<PathSegment> 
precedingPathSegment) {
+    this.precedingPathSegment = precedingPathSegment;
   }
 
   public void setServiceRoot(final URI uri) {

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/e6cdbf1f/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchRequestTransformator.java
----------------------------------------------------------------------
diff --git 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchRequestTransformator.java
 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchRequestTransformator.java
index 232bb7a..bf3cc82 100644
--- 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchRequestTransformator.java
+++ 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchRequestTransformator.java
@@ -86,6 +86,7 @@ public class BatchRequestTransformator implements 
BatchTransformator {
                                                                         
baseUri, 
                                                                         
pathInfo);
     statusLine.validateHttpMethod(isChangeSet);
+    BatchTransformatorCommon.validateHost(headers, baseUri);
 
     validateBody(statusLine, operation);
     InputStream bodyStream = getBodyStream(operation, headers, statusLine);

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/e6cdbf1f/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchTransformatorCommon.java
----------------------------------------------------------------------
diff --git 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchTransformatorCommon.java
 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchTransformatorCommon.java
index 1eaaa92..3ca3cfe 100644
--- 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchTransformatorCommon.java
+++ 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchTransformatorCommon.java
@@ -99,7 +99,19 @@ public class BatchTransformatorCommon {
 
     return -1;
   }
-  
+
+  public static void validateHost(final Header headers, final String baseUri) 
throws BatchException {
+    final HeaderField hostField = headers.getHeaderField(HttpHeaders.HOST);
+
+    if (hostField != null) {
+      if (hostField.getValues().size() > 1
+          || 
!URI.create(baseUri).getAuthority().equalsIgnoreCase(hostField.getValues().get(0).trim()))
 {
+        throw new 
BatchException(BatchException.INVALID_HEADER.addContent(hostField.getValues().get(0))
+            .addContent(hostField.getLineNumber()));
+      }
+    }
+  }
+
   public static class HttpResponsetStatusLine {
     private static final String REG_EX_STATUS_LINE = 
"(?:HTTP/[0-9]\\.[0-9])\\s([0-9]{3})\\s([\\S ]+)\\s*";
     private Line httpStatusLine;
@@ -181,30 +193,29 @@ public class BatchTransformatorCommon {
       }
     }
 
-    private PathInfo parseUri(final String uri)
-        throws BatchException {
-      final PathInfoImpl pathInfo = new PathInfoImpl();
-      final String odataPathSegmentsAsString;
-      final String queryParametersAsString;
-      Pattern regexRequestUri;
-
+    private PathInfo parseUri(final String uri) throws BatchException {
+      PathInfoImpl pathInfo = new PathInfoImpl();
       pathInfo.setServiceRoot(batchRequestPathInfo.getServiceRoot());
       
pathInfo.setPrecedingPathSegment(batchRequestPathInfo.getPrecedingSegments());
 
       try {
-        URI uriObject = new URI(uri);
+        final URI uriObject = new URI(uri);
+        String relativeUri = "";
         if (uriObject.isAbsolute()) {
-          regexRequestUri = Pattern.compile(requestBaseUri + 
"/([^/][^?]*)(\\?.*)?");
+          if (uri.startsWith(requestBaseUri + '/')) {
+            relativeUri = uri.substring(requestBaseUri.length() + 1);
+          }
+        } else if 
(uri.startsWith(batchRequestPathInfo.getServiceRoot().getRawPath())) {
+          relativeUri = 
uri.substring(batchRequestPathInfo.getServiceRoot().getRawPath().length());
         } else {
-          regexRequestUri = BatchParserCommon.PATTERN_RELATIVE_URI;
-
+          relativeUri = uri;
         }
 
-        Matcher uriParts = regexRequestUri.matcher(uri);
+        Matcher uriParts = 
BatchParserCommon.PATTERN_RELATIVE_URI.matcher(relativeUri);
 
         if (uriParts.lookingAt() && uriParts.groupCount() == 2) {
-          odataPathSegmentsAsString = uriParts.group(1);
-          queryParametersAsString = uriParts.group(2) != null ? 
uriParts.group(2) : "";
+          final String odataPathSegmentsAsString = uriParts.group(1);
+          final String queryParametersAsString = uriParts.group(2) != null ? 
uriParts.group(2) : "";
 
           
pathInfo.setODataPathSegment(parseODataPathSegments(odataPathSegmentsAsString));
           if (!odataPathSegmentsAsString.startsWith("$")) {

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/e6cdbf1f/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchHandlerTest.java
----------------------------------------------------------------------
diff --git 
a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchHandlerTest.java
 
b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchHandlerTest.java
index 218e163..d520c10 100644
--- 
a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchHandlerTest.java
+++ 
b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchHandlerTest.java
@@ -27,7 +27,7 @@ import java.io.InputStream;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.HashMap;
+import java.util.Collections;
 import java.util.List;
 
 import org.apache.olingo.odata2.api.ODataService;
@@ -35,6 +35,7 @@ import org.apache.olingo.odata2.api.ODataServiceFactory;
 import org.apache.olingo.odata2.api.batch.BatchHandler;
 import org.apache.olingo.odata2.api.batch.BatchRequestPart;
 import org.apache.olingo.odata2.api.batch.BatchResponsePart;
+import org.apache.olingo.odata2.api.commons.HttpContentType;
 import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
 import org.apache.olingo.odata2.api.edm.Edm;
 import org.apache.olingo.odata2.api.ep.EntityProvider;
@@ -66,7 +67,7 @@ import org.junit.Test;
 public class BatchHandlerTest {
 
   private BatchHandler handler;
-  private static final String CONTENT_TYPE = "multipart/mixed; 
boundary=batch_123";
+  private static final String CONTENT_TYPE = HttpContentType.MULTIPART_MIXED + 
"; boundary=batch_123";
   private static final String CRLF = "\r\n";
   private static String SERVICE_BASE = "http://localhost/odata/";;
   private static String SERVICE_ROOT = null;
@@ -81,7 +82,8 @@ public class BatchHandlerTest {
     when(serviceMock.getProcessor()).thenReturn(processor);
     Edm mockEdm = MockFacade.getMockEdm();
     when(serviceMock.getEntityDataModel()).thenReturn(mockEdm);
-    List<String> supportedContentTypes = 
Arrays.asList("application/json;charset=utf-8", "application/json");
+    List<String> supportedContentTypes = Arrays.asList(
+        HttpContentType.APPLICATION_JSON_UTF8, 
HttpContentType.APPLICATION_JSON);
     
when(serviceMock.getSupportedContentTypes(EntityMediaProcessor.class)).thenReturn(supportedContentTypes);
     
when(serviceMock.getSupportedContentTypes(EntityProcessor.class)).thenReturn(supportedContentTypes);
     
when(serviceMock.getSupportedContentTypes(EntitySimplePropertyProcessor.class)).thenReturn(supportedContentTypes);
@@ -93,9 +95,8 @@ public class BatchHandlerTest {
     SERVICE_ROOT = SERVICE_BASE;
     PathInfoImpl pathInfo = new PathInfoImpl();
     pathInfo.setServiceRoot(new URI(SERVICE_ROOT));
-    List<PathSegment> odataPathSegements = new ArrayList<PathSegment>();
-    odataPathSegements.add(new ODataPathSegmentImpl("$batch", null));
-    pathInfo.setODataPathSegment(odataPathSegements);
+    pathInfo.setODataPathSegment(Collections.<PathSegment> singletonList(
+        new ODataPathSegmentImpl("$batch", null)));
     EntityProviderBatchProperties properties = 
EntityProviderBatchProperties.init().pathInfo(pathInfo).build();
     InputStream content = readFile("/batchContentIdReferencing.batch");
     List<BatchRequestPart> parsedRequest = 
EntityProvider.parseBatchRequest(CONTENT_TYPE, content, properties);
@@ -110,14 +111,12 @@ public class BatchHandlerTest {
   public void contentIdReferencingWithAdditionalSegments() throws Exception {
     SERVICE_ROOT = SERVICE_BASE + "seg1/seg2/";
     PathInfoImpl pathInfo = new PathInfoImpl();
-    List<PathSegment> precedingPathSegements = new ArrayList<PathSegment>();
-    precedingPathSegements.add(new ODataPathSegmentImpl("seg1", null));
-    precedingPathSegements.add(new ODataPathSegmentImpl("seg2", null));
-    pathInfo.setPrecedingPathSegment(precedingPathSegements);
+    pathInfo.setPrecedingPathSegment(Arrays.asList(
+        (PathSegment) new ODataPathSegmentImpl("seg1", null),
+        (PathSegment) new ODataPathSegmentImpl("seg2", null)));
     pathInfo.setServiceRoot(new URI(SERVICE_ROOT));
-    List<PathSegment> odataPathSegements = new ArrayList<PathSegment>();
-    odataPathSegements.add(new ODataPathSegmentImpl("$batch", null));
-    pathInfo.setODataPathSegment(odataPathSegements);
+    pathInfo.setODataPathSegment(Collections.<PathSegment> singletonList(
+        new ODataPathSegmentImpl("$batch", null)));
     EntityProviderBatchProperties properties = 
EntityProviderBatchProperties.init().pathInfo(pathInfo).build();
     InputStream content = readFile("/batchContentIdReferencing.batch");
     List<BatchRequestPart> parsedRequest = 
EntityProvider.parseBatchRequest(CONTENT_TYPE, content, properties);
@@ -127,23 +126,19 @@ public class BatchHandlerTest {
 
     handler.handleBatchPart(parsedRequest.get(0));
   }
-  
+
   @Test
   public void contentIdReferencingWithAdditionalSegmentsAndMatrixParameter() 
throws Exception {
     SERVICE_ROOT = SERVICE_BASE + "seg1;v=1/seg2;v=2/";
     PathInfoImpl pathInfo = new PathInfoImpl();
-    List<PathSegment> precedingPathSegements = new ArrayList<PathSegment>();
-    HashMap<String, List<String>> matrixParameters1 = new HashMap<String, 
List<String>>();
-    matrixParameters1.put("v", Arrays.asList("1"));
-    HashMap<String, List<String>> matrixParameters2 = new HashMap<String, 
List<String>>();
-    matrixParameters1.put("v", Arrays.asList("2"));
-    precedingPathSegements.add(new ODataPathSegmentImpl("seg1", 
matrixParameters1));
-    precedingPathSegements.add(new ODataPathSegmentImpl("seg2", 
matrixParameters2));
-    pathInfo.setPrecedingPathSegment(precedingPathSegements);
+    pathInfo.setPrecedingPathSegment(Arrays.asList(
+        (PathSegment) new ODataPathSegmentImpl("seg1",
+            Collections.singletonMap("v", Collections.singletonList("1"))),
+        (PathSegment) new ODataPathSegmentImpl("seg2",
+            Collections.singletonMap("v", Collections.singletonList("2")))));
     pathInfo.setServiceRoot(new URI(SERVICE_ROOT));
-    List<PathSegment> odataPathSegements = new ArrayList<PathSegment>();
-    odataPathSegements.add(new ODataPathSegmentImpl("$batch", null));
-    pathInfo.setODataPathSegment(odataPathSegements);
+    pathInfo.setODataPathSegment(Collections.<PathSegment> singletonList(
+        new ODataPathSegmentImpl("$batch", null)));
     EntityProviderBatchProperties properties = 
EntityProviderBatchProperties.init().pathInfo(pathInfo).build();
     InputStream content = readFile("/batchContentIdReferencing.batch");
     List<BatchRequestPart> parsedRequest = 
EntityProvider.parseBatchRequest(CONTENT_TYPE, content, properties);

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/e6cdbf1f/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestParserTest.java
----------------------------------------------------------------------
diff --git 
a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestParserTest.java
 
b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestParserTest.java
index f7f88ba..cdf3c4d 100644
--- 
a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestParserTest.java
+++ 
b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestParserTest.java
@@ -51,7 +51,8 @@ public class BatchRequestParserTest {
   private static final String PUT_REQUEST_HEADER_CONTENT_ID = "BBB_REQUEST1";
   private static final String SERVICE_ROOT = "http://localhost/odata/";;
   private static EntityProviderBatchProperties batchProperties;
-  private static final String contentType = 
"multipart/mixed;boundary=batch_8194-cf13-1f56";
+  private static final String BOUNDARY = "batch_8194-cf13-1f56";
+  private static final String contentType = "multipart/mixed;boundary=" + 
BOUNDARY;
   private static final String MIME_HEADERS = "Content-Type: application/http" 
+ CRLF
       + "Content-Transfer-Encoding: binary" + CRLF;
   private static final String GET_REQUEST = MIME_HEADERS + CRLF
@@ -129,7 +130,7 @@ public class BatchRequestParserTest {
       throw new IOException("Requested file '" + fileName + "' was not 
found.");
     }
     String content = StringHelper.inputStreamToString(contentInputStream);
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + MIME_HEADERS
         + CRLF
         + "GET Employees?$filter=Age%20gt%2040 HTTP/1.1" + CRLF
@@ -137,7 +138,7 @@ public class BatchRequestParserTest {
         + "MaxDataServiceVersion: 2.0" + CRLF
         + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56" + CRLF
+        + "--" + BOUNDARY + CRLF
         + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + 
CRLF
         + CRLF
         + "--changeset_f980-1cb6-94dd" + CRLF
@@ -152,7 +153,7 @@ public class BatchRequestParserTest {
         + content + CRLF
         + CRLF
         + "--changeset_f980-1cb6-94dd--" + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     List<BatchRequestPart> BatchRequestParts = parse(batch);
     for (BatchRequestPart object : BatchRequestParts) {
       if (!object.isChangeSet()) {
@@ -187,7 +188,7 @@ public class BatchRequestParserTest {
     }
     StringHelper.inputStreamToString(contentInputStream);
     String batch = CRLF
-        + "--batch_8194-cf13-1f56" + CRLF
+        + "--" + BOUNDARY + CRLF
         + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + 
CRLF
         + CRLF
         + "--changeset_f980-1cb6-94dd" + CRLF
@@ -201,7 +202,7 @@ public class BatchRequestParserTest {
         + CRLF
         + "--changeset_f980-1cb6-94dd--" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     List<BatchRequestPart> batchRequestParts = parse(batch);
     for (BatchRequestPart object : batchRequestParts) {
       if (object.isChangeSet()) {
@@ -268,21 +269,21 @@ public class BatchRequestParserTest {
   public void testWrongBoundaryString() throws BatchException {
     String batch = "--batch_8194-cf13-1f5" + CRLF
         + GET_REQUEST
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testMissingHttpVersion() throws BatchException {
     String batch = ""
-        + "--batch_8194-cf13-1f56" + CRLF
+        + "--" + BOUNDARY + CRLF
         + "Content-Type: application/http" + CRLF
         + "Content-Transfer-Encoding:binary" + CRLF
         + CRLF
         + "GET Employees?$format=json" + CRLF
         + "Host: localhost:8080" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
 
     parseInvalidBatchBody(batch);
   }
@@ -290,14 +291,14 @@ public class BatchRequestParserTest {
   @Test(expected = BatchException.class)
   public void testMissingHttpVersion2() throws BatchException {
     String batch = ""
-        + "--batch_8194-cf13-1f56" + CRLF
+        + "--" + BOUNDARY + CRLF
         + "Content-Type: application/http" + CRLF
         + "Content-Transfer-Encoding:binary" + CRLF
         + CRLF
         + "GET Employees?$format=json " + CRLF
         + "Host: localhost:8080" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
 
     parseInvalidBatchBody(batch);
   }
@@ -305,45 +306,45 @@ public class BatchRequestParserTest {
   @Test(expected = BatchException.class)
   public void testMissingHttpVersion3() throws BatchException {
     String batch = ""
-        + "--batch_8194-cf13-1f56" + CRLF
+        + "--" + BOUNDARY + CRLF
         + "Content-Type: application/http" + CRLF
         + "Content-Transfer-Encoding:binary" + CRLF
         + CRLF
         + "GET Employees?$format=json SMTP:3.1" + CRLF
         + "Host: localhost:8080" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
 
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testBoundaryWithoutHyphen() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + GET_REQUEST
-        + "batch_8194-cf13-1f56" + CRLF
+        + BOUNDARY + CRLF
         + GET_REQUEST
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testNoBoundaryString() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + GET_REQUEST
         // + no boundary string
         + GET_REQUEST
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
 
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testBatchBoundaryEqualsChangeSetBoundary() throws BatchException 
{
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + "Content-Type: multipart/mixed;boundary=batch_8194-cf13-1f56" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56" + CRLF
+        + "--" + BOUNDARY + CRLF
         + MIME_HEADERS
         + CRLF
         + "PUT Employees('2')/EmployeeName HTTP/1.1" + CRLF
@@ -353,17 +354,16 @@ public class BatchRequestParserTest {
         + CRLF
         + "{\"EmployeeName\":\"Frederic Fall MODIFIED\"}" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     parseInvalidBatchBody(batch);
   }
 
   @Test
   public void testContentTypeCharset() throws BatchException {
-    final String contentType = "multipart/mixed; 
charset=UTF-8;boundary=batch_14d1-b293-b99a";
-    final String batch = ""
-        + "--batch_14d1-b293-b99a" + CRLF
+    final String contentType = "multipart/mixed; charset=UTF-8;boundary=" + 
BOUNDARY;
+    final String batch = "--" + BOUNDARY + CRLF
         + GET_REQUEST
-        + "--batch_14d1-b293-b99a--";
+        + "--" + BOUNDARY + "--";
     final BatchParser parser = new BatchParser(contentType, batchProperties, 
true);
     final List<BatchRequestPart> parts = parser.parseBatchRequest(new 
ByteArrayInputStream(batch.getBytes()));
 
@@ -372,11 +372,10 @@ public class BatchRequestParserTest {
 
   @Test
   public void testContentTypeCharsetWrongBoundaryAtEnd() throws BatchException 
{
-    final String contentType = "multipart/mixed; 
charset=UTF-8;boundary=batch_14d1-b293-b99a;boundary=wrong_boundary";
-    final String batch = ""
-        + "--batch_14d1-b293-b99a" + CRLF
+    final String contentType = "multipart/mixed; charset=UTF-8;boundary=" + 
BOUNDARY + ";boundary=wrong_boundary";
+    final String batch = "--" + BOUNDARY + CRLF
         + GET_REQUEST
-        + "--batch_14d1-b293-b99a--";
+        + "--" + BOUNDARY + "--";
     final BatchParser parser = new BatchParser(contentType, batchProperties, 
true);
     final List<BatchRequestPart> parts = parser.parseBatchRequest(new 
ByteArrayInputStream(batch.getBytes()));
 
@@ -385,11 +384,10 @@ public class BatchRequestParserTest {
 
   @Test(expected = BatchException.class)
   public void testContentTypeCharsetWrongBoundaryAtBeginning() throws 
BatchException {
-    final String contentType = "multipart/mixed; 
charset=UTF-8;boundary=wrong_boundary;boundary=batch_14d1-b293-b99a";
-    final String batch = ""
-        + "--batch_14d1-b293-b99a" + CRLF
+    final String contentType = "multipart/mixed; 
charset=UTF-8;boundary=wrong_boundary;boundary=" + BOUNDARY;
+    final String batch = "--" + BOUNDARY + CRLF
         + GET_REQUEST
-        + "--batch_14d1-b293-b99a--";
+        + "--" + BOUNDARY + "--";
     final BatchParser parser = new BatchParser(contentType, batchProperties, 
true);
     final List<BatchRequestPart> parts = parser.parseBatchRequest(new 
ByteArrayInputStream(batch.getBytes()));
 
@@ -398,67 +396,67 @@ public class BatchRequestParserTest {
 
   @Test(expected = BatchException.class)
   public void testNoContentType() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + "Content-Transfer-Encoding: binary" + CRLF
         + CRLF
         + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testMimeHeaderContentType() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + "Content-Type: text/plain" + CRLF
         + "Content-Transfer-Encoding: binary" + CRLF
         + CRLF
         + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testMimeHeaderEncoding() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + "Content-Type: application/http" + CRLF
         + "Content-Transfer-Encoding: 8bit" + CRLF
         + CRLF
         + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testGetRequestMissingCRLF() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + MIME_HEADERS
         + "Content-ID: 1" + CRLF
         + CRLF
         + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
         // + CRLF // Belongs to the GET request
         + CRLF // Belongs to the
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
 
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testInvalidMethodForBatch() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + MIME_HEADERS
         + CRLF
         + "POST Employees('1')/EmployeeName HTTP/1.1" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testNoBoundaryFound() throws BatchException {
-    String batch = "batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + MIME_HEADERS
         + CRLF
         + "POST Employees('1')/EmployeeName HTTP/1.1" + CRLF
@@ -474,18 +472,18 @@ public class BatchRequestParserTest {
 
   @Test(expected = BatchException.class)
   public void testNoMethod() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + MIME_HEADERS
         + CRLF
         + /* GET */"Employees('1')/EmployeeName HTTP/1.1" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testInvalidMethodForChangeset() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + 
CRLF
         + CRLF
         + "--changeset_f980-1cb6-94dd" + CRLF
@@ -495,13 +493,13 @@ public class BatchRequestParserTest {
         + "Content-Type: application/json;odata=verbose" + CRLF
         + "MaxDataServiceVersion: 2.0" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testInvalidChangeSetBoundary() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + "Content-Type: multipart/mixed;boundary=changeset_f980-1cb6-94dd" + 
CRLF
         + CRLF
         + "--changeset_f980-1cb6-94d"/* +"d" */+ CRLF
@@ -513,13 +511,13 @@ public class BatchRequestParserTest {
         + CRLF
         + "--changeset_f980-1cb6-94dd--" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testNestedChangeset() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + "Content-Type: multipart/mixed;boundary=changeset_f980-1cb6-94dd" + 
CRLF
         + CRLF
         + "--changeset_f980-1cb6-94dd" + CRLF
@@ -538,13 +536,13 @@ public class BatchRequestParserTest {
         + CRLF
         + "--changeset_f980-1cb6-94dd--" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     parse(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testMissingContentTransferEncoding() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + "Content-Type: multipart/mixed;boundary=changeset_f980-1cb6-94dd" + 
CRLF
         + CRLF
         + "--changeset_f980-1cb6-94dd" + CRLF
@@ -556,13 +554,13 @@ public class BatchRequestParserTest {
         + "MaxDataServiceVersion: 2.0" + CRLF
         + CRLF
         + "--changeset_f980-1cb6-94dd--" + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testMissingContentType() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + "Content-Type: multipart/mixed;boundary=changeset_f980-1cb6-94dd" + 
CRLF
         + CRLF
         + "--changeset_f980-1cb6-94dd" + CRLF
@@ -574,20 +572,20 @@ public class BatchRequestParserTest {
         + "MaxDataServiceVersion: 2.0" + CRLF
         + CRLF
         + "--changeset_f980-1cb6-94dd--" + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testNoCloseDelimiter() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + GET_REQUEST;
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testNoCloseDelimiter2() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + MIME_HEADERS
         + CRLF
         + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF;
@@ -596,39 +594,67 @@ public class BatchRequestParserTest {
 
   @Test(expected = BatchException.class)
   public void testInvalidUri() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + MIME_HEADERS
         + CRLF
         + "GET http://localhost/aa/odata/Employees('1')/EmployeeName HTTP/1.1" 
+ CRLF
         + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
+    parseInvalidBatchBody(batch);
+  }
+
+  @Test
+  public void uriWithAbsolutePath() throws Exception {
+    final String batch = "--" + BOUNDARY + CRLF
+        + MIME_HEADERS
+        + CRLF
+        + "GET /odata/Employees('1')/EmployeeName HTTP/1.1" + CRLF
+        + CRLF
+        + CRLF
+        + "--" + BOUNDARY + "--";
+    final List<BatchRequestPart> batchRequestParts = parse(batch);
+    assertEquals(1, batchRequestParts.size());
+    assertEquals(1, batchRequestParts.get(0).getRequests().size());
+    final ODataRequest request = batchRequestParts.get(0).getRequests().get(0);
+    assertEquals(ODataHttpMethod.GET, request.getMethod());
+  }
+
+  @Test(expected = BatchException.class)
+  public void uriWithWrongAbsolutePath() throws BatchException {
+    String batch = "--" + BOUNDARY + CRLF
+        + MIME_HEADERS
+        + CRLF
+        + "GET /wrong/Employees('1')/EmployeeName HTTP/1.1" + CRLF
+        + CRLF
+        + CRLF
+        + "--" + BOUNDARY + "--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
-  public void testUriWithAbsolutePath() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+  public void wrongHost() throws BatchException {
+    String batch = "--" + BOUNDARY + CRLF
         + MIME_HEADERS
         + CRLF
         + "GET /odata/Employees('1')/EmployeeName HTTP/1.1" + CRLF
+        + "Host: wrongHost" + CRLF
         + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testNoCloseDelimiter3() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF + GET_REQUEST + 
"--batch_8194-cf13-1f56-"/* no hash */;
+    String batch = "--" + BOUNDARY + CRLF
+        + GET_REQUEST + "--" + BOUNDARY + "-";
     parseInvalidBatchBody(batch);
   }
 
   @Test
   public void testAcceptHeaders() throws BatchException, URISyntaxException {
-    String batch =
-        "--batch_8194-cf13-1f56"
-            + CRLF
+    String batch = "--" + BOUNDARY + CRLF
             + MIME_HEADERS
             + CRLF
             + "GET Employees('2')/EmployeeName HTTP/1.1"
@@ -642,7 +668,7 @@ public class BatchRequestParserTest {
             + CRLF
             + CRLF
             + CRLF
-            + "--batch_8194-cf13-1f56--";
+            + "--" + BOUNDARY + "--";
     List<BatchRequestPart> batchRequestParts = parse(batch);
     for (BatchRequestPart multipart : batchRequestParts) {
       if (!multipart.isChangeSet()) {
@@ -660,7 +686,7 @@ public class BatchRequestParserTest {
 
   @Test
   public void testAcceptHeaders2() throws BatchException, URISyntaxException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + MIME_HEADERS
         + CRLF
         + "GET Employees('2')/EmployeeName HTTP/1.1" + CRLF
@@ -669,7 +695,7 @@ public class BatchRequestParserTest {
         + "Accept: */*;q=0.5, 
application/json;odata=verbose;q=1.0,application/atom+xml" + CRLF
         + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     List<BatchRequestPart> batchRequestParts = parse(batch);
     for (BatchRequestPart multipart : batchRequestParts) {
       if (!multipart.isChangeSet()) {
@@ -688,7 +714,7 @@ public class BatchRequestParserTest {
 
   @Test
   public void testAcceptHeaders3() throws BatchException, URISyntaxException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + MIME_HEADERS
         + CRLF
         + "GET Employees('2')/EmployeeName HTTP/1.1" + CRLF
@@ -697,7 +723,7 @@ public class BatchRequestParserTest {
         + "accept: 
*/*,application/atom+xml,application/atomsvc+xml,application/xml" + CRLF
         + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     List<BatchRequestPart> batchRequestParts = parse(batch);
     for (BatchRequestPart multipart : batchRequestParts) {
       if (!multipart.isChangeSet()) {
@@ -716,11 +742,9 @@ public class BatchRequestParserTest {
     }
   }
 
-  @SuppressWarnings("unused")
   @Test
   public void testNegativeContentLengthChangeSet() throws BatchException, 
IOException {
-    String batch = ""
-        + "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + 
CRLF
         + CRLF
         + "--changeset_f980-1cb6-94dd" + CRLF
@@ -735,17 +759,15 @@ public class BatchRequestParserTest {
         + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
         + "--changeset_f980-1cb6-94dd--" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     InputStream in = new ByteArrayInputStream(batch.getBytes());
     BatchParser parser = new BatchParser(contentType, batchProperties, true);
-    List<BatchRequestPart> batchRequestParts = parser.parseBatchRequest(in);
+    parser.parseBatchRequest(in);
   }
 
-  @SuppressWarnings("unused")
   @Test(expected = BatchException.class)
   public void testNegativeContentLengthRequest() throws BatchException, 
IOException {
-    String batch = ""
-        + "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + 
CRLF
         + CRLF
         + "--changeset_f980-1cb6-94dd" + CRLF
@@ -760,16 +782,15 @@ public class BatchRequestParserTest {
         + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
         + "--changeset_f980-1cb6-94dd--" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     InputStream in = new ByteArrayInputStream(batch.getBytes());
     BatchParser parser = new BatchParser(contentType, batchProperties, true);
-    List<BatchRequestPart> batchRequestParts = parser.parseBatchRequest(in);
+    parser.parseBatchRequest(in);
   }
 
   @Test
   public void testContentLengthGreatherThanBodyLength() throws BatchException, 
IOException {
-    String batch = ""
-        + "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + 
CRLF
         + CRLF
         + "--changeset_f980-1cb6-94dd" + CRLF
@@ -784,7 +805,7 @@ public class BatchRequestParserTest {
         + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
         + "--changeset_f980-1cb6-94dd--" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     InputStream in = new ByteArrayInputStream(batch.getBytes());
     BatchParser parser = new BatchParser(contentType, batchProperties, true);
     List<BatchRequestPart> batchRequestParts = parser.parseBatchRequest(in);
@@ -800,8 +821,7 @@ public class BatchRequestParserTest {
 
   @Test
   public void testContentLengthSmallerThanBodyLength() throws BatchException, 
IOException {
-    String batch = ""
-        + "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + 
CRLF
         + CRLF
         + "--changeset_f980-1cb6-94dd" + CRLF
@@ -816,7 +836,7 @@ public class BatchRequestParserTest {
         + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
         + "--changeset_f980-1cb6-94dd--" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     InputStream in = new ByteArrayInputStream(batch.getBytes());
     BatchParser parser = new BatchParser(contentType, batchProperties, true);
     List<BatchRequestPart> batchRequestParts = parser.parseBatchRequest(in);
@@ -832,8 +852,7 @@ public class BatchRequestParserTest {
 
   @Test(expected = BatchException.class)
   public void testNonNumericContentLength() throws BatchException {
-    String batch = ""
-        + "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + 
CRLF
         + CRLF
         + "--changeset_f980-1cb6-94dd" + CRLF
@@ -848,7 +867,7 @@ public class BatchRequestParserTest {
         + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
         + "--changeset_f980-1cb6-94dd--" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     InputStream in = new ByteArrayInputStream(batch.getBytes());
     BatchParser parser = new BatchParser(contentType, batchProperties, true);
     parser.parseBatchRequest(in);
@@ -856,7 +875,7 @@ public class BatchRequestParserTest {
 
   @Test
   public void testNonStrictParser() throws BatchException, IOException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + "Content-Type: multipart/mixed;boundary=changeset_8194-cf13-1f56" + 
CRLF
         + "--changeset_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
@@ -867,7 +886,7 @@ public class BatchRequestParserTest {
         + "MaxDataServiceVersion: 2.0" + CRLF
         + "{\"EmployeeName\":\"Frederic Fall MODIFIED\"}" + CRLF
         + "--changeset_8194-cf13-1f56--" + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
 
     InputStream in = new ByteArrayInputStream(batch.getBytes());
     BatchParser parser = new BatchParser(contentType, batchProperties, false);
@@ -888,7 +907,7 @@ public class BatchRequestParserTest {
 
   @Test(expected = BatchException.class)
   public void testNonStrictParserMoreCRLF() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + "Content-Type: multipart/mixed;boundary=changeset_8194-cf13-1f56" + 
CRLF
         + "--changeset_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
@@ -900,7 +919,7 @@ public class BatchRequestParserTest {
         + "MaxDataServiceVersion: 2.0" + CRLF
         + "{\"EmployeeName\":\"Frederic Fall MODIFIED\"}" + CRLF
         + "--changeset_8194-cf13-1f56--" + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
 
     InputStream in = new ByteArrayInputStream(batch.getBytes());
     BatchParser parser = new BatchParser(contentType, batchProperties, false);
@@ -909,7 +928,7 @@ public class BatchRequestParserTest {
 
   @Test
   public void testContentId() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + MIME_HEADERS
         + CRLF
         + "GET Employees HTTP/1.1" + CRLF
@@ -939,7 +958,7 @@ public class BatchRequestParserTest {
         + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
         + "--changeset_f980-1cb6-94dd--" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     InputStream in = new ByteArrayInputStream(batch.getBytes());
     BatchParser parser = new BatchParser(contentType, batchProperties, true);
     List<BatchRequestPart> batchRequestParts = parser.parseBatchRequest(in);
@@ -969,7 +988,7 @@ public class BatchRequestParserTest {
 
   @Test
   public void testNoContentId() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + MIME_HEADERS
         + CRLF
         + "GET Employees HTTP/1.1" + CRLF
@@ -995,7 +1014,7 @@ public class BatchRequestParserTest {
         + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
         + "--changeset_f980-1cb6-94dd--" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     InputStream in = new ByteArrayInputStream(batch.getBytes());
     BatchParser parser = new BatchParser(contentType, batchProperties, true);
     List<BatchRequestPart> batchRequestParts = parser.parseBatchRequest(in); 
// No exception should be thrown
@@ -1009,7 +1028,7 @@ public class BatchRequestParserTest {
         + CRLF
         + CRLF
         + "----1242" + CRLF
-        + "--batch_8194-cf13-1f56" + CRLF
+        +  "--" + BOUNDARY + CRLF
         + MIME_HEADERS
         + CRLF
         + "GET Employees HTTP/1.1" + CRLF
@@ -1044,7 +1063,7 @@ public class BatchRequestParserTest {
         + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
         + "--changeset_f980-1cb6-94dd--" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     InputStream in = new ByteArrayInputStream(batch.getBytes());
     BatchParser parser = new BatchParser(contentType, batchProperties, true);
     List<BatchRequestPart> batchRequestParts = parser.parseBatchRequest(in);
@@ -1069,8 +1088,7 @@ public class BatchRequestParserTest {
   @SuppressWarnings("unused")
   @Test
   public void testContentTypeCaseInsensitive() throws BatchException, 
IOException {
-    String batch = ""
-        + "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + "Content-Type: muLTiParT/mixed; boundary=changeset_f980-1cb6-94dd" + 
CRLF
         + CRLF
         + "--changeset_f980-1cb6-94dd" + CRLF
@@ -1085,7 +1103,7 @@ public class BatchRequestParserTest {
         + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
         + "--changeset_f980-1cb6-94dd--" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     InputStream in = new ByteArrayInputStream(batch.getBytes());
     BatchParser parser = new BatchParser(contentType, batchProperties, true);
     List<BatchRequestPart> batchRequestParts = parser.parseBatchRequest(in);
@@ -1093,8 +1111,7 @@ public class BatchRequestParserTest {
 
   @Test
   public void testContentTypeBoundaryCaseInsensitive() throws BatchException, 
IOException {
-    String batch = ""
-        + "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + "Content-Type: multipart/mixed; bOunDaRy=changeset_f980-1cb6-94dd" + 
CRLF
         + CRLF
         + "--changeset_f980-1cb6-94dd" + CRLF
@@ -1109,7 +1126,7 @@ public class BatchRequestParserTest {
         + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
         + "--changeset_f980-1cb6-94dd--" + CRLF
         + CRLF
-        + "--batch_8194-cf13-1f56--";
+        + "--" + BOUNDARY + "--";
     InputStream in = new ByteArrayInputStream(batch.getBytes());
     BatchParser parser = new BatchParser(contentType, batchProperties, true);
     List<BatchRequestPart> batchRequestParts = parser.parseBatchRequest(in);
@@ -1122,8 +1139,7 @@ public class BatchRequestParserTest {
 
   @Test
   public void testEpilog() throws BatchException, IOException {
-    String batch = ""
-        + "--batch_8194-cf13-1f56" + CRLF
+    String batch = "--" + BOUNDARY + CRLF
         + MIME_HEADERS
         + CRLF
         + "GET Employees HTTP/1.1" + CRLF
@@ -1157,10 +1173,8 @@ public class BatchRequestParserTest {
         + "This is an epilog and must be ignored" + CRLF
         + CRLF
         + CRLF
-        + "----1242"
-        + CRLF
-        + "--batch_8194-cf13-1f56--"
-        + CRLF
+        + "----1242" + CRLF
+        + "--" + BOUNDARY + "--" + CRLF
         + "This is an epilog and must be ignored" + CRLF
         + CRLF
         + CRLF

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/e6cdbf1f/odata2-lib/odata-core/src/test/resources/batchLarge.batch
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/resources/batchLarge.batch 
b/odata2-lib/odata-core/src/test/resources/batchLarge.batch
index faadea1..2656fe0 100644
--- a/odata2-lib/odata-core/src/test/resources/batchLarge.batch
+++ b/odata2-lib/odata-core/src/test/resources/batchLarge.batch
@@ -3,7 +3,7 @@ Content-Type: application/http
 Content-Transfer-Encoding: binary
 
 GET Employees HTTP/1.1
-Host: http://localhost/odata
+Host: localhost
 Connection: keep-alive
 Accept: application/atom+xml
 MaxDataServiceVersion: 2.0
@@ -18,7 +18,7 @@ Content-Type: application/http
 Content-Transfer-Encoding: binary
 
 GET Employees HTTP/1.1
-Host: http://localhost/odata
+Host: localhost
 Connection: keep-alive
 Accept: application/atom+xml
 MaxDataServiceVersion: 2.0
@@ -33,7 +33,7 @@ Content-Type: application/http
 Content-Transfer-Encoding: binary
 
 GET Employees HTTP/1.1
-Host: http://localhost/odata
+Host: localhost
 Connection: keep-alive
 Accept: application/atom+xml
 MaxDataServiceVersion: 2.0
@@ -52,7 +52,7 @@ Content-Transfer-Encoding: binary
 Content-ID: 1
 
 POST Employees HTTP/1.1
-Host: http://localhost/odata
+Host: localhost
 Connection: keep-alive
 Content-Type: application/atom+xml
 Accept: */*
@@ -267,7 +267,7 @@ Content-Transfer-Encoding: binary
 Content-ID: 1
 
 POST Employees HTTP/1.1
-Host: http://localhost/odata
+Host: localhost
 Connection: keep-alive
 Content-Type: application/atom+xml
 Accept: */*
@@ -482,7 +482,7 @@ Content-Transfer-Encoding: binary
 Content-ID: 1
 
 PUT Employees('1') HTTP/1.1
-Host: http://localhost/odata
+Host: localhost
 Connection: keep-alive
 
 Content-Type: application/atom+xml
@@ -528,7 +528,7 @@ Content-Transfer-Encoding: binary
 Content-ID: 1
 
 POST Employees HTTP/1.1
-Host: http://localhost/odata
+Host: localhost
 Connection: keep-alive
 Content-Type: application/atom+xml
 Accept: */*
@@ -743,7 +743,7 @@ Content-Transfer-Encoding: binary
 Content-ID: 1
 
 POST Employees HTTP/1.1
-Host: http://localhost/odata
+Host: localhost
 Connection: keep-alive
 Content-Type: application/atom+xml
 Accept: */*
@@ -958,7 +958,7 @@ Content-Transfer-Encoding: binary
 Content-ID: 1
 
 PUT Employees('1') HTTP/1.1
-Host: http://localhost/odata
+Host: localhost
 Connection: keep-alive
 Content-Type: application/atom+xml
 Accept: */*
@@ -1003,7 +1003,7 @@ Content-Transfer-Encoding: binary
 Content-ID: 1
 
 POST Employees HTTP/1.1
-Host: http://localhost/odata
+Host: localhost
 Connection: keep-alive
 Content-Type: application/atom+xml
 Accept: */*
@@ -1218,7 +1218,7 @@ Content-Transfer-Encoding: binary
 Content-ID: 1
 
 POST Employees HTTP/1.1
-Host: http://localhost/odata
+Host: localhost
 Connection: keep-alive
 Content-Type: application/atom+xml
 Accept: */*
@@ -1433,7 +1433,7 @@ Content-Transfer-Encoding: binary
 Content-ID: 1
 
 PUT Employees('1') HTTP/1.1
-Host: http://localhost/odata
+Host: localhost
 Connection: keep-alive
 Content-Type: application/atom+xml
 Accept: */*
@@ -1478,7 +1478,7 @@ Content-Transfer-Encoding: binary
 Content-ID: 1
 
 POST Employees HTTP/1.1
-Host: http://localhost/odata
+Host: localhost
 Connection: keep-alive
 Content-Type: application/atom+xml
 Accept: */*
@@ -1693,7 +1693,7 @@ Content-Transfer-Encoding: binary
 Content-ID: 1
 
 POST Employees HTTP/1.1
-Host: http://localhost/odata
+Host: localhost
 Connection: keep-alive
 Content-Type: application/atom+xml
 Accept: */*
@@ -1908,7 +1908,7 @@ Content-Transfer-Encoding: binary
 Content-ID: 1
 
 PUT Employees('1') HTTP/1.1
-Host: http://localhost/odata
+Host: localhost
 Connection: keep-alive
 Content-Type: application/atom+xml
 Accept: */*
@@ -1953,7 +1953,7 @@ Content-Transfer-Encoding: binary
 Content-ID: 1
 
 POST Employees HTTP/1.1
-Host: http://localhost/odata
+Host: localhost
 Connection: keep-alive
 Content-Type: application/atom+xml
 Accept: */*
@@ -2168,7 +2168,7 @@ Content-Transfer-Encoding: binary
 Content-ID: 1
 
 POST Employees HTTP/1.1
-Host: http://localhost/odata
+Host: localhost
 Connection: keep-alive
 Content-Type: application/atom+xml
 Accept: */*
@@ -2383,7 +2383,7 @@ Content-Transfer-Encoding: binary
 Content-ID: 1
 
 PUT Employees('1') HTTP/1.1
-Host: http://localhost/odata
+Host: localhost
 Connection: keep-alive
 Content-Type: application/atom+xml
 Accept: */*

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/e6cdbf1f/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/ClientBatchTest.java
----------------------------------------------------------------------
diff --git 
a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/ClientBatchTest.java
 
b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/ClientBatchTest.java
index 83dff6f..cf6c9f3 100644
--- 
a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/ClientBatchTest.java
+++ 
b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/ClientBatchTest.java
@@ -23,9 +23,11 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -40,7 +42,10 @@ import 
org.apache.olingo.odata2.api.client.batch.BatchChangeSetPart;
 import org.apache.olingo.odata2.api.client.batch.BatchPart;
 import org.apache.olingo.odata2.api.client.batch.BatchQueryPart;
 import org.apache.olingo.odata2.api.client.batch.BatchSingleResponse;
+import org.apache.olingo.odata2.api.commons.HttpContentType;
 import org.apache.olingo.odata2.api.commons.HttpHeaders;
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.commons.ODataHttpMethod;
 import org.apache.olingo.odata2.api.ep.EntityProvider;
 import org.apache.olingo.odata2.fit.ref.AbstractRefTest;
 import org.apache.olingo.odata2.testutil.helper.StringHelper;
@@ -52,15 +57,12 @@ public class ClientBatchTest extends AbstractRefTest {
     super(servletType);
   }
 
-  private static final String PUT = "PUT";
-  private static final String POST = "POST";
-  private static final String GET = "GET";
   private static final String BOUNDARY = "batch_123";
 
   @Test
-  public void testSimpleBatch() throws Exception {
+  public void simpleBatch() throws Exception {
     List<BatchPart> batch = new ArrayList<BatchPart>();
-    BatchPart request = BatchQueryPart.method(GET).uri("$metadata").build();
+    BatchPart request = 
BatchQueryPart.method(ODataHttpMethod.GET.name()).uri("$metadata").build();
     batch.add(request);
 
     InputStream body = EntityProvider.writeBatchRequest(batch, BOUNDARY);
@@ -83,14 +85,37 @@ public class ClientBatchTest extends AbstractRefTest {
   }
 
   @Test
-  public void testChangeSetBatch() throws Exception {
+  public void simpleBatchWithAbsoluteUri() throws Exception {
+    final String batchRequestBody = 
StringHelper.inputStreamToStringCRLFLineBreaks(
+        EntityProvider.writeBatchRequest(
+            Collections.<BatchPart> singletonList(
+                BatchQueryPart
+                    .method(ODataHttpMethod.GET.name())
+                    .uri(getEndpoint().getPath() + 
"Employees('2')/EmployeeName/$value")
+                    .build()),
+            BOUNDARY));
+    final HttpResponse batchResponse = execute(batchRequestBody);
+    final List<BatchSingleResponse> responses = 
EntityProvider.parseBatchResponse(
+        batchResponse.getEntity().getContent(),
+        batchResponse.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue());
+    assertEquals(1, responses.size());
+    final BatchSingleResponse response = responses.get(0);
+    assertEquals(Integer.toString(HttpStatusCodes.OK.getStatusCode()), 
response.getStatusCode());
+    assertEquals(HttpStatusCodes.OK.getInfo(), response.getStatusInfo());
+    assertEquals(EMPLOYEE_2_NAME, response.getBody());
+    assertEquals(HttpContentType.TEXT_PLAIN_UTF8, 
response.getHeader(HttpHeaders.CONTENT_TYPE));
+    assertNotNull(response.getHeader(HttpHeaders.CONTENT_LENGTH));
+  }
+
+  @Test
+  public void changeSetBatch() throws Exception {
     List<BatchPart> batch = new ArrayList<BatchPart>();
 
     BatchChangeSet changeSet = BatchChangeSet.newBuilder().build();
     Map<String, String> changeSetHeaders = new HashMap<String, String>();
-    changeSetHeaders.put("content-type", "application/json;odata=verbose");
+    changeSetHeaders.put(HttpHeaders.CONTENT_TYPE, 
HttpContentType.APPLICATION_JSON_VERBOSE);
 
-    BatchChangeSetPart changeRequest = BatchChangeSetPart.method(PUT)
+    BatchChangeSetPart changeRequest = 
BatchChangeSetPart.method(ODataHttpMethod.PUT.name())
         .uri("Employees('2')/EmployeeName")
         .body("{\"EmployeeName\":\"Frederic Fall MODIFIED\"}")
         .headers(changeSetHeaders)
@@ -98,7 +123,7 @@ public class ClientBatchTest extends AbstractRefTest {
     changeSet.add(changeRequest);
     batch.add(changeSet);
 
-    BatchPart request = BatchQueryPart.method(GET)
+    BatchPart request = BatchQueryPart.method(ODataHttpMethod.GET.name())
         .uri("Employees('2')/EmployeeName/$value")
         .build();
     batch.add(request);
@@ -110,7 +135,7 @@ public class ClientBatchTest extends AbstractRefTest {
 
     assertTrue(bodyAsString.contains("PUT Employees('2')/EmployeeName 
HTTP/1.1"));
     assertTrue(bodyAsString.contains("GET Employees('2')/EmployeeName/$value 
HTTP/1.1"));
-    assertTrue(bodyAsString.contains("content-type: 
application/json;odata=verbose"));
+    assertTrue(bodyAsString.contains("Content-Type: 
application/json;odata=verbose"));
 
     HttpResponse batchResponse = execute(bodyAsString);
     InputStream responseBody = batchResponse.getEntity().getContent();
@@ -129,14 +154,14 @@ public class ClientBatchTest extends AbstractRefTest {
   }
 
   @Test
-  public void testChangeSetBatchUmlauts() throws Exception {
+  public void changeSetBatchUmlauts() throws Exception {
     List<BatchPart> batch = new ArrayList<BatchPart>();
 
     BatchChangeSet changeSet = BatchChangeSet.newBuilder().build();
     Map<String, String> changeSetHeaders = new HashMap<String, String>();
-    changeSetHeaders.put("content-type", "application/json;odata=verbose");
+    changeSetHeaders.put(HttpHeaders.CONTENT_TYPE, 
HttpContentType.APPLICATION_JSON_VERBOSE);
 
-    BatchChangeSetPart changeRequest = BatchChangeSetPart.method(PUT)
+    BatchChangeSetPart changeRequest = 
BatchChangeSetPart.method(ODataHttpMethod.PUT.name())
         .uri("Employees('2')/EmployeeName")
         .body("{\"EmployeeName\":\"Frederic üäö Fall\"}")
         .headers(changeSetHeaders)
@@ -144,7 +169,7 @@ public class ClientBatchTest extends AbstractRefTest {
     changeSet.add(changeRequest);
     batch.add(changeSet);
 
-    BatchPart request = BatchQueryPart.method(GET)
+    BatchPart request = BatchQueryPart.method(ODataHttpMethod.GET.name())
         .uri("Employees('2')/EmployeeName/$value")
         .build();
     batch.add(request);
@@ -157,7 +182,7 @@ public class ClientBatchTest extends AbstractRefTest {
 
     assertTrue(bodyAsString.contains("PUT Employees('2')/EmployeeName 
HTTP/1.1"));
     assertTrue(bodyAsString.contains("GET Employees('2')/EmployeeName/$value 
HTTP/1.1"));
-    assertTrue(bodyAsString.contains("content-type: 
application/json;odata=verbose"));
+    assertTrue(bodyAsString.contains("Content-Type: 
application/json;odata=verbose"));
 
     HttpResponse batchResponse = 
execute(bodyStream.asStreamWithLineSeparation("\r\n"));
     InputStream responseBody = batchResponse.getEntity().getContent();
@@ -178,13 +203,14 @@ public class ClientBatchTest extends AbstractRefTest {
 
 
   @Test
-  public void testContentIdReferencing() throws Exception {
+  public void contentIdReferencing() throws Exception {
     List<BatchPart> batch = new ArrayList<BatchPart>();
     BatchChangeSet changeSet = BatchChangeSet.newBuilder().build();
     Map<String, String> changeSetHeaders = new HashMap<String, String>();
-    changeSetHeaders.put("content-type", "application/octet-stream");
-    changeSetHeaders.put("Accept", "application/atomsvc+xml;q=0.8, 
application/json;odata=verbose;q=0.5, */*;q=0.1");
-    BatchChangeSetPart changeRequest = BatchChangeSetPart.method(POST)
+    changeSetHeaders.put(HttpHeaders.CONTENT_TYPE, "application/octet-stream");
+    changeSetHeaders.put(HttpHeaders.ACCEPT,
+        "application/atom+xml;q=0.8, application/json;odata=verbose;q=0.5, 
*/*;q=0.1");
+    BatchChangeSetPart changeRequest = 
BatchChangeSetPart.method(ODataHttpMethod.POST.name())
         .uri("Employees")
         .contentId("1")
         .body("gAAAAgABwESAAMAAAABAAEA")
@@ -193,8 +219,8 @@ public class ClientBatchTest extends AbstractRefTest {
     changeSet.add(changeRequest);
 
     changeSetHeaders = new HashMap<String, String>();
-    changeSetHeaders.put("content-type", "application/json;odata=verbose");
-    BatchChangeSetPart changeRequest2 = BatchChangeSetPart.method(PUT)
+    changeSetHeaders.put(HttpHeaders.CONTENT_TYPE, 
HttpContentType.APPLICATION_JSON_VERBOSE);
+    BatchChangeSetPart changeRequest2 = 
BatchChangeSetPart.method(ODataHttpMethod.PUT.name())
         .uri("$1/EmployeeName")
         .contentId("2")
         .body("{\"EmployeeName\":\"Frederic Fall MODIFIED\"}")
@@ -205,7 +231,7 @@ public class ClientBatchTest extends AbstractRefTest {
 
     Map<String, String> getRequestHeaders = new HashMap<String, String>();
     getRequestHeaders.put("content-id", "3");
-    BatchPart request = BatchQueryPart.method(GET)
+    BatchPart request = BatchQueryPart.method(ODataHttpMethod.GET.name())
         .uri("Employees('7')/EmployeeName")
         .contentId("3")
         .headers(getRequestHeaders).build();
@@ -240,9 +266,9 @@ public class ClientBatchTest extends AbstractRefTest {
   }
 
   @Test
-  public void testErrorBatch() throws Exception {
+  public void errorBatch() throws Exception {
     List<BatchPart> batch = new ArrayList<BatchPart>();
-    BatchPart request = BatchQueryPart.method(GET)
+    BatchPart request = BatchQueryPart.method(ODataHttpMethod.GET.name())
         .uri("nonsense")
         .build();
     batch.add(request);
@@ -263,32 +289,25 @@ public class ClientBatchTest extends AbstractRefTest {
     }
   }
 
-  private HttpResponse execute(final String body) throws Exception {
+  private HttpResponse execute(final HttpEntity entity) throws IOException {
     final HttpPost post = new HttpPost(URI.create(getEndpoint().toString() + 
"$batch"));
 
-    post.setHeader("Content-Type", "multipart/mixed;boundary=" + BOUNDARY);
-    HttpEntity entity = new StringEntity(body);
+    post.setHeader(HttpHeaders.CONTENT_TYPE, "multipart/mixed;boundary=" + 
BOUNDARY);
     post.setEntity(entity);
     HttpResponse response = getHttpClient().execute(post);
 
     assertNotNull(response);
-    assertEquals(202, response.getStatusLine().getStatusCode());
+    assertEquals(HttpStatusCodes.ACCEPTED.getStatusCode(), 
response.getStatusLine().getStatusCode());
 
     return response;
   }
 
-  private HttpResponse execute(final InputStream body) throws Exception {
-    final HttpPost post = new HttpPost(URI.create(getEndpoint().toString() + 
"$batch"));
-
-    post.setHeader("Content-Type", "multipart/mixed;boundary=" + BOUNDARY);
-    HttpEntity entity = new InputStreamEntity(body, -1);
-    post.setEntity(entity);
-    HttpResponse response = getHttpClient().execute(post);
-
-    assertNotNull(response);
-    assertEquals(202, response.getStatusLine().getStatusCode());
+  private HttpResponse execute(final String body) throws IOException {
+    return execute(new StringEntity(body));
+  }
 
-    return response;
+  private HttpResponse execute(final InputStream body) throws IOException {
+    return execute(new InputStreamEntity(body, -1));
   }
 
   private void checkMimeHeaders(final String requestBody) {

Reply via email to