struts2-rest plugin..making both struts actions + rest actions work together but. giving java.lang.reflect.InvocationTargetException

不想你离开。 提交于 2019-12-06 02:43:36

ive solved the problem with customMapper..

this is my custom mapper class....

   package org.apache.struts2.rest.example;

    import javax.servlet.http.HttpServletRequest;
    import org.apache.struts2.dispatcher.mapper.ActionMapper;
    import org.apache.struts2.dispatcher.mapper.ActionMapping;
    import org.apache.struts2.dispatcher.mapper.DefaultActionMapper;
    import com.opensymphony.xwork2.config.ConfigurationManager;

   public class CustomActionMapper extends DefaultActionMapper {


    public ActionMapping getMapping(HttpServletRequest request, ConfigurationManager configManager) {

        return getActionMapper(request, configManager).getMapping(request, configManager);

    }

    private ActionMapper getActionMapper(HttpServletRequest request, ConfigurationManager configManager) {

        ActionMapping actionMapping = new ActionMapping();  

        parseNameAndNamespace(request.getRequestURI(), actionMapping, configManager);

        if (!(actionMapping.getNamespace()).contains("/rest")) {

            return container.getInstance(ActionMapper.class, "struts");

        } 
        else 
        {
            return container.getInstance(ActionMapper.class, "rest");


}
}

........................................... my struts.xml is as follows......

<?xml version="1.0" encoding="UTF-8" ?>


  <!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">



 <struts>
<!--  Overwrite Convention -->

    <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="myActionMapper" class="org.apache.struts2.rest.example.CustomActionMapper" />
    <constant name="struts.mapper.class" value="myActionMapper" />
    <constant name="struts.convention.action.suffix" value="Controller"/>
    <constant name="struts.convention.action.mapAllMatches" value="true"/>
    <constant name="struts.convention.default.parent.package" value="rest-default"/>
    <constant name="struts.convention.package.locators" value="example"/> 
    <constant name="struts.action.extension" value="xhtml,,xml,json,action"/>      
<!-- overwrite action complete -->


<!-- normal struts actions -->

<package name="userlogin" extends="struts-default" namespace="/">

<action name="*">
        <result name="error">/view/error/error.jsp</result>
    </action>
    ..................

</package>




<include file="..........xml" />
<include file=".............xml" /> 


<!-- normal stryts actions complete -->


</struts>

these are the libraries im using ..

- asm-3.1.jar
- asm-commons-3.1.jar
- commons-beanutils-1.7.0.jar
- commons-collections-3.1.jar
- commons-fileupload-1.2.2.jar
- commons-io-2.0.1.jar
- commons-lang-2.5.jar
- commons-logging-1.1.1.jar
- commons-logging-api-1.1.jar
- ezmorph-1.0.3.jar
- freemarker-2.3.16.jar
- javassist-3.11.0.GA.jar
- json-lib-2.1-jdk15.jar
- log4j-1.2.8.jar
- ognl-3.0.1.jar
- struts2-convention-plugin-2.2.3.jar
- struts2-core-2.2.3.jar
- struts2-json-plugin-2.2.3.jar
- struts2-rest-plugin-2.2.3.jar
- xpp3_min-1.1.3.4.O.jar
- xstream-1.2.2.jar
- xwork-core-2.2.3.jar

make sure you use compatible library versions....

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!