We migrating our old Struts 1 Application to Struts 2 using the struts1-plugin to wrap our actions.
This worked great with some actions but others throw the error shown below:
java.lang.InstantiationException
sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
java.lang.reflect.Constructor.newInstance(Constructor.java:526)
java.lang.Class.newInstance(Class.java:374)
com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:158)
com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:189)
com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:178)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.resolveModel(ScopedModelDrivenInterceptor.java:106)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:136)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:564)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
de.dak.intranet.webtier.extranet.StartPageFilter.doFilter(StartPageFilter.java:74)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
de.dak.intranet.webtier.auth.LoginFilter.doFilter(LoginFilter.java:288)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
The configuration for this action very straightforward:
<package name="extranet" extends="struts1-default" namespace="/extranet">
<action name="acceptConditions" class="org.apache.struts2.s1.Struts1Action>
<param name="className">de.intranet.webtier.extranet.AcceptConditionsAction</param>
<interceptor-ref name="struts1Stack"/>
<result name="success">/servlet/index.jsp</result>
</action>
</package>
I tried removing the interceptors in the action but that did not change anything.
The action class looks like this (actual logic was omitted):
public class AcceptConditionsAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
return mapping.findForward("success");
}
}
The link in our jsp template is build correctly with the s:action-tag and another action on the same site works perfectly when the link is clicked. This action however generates the stacktrace shown above and I cannot figure out where it is coming from or how to fix it. The breakpoint inside the action is never reached therefore the error has to occur while instantiating the action itself.
I hope somebody can help me figure out what is happening.
EDIT:
Working action for clarification:
<package name="extranet" extends="struts1-default" namespace="/extranet">
<interceptors>
<interceptor name="pwdForm" class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor>
<param name="className">de.intranet.webtier.extranet.PasswordForm</param>
<param name="name">pwdForm</param>
</interceptor>
</interceptors>
<action name="editPassword" class="org.apache.struts2.s1.Struts1Action">
<param name="className">de.intranet.webtier.extranet.EditPasswordAction</param>
<interceptor-ref name="pwdForm"/>
<interceptor-ref name="struts1Stack"/>
<result name="changePassword">/extranet/changePassword.jsp</result>
</action>
</package>
Java implementation looks like the AcceptConditionsAction. Only the execute-method was overwritten and no constructor defined.
Aleksandr pointed me to the answer:
The interceptor stack provided by the struts1-plugin (called struts1Stack) creates several interceptors that require a Form (i.e. scopedModelDriven, modelDriven and some others). If you don't use the entire stack and only add the interceptors needed by the action, it is not necessary anymore to define a FormBean.
remove interceptor-ref "strutsStack", add "staticParams" will do the trick.
as shown in below
<package name="extranet" extends="struts1-default" namespace="/extranet">
<action name="acceptConditions" class="org.apache.struts2.s1.Struts1Action>
<param name="className">de.intranet.webtier.extranet.AcceptConditionsAction</param>
<!--interceptor-ref name="struts1Stack"/-->
<interceptor-ref name="staticParams"/>
<result name="success">/servlet/index.jsp</result>
</action>
</package>
Related
This question already has an answer here:
Prevent same action called twice as long as user is in current session
(1 answer)
Closed 5 years ago.
I'm trying to avoid double-submit problems using tokenSession. My action methods are working fine without tokenSession technique.
I add <s:token/> in upsert_crypto_sources.jsp and tokenSession interceptor in struts.xml but I receive request as null in my action excludedMethod of list().
The list page doesn't need to avoid double submit problem but if I add <s:token/> in view_crypto_sources_list.jsp and remove list() from excludedMethod then I always receive result invalid.token.
My struts.xml is like:
<struts>
<package name="key-manager" namespace="/shared/km" extends="console-default" strict-method-invocation="true">
<action name="manage_cs_*" method="{1}" class="console.shared.km.ASC_ManageCryptoProfilesAction">
<interceptor-ref name="tokenSession">
<param name="excludeMethods">
list, initInsert, load, delete
</param>
</interceptor-ref>
<result name="list">/shared/km/view_crypto_sources_list.jsp</result>
<result name="insert">/shared/km/upsert_crypto_sources.jsp</result>
<result name="update">/shared/km/upsert_crypto_sources.jsp</result>
<result name="load">/shared/km/upsert_crypto_sources.jsp</result>
<allowed-methods>list, insert, load, update, delete, testConnection, forward, cancel</allowed-methods>
</action>
My action implements ServletRequestAware interface therefore it gets the request member variable set using setServletRequest() method.
I added a defaultStack interceptor and it is working fine:
<struts>
<package name="key-manager" namespace="/shared/km" extends="console-default" strict-method-invocation="true">
<action name="manage_cs_*" method="{1}" class="console.shared.km.ASC_ManageCryptoProfilesAction">
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="tokenSession">
<param name="excludeMethods">
list, initInsert, load, delete
</param>
</interceptor-ref>
<result name="list">/shared/km/view_crypto_sources_list.jsp</result>
<result name="insert">/shared/km/upsert_crypto_sources.jsp</result>
<result name="update">/shared/km/upsert_crypto_sources.jsp</result>
<result name="load">/shared/km/upsert_crypto_sources.jsp</result>
<allowed-methods>list, insert, load, update, delete, testConnection, forward, cancel</allowed-methods>
</action>
I'm using the below code for get the output in xls.
else if ("xls".equalsIgnoreCase(reporttype)) {
try
{
System.out.println("inside xls1");
response.setContentType("application/vnd.ms-excel");
System.out.println("inside xls2");
response.setHeader("Content-Disposition", "inline; filename=\""
+ strId + ".xls\"");
System.out.println("inside xls3");
exporter = new JRXlsExporter();
System.out.println("inside xls4");
exporter.setParameter(JRExporterParameter.JASPER_PRINT,
jasperPrint);
System.out.println("inside xls5");
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,
ouputStream);
System.out.println("inside xls6");
System.out.println("inside exporter for XLS: "+exporter);
}
catch(Exception e)
{
System.out.println("inside xls catch");
e.printStackTrace();
}
}
But it's occurred below error.
Struts Problem Report Struts has detected an unhandled
exception: Messages: No result defined for action
com.coin.fk.SalesAction and result Exception
File: file:/D:/blm/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/blm/WEB-INF/classes/struts.transaction.xml
Line number: 44 Column number: 77
<action name="salesAction_*" method="{1}" class="com.coin.fk.SalesAction">
<interceptor-ref name="defaultLoginStack"/>
<interceptor-ref name="defaultStack">
Stacktraces
No result defined for action com.coin.fk.SalesAction and result Exception - action - file:/D:/blm/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/blm/WEB-INF/classes/struts.transaction.xml:44:77
com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:350)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Unknown Source)
You are seeing this page because development mode is enabled. Development mode, or devMode, enables extra debugging behaviors and reports to assist developers. To disable this mode, set:
struts.devMode=false
in your WEB-INF/classes/struts.properties file.
How can I face this issue.
Pls help how to debug this error.
It does seems you are trying to configure Global Exceptions without having a Global Result name Exception.
Something like this:
<global-results>
<result name="exception">jsp/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception"
result="exception" />
</global-exception-mappings>
in this specific order.
It seems that you have two Interceptors Stack too, one with your custom Interceptor, and the Default Stack. You should use only one stack, with all the Interceptors you need, to avoid executing them two times on each request:
<action name="salesAction_*" method="{1}" class="com.coin.fk.SalesAction">
<interceptor-ref name="defaultLoginStack"/>
<interceptor-ref name="defaultStack">
<!--result ecc...-->
</action>
should become
<action name="salesAction_*" method="{1}" class="com.coin.fk.SalesAction">
<interceptor-ref name="defaultLoginStack"/>
<!--result ecc...-->
</action>
I'm using the struts2 tiles plugin (v2.2.3) and I'm having a problem using the I18nInterceptor with the ExecuteAndWaitInterceptor. Essentially when I add the execAndWait interceptor (see xml below) for some reason the localization no longer works and when I try to get localized text (e.g. TextProviderSupport.hasKey) I get a NullPointerException (see error) that I narrowed down to this code in LocalizedTextUtil...
public static String findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args) {
ValueStack valueStack = ActionContext.getContext().getValueStack();
return findText(aClass, aTextName, locale, defaultMessage, args, valueStack);
}
... I'm assuming the getValueStack() is null for some reason, but I cannot figure out why. Any ideas?
Thanks,
Ryan
<pre><code>
java.lang.NullPointerException
at com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:359)
at com.opensymphony.xwork2.TextProviderSupport.hasKey(TextProviderSupport.java:98)
at com.opensymphony.xwork2.ActionSupport.hasKey(ActionSupport.java:96)
at com.test.plus.PlusSupport.getCurrentLocale(PlusSupport.java:213)
at com.test.plus.import.Test.action.TestAction.testMethod(TestAction.java:801)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)
at org.apache.struts2.interceptor.BackgroundProcess$1.run(BackgroundProcess.java:57)
at java.lang.Thread.run(Unknown Source)
</code></pre>
Struts.xml
<action name="Test/m/testMethod" method="testMethod" class="com.test.plus.import.Test.action.TestAction">
<result type="tiles">/WEB-INF/jsp/import/Test/testMethod.jsp</result>
<result name="success" type="tiles">/WEB-INF/jsp/import/Test/testMethod.jsp</result>
<result name="input" type="tiles">/WEB-INF/jsp/import/Test/testMethod.jsp</result>
<result name="error" type="tiles">/WEB-INF/jsp/import/Test/testMethod.jsp</result>
<result name="wait" type="tiles">/WEB-INF/jsp/import/execAndWait.jsp</result>
<interceptor-ref name="plusStack"/>
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="execAndWait">
<param name="excludeMethods">input,back,cancel</param>
</interceptor-ref>
</action>
From http://struts.apache.org/2.x/docs/execute-and-wait-interceptor.html
Important: Because the action will be running in a seperate thread, you can't use ActionContext because it is a ThreadLocal. This means if you need to access, for example, session data, you need to implement SessionAware rather than calling ActionContext.getSession().
I am having the opposite problem of the fellow in this question:
Struts 2: excluding method from validation from just the defaultStack interceptor
The above question involved all methods being excluded, my issue is that no methods are being excluded!
I'm trying to get my authenticationInterceptor to ignore the showLogin method of my LoginAction:
<interceptors>
<interceptor name="authorizationInterceptor" class="org.companyname.struts.interceptor.AuthorizationInterceptor"/>
<interceptor-stack name="appDefault">
<interceptor-ref name="authorizationInterceptor"/>
<interceptor-ref name="defaultStack">
<param name="exception.logEnabled">true</param>
<param name="exception.logLevel">ERROR</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="appDefault" />
<action name="loginInitial" class="org.companyname.struts.action.LoginAction" method="showLogin">
<interceptor-ref name="appDefault">
<param name="authorizationInterceptor.excludeMethods">showLogin</param>
</interceptor-ref>
<result name="success">/login.jsp</result>
</action>
However, each time I forward to loginInitial, the interceptor grabs it, even though my showLogin method is being excluded.
I've checked for naming issues, and have tried putting several different values in the interceptor-ref within the action, and nothing seems to work.
What's the proper way to skip the authorizationInterceptor when I forward to loginIntial?
I believe my issue is the type of interceptor I'm using, the AbstractInterceptor. So, I just use different interceptor stacks on the actions I don't want intercepted:
<interceptor-stack name="appDefaultWithAuth">
<interceptor-ref name="defaultStack">
<param name="exception.logEnabled">true</param>
<param name="exception.logLevel">ERROR</param>
</interceptor-ref>
<interceptor-ref name="authorizationInterceptor"/>
</interceptor-stack>
<interceptor-stack name="appDefaultNoAuth">
<interceptor-ref name="defaultStack">
<param name="exception.logEnabled">true</param>
<param name="exception.logLevel">ERROR</param>
</interceptor-ref>
</interceptor-stack>
<default-interceptor-ref name="appDefaultWithAuth" />
<action name="loginInitial" class="org.company.struts.action.LoginAction" method="showLogin">
<interceptor-ref name="appDefaultNoAuth"/>
<result name="success">/login.jsp</result>
</action>
Hi
We have created a customized interceptor stack called appInterceptorStack and referred it as a <default-interceptor-ref name="appInterceptorStack"/>,
appInterceptorStack -> dont have validation and workflow interceptors attached to them.
But now for a specific action class I need to use validate method so I need validation interceptor
I created a new Interceptor stack with validation and workflow interceptors and referred it from action class. But only the default interceptor stack is getting executed. The changed one is not getting called, Please find the sample code below.
<package name="default" extends="struts-default">
<interceptor-stack name=”AppStack”>
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="params"/>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="params"/>
</interceptor-stack>
<interceptor-stack name=”GuiStack”>
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="params"/>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="params"/>
<interceptor-ref name="validation" />
<interceptor-ref name="workflow" />
</interceptor-stack>
<default-interceptor-ref name="AppStack"/>
<action name="test" class="com.jranch.Test">
<interceptor-ref name="GuiStack”/>
<result name="input">login.jsp</result>
<result name="success" type="redirect-action">/secure/home</result>
</action>
</package>
Can someone please help me?
The configuration looks correct. Can you turn on debug logging for com.opensymphony.
You can then see the interceptors being called in turn. This is the quickest way of seeing what is being called.