Skip to content

Commit a727fbc

Browse files
committed
Fixed @parameter to support query parameters again
1 parent cb45a0f commit a727fbc

2 files changed

Lines changed: 17 additions & 43 deletions

File tree

‎config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/handler/ParameterHandler.java‎

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@
2323
import org.ocpsoft.rewrite.annotation.api.HandlerChain;
2424
import org.ocpsoft.rewrite.annotation.spi.FieldAnnotationHandler;
2525
import org.ocpsoft.rewrite.bind.Binding;
26+
import org.ocpsoft.rewrite.config.Condition;
27+
import org.ocpsoft.rewrite.config.ConditionBuilder;
28+
import org.ocpsoft.rewrite.config.Or;
29+
import org.ocpsoft.rewrite.config.True;
2630
import org.ocpsoft.rewrite.el.El;
2731
import org.ocpsoft.rewrite.param.ParameterBuilder;
32+
import org.ocpsoft.rewrite.servlet.config.RequestParameter;
2833

2934
public class ParameterHandler extends FieldAnnotationHandler<org.ocpsoft.rewrite.annotation.Parameter>
3035
{
@@ -78,47 +83,15 @@ public void process(FieldContext context, org.ocpsoft.rewrite.annotation.Paramet
7883
Assert.notNull(enrichedBinding, "BindingBuilder was removed from the context");
7984
parameterBuilder.bindsTo(enrichedBinding);
8085

81-
//
82-
//
83-
// // add bindings to conditions by walking over the condition tree
84-
// AddBindingVisitor visitor = new AddBindingVisitor(context, chain, param, field);
85-
// context.getRuleBuilder().accept(visitor);
86-
// if (!visitor.isFound())
87-
// {
88-
//
89-
// /*
90-
// * Creates a condition that matches the query parameter we are looking for.
91-
// * It also provides access to a parameter which is named like the parameter that
92-
// * the AddBindingVisitor is expecting.
93-
// */
94-
//
95-
// // FIXME Commented out until this can be resolved via other means
96-
// Condition requestParameter = RequestParameter.matches("{name}", "{" + param + "}");
97-
// // .where("name").matches(param);
98-
// // FIXME End compilation comment-out
99-
//
100-
// /*
101-
// * Add the query parameter condition to the condition tree. We must make sure that
102-
// * the condition is evaluated even if the existing part of the tree evaluates to true.
103-
// */
104-
// ConditionBuilder composite = context.getRuleBuilder().getConditionBuilder().and(
105-
// Or.any(requestParameter, True.create()));
106-
// context.getRuleBuilder().when(composite);
107-
//
108-
// /*
109-
// * This new visitor will definitely find the expected parameter and add the binding.
110-
// */
111-
// AddBindingVisitor fallback = new AddBindingVisitor(context, chain, param, field);
112-
// context.getRuleBuilder().accept(fallback);
113-
//
114-
// Assert.assertTrue(fallback.isFound(),
115-
// "The parameter [" + param + "] bound to Field [" + field.getDeclaringClass().getName() + "."
116-
// + field.getName() + "] was not found in any condition.");
117-
//
118-
// }
119-
//
120-
// // continue
121-
// chain.proceed();
86+
/*
87+
* Add the query parameter condition to the condition tree that will capture a
88+
* corresponding query parameter. We must make sure that
89+
* the condition is evaluated even if the existing part of the tree evaluates to true.
90+
*/
91+
Condition requestParameter = RequestParameter.matches("{name}", "{" + param + "}");
92+
ConditionBuilder composite = context.getRuleBuilder().getConditionBuilder().and(
93+
Or.any(requestParameter, True.create()));
94+
context.getRuleBuilder().when(composite);
12295

12396
}
12497

‎config-annotations/src/test/java/org/ocpsoft/rewrite/annotation/query/QueryParameterTest.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package org.ocpsoft.rewrite.annotation.query;
22

3-
import static junit.framework.Assert.assertTrue;
43
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertThat;
55

66
import org.apache.http.client.methods.HttpGet;
7+
import org.hamcrest.Matchers;
78
import org.jboss.arquillian.container.test.api.Deployment;
89
import org.jboss.arquillian.junit.Arquillian;
910
import org.jboss.shrinkwrap.api.asset.StringAsset;
@@ -36,7 +37,7 @@ public void testQueryParameter() throws Exception
3637
{
3738
HttpAction<HttpGet> action = get("/query?q=foo");
3839
assertEquals(200, action.getStatusCode());
39-
assertTrue(action.getResponseContent().contains("Log: [foo]"));
40+
assertThat(action.getResponseContent(), Matchers.containsString("Log: [foo]"));
4041
}
4142

4243
}

0 commit comments

Comments
 (0)