Return-Path: Delivered-To: apmail-struts-user-archive@www.apache.org Received: (qmail 23486 invoked from network); 12 Feb 2008 13:29:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 12 Feb 2008 13:29:03 -0000 Received: (qmail 3117 invoked by uid 500); 12 Feb 2008 13:28:46 -0000 Delivered-To: apmail-struts-user-archive@struts.apache.org Received: (qmail 3094 invoked by uid 500); 12 Feb 2008 13:28:46 -0000 Mailing-List: contact user-help@struts.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Struts Users Mailing List" Reply-To: "Struts Users Mailing List" Delivered-To: mailing list user@struts.apache.org Received: (qmail 3083 invoked by uid 99); 12 Feb 2008 13:28:46 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Feb 2008 05:28:46 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of fdmanana@gmail.com designates 72.14.204.228 as permitted sender) Received: from [72.14.204.228] (HELO qb-out-0506.google.com) (72.14.204.228) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Feb 2008 13:28:15 +0000 Received: by qb-out-0506.google.com with SMTP id e11so8474651qbe.15 for ; Tue, 12 Feb 2008 05:28:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:reply-to:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; bh=Ugo2FZnDVyPZkOv9Pzf4Lr5aJsIaQ2ffTOLp1v2PpS8=; b=gsP/aL7bDNAp0CEdEB/UcLd/ex9LDmAOl0lTj4sMRpESIo4HhDSVLSYWEqIQFzcc9N6BUj6CduWYJ8QCNiSG7bpHuQthymCWPPC0H5LLa4gMZ9Ua5m8eLL5NSP5CVAQjI4P0qnWozfmiQi+Mt508F6wxuVvR6neQHsyrmtrE+yQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:reply-to:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=iR9YAYHC08ykv9gFmDcXsAQTp6ARm4oZVLwP3eL4ritMEDHyRwmXZCCL6cjUffJxE8qeJKeOjLFCLGtCYxmhGdOA3Hnrl9W3lgvFTWtfjQYpIWZ9laG06FUhX8PFiUf72bepDgb6cF4WdN79z0bAOWjdRq0NTiBXWhAXSjpAbc8= Received: by 10.64.196.9 with SMTP id t9mr813504qbf.78.1202822902229; Tue, 12 Feb 2008 05:28:22 -0800 (PST) Received: by 10.65.196.8 with HTTP; Tue, 12 Feb 2008 05:28:22 -0800 (PST) Message-ID: Date: Tue, 12 Feb 2008 14:28:22 +0100 From: "Filipe David Manana" Reply-To: fdmanana@ieee.org Sender: fdmanana@gmail.com To: "Dave Newton" Subject: Re: Struts2 action returning dynamically created Results Cc: "Struts Users Mailing List" In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <440671.23137.qm@web56705.mail.re3.yahoo.com> X-Google-Sender-Auth: ced6c0f40a8e1cc5 X-Virus-Checked: Checked by ClamAV on apache.org Nevermind. I managed to find a working solution without creating dymamic Result objects. So in the interceptor code: public String intercept(ActionInvocation invocation) throws Exception { ActionContext context = invocation.getInvocationContext(); Map session = context.getSession(); String action = invocation.getProxy().getActionName(); String namespace = invocation.getProxy().getNamespace(); if ( ( action.equals("login") || action.equals("doLogin") ) && namespace.equals("/") ) return invocation.invoke(); Object user = session.get("user"); if ( user == null ) { if ( session.get("_prev_uri_") == null ) { HttpServletRequest request = (HttpServletRequest) context .get(HTTP_REQUEST); StringBuffer uri = new StringBuffer(namespace); uri.append('/'); uri.append(action); uri.append(ACTION_EXT); // .action, read dynamically from struts.properties in the init() method if ( request.getQueryString() != null ) { uri.append('?'); uri.append(request.getQueryString()); } session.put("_prev_uri_", uri.toString()); } return "login"; } return invocation.invoke(); } In the doLogin action: public String doLogin() throws Exception { boolean validUser = false; // validate the user // etc... if ( !validUser ) { addActionError("Authentication failed. Invalid username/password provided."); return INPUT; } // valid user session.put("user", userName); redirectUri = (String) session.get("_prev_uri_"); session.remove("_prev_uri_"); if ( redirectUri == null ) return "gotohome"; return SUCCESS; } And in struts.xml: /jsp/login.jsp true ${redirectUri} home /home It was not working before, but now I changed the order of interceptors in my interceptor stack and is working :) If anyone interested in more details, let me know. Thanks anyway. On Feb 12, 2008 2:04 PM, Filipe David Manana wrote: > Yes I need. Because in the S2 configuration file I have to specify all > the parameters of the query string one by one. > In my app, I don't know the name and number of these parameters. So I > am building a Servlet Redirect Action Result in an interceptor like > this: > > public String intercept(ActionInvocation invocation) throws Exception > { > ActionContext context = invocation.getInvocationContext(); > Map session = context.getSession(); > String action = invocation.getProxy().getActionName(); > String namespace = invocation.getProxy().getNamespace(); > > if ( ( action.equals("login") || action.equals("doLogin") ) > && namespace.equals("/") ) > return invocation.invoke(); > > Object user = session.get("user"); > > if ( user == null ) > { > if ( session.get("_prev_uri_") == null ) > { > String method = invocation.getProxy().getMethod(); > ServletActionRedirectResult result = new > ServletActionRedirectResult(namespace, action, method); > > Map params = context.getParameters(); > Iterator it = params.entrySet().iterator(); > Map.Entry entry = null; > > while ( it.hasNext() ) > { > entry = (Map.Entry) it.next(); > result.addParameter((String) entry.getKey(), entry.getValue()); > } > > session.put("_prev_uri_", result); > } > // etc... > > I tried using a "redirect" type result in the xml config, and > appending the query string to the url, but struts2 ignores it. The > query string was obtained with the HttpServletRequest class. (I was > logging it and it was correct). > > Any suggestion? > > > On Feb 12, 2008 1:54 PM, Dave Newton wrote: > > Are you sure you need to do it like this? You can use OGNL expressions in > > your S2 configuration file to do things like set a URL to redirect to etc. > > > > Dave > > > > > > --- Filipe David Manana wrote: > > > > > Hi, > > > > > > I am trying to use an action that returns directly instances of the > > > Result class, due to the nature of my application where the result is > > > dynamically decided by some logic. > > > > > > My action class method is: > > > > > > public Result doLogin() throws Exception > > > { > > > // etc... > > > if ( !validUser ) > > > { > > > addActionError("Authentication failed. Invalid > > > username/password provided."); > > > return new ServletDispatcherResult("/jsp/login.jsp"); > > > } > > > > > > // valid user > > > session.put("user", userName); > > > > > > ServletActionRedirectResult result = > > > (ServletActionRedirectResult) session.get("_prev_uri_"); > > > > > > if ( result == null ) > > > { > > > result = new ServletActionRedirectResult("/home", "home", > > > "execute"); > > > } > > > > > > return result; > > > } > > > > > > My struts.xml: > > > > > > > > > > > > > > > After executing the action's method I always get a > > > NullPointerException from ServletActionRedirectResult :S > > > > > > exception > > > > > > javax.servlet.ServletException: java.lang.NullPointerException > > > > > > org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515) > > > > > > > > org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419) > > > > > > > > org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:99) > > > > > > root cause > > > > > > java.lang.NullPointerException > > > > > > > > org.apache.struts2.dispatcher.ServletActionRedirectResult.execute(ServletActionRedirectResult.java:184) > > > > > > > > com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:348) > > > > > > > > com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253) > > > > > > > > actions.CaptureLastURIRequestedInterceptor.intercept(CaptureLastURIRequestedInterceptor.java:48) > > > > > > > > com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224) > > > > > > > > com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223) > > > > > > > > com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) > > > > > > > > com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221) > > > > > > > > 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.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:99) > > > > > > Am I missing something? > > > > > > cheers > > > > > > -- > > > Filipe David Manana, > > > fdmanana@ieee.org > > > > > > Obvious facts are like secrets to those not trained to see them. > > > > > > --------------------------------------------------------------------- > > > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org > > > For additional commands, e-mail: user-help@struts.apache.org > > > > > > > > > > > > > > -- > Filipe David Manana, > fdmanana@ieee.org > > Obvious facts are like secrets to those not trained to see them. > -- Filipe David Manana, fdmanana@ieee.org Obvious facts are like secrets to those not trained to see them. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@struts.apache.org For additional commands, e-mail: user-help@struts.apache.org