Java Code Examples for org.apache.olingo.server.api.ODataRequest#setBody()

The following examples show how to use org.apache.olingo.server.api.ODataRequest#setBody() . 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: AsyncProcessor.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
static ODataRequest copyRequest(ODataRequest request) {
  ODataRequest req = new ODataRequest();
  req.setBody(copyRequestBody(request));
  req.setMethod(request.getMethod());
  req.setRawBaseUri(request.getRawBaseUri());
  req.setRawODataPath(request.getRawODataPath());
  req.setRawQueryPath(request.getRawQueryPath());
  req.setRawRequestUri(request.getRawRequestUri());
  req.setRawServiceResolutionUri(request.getRawServiceResolutionUri());

  for (Map.Entry<String, List<String>> header : request.getAllHeaders().entrySet()) {
    if (!HttpHeader.PREFER.toLowerCase().equals(
        header.getKey().toLowerCase())) {
      req.addHeader(header.getKey(), header.getValue());
    }
  }

  return req;
}
 
Example 2
Source File: ODataHandlerImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void dispatchEmptyContentWithoutContentType() {
  final String path = "ESAllPrim";
  final EntityCollectionProcessor processor = mock(EntityCollectionProcessor.class);
  
  ODataRequest request = new ODataRequest();
  request.setMethod(HttpMethod.POST);
  request.setRawBaseUri(BASE_URI);
  request.setRawRequestUri(BASE_URI);
  request.setRawODataPath(path);
  request.setBody(new ByteArrayInputStream(new byte[0]));

  final OData odata = OData.newInstance();
  final ServiceMetadata metadata = odata.createServiceMetadata(
      new EdmTechProvider(), Collections.<EdmxReference> emptyList());

  ODataHandlerImpl handler = new ODataHandlerImpl(odata, metadata, new ServerCoreDebugger(odata));

  if (processor != null) {
    handler.register(processor);
  }

  final ODataResponse response = handler.process(request);
  assertNotNull(response);
}
 
Example 3
Source File: ODataNettyHandlerImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
/**
 * Extract the information part of Netty Request and fill OData Request
 * @param odRequest
 * @param httpRequest
 * @param split
 * @param contextPath
 * @return
 * @throws ODataLibraryException
 */
private ODataRequest fillODataRequest(final ODataRequest odRequest, final HttpRequest httpRequest,
     final int split, final String contextPath) throws ODataLibraryException {
   final int requestHandle = debugger.startRuntimeMeasurement("ODataHttpHandlerImpl", "fillODataRequest");
   try {
   	ByteBuf byteBuf = ((HttpContent)httpRequest).content();
   	ByteBufInputStream inputStream = new ByteBufInputStream(byteBuf);
     odRequest.setBody(inputStream);
     
     odRequest.setProtocol(httpRequest.protocolVersion().text());
     odRequest.setMethod(extractMethod(httpRequest));
     int innerHandle = debugger.startRuntimeMeasurement("ODataNettyHandlerImpl", "copyHeaders");
     copyHeaders(odRequest, httpRequest);
     debugger.stopRuntimeMeasurement(innerHandle);
     innerHandle = debugger.startRuntimeMeasurement("ODataNettyHandlerImpl", "fillUriInformation");
     fillUriInformationFromHttpRequest(odRequest, httpRequest, split, contextPath);
     debugger.stopRuntimeMeasurement(innerHandle);

     return odRequest;
   } finally {
     debugger.stopRuntimeMeasurement(requestHandle);
   }
 }
 
Example 4
Source File: ODataHttpHandlerImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private ODataRequest fillODataRequest(final ODataRequest odRequest, final HttpServletRequest httpRequest,
    final int split) throws ODataLibraryException {
  final int requestHandle = debugger.startRuntimeMeasurement("ODataHttpHandlerImpl", "fillODataRequest");
  try {
    odRequest.setBody(httpRequest.getInputStream());
    odRequest.setProtocol(httpRequest.getProtocol());
    odRequest.setMethod(extractMethod(httpRequest));
    int innerHandle = debugger.startRuntimeMeasurement("ODataHttpHandlerImpl", "copyHeaders");
    copyHeaders(odRequest, httpRequest);
    debugger.stopRuntimeMeasurement(innerHandle);
    innerHandle = debugger.startRuntimeMeasurement("ODataHttpHandlerImpl", "fillUriInformation");
    fillUriInformation(odRequest, httpRequest, split);
    debugger.stopRuntimeMeasurement(innerHandle);

    return odRequest;
  } catch (final IOException e) {
    throw new DeserializerException("An I/O exception occurred.", e,
        DeserializerException.MessageKeys.IO_EXCEPTION);
  } finally {
    debugger.stopRuntimeMeasurement(requestHandle);
  }
}
 
Example 5
Source File: MockedBatchHandlerTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private ODataRequest buildODataRequest(final String content, final Map<String, List<String>> header)
    throws Exception {
  final ODataRequest request = new ODataRequest();

  for (final String key : header.keySet()) {
    request.addHeader(key, header.get(key));
  }

  request.setMethod(HttpMethod.POST);
  request.setRawBaseUri(BASE_URI);
  request.setRawODataPath(BATCH_ODATA_PATH);
  request.setRawQueryPath("");
  request.setRawRequestUri(BATCH_REQUEST_URI);
  request.setRawServiceResolutionUri("");

  request.setBody(new ByteArrayInputStream(content.getBytes("UTF-8")));

  return request;
}
 
Example 6
Source File: OData4HttpHandler.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
ODataRequest createODataRequest(final HttpServletRequest httpRequest, final int split)
    throws ODataLibraryException {
  try {
    ODataRequest odRequest = new ODataRequest();

    odRequest.setBody(httpRequest.getInputStream());
    copyHeaders(odRequest, httpRequest);
    odRequest.setMethod(extractMethod(httpRequest));
    fillUriInformation(odRequest, httpRequest, split);

    return odRequest;
  } catch (final IOException e) {
    throw new SerializerException(
        "An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION); //$NON-NLS-1$
  }
}
 
Example 7
Source File: BatchRequestTransformator.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private ODataRequest createRequest(final BatchQueryOperation operation, final String baseUri,
    final boolean isChangeSet) throws BatchDeserializerException {
  final HttpRequestStatusLine statusLine =
      new HttpRequestStatusLine(operation.getHttpStatusLine(), baseUri, rawServiceResolutionUri);
  statusLine.validateHttpMethod(isChangeSet);
  BatchTransformatorCommon.validateHost(operation.getHeaders(), baseUri);

  validateBody(statusLine, operation);
  Charset charset = getCharset(operation);
  InputStream bodyStream = getBodyStream(operation, statusLine, charset);

  validateForbiddenHeader(operation);

  final ODataRequest request = new ODataRequest();
  request.setBody(bodyStream);
  request.setMethod(statusLine.getMethod());
  request.setRawBaseUri(statusLine.getRawBaseUri());
  request.setRawODataPath(statusLine.getRawODataPath());
  request.setRawQueryPath(statusLine.getRawQueryPath());
  request.setRawRequestUri(statusLine.getRawRequestUri());
  request.setRawServiceResolutionUri(statusLine.getRawServiceResolutionUri());

  for (final HeaderField field : operation.getHeaders()) {
    request.addHeader(field.getFieldName(), field.getValues());
  }

  return request;
}