Java Code Examples for org.apache.olingo.odata2.api.processor.ODataResponse#getHeader()

The following examples show how to use org.apache.olingo.odata2.api.processor.ODataResponse#getHeader() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BatchResponseWriter.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private void appendResponsePartBody(final ODataResponse response) throws BatchException {
  writer.append(HttpHeaders.CONTENT_TYPE).append(COLON).append(SP)
      .append(HttpContentType.APPLICATION_HTTP).append(CRLF);
  writer.append(BatchHelper.HTTP_CONTENT_TRANSFER_ENCODING).append(COLON).append(SP)
      .append(BatchHelper.BINARY_ENCODING).append(CRLF);
  if (response.getHeader(BatchHelper.MIME_HEADER_CONTENT_ID) != null) {
    writer.append(BatchHelper.HTTP_CONTENT_ID).append(COLON).append(SP)
        .append(response.getHeader(BatchHelper.MIME_HEADER_CONTENT_ID)).append(CRLF);
  }
  writer.append(CRLF);
  writer.append("HTTP/1.1").append(SP).append(String.valueOf(response.getStatus().getStatusCode())).append(SP)
      .append(response.getStatus().getInfo()).append(CRLF);
  if (response.getHeader("Content-Type") != null) {
    BatchHelper.extractCharset(ContentType.parse(response.getHeader("Content-Type")));
  }
  appendHeader(response);
  if (!HttpStatusCodes.NO_CONTENT.equals(response.getStatus())) {
    BatchHelper.Body body = new BatchHelper.Body(response);
    writer.append(HttpHeaders.CONTENT_LENGTH).append(COLON).append(SP)
        .append(String.valueOf(body.getLength())).append(CRLF).append(CRLF);
    writer.append(body);
  } else {
    // No header if status code equals to 204 (No content)
    writer.append(CRLF);
  }
  writer.append(CRLF);
}
 
Example 2
Source File: BatchHandlerImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private void fillContentIdMap(final ODataResponse response, final String contentId, final String baseUri) {
  String location = response.getHeader(HttpHeaders.LOCATION);
  if (location != null) {
    String relLocation = location.replace(baseUri + "/", "");
    contentIdMap.put("$" + contentId, relLocation);
  }
}
 
Example 3
Source File: ODataServlet.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
protected void createResponse(final HttpServletResponse resp, final ODataResponse response,
                              final boolean omitResponseBody)
    throws IOException {

  resp.setStatus(response.getStatus().getStatusCode());
  resp.setContentType(response.getContentHeader());
  for (String headerName : response.getHeaderNames()) {
    resp.setHeader(headerName, response.getHeader(headerName));
  }

  if(omitResponseBody) {
    return;
  }

  Object entity = response.getEntity();
  if (entity != null) {
    ServletOutputStream out = resp.getOutputStream();
    int contentLength;

    if (entity instanceof InputStream) {
      contentLength = handleStream((InputStream) entity, out);
    } else if (entity instanceof String) {
      String body = (String) entity;
      final byte[] entityBytes = body.getBytes(DEFAULT_READ_CHARSET);
      out.write(entityBytes);
      contentLength = entityBytes.length;
    } else {
      throw new IOException("Illegal entity object in ODataResponse of type '" + entity.getClass() + "'.");
    }

    if (response.getHeader(HttpHeaders.CONTENT_LENGTH) != null) {
      // Override content length
      try {
        contentLength = Integer.parseInt(response.getHeader(HttpHeaders.CONTENT_LENGTH));
      } catch (NumberFormatException e) {
        // Ignore
      }
    }

    resp.setContentLength(contentLength);
    out.flush();
    out.close();
  }
}