SlideShare una empresa de Scribd logo
1 de 115
Descargar para leer sin conexión
Lato Sensu em
                               Sistemas Orientados a Objetos




                       Módulo 4.2
                         Struts 2




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                                    Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                                                  4
                                               1.




                                                                                    2 x
                                              k
             x




                                             or




                                                                                     2.
                              x
          0.




                                                                                       .2
                          1.




                                            W




                                                                              s
                                                                                 2.
     ts




                                                                            t
                         ts




                                        eb




                                                                                   k
                                                                       W u
  ru




                                                                                 or
                         ru




                                                                               bW
                                                                          r
                                       W
St




                                                                       St
                       St




                                                                        e
2000              2001        2002   2003    2004         2005        2006        2007        2008        2009



Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                               Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                            Struts 2
                              objetivo




                         simplificar o
                       desenvolvimento
                             web
Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                      Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                                  Struts 2
                                     objetivo




                           Redução do XML
                          convenção sobre configuração
                                   anotações


                         Actions são POJOs
                                melhor testabilidade
                       bind automático de parâmetros HTTP


Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                               Struts 2
                                   novidades



                           Interceptadores
                            pré e pós-processamento


                           Extensibilidade
                                      plugins


                             Result Types
                             JSP, Velocity, Freemarker


                       Injeção de dependências
                           Spring, Plexus, PicoContainer


Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                            Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                       In a nutshell



Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009



   http://
  servidor/
     app/
    action




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                             Desenvolvimento de Aplicaões Web Avançado - 1°/2009



   http://
  servidor/
     app/
    action


                       struts.xml




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                        Desenvolvimento de Aplicaões Web Avançado - 1°/2009



   http://
  servidor/
     app/
    action




                       ActionTeste.java



Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009



   http://
  servidor/
     app/
    action
                                                       ok.jsp




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                                                         XML mapeia POJO
                                                             comum




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                                                       método execute()
                                                        obrigatório qdo
                                                     nenhuma configuração
                                                        é feita no XML




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                                                       o retorno do método
                                                         execute() revela o
                                                        resultado da Action


Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                                                     Action
                                                        e
                                                   struts.xml




                                                      libs




                                                   web.xml
                                                    *.html
                                                     *.jsp

Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                           Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                       At a glance



Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009



   http://
  servidor/
     app/
    action




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009



   http://
  servidor/
     app/
    action




                       ?


Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                           Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                       Struts 1.x




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                           Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                       Struts 1.x




                                                                                 ?


Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                  Desenvolvimento de Aplicaões Web Avançado - 1°/2009


 http://
servidor/              FrontController!
   app/
  action




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                      Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                            web.xml
<filter>

 
 <filter-name>struts2</filter-name>

 
 <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>

<filter-mapping>

 <filter-name>struts2</filter-name>

 <url-pattern>/*</url-pattern>
</filter-mapping>




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                            Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                       Estratégia de
                 Mapeamento de Actions


Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009


                                   Estratégia de
                       Mapeamento de Actions


                       http://localhost:8080/app/entrar

                        LoginAction.execute()




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009


                                   Estratégia de
                       Mapeamento de Actions


                       http://localhost:8080/app/entrar

                        LoginAction.execute()




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009


                                   Estratégia de
                       Mapeamento de Actions


                       http://localhost:8080/app/entrar

                        LoginAction.execute()
         <action name=quot;entrarquot; class=quot;xpto.LoginActionquot;/>




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                           Desenvolvimento de Aplicaões Web Avançado - 1°/2009


                                      Estratégia de
                        Mapeamento de Actions


                           http://localhost:8080/app/entrar

                       ControleDeAcessoAction.login()
  <action name=quot;entrarquot; method=quot;loginquot; class=quot;xpto.ControleDeAcessoActionquot;/>




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                           Desenvolvimento de Aplicaões Web Avançado - 1°/2009


                                      Estratégia de
                        Mapeamento de Actions


                           http://localhost:8080/app/entrar

                       ControleDeAcessoAction.login()
  <action name=quot;entrarquot; method=quot;loginquot; class=quot;xpto.ControleDeAcessoActionquot;/>




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                            Desenvolvimento de Aplicaões Web Avançado - 1°/2009


                                      Estratégia de
                                  Mapeamento de Actions

                            Patterns Matching

                         http://localhost:8080/app/acesso_login

                       ControleDeAcessoAction.login()




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                            Desenvolvimento de Aplicaões Web Avançado - 1°/2009


                                      Estratégia de
                                  Mapeamento de Actions

                            Patterns Matching

                         http://localhost:8080/app/acesso_login

                       ControleDeAcessoAction.login()




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                            Desenvolvimento de Aplicaões Web Avançado - 1°/2009


                                      Estratégia de
                                  Mapeamento de Actions

                            Patterns Matching

                         http://localhost:8080/app/acesso_login

                       ControleDeAcessoAction.login()




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                               Desenvolvimento de Aplicaões Web Avançado - 1°/2009


                                       Estratégia de
                                   Mapeamento de Actions

                            Patterns Matching

                         http://localhost:8080/app/acesso_login

                       ControleDeAcessoAction.login()
   <action name=quot;acesso_     *quot;   method=quot;   {1}quot;   class=quot;xpto.ControleDeAcessoActionquot;/>




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                          Desenvolvimento de Aplicaões Web Avançado - 1°/2009


                                      Estratégia de
                                  Mapeamento de Actions

                             Patterns Matching


                       http://localhost:8080/app/Usuario/edit

                             UsuarioAction.edit()




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                          Desenvolvimento de Aplicaões Web Avançado - 1°/2009


                                      Estratégia de
                                  Mapeamento de Actions

                             Patterns Matching


                       http://localhost:8080/app/Usuario/edit

                             UsuarioAction.edit()




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                          Desenvolvimento de Aplicaões Web Avançado - 1°/2009


                                      Estratégia de
                                  Mapeamento de Actions

                             Patterns Matching


                       http://localhost:8080/app/Usuario/edit

                             UsuarioAction.edit()




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                           Desenvolvimento de Aplicaões Web Avançado - 1°/2009


                                       Estratégia de
                                   Mapeamento de Actions

                             Patterns Matching


                       http://localhost:8080/app/Usuario/edit

                             UsuarioAction.edit()
         <action name=quot;     */*quot;   method=quot;   {2}quot;    class=quot;xpto.        {1}Actionquot;/>



Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                         Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                       Binding



Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                               Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                       Dados de Requisição


                        usuario=alegomes
                          senha=123456


Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                  Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                       Nada de ActionForms!
                             bind automático




Friday, May 22, 2009
Friday, May 22, 2009
setUsuario(“alegomes”);
                         setSenha(“123456”);




Friday, May 22, 2009
setUsuario(“alegomes”);
                         setSenha(“123456”);




Friday, May 22, 2009
Friday, May 22, 2009
Friday, May 22, 2009
Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                     Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                           Testabilidade

                     Como Actions são POJOS, nenhuma
                   infra-estrutura mágica é necessária para
                      implementação de testes unitários.




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                        Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                       Tags



Friday, May 22, 2009
http://
servidor/
   app/
  action




                       login.jsp menu.jsp




Friday, May 22, 2009
struts.xml
<action name=quot;login_*quot; method=quot;{1}quot; class=quot;br.ucb.soo.wa.struts2.lab3.LoginActionquot;>
     
<result name=quot;loginOKquot;>menu.jsp</result>
    
 <result name=quot;loginNOKquot;>login.jsp</result>
</action>



                                   LoginAction.java
public class LoginAction {


   public static final String USUARIO_ESPERADO = quot;alegomesquot;;

   public static final String SENHA_ESPERADA = quot;123456quot;;


   private String usuario;

   private String senha;


   public String autenticar() {

   

   
   if (USUARIO_ESPERADO.equals(usuario) && SENHA_ESPERADA.equals(senha)) {

   
   
   return quot;loginOKquot;;

   
   } else {

   
   
   return quot;loginNOKquot;;

   
   }

   

   }


     //Gets e Sets
}
Friday, May 22, 2009
struts.xml
<action name=quot;login_*quot; method=quot;{1}quot; class=quot;br.ucb.soo.wa.struts2.lab3.LoginActionquot;>
     
<result name=quot;loginOKquot;>menu.jsp</result>
    
 <result name=quot;loginNOKquot;>login.jsp</result>
</action>



                                   LoginAction.java
public class LoginAction {


   public static final String USUARIO_ESPERADO = quot;alegomesquot;;

   public static final String SENHA_ESPERADA = quot;123456quot;;


   private String usuario;

   private String senha;


   public String autenticar() {

   

   
   if (USUARIO_ESPERADO.equals(usuario) && SENHA_ESPERADA.equals(senha)) {

   
   
   return quot;loginOKquot;;

   
   } else {

   
   
   return quot;loginNOKquot;;

   
   }

   

   }


     //Gets e Sets
}
Friday, May 22, 2009
senha
                                                                                  correta




                       <title>Menu do Sistema</title>
                       </head>
                       <body>
                       <h1>Seja bem vindo.</h1>

                       Escolha uma das   abaixo.

                       <ul>
                         <li><a   href=quot;servico_f1quot;>Funcionalidade   1</a></li>
                         <li><a   href=quot;servico_f1quot;>Funcionalidade   2</a></li>
                         <li><a   href=quot;servico_f1quot;>Funcionalidade   3</a></li>
                         <li><a   href=quot;servico_f1quot;>Funcionalidade   4</a></li>
                       </ul>
                       </body>
                       </html>




                                               menu.jsp
Friday, May 22, 2009
senha
                                                                        errada




                       <title>Tela de Autenticação</title>
                       </head>
                       <body>
                       <form action=quot;login_autenticarquot;>
                         Login: <input type=quot;textquot; value=quot;quot;/><p/>
                         Senha: <input type=quot;passwordquot; value=quot;quot;/><p/>
                         <input type=quot;submitquot;/>
                       </form>
                       </body>




                                      login.jsp
Friday, May 22, 2009
<h1>Seja bem vindo, <s:property value=quot;usuarioquot; />.</h1>




Friday, May 22, 2009
<h1>Seja bem vindo, <s:property value=quot;usuarioquot; />.</h1>




Friday, May 22, 2009
<s:form action=quot;login_autenticarquot;>
                         <s:textfield label=quot;Loginquot; name=quot;usuarioquot;/>
                         <s:password label=quot;Senhaquot; name=quot;senhaquot; />
                         <s:submit/>
                       </s:form>




Friday, May 22, 2009
Friday, May 22, 2009
Friday, May 22, 2009
Friday, May 22, 2009
Friday, May 22, 2009
mais infos...




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                            Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                         Results
                            &
                       Result Types


Friday, May 22, 2009
http://
servidor/
   app/
  action




                       login.vt menu.jsp




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                               Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                           Results

                       implementação da
                       Camada View
                        Resposta da Action

Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                           Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                                    Results
                                                            login.jsp             menu.jsp



     Velocity          Freemarker   XSTL




                                           Action
Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                       Result Types
                        Velocity    Freemarker          XSTL




<action name=quot;qqcoisa*quot; method=quot;{1}quot; class=quot;br.ucb.soo.wa.struts2.lab3.QQActionquot;>
     
<result name=quot;result1quot;>menu.jsp</result>
    
 <result name=quot;result1quot; type=”dispatcher”>some.jsp</result>
    
 <result name=quot;result2quot; type=”freemarker”>login.ftl</result>
   
 <result name=quot;result3quot; type=”velocity”>page.vt</result>
</action>




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                              Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                                     Result Types
                                          customizados


                       public interface Result extends Serializable {

                           public void execute(ActionInvocation invocation)
                               throws Exception;
                       }




    <result-types>
        <result-type name=quot;dispatcherquot;
                     default=quot;truequot;
                     class=quot;seu.pacote.SuaClassequot;/>
    </result-types>

Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                       Dependency Injection




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                            Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                       Interceptors



Friday, May 22, 2009
http://
servidor/
   app/
  action




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                               Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                       Revisão
                       Intercepting Filters




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                               Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                       Revisão
                       Intercepting Filters




   interceptors             action                   interceptors

Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                              Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                                Interceptors
                                           pra quê?



                        Tratamento de exceção
                            Evitar submit duplo
                             Upload de arquivo
                                   Ciclo de vida
                                      Validações

                       http://struts.apache.org/2.1.6/docs/interceptors.html
Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                            Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                               Interceptors
<package name=quot;defaultquot; extends=quot;struts-defaultquot;>
      <interceptors>
          <interceptor name=quot;timerquot; class=quot;...quot;/>
          <interceptor name=quot;loggerquot; class=quot;...quot;/>
      </interceptors>

      <action name=quot;loginquot; class=quot;tutorial.Loginquot;>
                   <interceptor-ref name=quot;timerquot;/>
                   <interceptor-ref name=quot;loggerquot;/>

         <result name=quot;inputquot;>login.jsp</result>
         <result name=quot;successquot; type=quot;redirectActionquot;>/secure/home</result>
   </action>
</package>




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                              Desenvolvimento de Aplicaões Web Avançado - 1°/2009




               Pacotes de Interceptors
<package name=quot;defaultquot; extends=quot;struts-defaultquot;>
   <interceptors>
        <interceptor name=quot;timerquot; class=quot;..quot;/>
        <interceptor name=quot;loggerquot; class=quot;..quot;/>

                   <interceptor-stack name=quot;myStackquot;>
                      <interceptor-ref name=quot;timerquot;/>
                      <interceptor-ref name=quot;loggerquot;/>
                   </interceptor-stack>

          </interceptors>

          <action name=quot;loginquot; class=quot;tutuorial.Loginquot;>
               <interceptor-ref name=quot;myStackquot;/>

         <result name=quot;inputquot;>login.jsp</result>
         <result name=quot;successquot; type=quot;redirectActionquot;>/secure/home</result>
    </action>
</package>

Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                                                 Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                                         Interceptors
<interceptor      name=quot;aliasquot; class=quot;com.opensymphony.xwork2.interceptor.AliasInterceptorquot;/>
<interceptor      name=quot;autowiringquot; class=quot;com.opensymphony.xwork2.spring.interceptor.ActionAutowiringInterceptorquot;/>
<interceptor      name=quot;chainquot; class=quot;com.opensymphony.xwork2.interceptor.ChainingInterceptorquot;/>
<interceptor      name=quot;conversionErrorquot; class=quot;org.apache.struts2.interceptor.StrutsConversionErrorInterceptorquot;/>
<interceptor      name=quot;clearSessionquot; class=quot;org.apache.struts2.interceptor.ClearSessionInterceptorquot; />
<interceptor      name=quot;createSessionquot; class=quot;org.apache.struts2.interceptor.CreateSessionInterceptorquot; />
<interceptor      name=quot;debuggingquot; class=quot;org.apache.struts2.interceptor.debugging.DebuggingInterceptorquot; />
<interceptor      name=quot;externalRefquot; class=quot;com.opensymphony.xwork2.interceptor.ExternalReferencesInterceptorquot;/>
<interceptor      name=quot;execAndWaitquot; class=quot;org.apache.struts2.interceptor.ExecuteAndWaitInterceptorquot;/>
<interceptor      name=quot;exceptionquot; class=quot;com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptorquot;/>
<interceptor      name=quot;fileUploadquot; class=quot;org.apache.struts2.interceptor.FileUploadInterceptorquot;/>
<interceptor      name=quot;i18nquot; class=quot;com.opensymphony.xwork2.interceptor.I18nInterceptorquot;/>
<interceptor      name=quot;loggerquot; class=quot;com.opensymphony.xwork2.interceptor.LoggingInterceptorquot;/>
<interceptor      name=quot;modelDrivenquot; class=quot;com.opensymphony.xwork2.interceptor.ModelDrivenInterceptorquot;/>
<interceptor      name=quot;scopedModelDrivenquot; class=quot;com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptorquot;/>
<interceptor      name=quot;paramsquot; class=quot;com.opensymphony.xwork2.interceptor.ParametersInterceptorquot;/>
<interceptor      name=quot;actionMappingParamsquot; class=quot;org.apache.struts2.interceptor.ActionMappingParametersInteceptorquot;/>
<interceptor      name=quot;preparequot; class=quot;com.opensymphony.xwork2.interceptor.PrepareInterceptorquot;/>
<interceptor      name=quot;staticParamsquot; class=quot;com.opensymphony.xwork2.interceptor.StaticParametersInterceptorquot;/>
<interceptor      name=quot;scopequot; class=quot;org.apache.struts2.interceptor.ScopeInterceptorquot;/>
<interceptor      name=quot;servletConfigquot; class=quot;org.apache.struts2.interceptor.ServletConfigInterceptorquot;/>
<interceptor      name=quot;sessionAutowiringquot; class=quot;org.apache.struts2.spring.interceptor.SessionContextAutowiringInterceptorquot;/>
<interceptor      name=quot;timerquot; class=quot;com.opensymphony.xwork2.interceptor.TimerInterceptorquot;/>
<interceptor      name=quot;tokenquot; class=quot;org.apache.struts2.interceptor.TokenInterceptorquot;/>
<interceptor      name=quot;tokenSessionquot; class=quot;org.apache.struts2.interceptor.TokenSessionStoreInterceptorquot;/>
<interceptor      name=quot;validationquot; class=quot;org.apache.struts2.interceptor.validation.AnnotationValidationInterceptorquot;/>
<interceptor      name=quot;workflowquot; class=quot;com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptorquot;/>
<interceptor      name=quot;storequot; class=quot;org.apache.struts2.interceptor.MessageStoreInterceptorquot; />
<interceptor      name=quot;checkboxquot; class=quot;org.apache.struts2.interceptor.CheckboxInterceptorquot; />
<interceptor      name=quot;profilingquot; class=quot;org.apache.struts2.interceptor.ProfilingActivationInterceptorquot; />
<interceptor      name=quot;rolesquot; class=quot;org.apache.struts2.interceptor.RolesInterceptorquot; />
<interceptor      name=quot;jsonValidationquot; class=quot;org.apache.struts2.interceptor.validation.JSONValidationInterceptorquot; />
<interceptor      name=quot;annotationWorkflowquot; class=quot;com.opensymphony.xwork2.interceptor.annotations.AnnotationWorkflowInterceptorquot; />

Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                             Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                                  Exemplo
 <action name=quot;login_*quot; method=quot;{1}quot; class=quot;br.ucb.soo.wa.struts2.lab3.LoginActionquot;>

                <interceptor-ref name=quot;loggerquot;/>

         <result name=quot;loginOKquot;>menu.jsp</result>
       
       <result name=quot;loginNOKquot;>login.jsp</result>
 </action>




   May 15, 2009 11:39:22 AM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
   INFO: Starting execution stack for action //login_autenticar
   May 15, 2009 11:39:22 AM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
   INFO: Finishing execution stack for action //login_autenticar



Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                   Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                          Interceptors

                       coisas muito mais complexas
                            podem ser feitas...




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                    Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                          Interceptors

                       coisas muito mais complexas
                            podem ser feitas...



                        ...e precisam ser testadas!


Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                             Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                        Testes
                       Direto na Action




                              :-/


Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                            Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                       Testes
                       Action Proxied




                            :-)


Friday, May 22, 2009
Friday, May 22, 2009
Friday, May 22, 2009
Ambos os sites propõem
                       classes da apoio aos testes




Friday, May 22, 2009
Friday, May 22, 2009
// create action context for my action, feed
 // into the action context all request parameters
 Map requestParameters = new HashMap();
 requestParameters.put(quot;param1quot;, quot;param1-valuequot;);
 requestParameters.put(quot;param2quot;, quot;param2-valuequot;);
 Map actionContext = StrutsTestCaseSupport.getInstance().buildActionContext(
                     quot;my.hostname.comquot;, quot;getquot;, quot;/myActionNamespace/myActionNamequot;, requestParameters);

 // create the proxy for the action, this encapsulates all
 // the interception stack up to the real action
 ActionProxy proxy = StrutsTestCaseSupport.getInstance().createActionProxy(
                     quot;myActionNamequot;, quot;myActionNameSpacequot;,actionContext);
 // inject parameters as required

 // let the full stack run
 String result =       proxy.execute();
 // confirm result
 assert    result.equals(quot;myTestResponseStringquot;);
 // look into mock HttpServletResponse, do whatever
 // tests I need to do: returned HTML, returned headers,
 // cookies, etc...
 String responseXml = ((MockHttpServletResponse) actionContext.get(StrutsStatics.HTTP_RESPONSE)).getContentAsString();
 assert responseXml.indexOf(quot;successquot;) != -1;




                           http://fassisrosa.blogspot.com/2006/11/unit-testing-struts-20.html
Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                                          Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                                                 Struts2
                                                         testes



                                              org.apache.struts2.util.StrutsTestCaseHelper

                                              Generic test setup methods to be used with any unit testing framework.


  com.opensymphony.xwork2.TestNGXWorkTestCase

  Base test class for TestNG unit tests. Provides common XWork variables and
  performs XWork setup and teardown processes


                                              com.opensymphony.xwork2.XWorkTestCase

                                              Base JUnit TestCase to extend for XWork specific JUnit tests. Uses the generic
                                              test setup for logic.


  com.opensymphony.xwork2.util.XWorkTestCaseHelper

  Generic test setup methods to be used with any unit testing framework.
Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                   Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                               Include

                       Mecanismo para modularização
                            das configurações.




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                                        Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                                              Include
                       <struts>

                           <include file=quot;billing-config.xmlquot; />
                           <include file=quot;admin-config.xmlquot; />
                           <include file=quot;reports-config.xmlquot; />

                           ...

                       </struts>



                                 struts-default.xml e struts-plugin.xml são incluídos
                                         implicitamente em todo struts.xml
Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                                 Packages

                       Mecanismo para organização lógica e
                       reaproveitamento de configurações




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                                     Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                                        Packages
   <struts>

            <package name=quot;exemploquot; extends=quot;struts-defaultquot;>

                 <action name=quot;login_*quot; method=quot;{1}quot; class=quot;br.ucb.soo.wa.struts2.lab3.LoginActionquot;>
                     <interceptor-ref name=quot;loggerquot;/>
                 
      <result name=quot;loginOKquot;>menu.jsp</result>
                 
      <result name=quot;loginNOKquot;>login.jsp</result>
                 </action>

                 <action name=quot;logout/*quot; class=quot;br.ucb.soo.wa.struts2.lab3.LogoutActionquot;>
                 
      <result>{1}.jsp</result>
                 </action>


            </package>

   </struts>


Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                     Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                              Validators

                       Verificação declarativa de campos




Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                                               Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                       Bundled Validators
                                     conversion validator
                                         date validator
                                       double validator
                                        email validator
                                     expression validator
                                  fieldexpression validator
                                          int validator
                                        regex validator
                                      required validator
                                   requiredstring validator
                                    stringlength validator
                                          url validator
                                       visitor validator


                         http://struts.apache.org/2.1.6/docs/validation.html
Friday, May 22, 2009
<interceptor name=quot;validationquot;
             class=quot;org.apache.struts2.interceptor.validation.AnnotationValidationInterceptorquot;/>




                                                                                    struts.xml
Friday, May 22, 2009
<interceptor name=quot;validationquot;
             class=quot;org.apache.struts2.interceptor.validation.AnnotationValidationInterceptorquot;/>


                                                                                  struts-default.xml




              <interceptor-ref name=quot;validationquot; />
                                                                                 struts.xml




Friday, May 22, 2009
Friday, May 22, 2009
<body>
                <s:form action=quot;login_autenticarquot; validate=quot;truequot;>
                  <s:textfield label=quot;Loginquot; name=quot;usuarioquot;/>
                  <s:password label=quot;Senhaquot; name=quot;senhaquot; />
                  <s:submit/>
                </s:form>
                </body>




                                                                     login.jsp
Friday, May 22, 2009
<validators>
           
 <field name=quot;usuarioquot;>
           
 
 <field-validator type=quot;requiredstringquot;>
           
 
 
 <message>Nome de usuario obrigatorio!</message>
           
 
 </field-validator>
           
 </field>
           
 <field name=quot;senhaquot;>
           
 
 <field-validator type=quot;requiredstringquot;>
           
 
 
 <message>Senha obrigatoria!</message>
           
 
 </field-validator>
           
 </field>
           </validators>




                       br/ucb/soo/wa/struts2/lab3/LoginAction-validation.xml
Friday, May 22, 2009
<validators>
           
 <field name=quot;usuarioquot;>
           
 
 <field-validator type=quot;requiredstringquot;>
           
 
 
 <message>Nome de usuario obrigatorio!</message>
           
 
 </field-validator>
           
 </field>
           
 <field name=quot;senhaquot;>
           
 
 <field-validator type=quot;requiredstringquot;>
           
 
 
 <message>Senha obrigatoria!</message>
           
 
 </field-validator>
           
 </field>
           </validators>




                       br/ucb/soo/wa/struts2/lab3/LoginAction-validation.xml
Friday, May 22, 2009
<validators>
           
 <field name=quot;usuarioquot;>
           
 
 <field-validator type=quot;requiredstringquot;>
           
 
 
 <message>Nome de usuario obrigatorio!</message>
           
 
 </field-validator>
           
 </field>
           
 <field name=quot;senhaquot;>
           
 
 <field-validator type=quot;requiredstringquot;>
           
 
 
 <message>Senha obrigatoria!</message>
           
 
 </field-validator>
           
 </field>
           </validators>




                       br/ucb/soo/wa/struts2/lab3/LoginAction-validation.xml
Friday, May 22, 2009
<validators>
           
 <field name=quot;usuarioquot;>
           
 
 <field-validator type=quot;requiredstringquot;>
           
 
 
 <message>Nome de usuario obrigatorio!</message>
           
 
 </field-validator>
           
 </field>
           
 <field name=quot;senhaquot;>
           
 
 <field-validator type=quot;requiredstringquot;>
           
 
 
 <message>Senha obrigatoria!</message>
           
 
 </field-validator>
           
 </field>
           </validators>




                       br/ucb/soo/wa/struts2/lab3/LoginAction-validation.xml
Friday, May 22, 2009
<validators>
           
 <field name=quot;usuarioquot;>
           
 
 <field-validator type=quot;requiredstringquot;>
           
 
 
 <message>Nome de usuario obrigatorio!</message>
           
 
 </field-validator>
           
 </field>
           
 <field name=quot;senhaquot;>
           
 
 <field-validator type=quot;requiredstringquot;>
           
 
 
 <message>Senha obrigatoria!</message>
           
 
 </field-validator>
           
 </field>
           </validators>




                       br/ucb/soo/wa/struts2/lab3/LoginAction-validation.xml
Friday, May 22, 2009
Friday, May 22, 2009
Lato Sensu em Sistemas Orientados a Objetos
                       Desenvolvimento de Aplicaões Web Avançado - 1°/2009




Friday, May 22, 2009
Friday, May 22, 2009




                       http://cwiki.apache.org/confluence/display/WW/Big+Picture
Lato Sensu em Sistemas Orientados a Objetos
                                                          Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                   Afinal, por que Struts2?
                       •   Baseado em Actions
                       •   Configurações
                           -   XML e Annotations

                       •   Actions POJO
                           -   alta testabilidade

                       •   Integrável
                           -   Spring, SiteMesh e Tiles

                       •   Opções de View
                           -   JSP, Freemarker, Velocity e XSLT


Friday, May 22, 2009
                       •   Plugável
Lato Sensu em Sistemas Orientados a Objetos
                                             Desenvolvimento de Aplicaões Web Avançado - 1°/2009




                                         Labs
                  “The Bootstap tutorials starts from the very
                    beginning and steps through creating a
                             simple application.”

                       http://struts.apache.org/2.x/docs/bootstrap.html




Friday, May 22, 2009
Lato Sensu em
                                  Sistemas Orientados a Objetos




                   Q&A MSc. Alexandre Gomes
                       alegomes@gmail.com
Friday, May 22, 2009

Más contenido relacionado

Similar a Struts 2.x

How To Deliver High Performing Highly Available Cloud Applications
How To Deliver High Performing Highly Available Cloud ApplicationsHow To Deliver High Performing Highly Available Cloud Applications
How To Deliver High Performing Highly Available Cloud ApplicationsBen Rushlo
 
Windows Azure Cases
Windows Azure CasesWindows Azure Cases
Windows Azure CasesEunbee Song
 
WEB 2.0: BUILDING RICH INTERNET APPLICATIONS WITH PHP
WEB 2.0: BUILDING RICH INTERNET APPLICATIONS WITH PHPWEB 2.0: BUILDING RICH INTERNET APPLICATIONS WITH PHP
WEB 2.0: BUILDING RICH INTERNET APPLICATIONS WITH PHPzend
 
Romulus Project start version en
Romulus Project start version enRomulus Project start version en
Romulus Project start version enGrupo Gesfor I+D+i
 
Decoupled microservices-Building scalable applications.pptx
Decoupled microservices-Building scalable applications.pptxDecoupled microservices-Building scalable applications.pptx
Decoupled microservices-Building scalable applications.pptxGreg Hoelzer
 
[DSBW Spring 2009] Unit 01: Introducing Web Engineering
[DSBW Spring 2009] Unit 01: Introducing Web Engineering[DSBW Spring 2009] Unit 01: Introducing Web Engineering
[DSBW Spring 2009] Unit 01: Introducing Web EngineeringCarles Farré
 
Web 2.0 and LiveQuotes Presentation
Web 2.0 and LiveQuotes PresentationWeb 2.0 and LiveQuotes Presentation
Web 2.0 and LiveQuotes PresentationJamie Thingelstad
 
[WSO2Con EU 2017] Microservice Architecture (MSA) and Integration Microservices
[WSO2Con EU 2017] Microservice Architecture (MSA) and Integration Microservices[WSO2Con EU 2017] Microservice Architecture (MSA) and Integration Microservices
[WSO2Con EU 2017] Microservice Architecture (MSA) and Integration MicroservicesWSO2
 
Maven - Gestão de Builds e Dependencias
Maven - Gestão de Builds e DependenciasMaven - Gestão de Builds e Dependencias
Maven - Gestão de Builds e DependenciasRuben Badaró
 
Webinar The App Lifecycle Platform
Webinar The App Lifecycle PlatformWebinar The App Lifecycle Platform
Webinar The App Lifecycle PlatformService2Media
 
Building Next-Gen Web Applications with the Spring 3 Web Stack
Building Next-Gen Web Applications with the Spring 3 Web StackBuilding Next-Gen Web Applications with the Spring 3 Web Stack
Building Next-Gen Web Applications with the Spring 3 Web StackJeremy Grelle
 
GOUSE_BAIG_DOTNET_5Yrs
GOUSE_BAIG_DOTNET_5YrsGOUSE_BAIG_DOTNET_5Yrs
GOUSE_BAIG_DOTNET_5YrsGouse Baig
 
Simplified Web2.0 application development with Project Zero
Simplified Web2.0 application development with Project ZeroSimplified Web2.0 application development with Project Zero
Simplified Web2.0 application development with Project ZeroShawn Zhu
 
Skills, Competencies And Methods
Skills, Competencies And MethodsSkills, Competencies And Methods
Skills, Competencies And MethodsHealthovate
 

Similar a Struts 2.x (20)

How To Deliver High Performing Highly Available Cloud Applications
How To Deliver High Performing Highly Available Cloud ApplicationsHow To Deliver High Performing Highly Available Cloud Applications
How To Deliver High Performing Highly Available Cloud Applications
 
Webinos Project
Webinos ProjectWebinos Project
Webinos Project
 
Windows Azure Cases
Windows Azure CasesWindows Azure Cases
Windows Azure Cases
 
WEB 2.0: BUILDING RICH INTERNET APPLICATIONS WITH PHP
WEB 2.0: BUILDING RICH INTERNET APPLICATIONS WITH PHPWEB 2.0: BUILDING RICH INTERNET APPLICATIONS WITH PHP
WEB 2.0: BUILDING RICH INTERNET APPLICATIONS WITH PHP
 
Romulus Project start version en
Romulus Project start version enRomulus Project start version en
Romulus Project start version en
 
Decoupled microservices-Building scalable applications.pptx
Decoupled microservices-Building scalable applications.pptxDecoupled microservices-Building scalable applications.pptx
Decoupled microservices-Building scalable applications.pptx
 
[DSBW Spring 2009] Unit 01: Introducing Web Engineering
[DSBW Spring 2009] Unit 01: Introducing Web Engineering[DSBW Spring 2009] Unit 01: Introducing Web Engineering
[DSBW Spring 2009] Unit 01: Introducing Web Engineering
 
Web 2.0 and LiveQuotes Presentation
Web 2.0 and LiveQuotes PresentationWeb 2.0 and LiveQuotes Presentation
Web 2.0 and LiveQuotes Presentation
 
Romulus project presentation
Romulus project presentationRomulus project presentation
Romulus project presentation
 
[WSO2Con EU 2017] Microservice Architecture (MSA) and Integration Microservices
[WSO2Con EU 2017] Microservice Architecture (MSA) and Integration Microservices[WSO2Con EU 2017] Microservice Architecture (MSA) and Integration Microservices
[WSO2Con EU 2017] Microservice Architecture (MSA) and Integration Microservices
 
Maven - Gestão de Builds e Dependencias
Maven - Gestão de Builds e DependenciasMaven - Gestão de Builds e Dependencias
Maven - Gestão de Builds e Dependencias
 
Stonehenge
StonehengeStonehenge
Stonehenge
 
Webinar The App Lifecycle Platform
Webinar The App Lifecycle PlatformWebinar The App Lifecycle Platform
Webinar The App Lifecycle Platform
 
Java/J2EE Companion
Java/J2EE CompanionJava/J2EE Companion
Java/J2EE Companion
 
Building Next-Gen Web Applications with the Spring 3 Web Stack
Building Next-Gen Web Applications with the Spring 3 Web StackBuilding Next-Gen Web Applications with the Spring 3 Web Stack
Building Next-Gen Web Applications with the Spring 3 Web Stack
 
GOUSE_BAIG_DOTNET_5Yrs
GOUSE_BAIG_DOTNET_5YrsGOUSE_BAIG_DOTNET_5Yrs
GOUSE_BAIG_DOTNET_5Yrs
 
Simplified Web2.0 application development with Project Zero
Simplified Web2.0 application development with Project ZeroSimplified Web2.0 application development with Project Zero
Simplified Web2.0 application development with Project Zero
 
How backbone.js is different from ember.js?
How backbone.js is different from ember.js?How backbone.js is different from ember.js?
How backbone.js is different from ember.js?
 
Web Synergy 20080911
Web Synergy 20080911Web Synergy 20080911
Web Synergy 20080911
 
Skills, Competencies And Methods
Skills, Competencies And MethodsSkills, Competencies And Methods
Skills, Competencies And Methods
 

Más de Alexandre Gomes

Construção de Software - 1º/2017
Construção de Software - 1º/2017Construção de Software - 1º/2017
Construção de Software - 1º/2017Alexandre Gomes
 
Programação Funcional com Javascript
Programação Funcional com JavascriptProgramação Funcional com Javascript
Programação Funcional com JavascriptAlexandre Gomes
 
UnB/PPCA/CS2016 - Projeto 2
UnB/PPCA/CS2016 - Projeto 2UnB/PPCA/CS2016 - Projeto 2
UnB/PPCA/CS2016 - Projeto 2Alexandre Gomes
 
Javascript do jeito certo
Javascript do jeito certoJavascript do jeito certo
Javascript do jeito certoAlexandre Gomes
 
Construção de Software - 1º/2016
Construção de Software - 1º/2016Construção de Software - 1º/2016
Construção de Software - 1º/2016Alexandre Gomes
 
Plano de Ensino de Tópicos Avançados em Engenharia de Software
Plano de Ensino de Tópicos Avançados em Engenharia de SoftwarePlano de Ensino de Tópicos Avançados em Engenharia de Software
Plano de Ensino de Tópicos Avançados em Engenharia de SoftwareAlexandre Gomes
 
Construção de Software - 1º semestre de 2014
Construção de Software - 1º semestre de 2014Construção de Software - 1º semestre de 2014
Construção de Software - 1º semestre de 2014Alexandre Gomes
 
Laboratório de Métodos Ágeis 1/2014 - Apresentação
Laboratório de Métodos Ágeis 1/2014 - ApresentaçãoLaboratório de Métodos Ágeis 1/2014 - Apresentação
Laboratório de Métodos Ágeis 1/2014 - ApresentaçãoAlexandre Gomes
 
OpenData, Web Semântica e afins.
OpenData, Web Semântica e afins.OpenData, Web Semântica e afins.
OpenData, Web Semântica e afins.Alexandre Gomes
 
Javascript do jeito certo
Javascript do jeito certoJavascript do jeito certo
Javascript do jeito certoAlexandre Gomes
 
Javascript orientado a testes
Javascript orientado a testesJavascript orientado a testes
Javascript orientado a testesAlexandre Gomes
 

Más de Alexandre Gomes (20)

Construção de Software - 1º/2017
Construção de Software - 1º/2017Construção de Software - 1º/2017
Construção de Software - 1º/2017
 
TDDing com Javascript
TDDing com JavascriptTDDing com Javascript
TDDing com Javascript
 
Aprendendo a Aprender
Aprendendo a AprenderAprendendo a Aprender
Aprendendo a Aprender
 
Programação Funcional com Javascript
Programação Funcional com JavascriptProgramação Funcional com Javascript
Programação Funcional com Javascript
 
UnB/PPCA/CS2016 - Projeto 2
UnB/PPCA/CS2016 - Projeto 2UnB/PPCA/CS2016 - Projeto 2
UnB/PPCA/CS2016 - Projeto 2
 
Javascript do jeito certo
Javascript do jeito certoJavascript do jeito certo
Javascript do jeito certo
 
Construção de Software - 1º/2016
Construção de Software - 1º/2016Construção de Software - 1º/2016
Construção de Software - 1º/2016
 
Plano de Ensino de Tópicos Avançados em Engenharia de Software
Plano de Ensino de Tópicos Avançados em Engenharia de SoftwarePlano de Ensino de Tópicos Avançados em Engenharia de Software
Plano de Ensino de Tópicos Avançados em Engenharia de Software
 
O Pensamento Ágil
O Pensamento ÁgilO Pensamento Ágil
O Pensamento Ágil
 
Manifesto 2.0
Manifesto 2.0Manifesto 2.0
Manifesto 2.0
 
Construção de Software - 1º semestre de 2014
Construção de Software - 1º semestre de 2014Construção de Software - 1º semestre de 2014
Construção de Software - 1º semestre de 2014
 
Business Modeling
Business ModelingBusiness Modeling
Business Modeling
 
Design Thinking
Design ThinkingDesign Thinking
Design Thinking
 
Manifesto Ágil
Manifesto ÁgilManifesto Ágil
Manifesto Ágil
 
Laboratório de Métodos Ágeis 1/2014 - Apresentação
Laboratório de Métodos Ágeis 1/2014 - ApresentaçãoLaboratório de Métodos Ágeis 1/2014 - Apresentação
Laboratório de Métodos Ágeis 1/2014 - Apresentação
 
Scraping by examples
Scraping by examplesScraping by examples
Scraping by examples
 
Scraping by examples
Scraping by examplesScraping by examples
Scraping by examples
 
OpenData, Web Semântica e afins.
OpenData, Web Semântica e afins.OpenData, Web Semântica e afins.
OpenData, Web Semântica e afins.
 
Javascript do jeito certo
Javascript do jeito certoJavascript do jeito certo
Javascript do jeito certo
 
Javascript orientado a testes
Javascript orientado a testesJavascript orientado a testes
Javascript orientado a testes
 

Último

.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptxHansamali Gamage
 
Keep Your Finger on the Pulse of Your Building's Performance with IES Live
Keep Your Finger on the Pulse of Your Building's Performance with IES LiveKeep Your Finger on the Pulse of Your Building's Performance with IES Live
Keep Your Finger on the Pulse of Your Building's Performance with IES LiveIES VE
 
Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.IPLOOK Networks
 
Automation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projectsAutomation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projectsDianaGray10
 
CyberSecurity - Computers In Libraries 2024
CyberSecurity - Computers In Libraries 2024CyberSecurity - Computers In Libraries 2024
CyberSecurity - Computers In Libraries 2024Brian Pichman
 
UiPath Studio Web workshop series - Day 1
UiPath Studio Web workshop series  - Day 1UiPath Studio Web workshop series  - Day 1
UiPath Studio Web workshop series - Day 1DianaGray10
 
Scenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosScenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosErol GIRAUDY
 
EMEA What is ThousandEyes? Webinar
EMEA What is ThousandEyes? WebinarEMEA What is ThousandEyes? Webinar
EMEA What is ThousandEyes? WebinarThousandEyes
 
Trailblazer Community - Flows Workshop (Session 2)
Trailblazer Community - Flows Workshop (Session 2)Trailblazer Community - Flows Workshop (Session 2)
Trailblazer Community - Flows Workshop (Session 2)Muhammad Tiham Siddiqui
 
Patch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 updatePatch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 updateadam112203
 
My key hands-on projects in Quantum, and QAI
My key hands-on projects in Quantum, and QAIMy key hands-on projects in Quantum, and QAI
My key hands-on projects in Quantum, and QAIVijayananda Mohire
 
Planetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile BrochurePlanetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile BrochurePlanetek Italia Srl
 
Extra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdfExtra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdfInfopole1
 
Top 10 Squarespace Development Companies
Top 10 Squarespace Development CompaniesTop 10 Squarespace Development Companies
Top 10 Squarespace Development CompaniesTopCSSGallery
 
LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0DanBrown980551
 
UiPath Studio Web workshop Series - Day 3
UiPath Studio Web workshop Series - Day 3UiPath Studio Web workshop Series - Day 3
UiPath Studio Web workshop Series - Day 3DianaGray10
 
Technical SEO for Improved Accessibility WTS FEST
Technical SEO for Improved Accessibility  WTS FESTTechnical SEO for Improved Accessibility  WTS FEST
Technical SEO for Improved Accessibility WTS FESTBillieHyde
 
2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdf2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdfThe Good Food Institute
 
Explore the UiPath Community and ways you can benefit on your journey to auto...
Explore the UiPath Community and ways you can benefit on your journey to auto...Explore the UiPath Community and ways you can benefit on your journey to auto...
Explore the UiPath Community and ways you can benefit on your journey to auto...DianaGray10
 

Último (20)

.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx
 
SheDev 2024
SheDev 2024SheDev 2024
SheDev 2024
 
Keep Your Finger on the Pulse of Your Building's Performance with IES Live
Keep Your Finger on the Pulse of Your Building's Performance with IES LiveKeep Your Finger on the Pulse of Your Building's Performance with IES Live
Keep Your Finger on the Pulse of Your Building's Performance with IES Live
 
Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.
 
Automation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projectsAutomation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projects
 
CyberSecurity - Computers In Libraries 2024
CyberSecurity - Computers In Libraries 2024CyberSecurity - Computers In Libraries 2024
CyberSecurity - Computers In Libraries 2024
 
UiPath Studio Web workshop series - Day 1
UiPath Studio Web workshop series  - Day 1UiPath Studio Web workshop series  - Day 1
UiPath Studio Web workshop series - Day 1
 
Scenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosScenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenarios
 
EMEA What is ThousandEyes? Webinar
EMEA What is ThousandEyes? WebinarEMEA What is ThousandEyes? Webinar
EMEA What is ThousandEyes? Webinar
 
Trailblazer Community - Flows Workshop (Session 2)
Trailblazer Community - Flows Workshop (Session 2)Trailblazer Community - Flows Workshop (Session 2)
Trailblazer Community - Flows Workshop (Session 2)
 
Patch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 updatePatch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 update
 
My key hands-on projects in Quantum, and QAI
My key hands-on projects in Quantum, and QAIMy key hands-on projects in Quantum, and QAI
My key hands-on projects in Quantum, and QAI
 
Planetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile BrochurePlanetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile Brochure
 
Extra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdfExtra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdf
 
Top 10 Squarespace Development Companies
Top 10 Squarespace Development CompaniesTop 10 Squarespace Development Companies
Top 10 Squarespace Development Companies
 
LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0
 
UiPath Studio Web workshop Series - Day 3
UiPath Studio Web workshop Series - Day 3UiPath Studio Web workshop Series - Day 3
UiPath Studio Web workshop Series - Day 3
 
Technical SEO for Improved Accessibility WTS FEST
Technical SEO for Improved Accessibility  WTS FESTTechnical SEO for Improved Accessibility  WTS FEST
Technical SEO for Improved Accessibility WTS FEST
 
2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdf2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdf
 
Explore the UiPath Community and ways you can benefit on your journey to auto...
Explore the UiPath Community and ways you can benefit on your journey to auto...Explore the UiPath Community and ways you can benefit on your journey to auto...
Explore the UiPath Community and ways you can benefit on your journey to auto...
 

Struts 2.x

  • 1. Lato Sensu em Sistemas Orientados a Objetos Módulo 4.2 Struts 2 Friday, May 22, 2009
  • 2. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Friday, May 22, 2009
  • 3. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 4 1. 2 x k x or 2. x 0. .2 1. W s 2. ts t ts eb k W u ru or ru bW r W St St St e 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 Friday, May 22, 2009
  • 4. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Friday, May 22, 2009
  • 5. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Struts 2 objetivo simplificar o desenvolvimento web Friday, May 22, 2009
  • 6. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Struts 2 objetivo Redução do XML convenção sobre configuração anotações Actions são POJOs melhor testabilidade bind automático de parâmetros HTTP Friday, May 22, 2009
  • 7. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Struts 2 novidades Interceptadores pré e pós-processamento Extensibilidade plugins Result Types JSP, Velocity, Freemarker Injeção de dependências Spring, Plexus, PicoContainer Friday, May 22, 2009
  • 8. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 In a nutshell Friday, May 22, 2009
  • 9. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 http:// servidor/ app/ action Friday, May 22, 2009
  • 10. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 http:// servidor/ app/ action struts.xml Friday, May 22, 2009
  • 11. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 http:// servidor/ app/ action ActionTeste.java Friday, May 22, 2009
  • 12. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 http:// servidor/ app/ action ok.jsp Friday, May 22, 2009
  • 13. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Friday, May 22, 2009
  • 14. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Friday, May 22, 2009
  • 15. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 XML mapeia POJO comum Friday, May 22, 2009
  • 16. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 método execute() obrigatório qdo nenhuma configuração é feita no XML Friday, May 22, 2009
  • 17. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 o retorno do método execute() revela o resultado da Action Friday, May 22, 2009
  • 18. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Action e struts.xml libs web.xml *.html *.jsp Friday, May 22, 2009
  • 19. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 At a glance Friday, May 22, 2009
  • 20. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 http:// servidor/ app/ action Friday, May 22, 2009
  • 21. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 http:// servidor/ app/ action ? Friday, May 22, 2009
  • 22. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Struts 1.x Friday, May 22, 2009
  • 23. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Struts 1.x ? Friday, May 22, 2009
  • 24. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 http:// servidor/ FrontController! app/ action Friday, May 22, 2009
  • 25. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 web.xml <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> Friday, May 22, 2009
  • 26. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Estratégia de Mapeamento de Actions Friday, May 22, 2009
  • 27. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Estratégia de Mapeamento de Actions http://localhost:8080/app/entrar LoginAction.execute() Friday, May 22, 2009
  • 28. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Estratégia de Mapeamento de Actions http://localhost:8080/app/entrar LoginAction.execute() Friday, May 22, 2009
  • 29. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Estratégia de Mapeamento de Actions http://localhost:8080/app/entrar LoginAction.execute() <action name=quot;entrarquot; class=quot;xpto.LoginActionquot;/> Friday, May 22, 2009
  • 30. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Estratégia de Mapeamento de Actions http://localhost:8080/app/entrar ControleDeAcessoAction.login() <action name=quot;entrarquot; method=quot;loginquot; class=quot;xpto.ControleDeAcessoActionquot;/> Friday, May 22, 2009
  • 31. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Estratégia de Mapeamento de Actions http://localhost:8080/app/entrar ControleDeAcessoAction.login() <action name=quot;entrarquot; method=quot;loginquot; class=quot;xpto.ControleDeAcessoActionquot;/> Friday, May 22, 2009
  • 32. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Estratégia de Mapeamento de Actions Patterns Matching http://localhost:8080/app/acesso_login ControleDeAcessoAction.login() Friday, May 22, 2009
  • 33. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Estratégia de Mapeamento de Actions Patterns Matching http://localhost:8080/app/acesso_login ControleDeAcessoAction.login() Friday, May 22, 2009
  • 34. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Estratégia de Mapeamento de Actions Patterns Matching http://localhost:8080/app/acesso_login ControleDeAcessoAction.login() Friday, May 22, 2009
  • 35. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Estratégia de Mapeamento de Actions Patterns Matching http://localhost:8080/app/acesso_login ControleDeAcessoAction.login() <action name=quot;acesso_ *quot; method=quot; {1}quot; class=quot;xpto.ControleDeAcessoActionquot;/> Friday, May 22, 2009
  • 36. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Friday, May 22, 2009
  • 37. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Friday, May 22, 2009
  • 38. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Estratégia de Mapeamento de Actions Patterns Matching http://localhost:8080/app/Usuario/edit UsuarioAction.edit() Friday, May 22, 2009
  • 39. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Estratégia de Mapeamento de Actions Patterns Matching http://localhost:8080/app/Usuario/edit UsuarioAction.edit() Friday, May 22, 2009
  • 40. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Estratégia de Mapeamento de Actions Patterns Matching http://localhost:8080/app/Usuario/edit UsuarioAction.edit() Friday, May 22, 2009
  • 41. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Estratégia de Mapeamento de Actions Patterns Matching http://localhost:8080/app/Usuario/edit UsuarioAction.edit() <action name=quot; */*quot; method=quot; {2}quot; class=quot;xpto. {1}Actionquot;/> Friday, May 22, 2009
  • 42. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Binding Friday, May 22, 2009
  • 43. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Dados de Requisição usuario=alegomes senha=123456 Friday, May 22, 2009
  • 44. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Nada de ActionForms! bind automático Friday, May 22, 2009
  • 46. setUsuario(“alegomes”); setSenha(“123456”); Friday, May 22, 2009
  • 47. setUsuario(“alegomes”); setSenha(“123456”); Friday, May 22, 2009
  • 51. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Testabilidade Como Actions são POJOS, nenhuma infra-estrutura mágica é necessária para implementação de testes unitários. Friday, May 22, 2009
  • 52. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Friday, May 22, 2009
  • 53. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Tags Friday, May 22, 2009
  • 54. http:// servidor/ app/ action login.jsp menu.jsp Friday, May 22, 2009
  • 55. struts.xml <action name=quot;login_*quot; method=quot;{1}quot; class=quot;br.ucb.soo.wa.struts2.lab3.LoginActionquot;> <result name=quot;loginOKquot;>menu.jsp</result> <result name=quot;loginNOKquot;>login.jsp</result> </action> LoginAction.java public class LoginAction { public static final String USUARIO_ESPERADO = quot;alegomesquot;; public static final String SENHA_ESPERADA = quot;123456quot;; private String usuario; private String senha; public String autenticar() { if (USUARIO_ESPERADO.equals(usuario) && SENHA_ESPERADA.equals(senha)) { return quot;loginOKquot;; } else { return quot;loginNOKquot;; } } //Gets e Sets } Friday, May 22, 2009
  • 56. struts.xml <action name=quot;login_*quot; method=quot;{1}quot; class=quot;br.ucb.soo.wa.struts2.lab3.LoginActionquot;> <result name=quot;loginOKquot;>menu.jsp</result> <result name=quot;loginNOKquot;>login.jsp</result> </action> LoginAction.java public class LoginAction { public static final String USUARIO_ESPERADO = quot;alegomesquot;; public static final String SENHA_ESPERADA = quot;123456quot;; private String usuario; private String senha; public String autenticar() { if (USUARIO_ESPERADO.equals(usuario) && SENHA_ESPERADA.equals(senha)) { return quot;loginOKquot;; } else { return quot;loginNOKquot;; } } //Gets e Sets } Friday, May 22, 2009
  • 57. senha correta <title>Menu do Sistema</title> </head> <body> <h1>Seja bem vindo.</h1> Escolha uma das abaixo. <ul> <li><a href=quot;servico_f1quot;>Funcionalidade 1</a></li> <li><a href=quot;servico_f1quot;>Funcionalidade 2</a></li> <li><a href=quot;servico_f1quot;>Funcionalidade 3</a></li> <li><a href=quot;servico_f1quot;>Funcionalidade 4</a></li> </ul> </body> </html> menu.jsp Friday, May 22, 2009
  • 58. senha errada <title>Tela de Autenticação</title> </head> <body> <form action=quot;login_autenticarquot;> Login: <input type=quot;textquot; value=quot;quot;/><p/> Senha: <input type=quot;passwordquot; value=quot;quot;/><p/> <input type=quot;submitquot;/> </form> </body> login.jsp Friday, May 22, 2009
  • 59. <h1>Seja bem vindo, <s:property value=quot;usuarioquot; />.</h1> Friday, May 22, 2009
  • 60. <h1>Seja bem vindo, <s:property value=quot;usuarioquot; />.</h1> Friday, May 22, 2009
  • 61. <s:form action=quot;login_autenticarquot;> <s:textfield label=quot;Loginquot; name=quot;usuarioquot;/> <s:password label=quot;Senhaquot; name=quot;senhaquot; /> <s:submit/> </s:form> Friday, May 22, 2009
  • 67. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Results & Result Types Friday, May 22, 2009
  • 68. http:// servidor/ app/ action login.vt menu.jsp Friday, May 22, 2009
  • 69. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Results implementação da Camada View Resposta da Action Friday, May 22, 2009
  • 70. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Results login.jsp menu.jsp Velocity Freemarker XSTL Action Friday, May 22, 2009
  • 71. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Result Types Velocity Freemarker XSTL <action name=quot;qqcoisa*quot; method=quot;{1}quot; class=quot;br.ucb.soo.wa.struts2.lab3.QQActionquot;> <result name=quot;result1quot;>menu.jsp</result> <result name=quot;result1quot; type=”dispatcher”>some.jsp</result> <result name=quot;result2quot; type=”freemarker”>login.ftl</result> <result name=quot;result3quot; type=”velocity”>page.vt</result> </action> Friday, May 22, 2009
  • 72. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Result Types customizados public interface Result extends Serializable { public void execute(ActionInvocation invocation) throws Exception; } <result-types> <result-type name=quot;dispatcherquot; default=quot;truequot; class=quot;seu.pacote.SuaClassequot;/> </result-types> Friday, May 22, 2009
  • 73. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Dependency Injection Friday, May 22, 2009
  • 74. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Interceptors Friday, May 22, 2009
  • 75. http:// servidor/ app/ action Friday, May 22, 2009
  • 76. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Revisão Intercepting Filters Friday, May 22, 2009
  • 77. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Revisão Intercepting Filters interceptors action interceptors Friday, May 22, 2009
  • 78. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Interceptors pra quê? Tratamento de exceção Evitar submit duplo Upload de arquivo Ciclo de vida Validações http://struts.apache.org/2.1.6/docs/interceptors.html Friday, May 22, 2009
  • 79. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Interceptors <package name=quot;defaultquot; extends=quot;struts-defaultquot;> <interceptors> <interceptor name=quot;timerquot; class=quot;...quot;/> <interceptor name=quot;loggerquot; class=quot;...quot;/> </interceptors> <action name=quot;loginquot; class=quot;tutorial.Loginquot;> <interceptor-ref name=quot;timerquot;/> <interceptor-ref name=quot;loggerquot;/> <result name=quot;inputquot;>login.jsp</result> <result name=quot;successquot; type=quot;redirectActionquot;>/secure/home</result> </action> </package> Friday, May 22, 2009
  • 80. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Pacotes de Interceptors <package name=quot;defaultquot; extends=quot;struts-defaultquot;> <interceptors> <interceptor name=quot;timerquot; class=quot;..quot;/> <interceptor name=quot;loggerquot; class=quot;..quot;/> <interceptor-stack name=quot;myStackquot;> <interceptor-ref name=quot;timerquot;/> <interceptor-ref name=quot;loggerquot;/> </interceptor-stack> </interceptors> <action name=quot;loginquot; class=quot;tutuorial.Loginquot;> <interceptor-ref name=quot;myStackquot;/> <result name=quot;inputquot;>login.jsp</result> <result name=quot;successquot; type=quot;redirectActionquot;>/secure/home</result> </action> </package> Friday, May 22, 2009
  • 81. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Interceptors <interceptor name=quot;aliasquot; class=quot;com.opensymphony.xwork2.interceptor.AliasInterceptorquot;/> <interceptor name=quot;autowiringquot; class=quot;com.opensymphony.xwork2.spring.interceptor.ActionAutowiringInterceptorquot;/> <interceptor name=quot;chainquot; class=quot;com.opensymphony.xwork2.interceptor.ChainingInterceptorquot;/> <interceptor name=quot;conversionErrorquot; class=quot;org.apache.struts2.interceptor.StrutsConversionErrorInterceptorquot;/> <interceptor name=quot;clearSessionquot; class=quot;org.apache.struts2.interceptor.ClearSessionInterceptorquot; /> <interceptor name=quot;createSessionquot; class=quot;org.apache.struts2.interceptor.CreateSessionInterceptorquot; /> <interceptor name=quot;debuggingquot; class=quot;org.apache.struts2.interceptor.debugging.DebuggingInterceptorquot; /> <interceptor name=quot;externalRefquot; class=quot;com.opensymphony.xwork2.interceptor.ExternalReferencesInterceptorquot;/> <interceptor name=quot;execAndWaitquot; class=quot;org.apache.struts2.interceptor.ExecuteAndWaitInterceptorquot;/> <interceptor name=quot;exceptionquot; class=quot;com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptorquot;/> <interceptor name=quot;fileUploadquot; class=quot;org.apache.struts2.interceptor.FileUploadInterceptorquot;/> <interceptor name=quot;i18nquot; class=quot;com.opensymphony.xwork2.interceptor.I18nInterceptorquot;/> <interceptor name=quot;loggerquot; class=quot;com.opensymphony.xwork2.interceptor.LoggingInterceptorquot;/> <interceptor name=quot;modelDrivenquot; class=quot;com.opensymphony.xwork2.interceptor.ModelDrivenInterceptorquot;/> <interceptor name=quot;scopedModelDrivenquot; class=quot;com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptorquot;/> <interceptor name=quot;paramsquot; class=quot;com.opensymphony.xwork2.interceptor.ParametersInterceptorquot;/> <interceptor name=quot;actionMappingParamsquot; class=quot;org.apache.struts2.interceptor.ActionMappingParametersInteceptorquot;/> <interceptor name=quot;preparequot; class=quot;com.opensymphony.xwork2.interceptor.PrepareInterceptorquot;/> <interceptor name=quot;staticParamsquot; class=quot;com.opensymphony.xwork2.interceptor.StaticParametersInterceptorquot;/> <interceptor name=quot;scopequot; class=quot;org.apache.struts2.interceptor.ScopeInterceptorquot;/> <interceptor name=quot;servletConfigquot; class=quot;org.apache.struts2.interceptor.ServletConfigInterceptorquot;/> <interceptor name=quot;sessionAutowiringquot; class=quot;org.apache.struts2.spring.interceptor.SessionContextAutowiringInterceptorquot;/> <interceptor name=quot;timerquot; class=quot;com.opensymphony.xwork2.interceptor.TimerInterceptorquot;/> <interceptor name=quot;tokenquot; class=quot;org.apache.struts2.interceptor.TokenInterceptorquot;/> <interceptor name=quot;tokenSessionquot; class=quot;org.apache.struts2.interceptor.TokenSessionStoreInterceptorquot;/> <interceptor name=quot;validationquot; class=quot;org.apache.struts2.interceptor.validation.AnnotationValidationInterceptorquot;/> <interceptor name=quot;workflowquot; class=quot;com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptorquot;/> <interceptor name=quot;storequot; class=quot;org.apache.struts2.interceptor.MessageStoreInterceptorquot; /> <interceptor name=quot;checkboxquot; class=quot;org.apache.struts2.interceptor.CheckboxInterceptorquot; /> <interceptor name=quot;profilingquot; class=quot;org.apache.struts2.interceptor.ProfilingActivationInterceptorquot; /> <interceptor name=quot;rolesquot; class=quot;org.apache.struts2.interceptor.RolesInterceptorquot; /> <interceptor name=quot;jsonValidationquot; class=quot;org.apache.struts2.interceptor.validation.JSONValidationInterceptorquot; /> <interceptor name=quot;annotationWorkflowquot; class=quot;com.opensymphony.xwork2.interceptor.annotations.AnnotationWorkflowInterceptorquot; /> Friday, May 22, 2009
  • 82. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Exemplo <action name=quot;login_*quot; method=quot;{1}quot; class=quot;br.ucb.soo.wa.struts2.lab3.LoginActionquot;> <interceptor-ref name=quot;loggerquot;/> <result name=quot;loginOKquot;>menu.jsp</result> <result name=quot;loginNOKquot;>login.jsp</result> </action> May 15, 2009 11:39:22 AM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info INFO: Starting execution stack for action //login_autenticar May 15, 2009 11:39:22 AM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info INFO: Finishing execution stack for action //login_autenticar Friday, May 22, 2009
  • 83. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Interceptors coisas muito mais complexas podem ser feitas... Friday, May 22, 2009
  • 84. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Interceptors coisas muito mais complexas podem ser feitas... ...e precisam ser testadas! Friday, May 22, 2009
  • 85. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Testes Direto na Action :-/ Friday, May 22, 2009
  • 86. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Friday, May 22, 2009
  • 87. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Friday, May 22, 2009
  • 88. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Testes Action Proxied :-) Friday, May 22, 2009
  • 91. Ambos os sites propõem classes da apoio aos testes Friday, May 22, 2009
  • 93. // create action context for my action, feed // into the action context all request parameters Map requestParameters = new HashMap(); requestParameters.put(quot;param1quot;, quot;param1-valuequot;); requestParameters.put(quot;param2quot;, quot;param2-valuequot;); Map actionContext = StrutsTestCaseSupport.getInstance().buildActionContext( quot;my.hostname.comquot;, quot;getquot;, quot;/myActionNamespace/myActionNamequot;, requestParameters); // create the proxy for the action, this encapsulates all // the interception stack up to the real action ActionProxy proxy = StrutsTestCaseSupport.getInstance().createActionProxy( quot;myActionNamequot;, quot;myActionNameSpacequot;,actionContext); // inject parameters as required // let the full stack run String result = proxy.execute(); // confirm result assert result.equals(quot;myTestResponseStringquot;); // look into mock HttpServletResponse, do whatever // tests I need to do: returned HTML, returned headers, // cookies, etc... String responseXml = ((MockHttpServletResponse) actionContext.get(StrutsStatics.HTTP_RESPONSE)).getContentAsString(); assert responseXml.indexOf(quot;successquot;) != -1; http://fassisrosa.blogspot.com/2006/11/unit-testing-struts-20.html Friday, May 22, 2009
  • 94. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Struts2 testes org.apache.struts2.util.StrutsTestCaseHelper Generic test setup methods to be used with any unit testing framework. com.opensymphony.xwork2.TestNGXWorkTestCase Base test class for TestNG unit tests. Provides common XWork variables and performs XWork setup and teardown processes com.opensymphony.xwork2.XWorkTestCase Base JUnit TestCase to extend for XWork specific JUnit tests. Uses the generic test setup for logic. com.opensymphony.xwork2.util.XWorkTestCaseHelper Generic test setup methods to be used with any unit testing framework. Friday, May 22, 2009
  • 95. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Include Mecanismo para modularização das configurações. Friday, May 22, 2009
  • 96. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Include <struts> <include file=quot;billing-config.xmlquot; /> <include file=quot;admin-config.xmlquot; /> <include file=quot;reports-config.xmlquot; /> ... </struts> struts-default.xml e struts-plugin.xml são incluídos implicitamente em todo struts.xml Friday, May 22, 2009
  • 97. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Packages Mecanismo para organização lógica e reaproveitamento de configurações Friday, May 22, 2009
  • 98. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Packages <struts> <package name=quot;exemploquot; extends=quot;struts-defaultquot;> <action name=quot;login_*quot; method=quot;{1}quot; class=quot;br.ucb.soo.wa.struts2.lab3.LoginActionquot;> <interceptor-ref name=quot;loggerquot;/> <result name=quot;loginOKquot;>menu.jsp</result> <result name=quot;loginNOKquot;>login.jsp</result> </action> <action name=quot;logout/*quot; class=quot;br.ucb.soo.wa.struts2.lab3.LogoutActionquot;> <result>{1}.jsp</result> </action> </package> </struts> Friday, May 22, 2009
  • 99. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Validators Verificação declarativa de campos Friday, May 22, 2009
  • 100. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Bundled Validators conversion validator date validator double validator email validator expression validator fieldexpression validator int validator regex validator required validator requiredstring validator stringlength validator url validator visitor validator http://struts.apache.org/2.1.6/docs/validation.html Friday, May 22, 2009
  • 101. <interceptor name=quot;validationquot; class=quot;org.apache.struts2.interceptor.validation.AnnotationValidationInterceptorquot;/> struts.xml Friday, May 22, 2009
  • 102. <interceptor name=quot;validationquot; class=quot;org.apache.struts2.interceptor.validation.AnnotationValidationInterceptorquot;/> struts-default.xml <interceptor-ref name=quot;validationquot; /> struts.xml Friday, May 22, 2009
  • 104. <body> <s:form action=quot;login_autenticarquot; validate=quot;truequot;> <s:textfield label=quot;Loginquot; name=quot;usuarioquot;/> <s:password label=quot;Senhaquot; name=quot;senhaquot; /> <s:submit/> </s:form> </body> login.jsp Friday, May 22, 2009
  • 105. <validators> <field name=quot;usuarioquot;> <field-validator type=quot;requiredstringquot;> <message>Nome de usuario obrigatorio!</message> </field-validator> </field> <field name=quot;senhaquot;> <field-validator type=quot;requiredstringquot;> <message>Senha obrigatoria!</message> </field-validator> </field> </validators> br/ucb/soo/wa/struts2/lab3/LoginAction-validation.xml Friday, May 22, 2009
  • 106. <validators> <field name=quot;usuarioquot;> <field-validator type=quot;requiredstringquot;> <message>Nome de usuario obrigatorio!</message> </field-validator> </field> <field name=quot;senhaquot;> <field-validator type=quot;requiredstringquot;> <message>Senha obrigatoria!</message> </field-validator> </field> </validators> br/ucb/soo/wa/struts2/lab3/LoginAction-validation.xml Friday, May 22, 2009
  • 107. <validators> <field name=quot;usuarioquot;> <field-validator type=quot;requiredstringquot;> <message>Nome de usuario obrigatorio!</message> </field-validator> </field> <field name=quot;senhaquot;> <field-validator type=quot;requiredstringquot;> <message>Senha obrigatoria!</message> </field-validator> </field> </validators> br/ucb/soo/wa/struts2/lab3/LoginAction-validation.xml Friday, May 22, 2009
  • 108. <validators> <field name=quot;usuarioquot;> <field-validator type=quot;requiredstringquot;> <message>Nome de usuario obrigatorio!</message> </field-validator> </field> <field name=quot;senhaquot;> <field-validator type=quot;requiredstringquot;> <message>Senha obrigatoria!</message> </field-validator> </field> </validators> br/ucb/soo/wa/struts2/lab3/LoginAction-validation.xml Friday, May 22, 2009
  • 109. <validators> <field name=quot;usuarioquot;> <field-validator type=quot;requiredstringquot;> <message>Nome de usuario obrigatorio!</message> </field-validator> </field> <field name=quot;senhaquot;> <field-validator type=quot;requiredstringquot;> <message>Senha obrigatoria!</message> </field-validator> </field> </validators> br/ucb/soo/wa/struts2/lab3/LoginAction-validation.xml Friday, May 22, 2009
  • 111. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Friday, May 22, 2009
  • 112. Friday, May 22, 2009 http://cwiki.apache.org/confluence/display/WW/Big+Picture
  • 113. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Afinal, por que Struts2? • Baseado em Actions • Configurações - XML e Annotations • Actions POJO - alta testabilidade • Integrável - Spring, SiteMesh e Tiles • Opções de View - JSP, Freemarker, Velocity e XSLT Friday, May 22, 2009 • Plugável
  • 114. Lato Sensu em Sistemas Orientados a Objetos Desenvolvimento de Aplicaões Web Avançado - 1°/2009 Labs “The Bootstap tutorials starts from the very beginning and steps through creating a simple application.” http://struts.apache.org/2.x/docs/bootstrap.html Friday, May 22, 2009
  • 115. Lato Sensu em Sistemas Orientados a Objetos Q&A MSc. Alexandre Gomes alegomes@gmail.com Friday, May 22, 2009