Hi Team,
Is any help for the above issue Thanks Krishna raj On Thu, Jun 12, 2014 at 9:05 PM, Krishnaraj A < akrajmscjavaquest...@gmail.com> wrote: > Hi Dave, > > I added my struts code. > > Junit Code: > > public class AdminValidation extends StrutsTestCase { > > @Test > public void testUserNameErrorMessage() throws Exception { > > HttpSession session = request.getSession(); > UserVO uservo1 =new UserVO(); > uservo1.setUserMailId("akrajmscjavaquest...@gmail.com"); > uservo1.setReturnedStatus("admin"); > uservo1.setAccessLevel("1293"); > uservo1.setIntranetId("Krishnaraj"); > uservo1.setSuperAdmin(true); > uservo1.setShowRegContact(false); > session.setAttribute("user", uservo1); > ActionProxy proxy = getActionProxy("/MainAdminPage.action"); > ActionContext context > =proxy.getInvocation().getInvocationContext(); > Map<String,Object> session = new HashMap<String,Object>(); > session.put("user", uservo1); > context.setSession(session); > String result = proxy.execute(); > assertEquals("Result returned form executing the action was not > success but it should have been.", "success", result); > } > } > > Struts.xml code: > > <interceptors> > <interceptor name="printMsgInterceptor" > class="com.interceptor.UserValidation"></interceptor> > <interceptor name="sessionClearInterceptor" > class="com.interceptor.SessionClearInterceptor"></interceptor> > <interceptor-stack name="newStack"> > <interceptor-ref name="printMsgInterceptor" /> > <interceptor-ref name="sessionClearInterceptor" /> > <interceptor-ref name="defaultStack" /> > </interceptor-stack> > </interceptors> > > > <action name="MainAdminPage" class="com.action.MainAdminAction"> > <interceptor-ref name="newStack" /> > <result>/MainAdmin.jsp</result> > <result name="Login_page">/Login.jsp</result> > </action> > > UserValidation.java code: > > public class UserValidation extends AbstractInterceptor implements > StrutsStatics { > > > private static final long serialVersionUID = 1L; > > public void init() { > > } > > public void destroy() { > } > > public String intercept(ActionInvocation invocation) throws Exception { > > final ActionContext context = invocation.getInvocationContext(); > String str =invocation.getAction().getClass().getSimpleName(); > Map<String,Object> session =context.getSession() ; > HttpServletRequest request=(HttpServletRequest) > context.get(HTTP_REQUEST); > HttpServletResponse response=(HttpServletResponse) > context.get(HTTP_RESPONSE); > String str1 =request.getRequestedSessionId(); > > request.setCharacterEncoding("UTF-8"); > final UserVO uservo =(UserVO) session.get("user"); > String userMailId; > if(uservo !=null){ > String mailID=uservo.getUserMailId(); > if(mailID != null){ > System.out.println("Success"); > } > } > > else { > return "login"; > > } > response.setHeader("Pragma","no-cache"); > response.setHeader("Cache-Control","no-store"); > response.setHeader("Expires","0"); > response.setDateHeader("Expires",-1); > response.setCharacterEncoding("UTF-8"); > return invocation.invoke(); > > } > } > > I debug the application by placing the break point. When the control go to > " return invocation.invoke();" it throws error. > > java.lang. > IllegalStateException: Action has already executed > > > Thanks, > Krishnaraj > > > > > On Thu, Jun 12, 2014 at 8:45 PM, Dave Newton <davelnew...@gmail.com> > wrote: > >> Without knowing what's in your interceptor stack it's impossible to help. >> >> Dave >> >> >> On Thu, Jun 12, 2014 at 11:11 AM, Krishnaraj A < >> akrajmscjavaquest...@gmail.com> wrote: >> >> > Hi Team, >> > >> > Iam new to using Struts2 unit testing. Iam using the Struts 2 JUnit >> plugin >> > <http://struts.apache.org/2.3.1.2/docs/junit-plugin.html>. The normal >> > actions which is working fine. But I have issue when I am testing the >> > action which has interceptor. >> > >> > <action name="MainAdminPage" class="com.action.MainAdminAction"> >> > <interceptor-ref name="newStack" /> >> > <result>/MainAdmin.jsp</result> >> > <result name="Login_page">/Login.jsp</result> >> > </action> >> > >> > When I start testing the control goes to interceptor and check all the >> > validation. >> > when it invoke "return invocation.invoke();". it throws error. >> > java.lang.IllegalStateException: Action has already executed >> > >> > I am not able to get the solution for the above problem. Can any one >> help >> > me in this problem to find the solution. Thanks in advance. >> > >> > Thanks, >> > Krishna raj >> > >> >> >> >> -- >> e: davelnew...@gmail.com >> m: 908-380-8699 >> s: davelnewton_skype >> t: @dave_newton <https://twitter.com/dave_newton> >> b: Bucky Bits <http://buckybits.blogspot.com/> >> g: davelnewton <https://github.com/davelnewton> >> so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton> >> > >