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

The following examples show how to use org.apache.olingo.odata2.api.processor.ODataResponse#getHeaderNames() . 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: DebugInfoResponse.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public DebugInfoResponse(final ODataResponse response, final String serviceRoot) {
  this.response = response;
  this.serviceRoot = serviceRoot;
  status = response.getStatus();
  headers = new HashMap<String, String>();
  for (final String name : response.getHeaderNames()) {
    headers.put(name, response.getHeader(name));
  }
}
 
Example 2
Source File: BatchResponseWriter.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private void appendHeader(final ODataResponse response) {
  for (String name : response.getHeaderNames()) {
    if (!BatchHelper.MIME_HEADER_CONTENT_ID.equalsIgnoreCase(name)
        && !BatchHelper.REQUEST_HEADER_CONTENT_ID.equalsIgnoreCase(name)) {
      writer.append(name).append(COLON).append(SP).append(response.getHeader(name)).append(CRLF);
    } else if (BatchHelper.REQUEST_HEADER_CONTENT_ID.equalsIgnoreCase(name)) {
      writer.append(BatchHelper.HTTP_CONTENT_ID).append(COLON).append(SP)
          .append(response.getHeader(name)).append(CRLF);
    }
  }
}
 
Example 3
Source File: ODataResponseImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
protected ODataResponseBuilder fromResponse(final ODataResponse response) {
  status = response.getStatus();
  entity = response.getEntity();

  headers = new HashMap<String, String>();
  for (String key : response.getHeaderNames()) {
    headers.put(key, response.getHeader(key));
  }

  return this;
}
 
Example 4
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();
  }
}
 
Example 5
Source File: RestUtil.java    From olingo-odata2 with Apache License 2.0 3 votes vote down vote up
public static Response convertResponse(final ODataResponse odataResponse, final boolean omitResponseBody) {
  try {
    ResponseBuilder responseBuilder =
        Response.noContent().status(odataResponse.getStatus().getStatusCode());
    if(!omitResponseBody) {
      responseBuilder.entity(odataResponse.getEntity());
    }

    for (final String name : odataResponse.getHeaderNames()) {
      responseBuilder = responseBuilder.header(name, odataResponse.getHeader(name));
    }

    return responseBuilder.build();
  } catch (RuntimeException e) {
    if (odataResponse != null) {
      try {
        odataResponse.close();
      } catch (IOException inner) {
        // if close throw an exception we ignore these and re-throw our exception
        throw e;
      }
    }
    throw e;
  }
}