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

The following examples show how to use org.apache.olingo.server.api.ODataRequest#setRawODataPath() . 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 uriParserExceptionResultsInRightResponseEdmCause() throws Exception {
  final OData odata = OData.newInstance();
  final ServiceMetadata serviceMetadata = odata.createServiceMetadata(
      new CsdlAbstractEdmProvider() {
        @Override
        public CsdlEntitySet getEntitySet(final FullQualifiedName entityContainer, final String entitySetName)
            throws ODataException {
          throw new ODataException("msg");
        }
      },
      Collections.<EdmxReference> emptyList());

  ODataRequest request = new ODataRequest();
  request.setMethod(HttpMethod.GET);
  request.setRawODataPath("EdmException");

  final ODataResponse response =
      new ODataHandlerImpl(odata, serviceMetadata, new ServerCoreDebugger(odata)).process(request);
  assertNotNull(response);
  assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode());
}
 
Example 3
Source File: ODataHandlerImplTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Test
public void handlerExtTest() throws Exception {
  final OData odata = OData.newInstance();
  final ServiceMetadata serviceMetadata = odata.createServiceMetadata(
      new CsdlAbstractEdmProvider() {
        @Override
        public CsdlEntitySet getEntitySet(final FullQualifiedName entityContainer, final String entitySetName)
            throws ODataException {
          throw new ODataException("msg");
        }
      },
      Collections.<EdmxReference> emptyList());

  ODataRequest request = new ODataRequest();
  request.setMethod(HttpMethod.GET);
  request.setRawODataPath("EdmException");
  ODataHandlerImpl handler =  new ODataHandlerImpl(odata, serviceMetadata, new ServerCoreDebugger(odata));
  Processor extension =  new TechnicalActionProcessor(null, serviceMetadata);
  handler.register(extension);
  assertNull(handler.getLastThrownException());
  assertNull(handler.getUriInfo());
}
 
Example 4
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 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: ODataHandlerImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private ODataResponse dispatch(final HttpMethod method, final String path, final String query,
    final String headerName, final String headerValue, final Processor processor) {
  ODataRequest request = new ODataRequest();
  request.setMethod(method);
  request.setRawBaseUri(BASE_URI);
  if (path.isEmpty()) {
    request.setRawRequestUri(BASE_URI);
  }
  request.setRawODataPath(path);
  request.setRawQueryPath(query);

  if (headerName != null) {
    request.addHeader(headerName, Collections.singletonList(headerValue));
  }

  if (headerName != HttpHeader.CONTENT_TYPE) {
    request.addHeader(HttpHeader.CONTENT_TYPE, Collections.singletonList(
        ContentType.JSON.toContentTypeString()));
  }

  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);
  return response;
}
 
Example 7
Source File: ODataHandlerImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private ODataResponse dispatchToValidateHeaders(final HttpMethod method, final String path, final String query,
    final Map<String, String> headers, final Processor processor) throws ODataHandlerException {
  ODataRequest request = new ODataRequest();
  request.setMethod(method);
  request.setRawBaseUri(BASE_URI);
  for (Entry<String, String> header : headers.entrySet()) {
    request.addHeader(header.getKey(), header.getValue());
  }
  if (path.isEmpty()) {
    request.setRawRequestUri(BASE_URI);
  }
  request.setRawODataPath(path);
  request.setRawQueryPath(query);

  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);
  return response;
}
 
Example 8
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;
}
 
Example 9
Source File: BatchReferenceRewriter.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
private void replaceContentIdReference(final ODataRequest request, final String contentId, final String resourceUri) {
  final String newUri = request.getRawODataPath().replace("/$" + contentId, resourceUri);
  request.setRawODataPath(newUri);
  request.setRawRequestUri(request.getRawBaseUri() + "/" + newUri);
}