users@jersey.java.net

[Jersey] 转发: Configuration of Struts 2 + Jersey in one app

From: <maryatdown_at_sina.cn>
Date: Sat, 24 Nov 2012 19:32:49 +0800

I need intergrate jersey into struts2 as well, met the same problem, does anyone here have the solution or suggestions?
many Thanks ahead.

m.m
----- 原始邮件 -----
发件人:Kevin Duffey <andjarnic_at_yahoo.com>
收件人:"users_at_jersey.java.net" <users_at_jersey.java.net>
主题:[Jersey] Configuration of Struts 2 + Jersey in one app
日期:2011年09月27日 14点28分

Hi all,
I can't seem to find any sort of information on how to configure both Jersey and Struts 2 in one app. I have the following web.xml:
    <servlet>
        <servlet-name>ServletAdaptor</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>ServletAdaptor</servlet-name>
       
 <url-pattern>/ajax/*</url-pattern>
    </servlet-mapping>

    <filter>
      <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
      <filter-name>struts2</filter-name>
       <url-pattern>/*</url-pattern>
    </filter-mapping>


    I am using Struts 2 annotation configuration for action classes, results, etc. However, I still have a struts.xml in the src/ that gets put into the WEB-INF/classes to configure a few things. One of them is an
 option not easily found on google about telling Struts to ignore one or more URL patterns. So given that I want ALL requests EXCEPT any url with ajax/* in it, to Struts 2, I have the above and added the ajax/* pattern to the struts.xml like so:


<struts>
    <constant name="struts.devMode" value="true" />
    <constant name="struts.convention.classes.reload" value="true" />
    <constant name="struts.enable.SlashesInActionNames" value="true" />
    <constant name="struts.action.excludePattern" value="/ajax/*?" />

    <package name="default" extends="struts-default" namespace="/">
        <action name="index">
            <result>/index.jsp</result>
       
 </action>
    </package>
</struts>



As you see, the excludePattern is used to tell Struts what to ignore. Still, I can't get any of my Jersey requests to get through to the resources. They are loading..I see them being round in the log output. The only error I get is that Struts has no action mapped to /ajax/somePath.

So if anyone has configured Struts 2 and Jersey, I'd be much appreciated in helping me resolve how to make them work together so that one (or a few url paths) make it through to Jersey, the rest go to Struts 2.

Thank you.