Java Code Examples for org.apache.olingo.server.api.OData#createServiceMetadata()

The following examples show how to use org.apache.olingo.server.api.OData#createServiceMetadata() . 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: DemoServlet.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  try {
    HttpSession session = req.getSession(true);
    Storage storage = (Storage) session.getAttribute(Storage.class.getName());
    if (storage == null) {
      storage = new Storage();
      session.setAttribute(Storage.class.getName(), storage);
    }

    // create odata handler and configure it with EdmProvider and Processor
    OData odata = OData.newInstance();
    ServiceMetadata edm = odata.createServiceMetadata(new DemoEdmProvider(), new ArrayList<EdmxReference>());
    ODataHttpHandler handler = odata.createHandler(edm);
    handler.register(new DemoEntityCollectionProcessor(storage));
    handler.register(new DemoEntityProcessor(storage));
    handler.register(new DemoPrimitiveProcessor(storage));

    // let the handler do the work
    handler.process(req, resp);
  } catch (RuntimeException e) {
    LOG.error("Server Error occurred in ExampleServlet", e);
    throw new ServletException(e);
  }

}
 
Example 2
Source File: DemoServlet.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  try {
    HttpSession session = req.getSession(true);
    Storage storage = (Storage) session.getAttribute(Storage.class.getName());
    if (storage == null) {
      storage = new Storage();
      session.setAttribute(Storage.class.getName(), storage);
    }

    // create odata handler and configure it with EdmProvider and Processor
    OData odata = OData.newInstance();
    ServiceMetadata edm = odata.createServiceMetadata(new DemoEdmProvider(), new ArrayList<EdmxReference>());
    ODataHttpHandler handler = odata.createHandler(edm);
    handler.register(new DemoEntityCollectionProcessor(storage));
    handler.register(new DemoEntityProcessor(storage));
    handler.register(new DemoPrimitiveProcessor(storage));
    handler.register(new DemoBatchProcessor(storage));
    
    // let the handler do the work
    handler.process(req, resp);
  } catch (RuntimeException e) {
    LOG.error("Server Error occurred in ExampleServlet", e);
    throw new ServletException(e);
  }
}
 
Example 3
Source File: DemoServlet.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  try {
    HttpSession session = req.getSession(true);
    Storage storage = (Storage) session.getAttribute(Storage.class.getName());
    if (storage == null) {
      storage = new Storage();
      session.setAttribute(Storage.class.getName(), storage);
    }

    // create odata handler and configure it with EdmProvider and Processor
    OData odata = OData.newInstance();
    ServiceMetadata edm = odata.createServiceMetadata(new DemoEdmProvider(), new ArrayList<EdmxReference>());
    ODataHttpHandler handler = odata.createHandler(edm);
    handler.register(new DemoEntityCollectionProcessor(storage));
    handler.register(new DemoEntityProcessor(storage));
    handler.register(new DemoPrimitiveProcessor(storage));
    handler.register(new DemoActionProcessor(storage));
    
    // let the handler do the work
    handler.process(req, resp);
  } catch (RuntimeException e) {
    LOG.error("Server Error occurred in ExampleServlet", e);
    throw new ServletException(e);
  }
}
 
Example 4
Source File: JaxrsODataService.java    From cxf with Apache License 2.0 6 votes vote down vote up
@GET
@Path("{id:.*}")
public Response service(@Context HttpServletRequest req, @Context HttpServletResponse resp) {

    String requestMapping = req.getContextPath() + req.getServletPath() + "/DemoService.svc";
    req.setAttribute("requestMapping", requestMapping);
    // create odata handler and configure it with EdmProvider and Processor
    OData odata = OData.newInstance();
    ServiceMetadata edm = odata.createServiceMetadata(new DemoEdmProvider(),
                                                      new ArrayList<EdmxReference>());
    ODataHttpHandler handler = odata.createHandler(edm);
    handler.register(new DemoEntityCollectionProcessor());

    // let the handler do the work
    handler.process(req, resp);
    return Response.ok().build();
}
 
Example 5
Source File: DemoServlet.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  try {
    HttpSession session = req.getSession(true);
    Storage storage = (Storage) session.getAttribute(Storage.class.getName());
    if (storage == null) {
      storage = new Storage();
      session.setAttribute(Storage.class.getName(), storage);
    }

    // create odata handler and configure it with EdmProvider and Processor
    OData odata = OData.newInstance();
    ServiceMetadata edm = odata.createServiceMetadata(new DemoEdmProvider(), new ArrayList<EdmxReference>());
    ODataHttpHandler handler = odata.createHandler(edm);
    handler.register(new DemoEntityCollectionProcessor(storage));
    handler.register(new DemoEntityProcessor(storage));
    handler.register(new DemoPrimitiveProcessor(storage));

    // let the handler do the work
    handler.process(req, resp);
  } catch (RuntimeException e) {
    LOG.error("Server Error occurred in ExampleServlet", e);
    throw new ServletException(e);
  }

}
 
Example 6
Source File: DemoServlet.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  try {
    HttpSession session = req.getSession(true);
    Storage storage = (Storage) session.getAttribute(Storage.class.getName());
    if (storage == null) {
      storage = new Storage();
      session.setAttribute(Storage.class.getName(), storage);
    }

    // create odata handler and configure it with EdmProvider and Processor
    OData odata = OData.newInstance();
    ServiceMetadata edm = odata.createServiceMetadata(new DemoEdmProvider(), new ArrayList<EdmxReference>());
    ODataHttpHandler handler = odata.createHandler(edm);
    handler.register(new DemoEntityCollectionProcessor(storage));
    handler.register(new DemoEntityProcessor(storage));
    handler.register(new DemoPrimitiveProcessor(storage));

    // let the handler do the work
    handler.process(req, resp);
  } catch (RuntimeException e) {
    LOG.error("Server Error occurred in DemoServlet", e);
    throw new ServletException(e);
  }

}
 
Example 7
Source File: DemoServlet.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  try {
    HttpSession session = req.getSession(true);
    Storage storage = (Storage) session.getAttribute(Storage.class.getName());
    if (storage == null) {
      storage = new Storage();
      session.setAttribute(Storage.class.getName(), storage);
    }

    // create odata handler and configure it with EdmProvider and Processor
    OData odata = OData.newInstance();
    ServiceMetadata edm = odata.createServiceMetadata(new DemoEdmProvider(), new ArrayList<EdmxReference>());
    ODataHttpHandler handler = odata.createHandler(edm);
    handler.register(new DemoEntityCollectionProcessor(storage));
    handler.register(new DemoEntityProcessor(storage));
    handler.register(new DemoPrimitiveProcessor(storage));
    
    // let the handler do the work
    handler.process(req, resp);
  } catch (RuntimeException e) {
    LOG.error("Server Error occurred in ExampleServlet", e);
    throw new ServletException(e);
  }
}
 
Example 8
Source File: DemoServlet.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  try {
    HttpSession session = req.getSession(true);
    Storage storage = (Storage) session.getAttribute(Storage.class.getName());
    if (storage == null) {
      storage = new Storage();
      session.setAttribute(Storage.class.getName(), storage);
    }

    // create odata handler and configure it with EdmProvider and Processor
    OData odata = OData.newInstance();
    ServiceMetadata edm = odata.createServiceMetadata(new DemoEdmProvider(), new ArrayList<EdmxReference>());
    ODataHttpHandler handler = odata.createHandler(edm);
    handler.register(new DemoEntityCollectionProcessor(storage));
    handler.register(new DemoEntityProcessor(storage));
    handler.register(new DemoPrimitiveProcessor(storage));
    
    // let the handler do the work
    handler.process(req, resp);
  } catch (RuntimeException e) {
    LOG.error("Server Error occurred in ExampleServlet", e);
    throw new ServletException(e);
  }
}
 
Example 9
Source File: DemoServlet.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  try {
    HttpSession session = req.getSession(true);
    Storage storage = (Storage) session.getAttribute(Storage.class.getName());
    if (storage == null) {
      storage = new Storage();
      session.setAttribute(Storage.class.getName(), storage);
    }

    // create odata handler and configure it with EdmProvider and Processor
    OData odata = OData.newInstance();
    ServiceMetadata edm = odata.createServiceMetadata(new DemoEdmProvider(), new ArrayList<EdmxReference>());
    ODataHttpHandler handler = odata.createHandler(edm);
    handler.register(new DemoEntityCollectionProcessor(storage));
    handler.register(new DemoEntityProcessor(storage));
    handler.register(new DemoPrimitiveProcessor(storage));

    // let the handler do the work
    handler.process(req, resp);
  } catch (RuntimeException e) {
    LOG.error("Server Error occurred in ExampleServlet", e);
    throw new ServletException(e);
  }

}
 
Example 10
Source File: DemoServlet.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  try {
    HttpSession session = req.getSession(true);
    Storage storage = (Storage) session.getAttribute(Storage.class.getName());
    if (storage == null) {
      storage = new Storage();
      session.setAttribute(Storage.class.getName(), storage);
    }

    // create odata handler and configure it with EdmProvider and Processor
    OData odata = OData.newInstance();
    ServiceMetadata edm = odata.createServiceMetadata(new DemoEdmProvider(), new ArrayList<EdmxReference>());
    ODataHttpHandler handler = odata.createHandler(edm);
    handler.register(new DemoEntityCollectionProcessor(storage));
    handler.register(new DemoEntityProcessor(storage));
    handler.register(new DemoPrimitiveProcessor(storage));

    // let the handler do the work
    handler.process(req, resp);
  } catch (RuntimeException e) {
    LOG.error("Server Error occurred in ExampleServlet", e);
    throw new ServletException(e);
  }

}
 
Example 11
Source File: DemoServlet.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  try {
    HttpSession session = req.getSession(true);
    Storage storage = (Storage) session.getAttribute(Storage.class.getName());
    if (storage == null) {
      storage = new Storage();
      session.setAttribute(Storage.class.getName(), storage);
    }

    // create odata handler and configure it with EdmProvider and Processor
    OData odata = OData.newInstance();
    ServiceMetadata edm = odata.createServiceMetadata(new DemoEdmProvider(), new ArrayList<EdmxReference>());
    ODataHttpHandler handler = odata.createHandler(edm);
    handler.register(new DemoEntityCollectionProcessor(storage));
    handler.register(new DemoEntityProcessor(storage));
    handler.register(new DemoPrimitiveProcessor(storage));

    // let the handler do the work
    handler.process(req, resp);
  } catch (RuntimeException e) {
    LOG.error("Server Error occurred in ExampleServlet", e);
    throw new ServletException(e);
  }

}
 
Example 12
Source File: DemoServlet.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  try {
    HttpSession session = req.getSession(true);
    Storage storage = (Storage) session.getAttribute(Storage.class.getName());
    if (storage == null) {
      storage = new Storage();
      session.setAttribute(Storage.class.getName(), storage);
    }

    // create odata handler and configure it with EdmProvider and Processor
    OData odata = OData.newInstance();
    ServiceMetadata edm = odata.createServiceMetadata(new DemoEdmProvider(), new ArrayList<EdmxReference>());
    ODataHttpHandler handler = odata.createHandler(edm);
    handler.register(new DemoEntityCollectionProcessor(storage));
    handler.register(new DemoEntityProcessor(storage));
    handler.register(new DemoPrimitiveProcessor(storage));

    // let the handler do the work
    handler.process(req, resp);
  } catch (RuntimeException e) {
    LOG.error("Server Error occurred in DemoServlet", e);
    throw new ServletException(e);
  }

}
 
Example 13
Source File: DemoServlet.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  try {
    OData odata = OData.newInstance();
    ServiceMetadata edm = odata.createServiceMetadata(new DemoEdmProvider(), new ArrayList<EdmxReference>());
    
    HttpSession session = req.getSession(true);
    Storage storage = (Storage) session.getAttribute(Storage.class.getName());
    if (storage == null) {
      storage = new Storage(odata, edm.getEdm());
      session.setAttribute(Storage.class.getName(), storage);
    }

   
    ODataHttpHandler handler = odata.createHandler(edm);
    handler.register(new DemoEntityCollectionProcessor(storage));
    handler.register(new DemoEntityProcessor(storage));
    handler.register(new DemoPrimitiveProcessor(storage));
    
    // let the handler do the work
    handler.process(req, resp);
  } catch (RuntimeException e) {
    LOG.error("Server Error occurred in ExampleServlet", e);
    throw new ServletException(e);
  }
}
 
Example 14
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 15
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 16
Source File: ProductsServlet.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Override
protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
    try {
        Storage storage = Storage.getInstance();

        // create odata handler and configure it with CsdlEdmProvider and Processor
        OData odata = OData.newInstance();
        ServiceMetadata edm = odata.createServiceMetadata(new ProductsEdmProvider(), new ArrayList<EdmxReference>());
        ODataHttpHandler handler = odata.createHandler(edm);
        handler.register(new ProductsEntityCollectionProcessor(storage));
        handler.register(new ProductEntityProcessor(storage));

        // let the handler do the work
        handler.process(req, resp);
    } catch (RuntimeException e) {
        LOG.error("Server Error occurred: ", e);
        throw new ServletException(e);
    }
}
 
Example 17
Source File: ODataServiceHandler.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public ODataServiceHandler(ODataDataHandler dataHandler, String namespace, String configID)
        throws ODataServiceFault {
    ODataAdapter processor = new ODataAdapter(dataHandler, namespace, configID);
    OData odata = OData4Impl.newInstance();
    ServiceMetadata edm = odata.createServiceMetadata(processor.getEdmProvider(), new ArrayList<EdmxReference>());
    this.handler = odata.createHandler(edm);
    this.handler.register(processor);
}
 
Example 18
Source File: DemoServlet.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  OData odata = OData.newInstance();
  ServiceMetadata edm = odata.createServiceMetadata(new DemoEdmProvider(), new ArrayList<EdmxReference>());
  
  try {
    HttpSession session = req.getSession(true);
    Storage storage = (Storage) session.getAttribute(Storage.class.getName());
    if (storage == null) {
      storage = new Storage(odata, edm.getEdm());
      session.setAttribute(Storage.class.getName(), storage);
    }

    // create odata handler and configure it with EdmProvider and Processor
    ODataHttpHandler handler = odata.createHandler(edm);
    handler.register(new DemoEntityCollectionProcessor(storage));
    handler.register(new DemoEntityProcessor(storage));
    handler.register(new DemoPrimitiveProcessor(storage));
    handler.register(new DemoActionProcessor(storage));
    handler.register(new DemoBatchProcessor(storage));

    // let the handler do the work
    handler.process(req, resp);
  } catch (RuntimeException e) {
    LOG.error("Server Error occurred in ExampleServlet", e);
    throw new ServletException(e);
  }

}
 
Example 19
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 20
Source File: TechnicalServlet.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
protected void service(final HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
  try {
    OData odata = OData.newInstance();
    EdmxReference reference = new EdmxReference(URI.create("../v4.0/cs02/vocabularies/Org.OData.Core.V1.xml"));
    reference.addInclude(new EdmxReferenceInclude("Org.OData.Core.V1", "Core"));
    final ServiceMetadata serviceMetadata = odata.createServiceMetadata(
        new EdmTechProvider(),
        Collections.singletonList(reference),
        new MetadataETagSupport(metadataETag));

    HttpSession session = request.getSession(true);
    DataProvider dataProvider = (DataProvider) session.getAttribute(DataProvider.class.getName());
    if (dataProvider == null) {
      dataProvider = new DataProvider(odata, serviceMetadata.getEdm());
      session.setAttribute(DataProvider.class.getName(), dataProvider);
      LOG.info("Created new data provider.");
    }

    ODataHttpHandler handler = odata.createHandler(serviceMetadata);
    // Register processors.
    handler.register(new TechnicalEntityProcessor(dataProvider, serviceMetadata));
    handler.register(new TechnicalPrimitiveComplexProcessor(dataProvider, serviceMetadata));
    handler.register(new TechnicalActionProcessor(dataProvider, serviceMetadata));
    handler.register(new TechnicalBatchProcessor(dataProvider));
    // Register helpers.
    handler.register(new ETagSupport());
    handler.register(new DefaultDebugSupport());
    // Process the request.
    handler.process(request, response);
  } catch (final RuntimeException e) {
    LOG.error("Server Error", e);
    throw new ServletException(e);
  }
}