Re: Help Struts2 + interceptor
Hi all, You can try this way: http://poulwiel.blogspot.com/2009/01/intercepting-all-actions-inside-my-app.html Best greetings, Paweł Wielgus. 2010/7/13 Fabio Alves de Araujo Ebner - DnaSolution fabio.eb...@dnasolution.com.br: The problem is: When he pass through interceptor and go to action cadastrarOrdemServico my var cdProjetoOS are set with null :( thanks, follow my all code: CLASS LoginClienteInterceptor .java --- package br.com.dnasolution.site.interceptor; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.Interceptor; public class LoginClienteInterceptor implements Interceptor { @Override public void destroy() { } @Override public void init() { } @Override public String intercept(ActionInvocation invocation) throws Exception { if(invocation.getInvocationContext().getSession().get(clienteLogado) != null){ return invocation.invoke(); }else{ return clienteNaoLogado; } } } Class LoginUsuarioInterceptor package br.com.dnasolution.site.interceptor; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.Interceptor; public class LoginUsuarioInterceptor implements Interceptor { @Override public void destroy() {} @Override public void init() { } @Override public String intercept(ActionInvocation invocation) throws Exception { if(invocation.getInvocationContext().getSession().get(usuarioLogado) != null){ return invocation.invoke(); }else{ return usuarioNaoLogado; } } } My STruts.xml !DOCTYPE struts PUBLIC -//Apache Software Foundation//DTD Struts Configuration 2.0//EN http://struts.apache.org/dtds/struts-2.0.dtd;struts package name=my-secure extends=convention-default interceptors interceptor name=loginUsuarioInterceptor class=br.com.dnasolution.site.interceptor.LoginUsuarioInterceptor /interceptor interceptor name=loginClienteInterceptor class=br.com.dnasolution.site.interceptor.LoginClienteInterceptor /interceptor interceptor-stack name=secureStack interceptor-ref name=defaultStack/ interceptor-ref name=loginClienteInterceptor/ interceptor-ref name=loginUsuarioInterceptor/ /interceptor-stack /interceptors default-interceptor-ref name=secureStack/ global-results result name=clienteNaoLogado/jsp/usuario/loginUsuario.jsp /result result name=clienteNaoLogado/jsp/cliente/loginCliente.jsp /result /global-results /package /struts My OrdemServicoAction.java package br.com.dnasolution.site.action; import java.util.Date; import java.util.List; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.InterceptorRef; import org.apache.struts2.convention.annotation.ParentPackage; import org.apache.struts2.convention.annotation.Result; import com.opensymphony.xwork2.ActionContext; @ParentPackage(my-secure) public class OrdemServicoAction { @Action(value = cadastrarOrdemServico, results = { �...@result(name = valido, location = /jsp/ordemservico/cadastro_sucesso.jsp), �...@result(name = invalido, location = /jsp/ordemservico/cadastro_falha.jsp) }, interceptorRefs = { @InterceptorRef(loginClienteInterceptor) }) public String cadastrarOrdemServico() { try { TbProjeto projetoOS = projetoService .getProjetoById(this.cdProjetoOS); TbTopicoOs topicoOs = topicoOsService.getTopicoById(cdTopicoOS); } - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Help Struts2 + interceptor
I'm fairly new to this myself so maybe someone else can jump in. First things first, put a print statement in the intercept methods of your interceptors so you at least know if the interceptor is even getting called. Secondly, I didn't ever use a line like this:interceptorRefs = { @InterceptorRef(loginClienteInterceptor) }) . Other than that, I'm not sure what else to do. Fabio Alves de Araujo Ebner - DnaSolution wrote: Hey man, this is my structure MY ACTION package br.com.dnasolution.site.action; /** import **// @ParentPackage(my-secure) public class OrdemServicoAction { @Action(value = cadastrarOrdemServico, results = {...@result(name = valido, location = /jsp/ordemservico/cadastro_sucesso.jsp), @Result(name = invalido, location = /jsp/ordemservico/cadastro_falha.jsp) }, interceptorRefs = { @InterceptorRef(loginClienteInterceptor) }) public String cadastrarOrdemServico() { /* code */ } MY INTERCEPTOR package br.com.dnasolution.site.interceptor; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.Interceptor; public class LoginClienteInterceptor implements Interceptor { @Override public void destroy() { // TODO Auto-generated method stub } @Override public void init() { // TODO Auto-generated method stub } @Override public String intercept(ActionInvocation invocation) throws Exception { if(invocation.getInvocationContext().getSession().get(clienteLogado) != null){ return invocation.invoke(); }else{ return clienteNaoLogado; } } } AND MY STRUTS.XML !DOCTYPE struts PUBLIC -//Apache Software Foundation//DTD Struts Configuration 2.0//EN http://struts.apache.org/dtds/struts-2.0.dtd;struts package name=my-secure extends=struts-default interceptors interceptor name=loginUsuarioInterceptor class=br.com.dnasolution.site.interceptor.LoginUsuarioInterceptor /interceptor interceptor name=loginClienteInterceptor class=br.com.dnasolution.site.interceptor.LoginClienteInterceptor /interceptor interceptor-stack name=secureStack interceptor-ref name=loginUsuarioInterceptor/ interceptor-ref name=loginClienteInterceptor/ interceptor-ref name=defaultStack/ /interceptor-stack /interceptors default-interceptor-ref name=secureStack/ global-results result name=clienteNaoLogado/jsp/usuario/loginUsuario.jsp /result result name=clienteNaoLogado/jsp/cliente/loginCliente.jsp /result /global-results /package /struts and still dosen't work :( - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Help Struts2 + interceptor
The problem is: When he pass through interceptor and go to action cadastrarOrdemServico my var cdProjetoOS are set with null :( thanks, follow my all code: CLASS LoginClienteInterceptor .java --- package br.com.dnasolution.site.interceptor; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.Interceptor; public class LoginClienteInterceptor implements Interceptor { @Override public void destroy() { } @Override public void init() { } @Override public String intercept(ActionInvocation invocation) throws Exception { if(invocation.getInvocationContext().getSession().get(clienteLogado) != null){ return invocation.invoke(); }else{ return clienteNaoLogado; } } } Class LoginUsuarioInterceptor package br.com.dnasolution.site.interceptor; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.Interceptor; public class LoginUsuarioInterceptor implements Interceptor { @Override public void destroy() {} @Override public void init() { } @Override public String intercept(ActionInvocation invocation) throws Exception { if(invocation.getInvocationContext().getSession().get(usuarioLogado) != null){ return invocation.invoke(); }else{ return usuarioNaoLogado; } } } My STruts.xml !DOCTYPE struts PUBLIC -//Apache Software Foundation//DTD Struts Configuration 2.0//EN http://struts.apache.org/dtds/struts-2.0.dtd;struts package name=my-secure extends=convention-default interceptors interceptor name=loginUsuarioInterceptor class=br.com.dnasolution.site.interceptor.LoginUsuarioInterceptor /interceptor interceptor name=loginClienteInterceptor class=br.com.dnasolution.site.interceptor.LoginClienteInterceptor /interceptor interceptor-stack name=secureStack interceptor-ref name=defaultStack/ interceptor-ref name=loginClienteInterceptor/ interceptor-ref name=loginUsuarioInterceptor/ /interceptor-stack /interceptors default-interceptor-ref name=secureStack/ global-results result name=clienteNaoLogado/jsp/usuario/loginUsuario.jsp /result result name=clienteNaoLogado/jsp/cliente/loginCliente.jsp /result /global-results /package /struts My OrdemServicoAction.java package br.com.dnasolution.site.action; import java.util.Date; import java.util.List; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.InterceptorRef; import org.apache.struts2.convention.annotation.ParentPackage; import org.apache.struts2.convention.annotation.Result; import com.opensymphony.xwork2.ActionContext; @ParentPackage(my-secure) public class OrdemServicoAction { @Action(value = cadastrarOrdemServico, results = { @Result(name = valido, location = /jsp/ordemservico/cadastro_sucesso.jsp), @Result(name = invalido, location = /jsp/ordemservico/cadastro_falha.jsp) }, interceptorRefs = { @InterceptorRef(loginClienteInterceptor) }) public String cadastrarOrdemServico() { try { TbProjeto projetoOS = projetoService .getProjetoById(this.cdProjetoOS); TbTopicoOs topicoOs = topicoOsService.getTopicoById(cdTopicoOS); } - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Help Struts2 + interceptor
Hi, i need help to use interceptor, i create one to test if the user are logged in my application until he execute one Action, but when the server pass throw interceptor and back to action, all my var are null, this is my struts.xml !DOCTYPE struts PUBLIC -//Apache Software Foundation//DTD Struts Configuration 2.0//EN http://struts.apache.org/dtds/struts-2.0.dtd;struts package name=loginClienteAndUsuario extends=struts-default interceptors interceptor name=loginUsuario class=br.com.dnasolution.site.interceptor.LoginUsuarioInterceptor /interceptor interceptor name=loginCliente class=br.com.dnasolution.site.interceptor.LoginClienteInterceptor /interceptor interceptor-stack name=myStack interceptor-ref name=loginCliente/ interceptor-ref name=loginUsuario/ interceptor-ref name=defaultStack/ /interceptor-stack /interceptors default-interceptor-ref name=myStack/ global-results result name=clienteNaoLogado/jsp/usuario/loginUsuario.jsp/result result name=clienteNaoLogado/jsp/cliente/loginCliente.jsp/result /global-results /package /struts tks
Re: Help Struts2 + interceptor
The action has to be a part of that package, it has to extend that package. Fabio Alves de Araujo Ebner - DnaSolution wrote: Hi, i need help to use interceptor, i create one to test if the user are logged in my application until he execute one Action, but when the server pass throw interceptor and back to action, all my var are null, this is my struts.xml !DOCTYPE struts PUBLIC -//Apache Software Foundation//DTD Struts Configuration 2.0//EN http://struts.apache.org/dtds/struts-2.0.dtd;struts package name=loginClienteAndUsuario extends=struts-default interceptors interceptor name=loginUsuario class=br.com.dnasolution.site.interceptor.LoginUsuarioInterceptor /interceptor interceptor name=loginCliente class=br.com.dnasolution.site.interceptor.LoginClienteInterceptor /interceptor interceptor-stack name=myStack interceptor-ref name=loginCliente/ interceptor-ref name=loginUsuario/ interceptor-ref name=defaultStack/ /interceptor-stack /interceptors default-interceptor-ref name=myStack/ global-results result name=clienteNaoLogado/jsp/usuario/loginUsuario.jsp/result result name=clienteNaoLogado/jsp/cliente/loginCliente.jsp/result /global-results /package /struts tks - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Help Struts2 + interceptor
so i put in my aciotn ParentPackage(loginClienteAndUsuario) and i got the same problem - Original Message - From: JP Cafaro jcafar...@gmail.com To: Struts Users Mailing List user@struts.apache.org Sent: Monday, July 12, 2010 2:18 PM Subject: Re: Help Struts2 + interceptor The action has to be a part of that package, it has to extend that package. Fabio Alves de Araujo Ebner - DnaSolution wrote: Hi, i need help to use interceptor, i create one to test if the user are logged in my application until he execute one Action, but when the server pass throw interceptor and back to action, all my var are null, this is my struts.xml !DOCTYPE struts PUBLIC -//Apache Software Foundation//DTD Struts Configuration 2.0//EN http://struts.apache.org/dtds/struts-2.0.dtd;struts package name=loginClienteAndUsuario extends=struts-default interceptors interceptor name=loginUsuario class=br.com.dnasolution.site.interceptor.LoginUsuarioInterceptor /interceptor interceptor name=loginCliente class=br.com.dnasolution.site.interceptor.LoginClienteInterceptor /interceptor interceptor-stack name=myStack interceptor-ref name=loginCliente/ interceptor-ref name=loginUsuario/ interceptor-ref name=defaultStack/ /interceptor-stack /interceptors default-interceptor-ref name=myStack/ global-results result name=clienteNaoLogado/jsp/usuario/loginUsuario.jsp/result result name=clienteNaoLogado/jsp/cliente/loginCliente.jsp/result /global-results /package /struts tks - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.830 / Virus Database: 271.1.1/2998 - Release Date: 07/12/10 03:36:00 - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Help Struts2 + interceptor
Here's how I do it: struts.xml: package name=my-secure extends=my-default interceptors interceptor name=authenticationInterceptor class=interceptors.AuthenticationInterceptor / interceptor-stack name=secureStack interceptor-ref name=authenticationInterceptor / interceptor-ref name=defaultStack / /interceptor-stack /interceptors default-interceptor-ref name=secureStack / /package where my-default is another package that extends struts-default, Then I have a package-info.java file in each package that has actions that need to use this interceptor, for example: @ParentPackage(my-secure) package actions.secure; import org.apache.struts2.convention.annotation.ParentPackage; Note, I'm using the convention plugin Fabio Alves de Araujo Ebner - DnaSolution wrote: so i put in my aciotn ParentPackage(loginClienteAndUsuario) and i got the same problem - Original Message - From: JP Cafaro jcafar...@gmail.com To: Struts Users Mailing List user@struts.apache.org Sent: Monday, July 12, 2010 2:18 PM Subject: Re: Help Struts2 + interceptor The action has to be a part of that package, it has to extend that package. Fabio Alves de Araujo Ebner - DnaSolution wrote: Hi, i need help to use interceptor, i create one to test if the user are logged in my application until he execute one Action, but when the server pass throw interceptor and back to action, all my var are null, this is my struts.xml !DOCTYPE struts PUBLIC -//Apache Software Foundation//DTD Struts Configuration 2.0//EN http://struts.apache.org/dtds/struts-2.0.dtd;struts package name=loginClienteAndUsuario extends=struts-default interceptors interceptor name=loginUsuario class=br.com.dnasolution.site.interceptor.LoginUsuarioInterceptor /interceptor interceptor name=loginCliente class=br.com.dnasolution.site.interceptor.LoginClienteInterceptor /interceptor interceptor-stack name=myStack interceptor-ref name=loginCliente/ interceptor-ref name=loginUsuario/ interceptor-ref name=defaultStack/ /interceptor-stack /interceptors default-interceptor-ref name=myStack/ global-results result name=clienteNaoLogado/jsp/usuario/loginUsuario.jsp/result result name=clienteNaoLogado/jsp/cliente/loginCliente.jsp/result /global-results /package /struts tks - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.830 / Virus Database: 271.1.1/2998 - Release Date: 07/12/10 03:36:00 - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Help Struts2 + interceptor
Hey man, this is my structure MY ACTION package br.com.dnasolution.site.action; /** import **// @ParentPackage(my-secure) public class OrdemServicoAction { @Action(value = cadastrarOrdemServico, results = {...@result(name = valido, location = /jsp/ordemservico/cadastro_sucesso.jsp), @Result(name = invalido, location = /jsp/ordemservico/cadastro_falha.jsp) }, interceptorRefs = { @InterceptorRef(loginClienteInterceptor) }) public String cadastrarOrdemServico() { /* code */ } MY INTERCEPTOR package br.com.dnasolution.site.interceptor; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.Interceptor; public class LoginClienteInterceptor implements Interceptor { @Override public void destroy() { // TODO Auto-generated method stub } @Override public void init() { // TODO Auto-generated method stub } @Override public String intercept(ActionInvocation invocation) throws Exception { if(invocation.getInvocationContext().getSession().get(clienteLogado) != null){ return invocation.invoke(); }else{ return clienteNaoLogado; } } } AND MY STRUTS.XML !DOCTYPE struts PUBLIC -//Apache Software Foundation//DTD Struts Configuration 2.0//EN http://struts.apache.org/dtds/struts-2.0.dtd;struts package name=my-secure extends=struts-default interceptors interceptor name=loginUsuarioInterceptor class=br.com.dnasolution.site.interceptor.LoginUsuarioInterceptor /interceptor interceptor name=loginClienteInterceptor class=br.com.dnasolution.site.interceptor.LoginClienteInterceptor /interceptor interceptor-stack name=secureStack interceptor-ref name=loginUsuarioInterceptor/ interceptor-ref name=loginClienteInterceptor/ interceptor-ref name=defaultStack/ /interceptor-stack /interceptors default-interceptor-ref name=secureStack/ global-results result name=clienteNaoLogado/jsp/usuario/loginUsuario.jsp /result result name=clienteNaoLogado/jsp/cliente/loginCliente.jsp /result /global-results /package /struts and still dosen't work :( - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org