blob: 37d4e20481a4167513dee715369ba5c0c2091c78 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<!--
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.
-->
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Apache Olingo provides libraries which enable developers to implement OData producers and OData consumers. The available OData Java library implements OData version 2.0. In future on goal is to provide an OData 4.0 compliant library once the OData standard is published at OASIS. The focus within the community is currently on the Java technology but it is up to the community to discuss if other environments find interest.">
<meta name="author" content="">
<link rel="icon" href="/favicon.ico">
<title>Apache Olingo Library</title>
<!-- Bootstrap core CSS -->
<link href="/css/bootstrap.css" rel="stylesheet" type="text/css"><!-- Custom styles for this template -->
<link href="/css/navbar.css" rel="stylesheet" type="text/css"><!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<link href="/css/offcanvas.css" rel="stylesheet" type="text/css"><!-- Custom styles for this template -->
<link rel="stylesheet" href="/css/main.css">
<!--[if lt IE 9]><script src="/js/ie8-responsive-file-warning.js"></script><![endif]-->
<style>
.headerlink {
visibility: hidden;
}
dt:hover > .headerlink, p:hover > .headerlink, td:hover > .headerlink, h1:hover > .headerlink, h2:hover > .headerlink, h3:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, h6:hover > .headerlink {
visibility: visible
} </style>
<script src="/js/ie-emulation-modes-warning.js" type="text/javascript">
</script><!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="/js/ie10-viewport-bug-workaround.js" type="text/javascript">
</script><!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="/js/html5shiv.min.js"></script>
<script src="/js/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<!-- Static navbar -->
<div class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<img class="navbar-brand" src="/img/OlingoOrangeTM.png" style="width:62px;" >
<a class="navbar-brand" href="/">Apache Olingo™</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">ASF <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="http://www.apache.org/foundation/">ASF Home</a></li>
<li><a href="http://projects.apache.org/">Projects</a></li>
<li><a href="http://people.apache.org/">People</a></li>
<li><a href="http://www.apache.org/foundation/getinvolved.html">Get Involved</a></li>
<li><a href="http://www.apache.org/dyn/closer.cgi">Download</a></li>
<li><a href="http://www.apache.org/security/">Security</a></li>
<li><a href="http://www.apache.org/foundation/sponsorship.html">Support Apache</a></li>
</ul>
</li>
<li><a href="http://www.apache.org/licenses/">License</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Download <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="/doc/odata2/download.html">Download OData 2.0 Java</a></li>
<li><a href="/doc/odata4/download.html">Download OData 4.0 Java</a></li>
<li><a href="/doc/javascript/download.html">Download OData 4.0 JavaScript</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Documentation <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="/doc/odata2/index.html">Documentation OData 2.0 Java</a></li>
<li><a href="/doc/odata4/index.html">Documentation OData 4.0 Java</a></li>
<li><a href="/doc/javascript/index.html">Documentation OData 4.0 JavaScript</a></li>
</ul>
</li>
<li><a href="/support.html">Support</a></li>
<li><a href="/contribute.html">Contribute</a></li>
</ul>
<a class="navbar-right" href="http://www.apache.org/foundation/" target="_blank">
<img class="navbar-right" height="50px" src="/img/asf_logo_url.svg" alt="Apache Software Foundation">
</a>
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
</div><!-- Main component for a primary marketing message or call to action -->
<h1 id="batch">Batch<a class="headerlink" href="#batch" title="Permalink">&para;</a></h1>
<h3 id="how-to-process-an-odata-batch-request">How to process an OData Batch Request<a class="headerlink" href="#how-to-process-an-odata-batch-request" title="Permalink">&para;</a></h3>
<h5 id="implement-the-method-executebatch-of-the-class-odatasingleprocessor">Implement the method executeBatch of the class ODataSingleProcessor.<a class="headerlink" href="#implement-the-method-executebatch-of-the-class-odatasingleprocessor" title="Permalink">&para;</a></h5>
<ul>
<li>Use the method <code>EntityProvider.parseBatchRequest(contentType, content, batchProperties)</code> in order to parse the Batch Request Body. As a result you get a list with batch parts. Each part separately represents a ChangeSet or a query operation.</li>
<li>Call <code>handler.handleBathPart(batchRequestPart)</code> while looping over the list. The handler delegates the processing of a batch part depending on the type of that batch part.</li>
<li>When all batch parts are completely processed, use the method <code>EntityProvider.writeBatchResponse(final List&lt;BatchResponsePart&gt; batchResponseParts)</code> in order to write all responses in one Batch Response.
The following example shows a possible implementation:</li>
</ul>
<p><strong>Sample Code</strong></p>
<pre><code>@Override
public ODataResponse executeBatch(final BatchHandler handler, final String contentType, final InputStream content)
throws ODataException {
List&lt;BatchResponsePart&gt; batchResponseParts = new ArrayList&lt;BatchResponsePart&gt;();
PathInfo pathInfo = getContext().getPathInfo();
EntityProviderBatchProperties batchProperties = EntityProviderBatchProperties.init().pathInfo(pathInfo).build();
List&lt;BatchRequestPart&gt; batchParts = EntityProvider.parseBatchRequest(contentType, content, batchProperties);
for (BatchRequestPart batchPart : batchParts) {
batchResponseParts.add(handler.handleBatchPart(batchPart));
}
return EntityProvider.writeBatchResponse(batchResponseParts);
}
</code></pre>
<p><strong>NOTE:</strong> The parameter batchProperties of the method parseBatchRequest contains OData URI informations as PathInfo-object. These informations are necessary for the parsing, that's why the PathInfo-object should not be null.</p>
<h5 id="implement-the-method-executechangeset-of-the-class-odatasingleprocessor">Implement the method executeChangeSet of the class ODataSingleProcessor.<a class="headerlink" href="#implement-the-method-executechangeset-of-the-class-odatasingleprocessor" title="Permalink">&para;</a></h5>
<p>In order to process a request invoke <code>handler.handleRequest(request)</code>, that delegates a handling of the request to the request handler and provides ODataResponse.
Define a rollback semantics that may be applied when a request within a ChangeSet fails.
The following example shows a possible implementation:</p>
<pre><code>@Override
public BatchResponsePart executeChangeSet(final BatchHandler handler, final List&lt;ODataRequest&gt; requests) throws ODataException {
List&lt;ODataResponse&gt; responses = new ArrayList&lt;ODataResponse&gt;();
for (ODataRequest request : requests) {
ODataResponse response = handler.handleRequest(request);
if (response.getStatus().getStatusCode() &gt;= HttpStatusCodes.BAD_REQUEST.getStatusCode()) {
// Rollback
List&lt;ODataResponse&gt; errorResponses = new ArrayList&lt;ODataResponse&gt;(1);
errorResponses.add(response);
return BatchResponsePart.responses(errorResponses).changeSet(false).build();
}
responses.add(response);
}
return BatchResponsePart.responses(responses).changeSet(true).build();
}
</code></pre>
<p><strong>NOTE:</strong> If a request within a ChangeSet fails, a Batch Response Part contains only the error response and the flag changeSet is set to false.</p>
<h5 id="batch-request-body-example">Batch Request Body Example<a class="headerlink" href="#batch-request-body-example" title="Permalink">&para;</a></h5>
<pre><code>--batch_123
Content-Type: multipart/mixed; boundary=changeset_321
--changeset_321
Content-Type: application/http
Content-Transfer-Encoding: binary
PUT Employees('2')/EmployeeName HTTP/1.1
Content-Length: 100
DataServiceVersion: 1.0
Content-Type: application/json;odata=verbose
MaxDataServiceVersion: 2.0
{"EmployeeName":"Frederic Fall MODIFIED"}
--changeset_321--
--batch_123
Content-Type: application/http
Content-Transfer-Encoding: binary
GET Employees('2')/EmployeeName?$format=json HTTP/1.1
Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1
MaxDataServiceVersion: 2.0
--batch_123--
</code></pre>
<p><strong>NOTE:</strong></p>
<ul>
<li>A Content-Type header of the Batch Request must specify a content type of "multipart/mixed" and a boundary parameter.</li>
<li>Each Batch Part is separated by the boundary string, that must occur at the beginning of a line, following a CRLF.</li>
<li>The boundary of the ChangeSet should be different from that used by the Batch.</li>
</ul>
<h5 id="request-line-of-a-single-request">Request Line of a single request<a class="headerlink" href="#request-line-of-a-single-request" title="Permalink">&para;</a></h5>
<p>The following request lines of a single request (e.g. a retrieve request) will be accepted:</p>
<ul>
<li>GET http://<scheme>/&lt;service_name&gt;/&lt;resource_path&gt; HTTP/1.1 - the request line with an absolute URI</scheme></li>
<li>GET &lt;resource_path&gt; HTTP/1.1 - the request line that contains a relative-path reference
Query Options can optionally follow the Resource Path.</li>
</ul>
<p><strong>Note:</strong> An absolute-path reference like /&lt;service_name&gt;/&lt;resource_path&gt; will not be accepted</p>
<h5 id="content-id">Content-ID<a class="headerlink" href="#content-id" title="Permalink">&para;</a></h5>
<p>The new entity may be referenced by subsequent requests within the same ChangeSet by referring to the Content-Id value. $<contentidvalue> acts as an alias for the Resource Path of the new entity.
In order to refer the new entity the Request URI must begin with $<contentidvalue>:</contentidvalue></contentidvalue></p>
<pre><code>POST Customers HTTP/1.1
Content-ID: newCustomer
...
PUT $newCustomer/Name HTTP/1.1
</code></pre>
<p><strong>Note:</strong> Requests in different ChangeSets cannot reference one another, even if they are in the same Batch</p>
<p><strong>Note:</strong> Client are expected to take care of the percent encoding of the special characters from their end, if there are any.
Also, for batch requests the encoding of the parameters in the URLs in the payload are expected to be taken care by the client.</p>
<h3 id="references">References<a class="headerlink" href="#references" title="Permalink">&para;</a></h3>
<p><a href="http://www.odata.org/documentation/odata-v2-documentation/batch-processing/" title="External Link">http://www.odata.org/documentation/odata-v2-documentation/batch-processing/</a></p>
<div align="center">
<p>Copyright © 2013-2022, The Apache Software Foundation<br>
Apache Olingo, Olingo, Apache, the Apache feather, and
the Apache Olingo project logo are trademarks of the Apache Software
Foundation.</p>
<small><a href="/doc/odata2/privacy.html">Privacy</a></small>
</div>
</div><!-- /container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="/js/jquery.js" type="text/javascript">
</script>
<script src="/js/bootstrap.js" type="text/javascript">
</script>
<script src="/js/offcanvas.js" type="text/javascript">
</script>
<link rel="stylesheet" href="/css/docco.css">
<script src="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.0.1/build/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
</body>
</html>