Java Code Examples for org.apache.olingo.odata2.api.processor.ODataContext#getRequestHeaders()

The following examples show how to use org.apache.olingo.odata2.api.processor.ODataContext#getRequestHeaders() . 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: FitStaticServiceFactory.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
  public ODataService createService(final ODataContext ctx) throws ODataException {

    assertNotNull(ctx);
    assertNotNull(ctx.getAcceptableLanguages());
    assertNotNull(ctx.getParameter(ODataContext.HTTP_SERVLET_REQUEST_OBJECT));

    final Map<String, List<String>> requestHeaders = ctx.getRequestHeaders();
    final String host = requestHeaders.get("Host").get(0);

    String tmp[] = host.split(":", 2);
    String port = (tmp.length == 2 && tmp[1] != null) ? tmp[1] : "80";

    // access and validation in synchronized block
    synchronized (PORT_2_SERVICE) {
      final ODataService service = PORT_2_SERVICE.get(port);
//      if (service == null) {
//        throw new IllegalArgumentException("no static service set for JUnit test");
//      }
      return service;
    }
  }
 
Example 2
Source File: ODataExceptionWrapper.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public ODataExceptionWrapper(final ODataContext context, final Map<String, String> queryParameters,
    final List<String> acceptHeaderContentTypes) {
  contentType = getContentType(queryParameters, acceptHeaderContentTypes).toContentTypeString();
  messageLocale = MessageService.getSupportedLocale(getLanguages(context), DEFAULT_RESPONSE_LOCALE);
  httpRequestHeaders = context.getRequestHeaders();
  try {
    requestUri = context.getPathInfo().getRequestUri();
    errorContext.setPathInfo(context.getPathInfo());
    callback = getErrorHandlerCallbackFromContext(context);
  } catch (Exception e) {
    throw new ODataRuntimeException("Exception occurred", e);
  }
}
 
Example 3
Source File: BatchHandlerImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private ODataRequestHandler createHandler(final ODataRequest request) throws ODataException {
  ODataContextImpl context = new ODataContextImpl(request, factory);
  ODataContext parentContext = service.getProcessor().getContext();
  context.setBatchParentContext(parentContext);
  context.setService(service);
  if (parentContext != null && parentContext.getParameter(BATCH_ODATA_REQUEST_HEADERS) != null) {
    context.setParameter(BATCH_ODATA_REQUEST_HEADERS, parentContext.getParameter(BATCH_ODATA_REQUEST_HEADERS));
  } else if (parentContext != null && parentContext.getRequestHeaders() != null) {
    context.setParameter(BATCH_ODATA_REQUEST_HEADERS, parentContext.getRequestHeaders());
  }
  service.getProcessor().setContext(context);
  return new ODataRequestHandler(factory, service, context);
}
 
Example 4
Source File: ContextTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void checkRequestHeaders() throws ClientProtocolException, IOException, ODataException {
  final HttpGet get = new HttpGet(URI.create(getEndpoint().toString() + "/$metadata"));
  get.setHeader("ConTenT-laNguaGe", "de, en");
  getHttpClient().execute(get);

  final ODataContext ctx = getService().getProcessor().getContext();
  assertNotNull(ctx);

  final Map<String, List<String>> header = ctx.getRequestHeaders();
  assertEquals("de, en", header.get(HttpHeaders.CONTENT_LANGUAGE).get(0));
}
 
Example 5
Source File: ContextTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void checkNewRequestHeaders() throws ClientProtocolException, IOException, ODataException {
  final HttpGet get = new HttpGet(URI.create(getEndpoint().toString() + "/$metadata"));
  get.setHeader("ConTenT-laNguaGe", "de, en");
  getHttpClient().execute(get);

  final ODataContext ctx = getService().getProcessor().getContext();
  assertNotNull(ctx);

  final Map<String, List<String>> header = ctx.getRequestHeaders();
  assertNotNull(header);
  assertNotNull(header.get(HttpHeaders.CONTENT_LANGUAGE));
  assertEquals(1, header.get(HttpHeaders.CONTENT_LANGUAGE).size());
  assertEquals("de, en", header.get(HttpHeaders.CONTENT_LANGUAGE).get(0));
}