本文整理汇总了Java中org.apache.olingo.odata2.api.ep.EntityProvider.parseBatchResponse方法的典型用法代码示例。如果您正苦于以下问题:Java EntityProvider.parseBatchResponse方法的具体用法?Java EntityProvider.parseBatchResponse怎么用?Java EntityProvider.parseBatchResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.olingo.odata2.api.ep.EntityProvider
的用法示例。
在下文中一共展示了EntityProvider.parseBatchResponse方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tooBigContentLegthDoesNotResultInException
import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
@Test
public void tooBigContentLegthDoesNotResultInException() throws BatchException {
String getResponse = "--batch_123" + CRLF
+ "Content-Type: application/http" + CRLF
+ "Content-Transfer-Encoding: binary" + CRLF
+ "Content-ID: 1" + CRLF
+ CRLF
+ "HTTP/1.1 200 OK" + CRLF
+ "DataServiceVersion: 2.0" + CRLF
+ "Content-Type: text/plain;charset=utf-8" + CRLF
+ "Content-Length: 100" + CRLF
+ CRLF
+ "Frederic Fall" + CRLF
+ "--batch_123--";
InputStream in = new ByteArrayInputStream(getResponse.getBytes());
List<BatchSingleResponse> batchResponse =
EntityProvider.parseBatchResponse(in, "multipart/mixed;boundary=batch_123");
BatchSingleResponse response = batchResponse.get(0);
assertEquals("100", response.getHeader("Content-Length"));
assertEquals("Frederic Fall", response.getBody());
}
示例2: simpleBatch
import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
@Test
public void simpleBatch() throws Exception {
List<BatchPart> batch = new ArrayList<BatchPart>();
BatchPart request = BatchQueryPart.method(ODataHttpMethod.GET.name()).uri("$metadata").build();
batch.add(request);
InputStream body = EntityProvider.writeBatchRequest(batch, BOUNDARY);
String batchRequestBody = StringHelper.inputStreamToStringCRLFLineBreaks(body);
checkMimeHeaders(batchRequestBody);
checkBoundaryDelimiters(batchRequestBody);
assertTrue(batchRequestBody.contains("GET $metadata HTTP/1.1"));
HttpResponse batchResponse = execute(batchRequestBody);
InputStream responseBody = batchResponse.getEntity().getContent();
String contentType = batchResponse.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue();
List<BatchSingleResponse> responses = EntityProvider.parseBatchResponse(responseBody, contentType);
for (BatchSingleResponse response : responses) {
assertEquals("200", response.getStatusCode());
assertEquals("OK", response.getStatusInfo());
assertTrue(response.getBody().contains("<edmx:Edmx"));
assertEquals("application/xml;charset=utf-8", response.getHeader(HttpHeaders.CONTENT_TYPE));
assertNotNull(response.getHeader(HttpHeaders.CONTENT_LENGTH));
}
}
示例3: simpleBatchWithAbsoluteUri
import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
@Test
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));
}
示例4: errorBatch
import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
@Test
public void errorBatch() throws Exception {
List<BatchPart> batch = new ArrayList<BatchPart>();
BatchPart request = BatchQueryPart.method(ODataHttpMethod.GET.name())
.uri("nonsense")
.build();
batch.add(request);
InputStream body = EntityProvider.writeBatchRequest(batch, BOUNDARY);
String bodyAsString = StringHelper.inputStreamToStringCRLFLineBreaks(body);
checkMimeHeaders(bodyAsString);
checkBoundaryDelimiters(bodyAsString);
assertTrue(bodyAsString.contains("GET nonsense HTTP/1.1"));
HttpResponse batchResponse = execute(bodyAsString);
InputStream responseBody = batchResponse.getEntity().getContent();
String contentType = batchResponse.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue();
List<BatchSingleResponse> responses = EntityProvider.parseBatchResponse(responseBody, contentType);
for (BatchSingleResponse response : responses) {
assertEquals("404", response.getStatusCode());
assertEquals("Not Found", response.getStatusInfo());
}
}
示例5: boundaryInBodyMustBeIgnored
import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
@Test
public void boundaryInBodyMustBeIgnored() throws BatchException {
String getResponse = "--batch_123" + CRLF
+ "Content-Type: application/http" + CRLF
+ "Content-Transfer-Encoding: binary" + CRLF
+ CRLF
+ "HTTP/1.1 200 OK" + CRLF
+ "Content-Type: text/plain;charset=utf-8" + CRLF
+ "Content-Length: 13" + CRLF
+ CRLF
+ "Frederic Fall" + CRLF
+ CRLF
+ "batch_123" + CRLF
+ "Content-Type: application/http" + CRLF
+ "Content-Transfer-Encoding: binary" + CRLF
+ CRLF
+ "HTTP/1.1 200 OK" + CRLF
+ "Content-Type: text/plain;charset=utf-8" + CRLF
+ CRLF
+ "Walter Winter" + CRLF
+ CRLF
+ "--batch_123--";
InputStream in = new ByteArrayInputStream(getResponse.getBytes());
List<BatchSingleResponse> batchResponse =
EntityProvider.parseBatchResponse(in, "multipart/mixed;boundary=batch_123");
BatchSingleResponse response = batchResponse.get(0);
assertEquals("13", response.getHeader("Content-Length"));
assertEquals("Frederic Fall", response.getBody());
}
示例6: testBatchWithChangesetWithRawBytesInPutOperation
import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
@Test
public void testBatchWithChangesetWithRawBytesInPutOperation() throws Exception {
InputStream requestPayload = createBatchRequestWithRawBytes(PUT);
final HttpPost put = new HttpPost(URI.create(getEndpoint().toString() + "$batch"));
put.setHeader("Content-Type", "multipart/mixed;boundary=" + BOUNDARY);
HttpEntity entity = new InputStreamEntity(requestPayload, -1);
put.setEntity(entity);
HttpResponse response = getHttpClient().execute(put);
byte[] actualData = Util.getInstance().getBinaryContent();
byte[] expectedData = rawBytes();
// Comparing data stored in the data source and the data sent in the request
assertArrayEquals(actualData, expectedData);
assertNotNull(response);
assertEquals(202, response.getStatusLine().getStatusCode());
String responseBody = StringHelper.inputStreamToStringCRLFLineBreaks(response.getEntity().getContent());
assertTrue(responseBody.contains("204 No Content"));
HttpResponse resp = execute("/simpleGet.batch", BOUNDARY);
InputStream in = resp.getEntity().getContent();
StringHelper.Stream batchRequestStream = StringHelper.toStream(in);
String requestBody = batchRequestStream.asString();
String contentType = resp.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue();
List<BatchSingleResponse> responses = EntityProvider.parseBatchResponse(
new ByteArrayInputStream(requestBody.getBytes("iso-8859-1")), contentType);
for (BatchSingleResponse batchResp : responses) {
assertEquals("200", batchResp.getStatusCode());
assertEquals("OK", batchResp.getStatusInfo());
assertArrayEquals(batchResp.getBody().getBytes("iso-8859-1"), actualData);
}
}
示例7: testBatchWithChangesetWithRawBytesInPOSTOperation
import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
@Test
public void testBatchWithChangesetWithRawBytesInPOSTOperation() throws Exception {
InputStream requestPayload = createBatchRequestWithRawBytes(POST);
final HttpPost put = new HttpPost(URI.create(getEndpoint().toString() + "$batch"));
put.setHeader("Content-Type", "multipart/mixed;boundary=" + BOUNDARY);
HttpEntity entity = new InputStreamEntity(requestPayload, -1);
put.setEntity(entity);
HttpResponse response = getHttpClient().execute(put);
byte[] actualData = Util.getInstance().getBinaryContent();
byte[] expectedData = rawBytes();
// Comparing data stored in the data source and the data sent in the request
assertArrayEquals(actualData, expectedData);
assertNotNull(response);
assertEquals(202, response.getStatusLine().getStatusCode());
String responseBody = StringHelper.inputStreamToStringCRLFLineBreaks(response.getEntity().getContent());
assertTrue(responseBody.contains("201 Created"));
HttpResponse resp = execute("/simpleGet1.batch", BOUNDARY);
InputStream in = resp.getEntity().getContent();
StringHelper.Stream batchRequestStream = StringHelper.toStream(in);
String requestBody = batchRequestStream.asString();
String contentType = resp.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue();
List<BatchSingleResponse> responses = EntityProvider.parseBatchResponse(
new ByteArrayInputStream(requestBody.getBytes("iso-8859-1")), contentType);
for (BatchSingleResponse batchResp : responses) {
assertEquals("200", batchResp.getStatusCode());
assertEquals("OK", batchResp.getStatusInfo());
assertArrayEquals(batchResp.getBody().getBytes("iso-8859-1"), expectedData);
}
}
示例8: testBatchWithChangesetWithImageObjectInPutOperation
import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
@Test
public void testBatchWithChangesetWithImageObjectInPutOperation() throws Exception {
InputStream requestPayload = createBatchRequestWithImage("/Employee_1.png", PUT);
final HttpPost put = new HttpPost(URI.create(getEndpoint().toString() + "$batch"));
put.setHeader("Content-Type", "multipart/mixed;boundary=" + BOUNDARY);
HttpEntity entity = new InputStreamEntity(requestPayload, -1);
put.setEntity(entity);
HttpResponse response = getHttpClient().execute(put);
byte[] actualData = Util.getInstance().getBinaryContent();
byte[] expectedData = getImageData("/Employee_1.png");
// Comparing data stored in the data source and the data sent in the request
assertArrayEquals(actualData, expectedData);
assertNotNull(response);
assertEquals(202, response.getStatusLine().getStatusCode());
String responseBody = StringHelper.inputStreamToStringCRLFLineBreaks(response.getEntity().getContent());
assertTrue(responseBody.contains("204 No Content"));
HttpResponse resp = execute("/simpleGet.batch", BOUNDARY);
InputStream in = resp.getEntity().getContent();
StringHelper.Stream batchRequestStream = StringHelper.toStream(in);
String requestBody = batchRequestStream.asString();
String contentType = resp.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue();
List<BatchSingleResponse> responses = EntityProvider.parseBatchResponse(
new ByteArrayInputStream(requestBody.getBytes("iso-8859-1")), contentType);
for (BatchSingleResponse batchResp : responses) {
assertEquals("200", batchResp.getStatusCode());
assertEquals("OK", batchResp.getStatusInfo());
assertArrayEquals(batchResp.getBody().getBytes("iso-8859-1"), actualData);
}
}
示例9: testContentFormatErrorBatch
import org.apache.olingo.odata2.api.ep.EntityProvider; //导入方法依赖的package包/类
@Test
public void testContentFormatErrorBatch() throws Exception {
List<BatchPart> batch = new ArrayList<BatchPart>();
Map<String, String> headers = new HashMap<String, String>();
headers.put("DataServiceVersion", "2.0");
headers.put("MaxDataServiceVersion", "3.0");
headers.put("Accept", "application/json;odata=verbose");
BatchPart request = BatchQueryPart.method(ODataHttpMethod.GET.name())
.uri("nonsense")
.headers(headers)
.build();
batch.add(request);
InputStream body = EntityProvider.writeBatchRequest(batch, BOUNDARY);
String bodyAsString = StringHelper.inputStreamToStringCRLFLineBreaks(body);
checkMimeHeaders(bodyAsString);
checkBoundaryDelimiters(bodyAsString);
assertTrue(bodyAsString.contains("GET nonsense HTTP/1.1"));
HttpResponse batchResponse = execute(bodyAsString);
InputStream responseBody = batchResponse.getEntity().getContent();
String contentType = batchResponse.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue();
List<BatchSingleResponse> responses = EntityProvider.parseBatchResponse(responseBody, contentType);
for (BatchSingleResponse response : responses) {
assertEquals("404", response.getStatusCode());
assertEquals("Not Found", response.getStatusInfo());
assertEquals("application/json", response.getHeaders().get("Content-Type"));
assertEquals("{\"error\":{\"code\":null,\"message\":{\"lang\":\"en\",\"value\":"
+ "\"Could not find an entity set or function import for 'nonsense'.\"}}}", response.getBody());
}
}