use of org.apache.struts2.dispatcher.Parameter in project struts by apache.
the class ParameterRemoverInterceptor method intercept.
/**
* Decide if the parameter should be removed from the parameter map based on
* <code>paramNames</code> and <code>paramValues</code>.
*
* @see com.opensymphony.xwork2.interceptor.AbstractInterceptor
*/
@Override
public String intercept(ActionInvocation invocation) throws Exception {
if (!(invocation.getAction() instanceof NoParameters) && (null != this.paramNames)) {
ActionContext ac = invocation.getInvocationContext();
HttpParameters parameters = ac.getParameters();
if (parameters != null) {
for (String removeName : paramNames) {
try {
Parameter parameter = parameters.get(removeName);
if (parameter.isDefined() && this.paramValues.contains(parameter.getValue())) {
parameters.remove(removeName);
}
} catch (Exception e) {
LOG.error("Failed to convert parameter to string", e);
}
}
}
}
return invocation.invoke();
}
use of org.apache.struts2.dispatcher.Parameter in project struts by apache.
the class AnchorTagTest method testParametersPriority.
/**
* To test priority of parameter passed in to url component though
* various way
* - current request url
* - tag's value attribute
* - tag's nested param tag
* <br>
* id1
* ===
* - found in current request url
* - found in tag's value attribute
* - found in tag's param tag
* CONCLUSION: tag's param tag takes precedence (paramId1)
* <br>
* id2
* ===
* - found in current request url
* - found in tag's value attribute
* CONCLUSION: tag's value attribute take precedence (tagId2)
* <br>
* urlParam1
* =========
* - found in current request url
* CONCLUSION: param in current request url will be used (urlValue1)
* <br>
* urlParam2
* =========
* - found in current request url
* CONCLUSION: param in current request url will be used. (urlValue2)
* <br>
* tagId
* =====
* - found in tag's value attribute
* CONCLUSION: param in tag's value attribute wil; be used. (tagValue)
* <br>
* param1
* ======
* - found in nested param tag
* CONCLUSION: param in nested param tag will be used. (param1value)
* <br>
* param2
* ======
* - found in nested param tag
* CONCLUSION: param in nested param tag will be used. (param2value)
*/
public void testParametersPriority() throws Exception {
request.setQueryString("id1=urlId1&id2=urlId2&urlParam1=urlValue1&urlParam2=urlValue2");
tag.setValue("testAction.action?id1=tagId1&id2=tagId2&tagId=tagValue");
ParamTag param1 = new ParamTag();
param1.setPageContext(pageContext);
param1.setName("param1");
param1.setValue("%{'param1value'}");
ParamTag param2 = new ParamTag();
param2.setPageContext(pageContext);
param2.setName("param2");
param2.setValue("%{'param2value'}");
ParamTag param3 = new ParamTag();
param3.setPageContext(pageContext);
param3.setName("id1");
param3.setValue("%{'paramId1'}");
tag.doStartTag();
param1.doStartTag();
param1.doEndTag();
param2.doStartTag();
param2.doEndTag();
param3.doStartTag();
param3.doEndTag();
tag.doEndTag();
assertEquals(wrapWithAnchor("testAction.action?id1=paramId1&id2=tagId2&" + "amp;tagId=tagValue&urlParam1=urlValue1&urlParam2=urlValue2&param1=param1value&param2=param2value"), writer.toString());
// Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
AnchorTag freshTag = new AnchorTag();
freshTag.setPageContext(pageContext);
assertFalse("Tag state after doEndTag() under default tag clear state is equal to new Tag with pageContext/parent set. " + "May indicate that clearTagStateForTagPoolingServers() calls are not working properly.", strutsBodyTagsAreReflectionEqual(tag, freshTag));
}
use of org.apache.struts2.dispatcher.Parameter in project struts by apache.
the class AnchorTagTest method testParametersPriorityWithIncludeParamsAsNONE_clearTagStateSet.
/**
* <p>
* To test priority of parameter passed in to url component though
* various way, with includeParams="NONE"
* </p>
*
* - current request url<br>
* - tag's value attribute<br>
* - tag's nested param tag<br>
*
* <p>
* In this case only parameters from the tag itself is taken into account.
* Those from request will not count, only those in tag's value attribute
* and nested param tag.
* </p>
* @throws Exception
*/
public void testParametersPriorityWithIncludeParamsAsNONE_clearTagStateSet() throws Exception {
request.setQueryString("id1=urlId1&id2=urlId2&urlParam1=urlValue1&urlParam2=urlValue2");
// Explicitly request tag state clearing.
tag.setPerformClearTagStateForTagPoolingServers(true);
tag.setValue("testAction.action?id1=tagId1&id2=tagId2&tagId=tagValue");
tag.setIncludeParams("NONE");
ParamTag param1 = new ParamTag();
// Explicitly request tag state clearing.
param1.setPerformClearTagStateForTagPoolingServers(true);
param1.setPageContext(pageContext);
param1.setName("param1");
param1.setValue("%{'param1value'}");
ParamTag param2 = new ParamTag();
// Explicitly request tag state clearing.
param2.setPerformClearTagStateForTagPoolingServers(true);
param2.setPageContext(pageContext);
param2.setName("param2");
param2.setValue("%{'param2value'}");
ParamTag param3 = new ParamTag();
// Explicitly request tag state clearing.
param3.setPerformClearTagStateForTagPoolingServers(true);
param3.setPageContext(pageContext);
param3.setName("id1");
param3.setValue("%{'paramId1'}");
tag.doStartTag();
// Ensure component tag state clearing is set true (to match tag).
setComponentTagClearTagState(tag, true);
param1.doStartTag();
// Ensure component tag state clearing is set true (to match tag).
setComponentTagClearTagState(param1, true);
param1.doEndTag();
param2.doStartTag();
// Ensure component tag state clearing is set true (to match tag).
setComponentTagClearTagState(param2, true);
param2.doEndTag();
param3.doStartTag();
// Ensure component tag state clearing is set true (to match tag).
setComponentTagClearTagState(param3, true);
param3.doEndTag();
tag.doEndTag();
assertEquals(wrapWithAnchor("testAction.action?id1=paramId1&id2=tagId2&tagId=tagValue&param1=param1value&param2=param2value"), writer.toString());
// Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
ParamTag freshParamTag = new ParamTag();
freshParamTag.setPerformClearTagStateForTagPoolingServers(true);
freshParamTag.setPageContext(pageContext);
assertTrue("Tag state after doEndTag() and explicit tag state clearing is inequal to new Tag with pageContext/parent set. " + "May indicate that clearTagStateForTagPoolingServers() calls are not working properly.", strutsBodyTagsAreReflectionEqual(param1, freshParamTag));
assertTrue("Tag state after doEndTag() and explicit tag state clearing is inequal to new Tag with pageContext/parent set. " + "May indicate that clearTagStateForTagPoolingServers() calls are not working properly.", strutsBodyTagsAreReflectionEqual(param2, freshParamTag));
assertTrue("Tag state after doEndTag() and explicit tag state clearing is inequal to new Tag with pageContext/parent set. " + "May indicate that clearTagStateForTagPoolingServers() calls are not working properly.", strutsBodyTagsAreReflectionEqual(param3, freshParamTag));
// Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
AnchorTag freshTag = new AnchorTag();
freshTag.setPerformClearTagStateForTagPoolingServers(true);
freshTag.setPageContext(pageContext);
assertTrue("Tag state after doEndTag() and explicit tag state clearing is inequal to new Tag with pageContext/parent set. " + "May indicate that clearTagStateForTagPoolingServers() calls are not working properly.", strutsBodyTagsAreReflectionEqual(tag, freshTag));
}
use of org.apache.struts2.dispatcher.Parameter in project struts by apache.
the class URLTagTest method testIncludeParamsDefaultToGET.
public void testIncludeParamsDefaultToGET() throws Exception {
request.setQueryString("one=oneVal&two=twoVal&three=threeVal");
// request parameter map should not have any effect, as includeParams
// default to GET, which get its param from request.getQueryString()
Map<String, String> tmp = new HashMap<>();
tmp.put("one", "aaa");
tmp.put("two", "bbb");
tmp.put("three", "ccc");
request.setParameterMap(tmp);
tag.setValue("TestAction.acton");
tag.doStartTag();
URL url = (URL) tag.getComponent();
Map parameters = url.getParameters();
tag.doEndTag();
assertEquals(parameters.get("one"), "oneVal");
assertEquals(parameters.get("two"), "twoVal");
assertEquals(parameters.get("three"), "threeVal");
// Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
URLTag freshTag = new URLTag();
freshTag.setPageContext(pageContext);
assertFalse("Tag state after doEndTag() under default tag clear state is equal to new Tag with pageContext/parent set. " + "May indicate that clearTagStateForTagPoolingServers() calls are not working properly.", strutsBodyTagsAreReflectionEqual(tag, freshTag));
}
use of org.apache.struts2.dispatcher.Parameter in project struts by apache.
the class URLTagTest method testIncludeParamsDefaultToGET_clearTagStateSet.
public void testIncludeParamsDefaultToGET_clearTagStateSet() throws Exception {
request.setQueryString("one=oneVal&two=twoVal&three=threeVal");
// request parameter map should not have any effect, as includeParams
// default to GET, which get its param from request.getQueryString()
Map tmp = new HashMap();
tmp.put("one", "aaa");
tmp.put("two", "bbb");
tmp.put("three", "ccc");
request.setParameterMap(tmp);
// Explicitly request tag state clearing.
tag.setPerformClearTagStateForTagPoolingServers(true);
tag.setValue("TestAction.acton");
tag.doStartTag();
// Ensure component tag state clearing is set true (to match tag).
setComponentTagClearTagState(tag, true);
URL url = (URL) tag.getComponent();
Map parameters = url.getParameters();
tag.doEndTag();
assertEquals(parameters.get("one"), "oneVal");
assertEquals(parameters.get("two"), "twoVal");
assertEquals(parameters.get("three"), "threeVal");
// Basic sanity check of clearTagStateForTagPoolingServers() behaviour for Struts Tags after doEndTag().
URLTag freshTag = new URLTag();
freshTag.setPerformClearTagStateForTagPoolingServers(true);
freshTag.setPageContext(pageContext);
assertTrue("Tag state after doEndTag() and explicit tag state clearing is inequal to new Tag with pageContext/parent set. " + "May indicate that clearTagStateForTagPoolingServers() calls are not working properly.", strutsBodyTagsAreReflectionEqual(tag, freshTag));
}
Aggregations