How can I solve olingo odata V2 $filter error?

589 views Asked by At

I have an olingo OData V2 service, which is working almost perfect. CRUD methods are tested from POSTMAN. It is running on Tomcat, the db is MySQL and the project is in Eclipse.

This is the service's code:

package main;

import org.apache.olingo.odata2.jpa.processor.ref.factory.JPAEntityManagerFactory;
import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
import org.apache.olingo.odata2.processor.api.jpa.ODataJPAServiceFactory;
import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;

public class ODataServiceFromGenerator extends ODataJPAServiceFactory {  
      private static final String PERSISTENCE_UNIT_NAME = "cars";

    @Override
    public ODataJPAContext initializeODataJPAContext() {

        ODataJPAContext oDataJPAContext;
        try {
            oDataJPAContext = getODataJPAContext();
            oDataJPAContext.setEntityManagerFactory(JPAEntityManagerFactory
                    .getEntityManagerFactory(PERSISTENCE_UNIT_NAME));
            oDataJPAContext.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);
            return oDataJPAContext;
        } catch (ODataJPARuntimeException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        }

  }

}

I can reach the metadata in this url: http://localhost:8080/GeneratorTry/cars.svc/$metadata

When I try to filter one of my EntitySet ( http://localhost:8080/GeneratorTry/cars.svc/Vendors?$filter=startswith(Mobile,'+36') ) I get this error:

HTTP Status 500 – Internal Server Error

Type Exception Report

Message org.apache.cxf.interceptor.Fault: org.apache.olingo.odata2.core.uri.expression.FilterParserImpl

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

java.lang.RuntimeException:
org.apache.cxf.interceptor.Fault:
org.apache.olingo.odata2.core.uri.expression.FilterParserImpl
  org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:116)
  org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:331)
  org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
  org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:239)
  org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:223)
  org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:203)
  org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:137)
  org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:158)
  org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:243)
  org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:168)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
  org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:219)
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Root Cause

org.apache.cxf.interceptor.Fault:
org.apache.olingo.odata2.core.uri.expression.FilterParserImpl
  org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:162)
  org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:128)
  org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:198)
  org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:261)
  org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:100)
  org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
  org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94)
  org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
  org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
  org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:239)
  org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:223)
  org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:203)
  org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:137)
  org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:158)
  org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:243)
  org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:168)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
  org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:219)
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Root Cause

java.lang.NoClassDefFoundError:
org.apache.olingo.odata2.core.uri.expression.FilterParserImpl
  org.apache.olingo.odata2.core.uri.UriParserImpl.parseOrderByString(UriParserImpl.java:848)
  org.apache.olingo.odata2.core.uri.UriParserImpl.handleSystemQueryOptionOrderBy(UriParserImpl.java:604)
  org.apache.olingo.odata2.core.uri.UriParserImpl.handleSystemQueryOptions(UriParserImpl.java:560)
  org.apache.olingo.odata2.core.uri.UriParserImpl.parse(UriParserImpl.java:114)
  org.apache.olingo.odata2.core.ODataRequestHandler.handle(ODataRequestHandler.java:101)
  org.apache.olingo.odata2.core.rest.ODataSubLocator.handle(ODataSubLocator.java:148)
  org.apache.olingo.odata2.core.rest.ODataSubLocator.handleGet(ODataSubLocator.java:53)
  sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  java.lang.reflect.Method.invoke(Unknown Source)
  org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:180)
  org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
  org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:198)
  org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:261)
  org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:100)
  org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
  org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94)
  org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
  org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
  org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:239)
  org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:223)
  org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:203)
  org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:137)
  org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:158)
  org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:243)
  org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:168)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
  org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:219)
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Note The full stack trace of the root cause is available in the server logs.

Apache Tomcat/9.0.35

The error message is the same with $orderby, but it is working with $select, $top, $skip, $count.

Welcome any idea! Thank you for help in advance!

1

There are 1 answers

0
Senén P. On

Have a look of this source: https://olingo.apache.org/doc/odata2/tutorials/Olingo_Tutorial_AdvancedRead_FilterVisitor.html

You can use uriInfo.getFilter() to get the expression from the request.