Request Parameter not being set on Action

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Request Parameter not being set on Action

Rubens Gomes-4
The request below is sent , but the parameters (request_locale/pageUrl) are not set on the action.  

http://localhost:8080/change-locale.do?request_locale=en&pageUrl=%2Fview-login.do

I am using the defaultStack which includes both the param and actionmapping interceptors.  

I am running Struts 2 (2.5.10.1) with Spring Boot (1.5.6.RELEASE) as a war application (Tomcat embedded).  

While debugging the ParametersInterceptor I see the following:

action: com.ezlista.web.struts2.action.ChangeLocaleAction@a5da385
HttpParameters parameters: {pageUrl=/view-login.do}
setParameters(action, stack, parameters);

I also see that the action mapping interceptor is being called with the above parameter; however, the action setter is not called.

P.S. I am *not* using the struts2+spring plugin because I had isssues when spring creates/manages the struts 2 actions.

Rubens
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Request Parameter not being set on Action

Lukasz Lenart
2017-08-02 8:34 GMT+02:00 Rubens Gomes <[hidden email]>:
> The request below is sent , but the parameters (request_locale/pageUrl) are not set on the action.
>
> http://localhost:8080/change-locale.do?request_locale=en&pageUrl=%2Fview-login.do

The "request_locale" parameter is a special parameter that tells
I18NInterceptor to change locale, it will be removed after that so you
cannot access it in an action.
If you need to access locale in an action and assuming your extending
the ActionSupport class just call the "getLocale()" method.

Regarding the "pageUrl" parameter, can you start with a simple
example? Or maybe post your struts.xml plus an action's class?



Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Request Parameter not being set on Action

Rubens Gomes-4
I noticed that the request_locale was not found, and that's fine.  However, the pageUrl was found in the HttpParameters and it is not being set on the action.  Below is the Action class and struts.xml:


@SuppressWarnings("serial")
@Results( {
  @Result(name=Action.INPUT,
          location="/WEB-INF/content/${device}/error.jsp",
          type="dispatcher"),
  @Result(name=Action.SUCCESS,
          location="${redirectURL}",
          type="redirect")
} )
public class ChangeLocaleAction extends BaseAction
{
    private String pageUrl;


    public ChangeLocaleAction()
    {
        super();
    }


    @Override
    public void validate()
    {

        if(StringUtils.isBlank(pageUrl))
        {
            addActionError( getText("error.urlmissing") );
        }

    }


    @Override
    public String execute()
    {

        try
        {
            pageUrl = URLDecoder.decode(pageUrl, "UTF-8");
            HttpServletRequest request = getRequest();

            if(request == null)
            {
                throw new IllegalArgumentException("HTTP request not found.");
            }

            /*
             * The redirect automatically inserts the context path.  We need
             * to remove the context path in redirectURL to prevent duplicate
             * contextPaths in the redirect.
             */
            String contextPath = request.getContextPath();

            if (pageUrl.startsWith(contextPath))
            {
                pageUrl = pageUrl.replaceFirst(contextPath, "");
                logger.debug("redirectURL set to [{}]", pageUrl);
            }

        }
        catch(UnsupportedEncodingException ex)
        {
            throw new RuntimeException("error decoding url: " + pageUrl, ex);
        }

        return SUCCESS;
    }


    /**
     * @return the pageUrl
     */
    public String getPageUrl()
    {
        return pageUrl;
    }


    /**
     * @param pageUrl the pageUrl to set
     */
    public void setPageUrl(String pageUrl)
    {
        this.pageUrl = pageUrl;
    }


}



<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
    "http://struts.apache.org/dtds/struts-2.5.dtd">

<struts>
  <constant name="struts.devMode" value="true" />

  <constant name="struts.action.extension" value="do" />

  <constant name="struts.convention.action.packages" value="com.ezlista.web.struts2.action" />
  <constant name="struts.convention.classes.reload" value="true" />
  <constant name="struts.convention.default.parent.package" value="ezlista-package" />
  <constant name="struts.convention.package.locators" value="action" />
  <constant name="struts.convention.package.locators.basePackage" value="com.ezlista.web.struts2" />
  <constant name="struts.convention.result.path" value="/WEB-INF/content/"/>

  <constant name="struts.custom.i18n.resources" value="messages" />

  <constant name="struts.date.format" value="dd/MM/yyyy hh:mm" />

  <constant name="struts.freemarker.templatesCache" value="true" />

  <constant name="struts.i18n.encoding" value="UTF-8" />

  <constant name="struts.serve.static" value="true" />

  <constant name="struts.ui.theme" value="simple" />
  <constant name="struts.ui.templateDir" value="template" />


  <package name="ezlista-package" extends="json-default">

    <interceptors>

      <interceptor name="valueStack"
                   class="com.ezlista.web.struts2.interceptor.ValueStackInterceptor" />

      <interceptor-stack name="ezlistaStack">
        <interceptor-ref name="valueStack" />
        <interceptor-ref name="defaultStack">
          <param name="exception.logEnabled">true</param>
          <param name="exception.logLevel">ERROR</param>
          <param name="exception.logCategory">com.ezlista</param>
          <param name="params.excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*,^_csrf</param>
        </interceptor-ref>
      </interceptor-stack>

    </interceptors>

    <default-interceptor-ref name="ezlistaStack" />

    <default-action-ref name="default-action" />

    <global-results>
      <result name="login" type="redirectAction">/view-login.do</result>
      <result name="error">/WEB-INF/content/${device}/error.jsp</result>
      <result name="exception">/WEB-INF/content/${device}/error.jsp</result>
      <result name="warning">/WEB-INF/content/${device}/warning.jsp</result>
    </global-results>

    <global-exception-mappings>
      <exception-mapping exception="java.lang.Exception" result="exception" />
    </global-exception-mappings>

    <action name="default-action" class="com.ezlista.web.struts2.action.DefaultAction" />

  </package>


  <package name="home" extends="ezlista-package" namespace="/">

    <action name="about" class="com.ezlista.web.struts2.action.DummyAction">
      <result>/WEB-INF/content/${device}/about.jsp</result>
    </action>

    <action name="help" class="com.ezlista.web.struts2.action.DummyAction">
      <result>/WEB-INF/content/${device}/help.jsp</result>
    </action>

    <action name="language-help" class="com.ezlista.web.struts2.action.DummyAction">
      <result>/WEB-INF/content/${device}/language-help.jsp</result>
    </action>

    <action name="pending-email-help" class="com.ezlista.web.struts2.action.DummyAction">
      <result>/WEB-INF/content/${device}/pending-email-help.jsp</result>
    </action>

    <action name="privacy" class="com.ezlista.web.struts2.action.DummyAction">
      <result>/WEB-INF/content/${device}/privacy.jsp</result>
    </action>

    <action name="remember-help" class="com.ezlista.web.struts2.action.DummyAction">
      <result>/WEB-INF/content/${device}/remember-help.jsp</result>
    </action>

    <action name="terms" class="com.ezlista.web.struts2.action.DummyAction">
      <result>/WEB-INF/content/${device}/terms.jsp</result>
    </action>

    <action name="terms-service" class="com.ezlista.web.struts2.action.DummyAction">
      <result>/WEB-INF/content/${device}/terms-service.jsp</result>
    </action>

    <action name="view-session-timeout" class="com.ezlista.web.struts2.action.DummyAction">
      <result>/WEB-INF/content/${device}/session-timeout.jsp</result>
    </action>

  </package>


</struts>








________________________________________
From: Lukasz Lenart <[hidden email]>
Sent: Wednesday, August 2, 2017 5:01 AM
To: Struts Users Mailing List
Subject: Re: Request Parameter not being set on Action

2017-08-02 8:34 GMT+02:00 Rubens Gomes <[hidden email]>:
> The request below is sent , but the parameters (request_locale/pageUrl) are not set on the action.
>
> http://localhost:8080/change-locale.do?request_locale=en&pageUrl=%2Fview-login.do

The "request_locale" parameter is a special parameter that tells
I18NInterceptor to change locale, it will be removed after that so you
cannot access it in an action.
If you need to access locale in an action and assuming your extending
the ActionSupport class just call the "getLocale()" method.

Regarding the "pageUrl" parameter, can you start with a simple
example? Or maybe post your struts.xml plus an action's class?



Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Request Parameter not being set on Action

Lukasz Lenart
What does the ValueStackInterceptor do?

2017-08-02 16:23 GMT+02:00 Rubens Gomes <[hidden email]>:

> I noticed that the request_locale was not found, and that's fine.  However, the pageUrl was found in the HttpParameters and it is not being set on the action.  Below is the Action class and struts.xml:
>
>
> @SuppressWarnings("serial")
> @Results( {
>   @Result(name=Action.INPUT,
>           location="/WEB-INF/content/${device}/error.jsp",
>           type="dispatcher"),
>   @Result(name=Action.SUCCESS,
>           location="${redirectURL}",
>           type="redirect")
> } )
> public class ChangeLocaleAction extends BaseAction
> {
>     private String pageUrl;
>
>
>     public ChangeLocaleAction()
>     {
>         super();
>     }
>
>
>     @Override
>     public void validate()
>     {
>
>         if(StringUtils.isBlank(pageUrl))
>         {
>             addActionError( getText("error.urlmissing") );
>         }
>
>     }
>
>
>     @Override
>     public String execute()
>     {
>
>         try
>         {
>             pageUrl = URLDecoder.decode(pageUrl, "UTF-8");
>             HttpServletRequest request = getRequest();
>
>             if(request == null)
>             {
>                 throw new IllegalArgumentException("HTTP request not found.");
>             }
>
>             /*
>              * The redirect automatically inserts the context path.  We need
>              * to remove the context path in redirectURL to prevent duplicate
>              * contextPaths in the redirect.
>              */
>             String contextPath = request.getContextPath();
>
>             if (pageUrl.startsWith(contextPath))
>             {
>                 pageUrl = pageUrl.replaceFirst(contextPath, "");
>                 logger.debug("redirectURL set to [{}]", pageUrl);
>             }
>
>         }
>         catch(UnsupportedEncodingException ex)
>         {
>             throw new RuntimeException("error decoding url: " + pageUrl, ex);
>         }
>
>         return SUCCESS;
>     }
>
>
>     /**
>      * @return the pageUrl
>      */
>     public String getPageUrl()
>     {
>         return pageUrl;
>     }
>
>
>     /**
>      * @param pageUrl the pageUrl to set
>      */
>     public void setPageUrl(String pageUrl)
>     {
>         this.pageUrl = pageUrl;
>     }
>
>
> }
>
>
>
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE struts PUBLIC
>     "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
>     "http://struts.apache.org/dtds/struts-2.5.dtd">
>
> <struts>
>   <constant name="struts.devMode" value="true" />
>
>   <constant name="struts.action.extension" value="do" />
>
>   <constant name="struts.convention.action.packages" value="com.ezlista.web.struts2.action" />
>   <constant name="struts.convention.classes.reload" value="true" />
>   <constant name="struts.convention.default.parent.package" value="ezlista-package" />
>   <constant name="struts.convention.package.locators" value="action" />
>   <constant name="struts.convention.package.locators.basePackage" value="com.ezlista.web.struts2" />
>   <constant name="struts.convention.result.path" value="/WEB-INF/content/"/>
>
>   <constant name="struts.custom.i18n.resources" value="messages" />
>
>   <constant name="struts.date.format" value="dd/MM/yyyy hh:mm" />
>
>   <constant name="struts.freemarker.templatesCache" value="true" />
>
>   <constant name="struts.i18n.encoding" value="UTF-8" />
>
>   <constant name="struts.serve.static" value="true" />
>
>   <constant name="struts.ui.theme" value="simple" />
>   <constant name="struts.ui.templateDir" value="template" />
>
>
>   <package name="ezlista-package" extends="json-default">
>
>     <interceptors>
>
>       <interceptor name="valueStack"
>                    class="com.ezlista.web.struts2.interceptor.ValueStackInterceptor" />
>
>       <interceptor-stack name="ezlistaStack">
>         <interceptor-ref name="valueStack" />
>         <interceptor-ref name="defaultStack">
>           <param name="exception.logEnabled">true</param>
>           <param name="exception.logLevel">ERROR</param>
>           <param name="exception.logCategory">com.ezlista</param>
>           <param name="params.excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*,^_csrf</param>
>         </interceptor-ref>
>       </interceptor-stack>
>
>     </interceptors>
>
>     <default-interceptor-ref name="ezlistaStack" />
>
>     <default-action-ref name="default-action" />
>
>     <global-results>
>       <result name="login" type="redirectAction">/view-login.do</result>
>       <result name="error">/WEB-INF/content/${device}/error.jsp</result>
>       <result name="exception">/WEB-INF/content/${device}/error.jsp</result>
>       <result name="warning">/WEB-INF/content/${device}/warning.jsp</result>
>     </global-results>
>
>     <global-exception-mappings>
>       <exception-mapping exception="java.lang.Exception" result="exception" />
>     </global-exception-mappings>
>
>     <action name="default-action" class="com.ezlista.web.struts2.action.DefaultAction" />
>
>   </package>
>
>
>   <package name="home" extends="ezlista-package" namespace="/">
>
>     <action name="about" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/about.jsp</result>
>     </action>
>
>     <action name="help" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/help.jsp</result>
>     </action>
>
>     <action name="language-help" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/language-help.jsp</result>
>     </action>
>
>     <action name="pending-email-help" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/pending-email-help.jsp</result>
>     </action>
>
>     <action name="privacy" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/privacy.jsp</result>
>     </action>
>
>     <action name="remember-help" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/remember-help.jsp</result>
>     </action>
>
>     <action name="terms" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/terms.jsp</result>
>     </action>
>
>     <action name="terms-service" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/terms-service.jsp</result>
>     </action>
>
>     <action name="view-session-timeout" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/session-timeout.jsp</result>
>     </action>
>
>   </package>
>
>
> </struts>
>
>
>
>
>
>
>
>
> ________________________________________
> From: Lukasz Lenart <[hidden email]>
> Sent: Wednesday, August 2, 2017 5:01 AM
> To: Struts Users Mailing List
> Subject: Re: Request Parameter not being set on Action
>
> 2017-08-02 8:34 GMT+02:00 Rubens Gomes <[hidden email]>:
>> The request below is sent , but the parameters (request_locale/pageUrl) are not set on the action.
>>
>> http://localhost:8080/change-locale.do?request_locale=en&pageUrl=%2Fview-login.do
>
> The "request_locale" parameter is a special parameter that tells
> I18NInterceptor to change locale, it will be removed after that so you
> cannot access it in an action.
> If you need to access locale in an action and assuming your extending
> the ActionSupport class just call the "getLocale()" method.
>
> Regarding the "pageUrl" parameter, can you start with a simple
> example? Or maybe post your struts.xml plus an action's class?
>
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Request Parameter not being set on Action

Rubens Gomes-4
below is the ValueStackInterceptor code - it places a "device" property String in the stack.  I also noticed an additional problem with another action that is handling parameters submitted from a form (HTTP POST request).  The Param Interceptor (?) is setting those form  properties to "null" in the action.  However, the properties are being populated with values on the form.  Why is "null" being passed to the setter?

package com.ezlista.web.struts2.interceptor;

import static com.ezlista.common.Constants.DEVICE_SELECTED_KEY;

import java.lang.invoke.MethodHandles;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ezlista.common.AppUtils;
import com.ezlista.web.session.UserSession;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.util.ValueStack;

/**
 * Interceptor to update the ValueStack with some required data needed by the OGNL
 * framework.
 *
 * @author  Rubens Gomes
 */
@SuppressWarnings("serial")
public class ValueStackInterceptor extends AbstractInterceptor
{
    static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

    public ValueStackInterceptor()
    {
        super();
        logger.debug("Constructed");

    }

    @Override
    public String intercept(ActionInvocation invocation) throws Exception
    {
        logger.debug("Inside the ValueStackInterceptor interceptor...");

        ActionContext actionContext = ServletActionContext.getContext();

        if(actionContext == null)
        {
            logger.error("Struts2 ActionContext not found inside ValueStackInterceptor");
            throw new IllegalStateException("ActionContext not found.");
        }


        ValueStack stack = actionContext.getValueStack();

        if(stack == null)
        {
            logger.error("Struts2 OGNL value stack not found inside ActionContext");
            throw new IllegalStateException("OGNL Struts2 ValueStack not found.");
        }

        HttpServletRequest request = ServletActionContext.getRequest();

        logger.debug("retrieving detected device from the userSession...");

        UserSession userSession = AppUtils.getUserSession(request);

        String deviceSelected = userSession.getDevice();
        logger.info("Device [{}] determined from UserSession", deviceSelected);

        logger.info("Storing device [{}] in ValueStack", deviceSelected);
        stack.set(DEVICE_SELECTED_KEY, deviceSelected);

        /* --- Reverse Path --- */
        return invocation.invoke();
    }

}


Sent from Outlook
________________________________________
From: Lukasz Lenart <[hidden email]>
Sent: Thursday, August 3, 2017 4:52 AM
To: Struts Users Mailing List
Subject: Re: Request Parameter not being set on Action

What does the ValueStackInterceptor do?

2017-08-02 16:23 GMT+02:00 Rubens Gomes <[hidden email]>:

> I noticed that the request_locale was not found, and that's fine.  However, the pageUrl was found in the HttpParameters and it is not being set on the action.  Below is the Action class and struts.xml:
>
>
> @SuppressWarnings("serial")
> @Results( {
>   @Result(name=Action.INPUT,
>           location="/WEB-INF/content/${device}/error.jsp",
>           type="dispatcher"),
>   @Result(name=Action.SUCCESS,
>           location="${redirectURL}",
>           type="redirect")
> } )
> public class ChangeLocaleAction extends BaseAction
> {
>     private String pageUrl;
>
>
>     public ChangeLocaleAction()
>     {
>         super();
>     }
>
>
>     @Override
>     public void validate()
>     {
>
>         if(StringUtils.isBlank(pageUrl))
>         {
>             addActionError( getText("error.urlmissing") );
>         }
>
>     }
>
>
>     @Override
>     public String execute()
>     {
>
>         try
>         {
>             pageUrl = URLDecoder.decode(pageUrl, "UTF-8");
>             HttpServletRequest request = getRequest();
>
>             if(request == null)
>             {
>                 throw new IllegalArgumentException("HTTP request not found.");
>             }
>
>             /*
>              * The redirect automatically inserts the context path.  We need
>              * to remove the context path in redirectURL to prevent duplicate
>              * contextPaths in the redirect.
>              */
>             String contextPath = request.getContextPath();
>
>             if (pageUrl.startsWith(contextPath))
>             {
>                 pageUrl = pageUrl.replaceFirst(contextPath, "");
>                 logger.debug("redirectURL set to [{}]", pageUrl);
>             }
>
>         }
>         catch(UnsupportedEncodingException ex)
>         {
>             throw new RuntimeException("error decoding url: " + pageUrl, ex);
>         }
>
>         return SUCCESS;
>     }
>
>
>     /**
>      * @return the pageUrl
>      */
>     public String getPageUrl()
>     {
>         return pageUrl;
>     }
>
>
>     /**
>      * @param pageUrl the pageUrl to set
>      */
>     public void setPageUrl(String pageUrl)
>     {
>         this.pageUrl = pageUrl;
>     }
>
>
> }
>
>
>
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE struts PUBLIC
>     "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
>     "http://struts.apache.org/dtds/struts-2.5.dtd">
>
> <struts>
>   <constant name="struts.devMode" value="true" />
>
>   <constant name="struts.action.extension" value="do" />
>
>   <constant name="struts.convention.action.packages" value="com.ezlista.web.struts2.action" />
>   <constant name="struts.convention.classes.reload" value="true" />
>   <constant name="struts.convention.default.parent.package" value="ezlista-package" />
>   <constant name="struts.convention.package.locators" value="action" />
>   <constant name="struts.convention.package.locators.basePackage" value="com.ezlista.web.struts2" />
>   <constant name="struts.convention.result.path" value="/WEB-INF/content/"/>
>
>   <constant name="struts.custom.i18n.resources" value="messages" />
>
>   <constant name="struts.date.format" value="dd/MM/yyyy hh:mm" />
>
>   <constant name="struts.freemarker.templatesCache" value="true" />
>
>   <constant name="struts.i18n.encoding" value="UTF-8" />
>
>   <constant name="struts.serve.static" value="true" />
>
>   <constant name="struts.ui.theme" value="simple" />
>   <constant name="struts.ui.templateDir" value="template" />
>
>
>   <package name="ezlista-package" extends="json-default">
>
>     <interceptors>
>
>       <interceptor name="valueStack"
>                    class="com.ezlista.web.struts2.interceptor.ValueStackInterceptor" />
>
>       <interceptor-stack name="ezlistaStack">
>         <interceptor-ref name="valueStack" />
>         <interceptor-ref name="defaultStack">
>           <param name="exception.logEnabled">true</param>
>           <param name="exception.logLevel">ERROR</param>
>           <param name="exception.logCategory">com.ezlista</param>
>           <param name="params.excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*,^_csrf</param>
>         </interceptor-ref>
>       </interceptor-stack>
>
>     </interceptors>
>
>     <default-interceptor-ref name="ezlistaStack" />
>
>     <default-action-ref name="default-action" />
>
>     <global-results>
>       <result name="login" type="redirectAction">/view-login.do</result>
>       <result name="error">/WEB-INF/content/${device}/error.jsp</result>
>       <result name="exception">/WEB-INF/content/${device}/error.jsp</result>
>       <result name="warning">/WEB-INF/content/${device}/warning.jsp</result>
>     </global-results>
>
>     <global-exception-mappings>
>       <exception-mapping exception="java.lang.Exception" result="exception" />
>     </global-exception-mappings>
>
>     <action name="default-action" class="com.ezlista.web.struts2.action.DefaultAction" />
>
>   </package>
>
>
>   <package name="home" extends="ezlista-package" namespace="/">
>
>     <action name="about" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/about.jsp</result>
>     </action>
>
>     <action name="help" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/help.jsp</result>
>     </action>
>
>     <action name="language-help" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/language-help.jsp</result>
>     </action>
>
>     <action name="pending-email-help" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/pending-email-help.jsp</result>
>     </action>
>
>     <action name="privacy" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/privacy.jsp</result>
>     </action>
>
>     <action name="remember-help" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/remember-help.jsp</result>
>     </action>
>
>     <action name="terms" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/terms.jsp</result>
>     </action>
>
>     <action name="terms-service" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/terms-service.jsp</result>
>     </action>
>
>     <action name="view-session-timeout" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/session-timeout.jsp</result>
>     </action>
>
>   </package>
>
>
> </struts>
>
>
>
>
>
>
>
>
> ________________________________________
> From: Lukasz Lenart <[hidden email]>
> Sent: Wednesday, August 2, 2017 5:01 AM
> To: Struts Users Mailing List
> Subject: Re: Request Parameter not being set on Action
>
> 2017-08-02 8:34 GMT+02:00 Rubens Gomes <[hidden email]>:
>> The request below is sent , but the parameters (request_locale/pageUrl) are not set on the action.
>>
>> http://localhost:8080/change-locale.do?request_locale=en&pageUrl=%2Fview-login.do
>
> The "request_locale" parameter is a special parameter that tells
> I18NInterceptor to change locale, it will be removed after that so you
> cannot access it in an action.
> If you need to access locale in an action and assuming your extending
> the ActionSupport class just call the "getLocale()" method.
>
> Regarding the "pageUrl" parameter, can you start with a simple
> example? Or maybe post your struts.xml plus an action's class?
>
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Request Parameter not being set on Action

Rubens Gomes-4
BTW,  I just placed the entire source code in my personal GitHub below.  Please, notice that this code is still under development.  I am still working on some compiling errors with an action class (EditAccountAction.java /lista/src/main/java/com/ezlista/web/struts2/action/account).

https://github.com/rubensgomes/ezlista.com


________________________________________
From: Rubens Gomes <[hidden email]>
Sent: Thursday, August 3, 2017 12:43 PM
To: Struts Users Mailing List
Subject: Re: Request Parameter not being set on Action

below is the ValueStackInterceptor code - it places a "device" property String in the stack.  I also noticed an additional problem with another action that is handling parameters submitted from a form (HTTP POST request).  The Param Interceptor (?) is setting those form  properties to "null" in the action.  However, the properties are being populated with values on the form.  Why is "null" being passed to the setter?

package com.ezlista.web.struts2.interceptor;

import static com.ezlista.common.Constants.DEVICE_SELECTED_KEY;

import java.lang.invoke.MethodHandles;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ezlista.common.AppUtils;
import com.ezlista.web.session.UserSession;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.util.ValueStack;

/**
 * Interceptor to update the ValueStack with some required data needed by the OGNL
 * framework.
 *
 * @author  Rubens Gomes
 */
@SuppressWarnings("serial")
public class ValueStackInterceptor extends AbstractInterceptor
{
    static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

    public ValueStackInterceptor()
    {
        super();
        logger.debug("Constructed");

    }

    @Override
    public String intercept(ActionInvocation invocation) throws Exception
    {
        logger.debug("Inside the ValueStackInterceptor interceptor...");

        ActionContext actionContext = ServletActionContext.getContext();

        if(actionContext == null)
        {
            logger.error("Struts2 ActionContext not found inside ValueStackInterceptor");
            throw new IllegalStateException("ActionContext not found.");
        }


        ValueStack stack = actionContext.getValueStack();

        if(stack == null)
        {
            logger.error("Struts2 OGNL value stack not found inside ActionContext");
            throw new IllegalStateException("OGNL Struts2 ValueStack not found.");
        }

        HttpServletRequest request = ServletActionContext.getRequest();

        logger.debug("retrieving detected device from the userSession...");

        UserSession userSession = AppUtils.getUserSession(request);

        String deviceSelected = userSession.getDevice();
        logger.info("Device [{}] determined from UserSession", deviceSelected);

        logger.info("Storing device [{}] in ValueStack", deviceSelected);
        stack.set(DEVICE_SELECTED_KEY, deviceSelected);

        /* --- Reverse Path --- */
        return invocation.invoke();
    }

}


Sent from Outlook
________________________________________
From: Lukasz Lenart <[hidden email]>
Sent: Thursday, August 3, 2017 4:52 AM
To: Struts Users Mailing List
Subject: Re: Request Parameter not being set on Action

What does the ValueStackInterceptor do?

2017-08-02 16:23 GMT+02:00 Rubens Gomes <[hidden email]>:

> I noticed that the request_locale was not found, and that's fine.  However, the pageUrl was found in the HttpParameters and it is not being set on the action.  Below is the Action class and struts.xml:
>
>
> @SuppressWarnings("serial")
> @Results( {
>   @Result(name=Action.INPUT,
>           location="/WEB-INF/content/${device}/error.jsp",
>           type="dispatcher"),
>   @Result(name=Action.SUCCESS,
>           location="${redirectURL}",
>           type="redirect")
> } )
> public class ChangeLocaleAction extends BaseAction
> {
>     private String pageUrl;
>
>
>     public ChangeLocaleAction()
>     {
>         super();
>     }
>
>
>     @Override
>     public void validate()
>     {
>
>         if(StringUtils.isBlank(pageUrl))
>         {
>             addActionError( getText("error.urlmissing") );
>         }
>
>     }
>
>
>     @Override
>     public String execute()
>     {
>
>         try
>         {
>             pageUrl = URLDecoder.decode(pageUrl, "UTF-8");
>             HttpServletRequest request = getRequest();
>
>             if(request == null)
>             {
>                 throw new IllegalArgumentException("HTTP request not found.");
>             }
>
>             /*
>              * The redirect automatically inserts the context path.  We need
>              * to remove the context path in redirectURL to prevent duplicate
>              * contextPaths in the redirect.
>              */
>             String contextPath = request.getContextPath();
>
>             if (pageUrl.startsWith(contextPath))
>             {
>                 pageUrl = pageUrl.replaceFirst(contextPath, "");
>                 logger.debug("redirectURL set to [{}]", pageUrl);
>             }
>
>         }
>         catch(UnsupportedEncodingException ex)
>         {
>             throw new RuntimeException("error decoding url: " + pageUrl, ex);
>         }
>
>         return SUCCESS;
>     }
>
>
>     /**
>      * @return the pageUrl
>      */
>     public String getPageUrl()
>     {
>         return pageUrl;
>     }
>
>
>     /**
>      * @param pageUrl the pageUrl to set
>      */
>     public void setPageUrl(String pageUrl)
>     {
>         this.pageUrl = pageUrl;
>     }
>
>
> }
>
>
>
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE struts PUBLIC
>     "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
>     "http://struts.apache.org/dtds/struts-2.5.dtd">
>
> <struts>
>   <constant name="struts.devMode" value="true" />
>
>   <constant name="struts.action.extension" value="do" />
>
>   <constant name="struts.convention.action.packages" value="com.ezlista.web.struts2.action" />
>   <constant name="struts.convention.classes.reload" value="true" />
>   <constant name="struts.convention.default.parent.package" value="ezlista-package" />
>   <constant name="struts.convention.package.locators" value="action" />
>   <constant name="struts.convention.package.locators.basePackage" value="com.ezlista.web.struts2" />
>   <constant name="struts.convention.result.path" value="/WEB-INF/content/"/>
>
>   <constant name="struts.custom.i18n.resources" value="messages" />
>
>   <constant name="struts.date.format" value="dd/MM/yyyy hh:mm" />
>
>   <constant name="struts.freemarker.templatesCache" value="true" />
>
>   <constant name="struts.i18n.encoding" value="UTF-8" />
>
>   <constant name="struts.serve.static" value="true" />
>
>   <constant name="struts.ui.theme" value="simple" />
>   <constant name="struts.ui.templateDir" value="template" />
>
>
>   <package name="ezlista-package" extends="json-default">
>
>     <interceptors>
>
>       <interceptor name="valueStack"
>                    class="com.ezlista.web.struts2.interceptor.ValueStackInterceptor" />
>
>       <interceptor-stack name="ezlistaStack">
>         <interceptor-ref name="valueStack" />
>         <interceptor-ref name="defaultStack">
>           <param name="exception.logEnabled">true</param>
>           <param name="exception.logLevel">ERROR</param>
>           <param name="exception.logCategory">com.ezlista</param>
>           <param name="params.excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*,^_csrf</param>
>         </interceptor-ref>
>       </interceptor-stack>
>
>     </interceptors>
>
>     <default-interceptor-ref name="ezlistaStack" />
>
>     <default-action-ref name="default-action" />
>
>     <global-results>
>       <result name="login" type="redirectAction">/view-login.do</result>
>       <result name="error">/WEB-INF/content/${device}/error.jsp</result>
>       <result name="exception">/WEB-INF/content/${device}/error.jsp</result>
>       <result name="warning">/WEB-INF/content/${device}/warning.jsp</result>
>     </global-results>
>
>     <global-exception-mappings>
>       <exception-mapping exception="java.lang.Exception" result="exception" />
>     </global-exception-mappings>
>
>     <action name="default-action" class="com.ezlista.web.struts2.action.DefaultAction" />
>
>   </package>
>
>
>   <package name="home" extends="ezlista-package" namespace="/">
>
>     <action name="about" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/about.jsp</result>
>     </action>
>
>     <action name="help" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/help.jsp</result>
>     </action>
>
>     <action name="language-help" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/language-help.jsp</result>
>     </action>
>
>     <action name="pending-email-help" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/pending-email-help.jsp</result>
>     </action>
>
>     <action name="privacy" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/privacy.jsp</result>
>     </action>
>
>     <action name="remember-help" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/remember-help.jsp</result>
>     </action>
>
>     <action name="terms" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/terms.jsp</result>
>     </action>
>
>     <action name="terms-service" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/terms-service.jsp</result>
>     </action>
>
>     <action name="view-session-timeout" class="com.ezlista.web.struts2.action.DummyAction">
>       <result>/WEB-INF/content/${device}/session-timeout.jsp</result>
>     </action>
>
>   </package>
>
>
> </struts>
>
>
>
>
>
>
>
>
> ________________________________________
> From: Lukasz Lenart <[hidden email]>
> Sent: Wednesday, August 2, 2017 5:01 AM
> To: Struts Users Mailing List
> Subject: Re: Request Parameter not being set on Action
>
> 2017-08-02 8:34 GMT+02:00 Rubens Gomes <[hidden email]>:
>> The request below is sent , but the parameters (request_locale/pageUrl) are not set on the action.
>>
>> http://localhost:8080/change-locale.do?request_locale=en&pageUrl=%2Fview-login.do
>
> The "request_locale" parameter is a special parameter that tells
> I18NInterceptor to change locale, it will be removed after that so you
> cannot access it in an action.
> If you need to access locale in an action and assuming your extending
> the ActionSupport class just call the "getLocale()" method.
>
> Regarding the "pageUrl" parameter, can you start with a simple
> example? Or maybe post your struts.xml plus an action's class?
>
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...