Chris Clark
Chris Clark

Reputation: 41

In Tomee cxf is intercepting calls to struts - how can I stop requests to struts URLs being intercepted?

Our application was previously running in Tomee 1.5.2 and it worked fine. It has a mix of some legacy struts code (referenced by URLs ending in .do), some new JSF code and some jax-rs Restful services.

What I am getting is a 404 not found for the struts URL.

I updated to Tomee 1.7.2 Plus, and so have the CXF version 2.6.16 jaxrs libs. Now when I try to access a struts URL, the CXF code intercepts that URL and can't match it to anything and so throws an exception.

Is there any way to specify which paths CXF will intercept? (We don't use spring, so all the cxf docs that mention spring are of no use)

The version of struts is 1.2.9. The web.xml is below.

This is my web.xml

<?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">


    <filter-mapping>
        <filter-name>EncodingRequestFilter</filter-name>
        <url-pattern>*.do</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>

    <session-config>
        <session-timeout>60</session-timeout>
    </session-config>

    <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>rmt_theme</param-value>
    </context-param>

     .....

    <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>2</param-value>

        </init-param>
        <init-param>
            <param-name>config</param-name>
            <param-value>/WEB-INF/struts-config.xml</param-value>

        </init-param>
        <load-on-startup>2</load-on-startup>

    </servlet>

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>

    ... a lot of servlet mappings

    <mime-mapping>
    ...a whole lot of mime mappings deleted here for readability.
    ... 


    ...

    <welcome-file-list>
        <welcome-file>index.jsf</welcome-file>
    </welcome-file-list>
</web-app>

This is the logs with the FINE level activated.

    Sep 09, 2015 2:59:43 PM org.apache.cxf.transport.http.AbstractHTTPDestination invoke
    FINE: Create a new message for processing
    Sep 09, 2015 2:59:43 PM org.apache.cxf.transport.http.Headers copyFromRequest
    FINE: Request Headers: {Accept=[text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8], accept-encoding=[gzip, deflate, sdch], accept-language=[en,es;q=0.8,en-GB;q=0.6,en-US;q=0.4,es-419;q=0.2], cache-control=[no-cache], connection=[keep-alive], Content-Type=[null], cookie=[treeOpenStatex-userStockSites=; JSESSIONID=9303FA8BA796D5C8E224C9AC546675BA; jpreLoader=loaded; primefaces.download=true; oam.Flash.RENDERMAP.TOKEN=-6lb69gdo9], host=[localhost:8080], pragma=[no-cache], referer=[http://localhost:8080/chemalert/], upgrade-insecure-requests=[1], user-agent=[Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36]}
    Sep 09, 2015 2:59:43 PM org.apache.cxf.phase.PhaseInterceptorChain add
    FINE: Adding interceptor org.apache.cxf.transport.https.CertConstraintsInterceptor@34848be9 to phase pre-stream
    Sep 09, 2015 2:59:43 PM org.apache.cxf.phase.PhaseInterceptorChain outputChainToLog
    FINE: Chain org.apache.cxf.phase.PhaseInterceptorChain@7351c0b4 was created. Current flow:
      receive [PolicyInInterceptor, SaajInFaultInterceptor]
      pre-stream [CertConstraintsInterceptor]
      unmarshal [JAXRSInInterceptor]
      pre-logical [OneWayProcessorInterceptor]
      invoke [ServiceInvokerInterceptor]
      post-invoke [SaajInInterceptor, OutgoingChainInterceptor]

    Sep 09, 2015 2:59:43 PM org.apache.cxf.phase.PhaseInterceptorChain doIntercept
    FINE: Invoking handleMessage on interceptor org.apache.cxf.ws.policy.PolicyInInterceptor@35ca0cf
    Sep 09, 2015 2:59:43 PM org.apache.cxf.phase.PhaseInterceptorChain doIntercept
    FINE: Invoking handleMessage on interceptor org.apache.openejb.server.cxf.client.SaajInFaultInterceptor@121fe3c8
    Sep 09, 2015 2:59:43 PM org.apache.cxf.phase.PhaseInterceptorChain doIntercept
    FINE: Invoking handleMessage on interceptor org.apache.cxf.transport.https.CertConstraintsInterceptor@34848be9
    Sep 09, 2015 2:59:43 PM org.apache.cxf.phase.PhaseInterceptorChain doIntercept
    FINE: Invoking handleMessage on interceptor org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor@3239ff45
    Sep 09, 2015 2:59:43 PM org.apache.cxf.jaxrs.utils.JAXRSUtils selectResourceClass
    FINE: Trying to select a resource class, request path : /admin/adminHome.do
    Sep 09, 2015 2:59:43 PM org.apache.cxf.jaxrs.utils.JAXRSUtils selectResourceClass
    FINE: No resource class match for org.saiku.web.rest.resources.AdminResource, request path : /admin/adminHome.do
    Sep 09, 2015 2:59:43 PM org.apache.cxf.jaxrs.utils.JAXRSUtils selectResourceClass
    FINE: No resource class match for org.saiku.web.rest.resources.QueryResource, request path : /admin/adminHome.do
    Sep 09, 2015 2:59:43 PM org.apache.cxf.jaxrs.utils.JAXRSUtils selectResourceClass
    FINE: No resource class match for org.saiku.web.rest.resources.BasicTagRepositoryResource, request path : /admin/adminHome.do
    Sep 09, 2015 2:59:43 PM org.apache.cxf.jaxrs.utils.JAXRSUtils selectResourceClass
    FINE: No resource class match for org.saiku.web.rest.resources.InfoResource, request path : /admin/adminHome.do
    Sep 09, 2015 2:59:43 PM org.apache.cxf.jaxrs.utils.JAXRSUtils selectResourceClass
    FINE: No resource class match for org.saiku.web.rest.resources.FilterRepositoryResource, request path : /admin/adminHome.do
    Sep 09, 2015 2:59:43 PM org.apache.cxf.jaxrs.utils.JAXRSUtils selectResourceClass
    FINE: No resource class match for org.saiku.web.rest.resources.SessionResource, request path : /admin/adminHome.do
    Sep 09, 2015 2:59:43 PM org.apache.cxf.jaxrs.utils.JAXRSUtils selectResourceClass
    FINE: No resource class match for org.saiku.web.rest.resources.StatisticsResource, request path : /admin/adminHome.do
    Sep 09, 2015 2:59:43 PM org.apache.cxf.jaxrs.utils.JAXRSUtils selectResourceClass
    FINE: No resource class match for au.com.blah.analytics.web.rest.PredefinedQueryResource, request path : /admin/adminHome.do
    Sep 09, 2015 2:59:43 PM org.apache.cxf.jaxrs.utils.JAXRSUtils selectResourceClass
    FINE: No resource class match for org.saiku.web.rest.resources.DataSourceResource, request path : /admin/adminHome.do
    Sep 09, 2015 2:59:43 PM org.apache.cxf.jaxrs.utils.JAXRSUtils selectResourceClass
    FINE: No resource class match for org.saiku.web.rest.resources.ExporterResource, request path : /admin/adminHome.do
    Sep 09, 2015 2:59:43 PM org.apache.cxf.jaxrs.utils.JAXRSUtils selectResourceClass
    FINE: No resource class match for org.saiku.web.rest.resources.OlapDiscoverResource, request path : /admin/adminHome.do
    Sep 09, 2015 2:59:43 PM org.apache.cxf.jaxrs.utils.JAXRSUtils selectResourceClass
    FINE: No resource class match for org.saiku.web.rest.resources.BasicRepositoryResource2, request path : /admin/adminHome.do
    Sep 09, 2015 2:59:43 PM org.apache.cxf.jaxrs.utils.JAXRSUtils selectResourceClass
    FINE: No resource class match for org.saiku.web.rest.resources.Query2Resource, request path : /admin/adminHome.do
    Sep 09, 2015 2:59:43 PM org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor processRequest
    WARNING: No root resource matching request path /chemalert/admin/adminHome.do has been found, Relative Path: /admin/adminHome.do. Please enable FINE/TRACE log level for more details.
    Sep 09, 2015 2:59:43 PM org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse
    WARNING: javax.ws.rs.WebApplicationException
        at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:162)
        at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:91)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
        at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
        at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:240)
        at org.apache.openejb.server.cxf.rs.CxfRsHttpListener.doInvoke(CxfRsHttpListener.java:227)
        at org.apache.tomee.webservices.CXFJAXRSFilter.doFilter(CXFJAXRSFilter.java:94)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at au.com.blah.web.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:29)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
        at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:614)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:745)

    Sep 09, 2015 2:59:43 PM org.apache.cxf.phase.PhaseInterceptorChain doIntercept
    FINE: Invoking handleMessage on interceptor org.apache.cxf.interceptor.OneWayProcessorInterceptor@5fd546d4
    Sep 09, 2015 2:59:43 PM org.apache.cxf.phase.PhaseInterceptorChain doIntercept
    FINE: Invoking handleMessage on interceptor org.apache.cxf.interceptor.ServiceInvokerInterceptor@74a3639c
    Sep 09, 2015 2:59:43 PM org.apache.cxf.phase.PhaseInterceptorChain doIntercept
    FINE: Invoking handleMessage on interceptor org.apache.openejb.server.cxf.client.SaajInInterceptor@6dbba9fa
    Sep 09, 2015 2:59:43 PM org.apache.cxf.phase.PhaseInterceptorChain doIntercept
    FINE: Invoking handleMessage on interceptor org.apache.cxf.interceptor.OutgoingChainInterceptor@6f91c6a5
    Sep 09, 2015 2:59:43 PM org.apache.cxf.interceptor.OutgoingChainInterceptor getChain
    FINE: Interceptors contributed by bus: [org.apache.cxf.ws.policy.PolicyOutInterceptor@6cad111a, org.apache.openejb.server.cxf.client.SaajOutInterceptor@9bc91f]
    Sep 09, 2015 2:59:43 PM org.apache.cxf.interceptor.OutgoingChainInterceptor getChain
    FINE: Interceptors contributed by service: []
    Sep 09, 2015 2:59:43 PM org.apache.cxf.interceptor.OutgoingChainInterceptor getChain
    FINE: Interceptors contributed by endpoint: [org.apache.cxf.interceptor.MessageSenderInterceptor@73183b04]
    Sep 09, 2015 2:59:43 PM org.apache.cxf.interceptor.OutgoingChainInterceptor getChain
    FINE: Interceptors contributed by binding: [org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor@343caabe]
    Sep 09, 2015 2:59:43 PM org.apache.cxf.phase.PhaseInterceptorChain outputChainToLog
    FINE: Chain org.apache.cxf.phase.PhaseInterceptorChain@5173e983 was created. Current flow:
      setup [PolicyOutInterceptor, SaajOutInterceptor]
      prepare-send [MessageSenderInterceptor]
      marshal [JAXRSOutInterceptor]

    Sep 09, 2015 2:59:43 PM org.apache.cxf.phase.PhaseInterceptorChain doIntercept
    FINE: Invoking handleMessage on interceptor org.apache.cxf.ws.policy.PolicyOutInterceptor@6cad111a
    Sep 09, 2015 2:59:43 PM org.apache.cxf.ws.policy.PolicyOutInterceptor handle
    FINE: No binding operation info.
    Sep 09, 2015 2:59:43 PM org.apache.cxf.phase.PhaseInterceptorChain doIntercept
    FINE: Invoking handleMessage on interceptor org.apache.openejb.server.cxf.client.SaajOutInterceptor@9bc91f
    Sep 09, 2015 2:59:43 PM org.apache.cxf.phase.PhaseInterceptorChain doIntercept
    FINE: Invoking handleMessage on interceptor org.apache.cxf.interceptor.MessageSenderInterceptor@73183b04
    Sep 09, 2015 2:59:43 PM org.apache.cxf.phase.PhaseInterceptorChain add
    FINE: Adding interceptor org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor@575a516b to phase prepare-send-ending
    Sep 09, 2015 2:59:43 PM org.apache.cxf.phase.PhaseInterceptorChain outputChainToLog
    FINE: Chain org.apache.cxf.phase.PhaseInterceptorChain@5173e983 was modified. Current flow:
      setup [PolicyOutInterceptor, SaajOutInterceptor]
      prepare-send [MessageSenderInterceptor]
      marshal [JAXRSOutInterceptor]
      prepare-send-ending [MessageSenderEndingInterceptor]

    Sep 09, 2015 2:59:43 PM org.apache.cxf.phase.PhaseInterceptorChain doIntercept
    FINE: Invoking handleMessage on interceptor org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor@343caabe
    Sep 09, 2015 2:59:43 PM org.apache.cxf.phase.PhaseInterceptorChain doIntercept
    FINE: Invoking handleMessage on interceptor org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor@575a516b
    Sep 09, 2015 2:59:43 PM org.apache.cxf.ws.addressing.ContextUtils retrieveMAPs
    FINE: retrieving MAPs from context property javax.xml.ws.addressing.context.inbound
    Sep 09, 2015 2:59:43 PM org.apache.cxf.ws.addressing.ContextUtils retrieveMAPs
    FINE: WS-Addressing - failed to retrieve Message Addressing Properties from context

Upvotes: 2

Views: 620

Answers (1)

Chris Clark
Chris Clark

Reputation: 41

To answer my own question.

It seems that the difference between CXF in tomee 1.5.2 and 1.7.2 is that the jax-rs deployment unit used to be each endpoint but in the later version the deployment unit is the whole application (see here for a little more detail https://rmannibucau.wordpress.com/2013/01/09/tomeeopenejb-jaxrs-refactoring/).

So to fix my issue I had to map the rest services to some URL to avoid it treating the whole app as a rest service (if that makes sense).

To do this I added the following to the web.xml

<servlet>
    <servlet-name>javax.ws.rs.core.Application</servlet-name>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>javax.ws.rs.core.Application</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

Then I changed any URL that called a rest service to include the /rest/ at the start.

(An alternative to using an entry in the web.xml is to use javax.ws.rs.core.Application as in this example http://tomee.apache.org/examples-trunk/rest-example-with-application/README.html)

Upvotes: 1

Related Questions