struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hantsy Bai <han...@gmail.com>
Subject Re: Struts2+Spring2+Interceptor+Invalid action class configuration that references an unknown class named
Date Fri, 21 May 2010 18:58:46 GMT
于 2010/5/22 1:05, rocks 写道:
> Dear,
>
> Apologize the posting same subject, but I did not find any solution so far.
> I am developing a web application based on struts 2.1.8.1+ spring 2+
> hibernate 3 + tomcat 5.5. There is requisite library like
> struts2-convention-plugin-2.1.8.1.jar in my classpath.
>
> For authentication I am using struts interceptor.
> Below are my configuration files.
>
> struts.xml :=
>
> <?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>
> 	<constant name="struts.objectFactory" value="spring" />
>      <constant name="struts.devMode" value="false" />
> 	<constant name="struts.action.extension" value="do"/>
> 	<constant name="struts.objectFactory.spring.autoWire"
> value="AUTOWIRE_BY_NAME"/>
>
>      <!-- Add packages here -->
>      <package name="dafault" extends="struts-default">
>      	
> 		<result-types>
> 			<result-type name="tiles"
> class="org.apache.struts2.views.tiles.TilesResult" />
> 		</result-types>
>     		
>     		<interceptors>
>              <interceptor name="loginInterceptor"
> class="com.ncr.framework.interceptor.LoginInterceptor"/>
>
>              <interceptor-stack name="capabilityStack">
> 	        	<interceptor-ref name="defaultStack"/>
> 	        	<interceptor-ref name="loginInterceptor"/>
> 	</interceptor-stack>
> 	
>          </interceptors>
>
>          <default-interceptor-ref name="capabilityStack"/>
> 				
> 		<action name="logon" class="loginAction" method="execute">
>              <result name="success" type="tiles">page.Login</result>
> 		</action>
> </package>
> </struts>
>
> applicationContext.xml :-
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE beans SYSTEM "WEB-INF/spring-beans-2.0.dtd">
> <beans>
> 		<bean id="loginAction" scope="prototype"
> class="com.ncr.user.actions.LoginAction">
> 		<constructor-arg ref="adminService" />
> 	</bean>
> </beans>
>
> LoginInterceptor.java
>
> public class LoginInterceptor extends AbstractInterceptor {
> public String intercept(ActionInvocation invocation) throws Exception {
> 		ActionContext context = invocation.getInvocationContext();
> 		Map<String, Object>  contextMap = context.getContextMap();
> 		HttpServletRequestWrapper request = (HttpServletRequestWrapper) contextMap
> 				.get(HTTP_REQUEST);
> 		synchronized (request) {
> 			ThreadContext.setRequest(request);
> 			UserInfo userInfo = UserContext.getCurrentUserInfo();
>
> 			if (userInfo == null
> 					&&  !"authenticate".equals(contextMap.get(ACTION_NAME))) {
> 				return "logon";
> 			}
> 			return invocation.invoke();
> 		}
> 	}}
>
> When I hit url http://localhost:8080/mytest/logon.do it throws an error.
>
> java.lang.RuntimeException: Invalid action class configuration that
> references an unknown class named [loginAction]
>
> org.apache.struts2.convention.ConventionsServiceImpl.determineResultPath(ConventionsServiceImpl.java:100)
>
> org.apache.struts2.convention.ConventionUnknownHandler.determinePath(ConventionUnknownHandler.java:385)
>
> org.apache.struts2.convention.ConventionUnknownHandler.handleUnknownResult(ConventionUnknownHandler.java:274)
>
> com.opensymphony.xwork2.DefaultUnknownHandlerManager.handleUnknownResult(DefaultUnknownHandlerManager.java:76)
>
> com.opensymphony.xwork2.DefaultActionInvocation.createResult(DefaultActionInvocation.java:215)
>
> com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:356)
>
> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:266)
>
> com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
>
>
> As per my investigation, I found that ClassLoaderUtils's below method could
> not return class name for 'loginAction'. There should be some way for to map
> 'loginAction' to the class com.ncr.user.actions.LoginAction.
>
> public static Class loadClass(String className, Class callingClass)
> 			throws ClassNotFoundException {
> 		try {
> 			
> 			return Thread.currentThread().getContextClassLoader().loadClass(
> 					className);
> 		} catch (ClassNotFoundException e) {
> 			try {
> 				return Class.forName(className);
> 			} catch (ClassNotFoundException ex) {
> 				try {
> 					return ClassLoaderUtils.class.getClassLoader().loadClass(
> 							className);
> 				} catch (ClassNotFoundException exc) {
> 					return callingClass.getClassLoader().loadClass(className);
> 				}
> 			}
> 		}
> 	}
>
> When I remove the entry '<default-interceptor-ref name="capabilityStack"/>'
> from struts.xml then it's working perfectly fine i.e desired page is coming.
>
> I also noticed that in the classes variable of
> Thread.currentThread().getContextClassLoader()(WebappClassLoader) which is
> private contains class com.ncr.user.actions.LoginAction but i did not find
> any way to get it.
>
> Your kind guesture is appreciated.
>
> -Dev
>    
Convention plugin provide annotation configration for struts2 instead of 
the XML configuration.
But it is optional, if you do not use it, there is no need add it to 
your project. From you provided, I do not know the content of LoginAction.




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message