Examples of ODataResponse


Examples of org.apache.olingo.odata2.api.processor.ODataResponse

  @Context
  Application app;

  @Override
  public Response toResponse(final Exception exception) {
    ODataResponse response;
    try {
      if (exception instanceof WebApplicationException) {
        response = handleWebApplicationException(exception);
      } else {
        response = handleException(exception);
View Full Code Here

Examples of org.apache.olingo.odata2.api.processor.ODataResponse

    return callback == null ?
        new ProviderFacadeImpl().writeErrorDocument(errorContext) : executeErrorCallback(errorContext, callback);
  }

  private ODataResponse executeErrorCallback(final ODataErrorContext errorContext, final ODataErrorCallback callback) {
    ODataResponse oDataResponse;
    try {
      oDataResponse = callback.handleError(errorContext);
    } catch (ODataApplicationException e) {
      oDataResponse = handleException(e);
    }
View Full Code Here

Examples of org.apache.olingo.odata2.api.processor.ODataResponse

public class BatchResponseTest {

  @Test
  public void testBatchResponse() throws BatchException, IOException {
    List<BatchResponsePart> parts = new ArrayList<BatchResponsePart>();
    ODataResponse response = ODataResponse.entity("Walter Winter")
        .status(HttpStatusCodes.OK)
        .contentHeader("application/json")
        .build();
    List<ODataResponse> responses = new ArrayList<ODataResponse>(1);
    responses.add(response);
    parts.add(BatchResponsePart.responses(responses).changeSet(false).build());

    ODataResponse changeSetResponse = ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
    responses = new ArrayList<ODataResponse>(1);
    responses.add(changeSetResponse);
    parts.add(BatchResponsePart.responses(responses).changeSet(true).build());

    BatchResponseWriter writer = new BatchResponseWriter();
    ODataResponse batchResponse = writer.writeResponse(parts);

    assertEquals(202, batchResponse.getStatus().getStatusCode());
    assertNotNull(batchResponse.getEntity());
    String body = (String) batchResponse.getEntity();

    assertTrue(body.contains("--batch"));
    assertTrue(body.contains("--changeset"));
    assertTrue(body.contains("HTTP/1.1 200 OK"));
    assertTrue(body.contains("Content-Type: application/http"));
    assertTrue(body.contains("Content-Transfer-Encoding: binary"));
    assertTrue(body.contains("Walter Winter"));
    assertTrue(body.contains("multipart/mixed; boundary=changeset"));
    assertTrue(body.contains("HTTP/1.1 204 No Content"));

    String contentHeader = batchResponse.getContentHeader();
    BatchResponseParser parser = new BatchResponseParser(contentHeader);
    List<BatchSingleResponse> result = parser.parse(new ByteArrayInputStream(body.getBytes()));
    assertEquals(2, result.size());
  }
View Full Code Here

Examples of org.apache.olingo.odata2.api.processor.ODataResponse

  }

  @Test
  public void testChangeSetResponse() throws BatchException, IOException {
    List<BatchResponsePart> parts = new ArrayList<BatchResponsePart>();
    ODataResponse changeSetResponse = ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
    List<ODataResponse> responses = new ArrayList<ODataResponse>(1);
    responses.add(changeSetResponse);
    parts.add(BatchResponsePart.responses(responses).changeSet(true).build());

    BatchResponseWriter writer = new BatchResponseWriter();
    ODataResponse batchResponse = writer.writeResponse(parts);

    assertEquals(202, batchResponse.getStatus().getStatusCode());
    assertNotNull(batchResponse.getEntity());
    String body = (String) batchResponse.getEntity();
    assertTrue(body.contains("--batch"));
    assertTrue(body.contains("--changeset"));
    assertTrue(body.indexOf("--changeset") != body.lastIndexOf("--changeset"));
    assertFalse(body.contains("HTTP/1.1 200 OK" + "\r\n"));
    assertTrue(body.contains("Content-Type: application/http" + "\r\n"));
    assertTrue(body.contains("Content-Transfer-Encoding: binary" + "\r\n"));
    assertTrue(body.contains("HTTP/1.1 204 No Content" + "\r\n"));
    assertTrue(body.contains("Content-Type: multipart/mixed; boundary=changeset"));

    String contentHeader = batchResponse.getContentHeader();
    BatchResponseParser parser = new BatchResponseParser(contentHeader);
    List<BatchSingleResponse> result = parser.parse(new ByteArrayInputStream(body.getBytes()));
    assertEquals(1, result.size());
  }
View Full Code Here

Examples of org.apache.olingo.odata2.api.processor.ODataResponse

  }

  @Test
  public void testTwoChangeSetResponse() throws BatchException, IOException {
    List<BatchResponsePart> parts = new ArrayList<BatchResponsePart>();
    ODataResponse changeSetResponse = ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
    ODataResponse changeSetResponseTwo = ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
    List<ODataResponse> responses = new ArrayList<ODataResponse>(1);
    responses.add(changeSetResponse);
    responses.add(changeSetResponseTwo);
    parts.add(BatchResponsePart.responses(responses).changeSet(true).build());

    BatchResponseWriter writer = new BatchResponseWriter();
    ODataResponse batchResponse = writer.writeResponse(parts);

    assertEquals(202, batchResponse.getStatus().getStatusCode());
    assertNotNull(batchResponse.getEntity());
    String body = (String) batchResponse.getEntity();
    assertTrue(body.contains("--batch"));
    assertTrue(body.contains("--changeset"));
    assertTrue(body.indexOf("--changeset") != body.lastIndexOf("--changeset"));
    assertFalse(body.contains("HTTP/1.1 200 OK" + "\r\n"));
    assertTrue(body.contains("Content-Type: application/http" + "\r\n"));
    assertTrue(body.contains("Content-Transfer-Encoding: binary" + "\r\n"));
    assertTrue(body.contains("HTTP/1.1 204 No Content" + "\r\n"));
    assertTrue(body.contains("Content-Type: multipart/mixed; boundary=changeset"));

    String contentHeader = batchResponse.getContentHeader();
    BatchResponseParser parser = new BatchResponseParser(contentHeader);
    StringHelper.Stream content = StringHelper.toStream(body);
    List<BatchSingleResponse> result = parser.parse(content.asStream());
    assertEquals(2, result.size());
    assertEquals("Failing content:\n" + content.asString(), 20, content.linesCount());
View Full Code Here

Examples of org.apache.olingo.odata2.api.processor.ODataResponse

    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("Id", "42");
    List<Map<String, Object>> propertiesList = new ArrayList<Map<String, Object>>();
    propertiesList.add(properties);
    propertiesList.add(properties);
    final ODataResponse result =
        new ProviderFacadeImpl().writeLinks(HttpContentType.APPLICATION_JSON, entitySet, propertiesList,
            EntityProviderWriteProperties.serviceRoot(URI.create("http://root/")).build());
    assertEquals("{\"d\":[{\"uri\":\"http://root/Rooms('42')\"},{\"uri\":\"http://root/Rooms('42')\"}]}",
        StringHelper.inputStreamToString((InputStream) result.getEntity()));
  }
View Full Code Here

Examples of org.apache.olingo.odata2.api.processor.ODataResponse

        StringHelper.inputStreamToString((InputStream) result.getEntity()));
  }

  @Test
  public void writeServiceDocument() throws Exception {
    final ODataResponse result =
        new ProviderFacadeImpl()
            .writeServiceDocument(HttpContentType.APPLICATION_JSON, MockFacade.getMockEdm(), "root");
    assertEquals("{\"d\":{\"EntitySets\":[]}}", StringHelper.inputStreamToString((InputStream) result.getEntity()));
  }
View Full Code Here

Examples of org.apache.olingo.odata2.api.processor.ODataResponse

  @Test
  public void writePropertyValue() throws Exception {
    final EdmProperty property =
        (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("EntryDate");
    final ODataResponse result = new ProviderFacadeImpl().writePropertyValue(property, 987654321000L);
    assertNull("BasicProvider should not set content header", result.getContentHeader());

    assertEquals("2001-04-19T04:25:21", StringHelper.inputStreamToString((InputStream) result.getEntity()));
  }
View Full Code Here

Examples of org.apache.olingo.odata2.api.processor.ODataResponse

    assertEquals("2001-04-19T04:25:21", StringHelper.inputStreamToString((InputStream) result.getEntity()));
  }

  @Test
  public void writeText() throws Exception {
    final ODataResponse result = new ProviderFacadeImpl().writeText("test");
    assertNull("BasicProvider should not set content header", result.getContentHeader());
    assertEquals("test", StringHelper.inputStreamToString((InputStream) result.getEntity()));
  }
View Full Code Here

Examples of org.apache.olingo.odata2.api.processor.ODataResponse

    assertEquals("test", StringHelper.inputStreamToString((InputStream) result.getEntity()));
  }

  @Test
  public void writeBinary() throws Exception {
    final ODataResponse result =
        new ProviderFacadeImpl().writeBinary(HttpContentType.APPLICATION_OCTET_STREAM, new byte[] { 102, 111, 111 });
    assertEquals(HttpContentType.APPLICATION_OCTET_STREAM, result.getContentHeader());
    assertEquals("foo", StringHelper.inputStreamToString((InputStream) result.getEntity()));
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.