Skip to content

Commit a02559b

Browse files
committed
ParameterBinding is working, changed rule signature, created UrlMapping rule
1 parent 6354a07 commit a02559b

38 files changed

Lines changed: 672 additions & 284 deletions

‎api-tests/src/test/java/com/ocpsoft/rewrite/config/ConfigurationBuilderTest.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ public class ConfigurationBuilderTest
3636
public void testBuildConfiguration()
3737
{
3838
Configuration config = ConfigurationBuilder.begin().defineRule()
39-
.when(And.all(Inbound.only(), new True()))
39+
.when(And.all(Direction.isInbound(), new True()))
4040
.perform(operation);
4141

4242
Rule rule = config.getRules().get(0);
4343
InboundRewrite rewrite = new MockInboundRewrite();
4444
EvaluationContext context = new MockEvaluationContext();
45-
if (rule.getCondition().evaluate(rewrite, context))
45+
if (rule.evaluate(rewrite, context))
4646
{
47-
rule.getOperation().perform(rewrite, context);
47+
rule.perform(rewrite, context);
4848
}
4949
Assert.assertTrue(performed);
5050
}

api-tests/src/test/java/com/ocpsoft/rewrite/config/OutboundTest.java renamed to api-tests/src/test/java/com/ocpsoft/rewrite/config/DirectionTest.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,34 @@
2424
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
2525
*
2626
*/
27-
public class OutboundTest
27+
public class DirectionTest
2828
{
2929

30+
@Test
31+
public void testInboundReturnsTrue()
32+
{
33+
Condition condition = Direction.isInbound();
34+
Assert.assertTrue(condition.evaluate(new MockInboundRewrite(), new MockEvaluationContext()));
35+
}
36+
37+
@Test
38+
public void testNotInboundReturnsFalse()
39+
{
40+
Condition condition = Direction.isInbound();
41+
Assert.assertFalse(condition.evaluate(new MockRewrite(), new MockEvaluationContext()));
42+
}
43+
3044
@Test
3145
public void testOutboundReturnsTrue()
3246
{
33-
Condition condition = new Outbound();
47+
Condition condition = Direction.isOutbound();
3448
Assert.assertTrue(condition.evaluate(new MockOutboundRewrite(), new MockEvaluationContext()));
3549
}
3650

3751
@Test
3852
public void testNotOutboundReturnsFalse()
3953
{
40-
Condition condition = new Outbound();
54+
Condition condition = Direction.isOutbound();
4155
Assert.assertFalse(condition.evaluate(new MockRewrite(), new MockEvaluationContext()));
4256
}
4357
}

‎api-tests/src/test/java/com/ocpsoft/rewrite/config/InboundTest.java‎

Lines changed: 0 additions & 43 deletions
This file was deleted.

‎api/src/main/java/com/ocpsoft/rewrite/config/Direction.java‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,41 @@
1515
*/
1616
package com.ocpsoft.rewrite.config;
1717

18+
import com.ocpsoft.rewrite.EvaluationContext;
19+
import com.ocpsoft.rewrite.event.InboundRewrite;
20+
import com.ocpsoft.rewrite.event.OutboundRewrite;
21+
import com.ocpsoft.rewrite.event.Rewrite;
22+
1823
/**
1924
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
2025
*/
2126
public abstract class Direction extends ConditionBuilder
2227
{
23-
public static Inbound isInbound()
28+
public static Direction isInbound()
29+
{
30+
return new Inbound();
31+
}
32+
33+
public static Direction isOutbound()
34+
{
35+
return new Outbound();
36+
}
37+
38+
private static class Inbound extends Direction
2439
{
25-
return Inbound.only();
40+
@Override
41+
public boolean evaluate(final Rewrite event, final EvaluationContext context)
42+
{
43+
return event instanceof InboundRewrite;
44+
}
2645
}
2746

28-
public static Outbound isOutbound()
47+
private static class Outbound extends Direction
2948
{
30-
return Outbound.only();
49+
@Override
50+
public boolean evaluate(final Rewrite event, final EvaluationContext context)
51+
{
52+
return event instanceof OutboundRewrite;
53+
}
3154
}
3255
}

‎api/src/main/java/com/ocpsoft/rewrite/config/InboundRule.java‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.ocpsoft.rewrite.config;
1717

18+
import com.ocpsoft.rewrite.EvaluationContext;
19+
import com.ocpsoft.rewrite.event.Rewrite;
1820

1921
/**
2022
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
@@ -32,9 +34,9 @@ public InboundRule setCondition(final Condition condition)
3234
}
3335

3436
@Override
35-
public Condition getCondition()
37+
public boolean evaluate(final Rewrite event, final EvaluationContext context)
3638
{
37-
return Direction.isInbound().and(condition);
39+
return Direction.isInbound().and(condition).evaluate(event, context);
3840
}
3941

4042
public void setOperation(final InboundOperation operation)
@@ -43,9 +45,9 @@ public void setOperation(final InboundOperation operation)
4345
}
4446

4547
@Override
46-
public Operation getOperation()
48+
public void perform(final Rewrite event, final EvaluationContext context)
4749
{
48-
return operation;
50+
operation.perform(event, context);
4951
}
5052

5153
}

‎api/src/main/java/com/ocpsoft/rewrite/config/Outbound.java‎

Lines changed: 0 additions & 42 deletions
This file was deleted.

‎api/src/main/java/com/ocpsoft/rewrite/config/Rule.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.ocpsoft.rewrite.config;
1717

18+
import com.ocpsoft.rewrite.EvaluationContext;
19+
import com.ocpsoft.rewrite.event.Rewrite;
1820

1921
/**
2022
* Encapsulates the conditions and outcomes of a Rewrite rule.
@@ -24,7 +26,7 @@
2426
*/
2527
public interface Rule
2628
{
27-
public Condition getCondition();
29+
public boolean evaluate(Rewrite event, EvaluationContext context);
2830

29-
public Operation getOperation();
31+
public void perform(Rewrite event, EvaluationContext context);
3032
}

‎api/src/main/java/com/ocpsoft/rewrite/config/RuleBuilder.java‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
package com.ocpsoft.rewrite.config;
1717

18+
import com.ocpsoft.rewrite.EvaluationContext;
19+
import com.ocpsoft.rewrite.event.Rewrite;
20+
1821
/**
1922
* Build a {@link Configuration} rule.
2023
*
@@ -43,14 +46,14 @@ public RuleBuilder perform(final Operation operation)
4346
}
4447

4548
@Override
46-
public Condition getCondition()
49+
public boolean evaluate(final Rewrite event, final EvaluationContext context)
4750
{
48-
return condition;
51+
return condition.evaluate(event, context);
4952
}
5053

5154
@Override
52-
public Operation getOperation()
55+
public void perform(final Rewrite event, final EvaluationContext context)
5356
{
54-
return operation;
57+
operation.perform(event, context);
5558
}
5659
}

‎config-tuckey/src/main/java/com/ocpsoft/rewrite/config/tuckey/TuckeyRewriteRuleAdaptor.java‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424

2525
import org.tuckey.web.filters.urlrewrite.UrlRewriter;
2626

27-
import com.ocpsoft.rewrite.config.Condition;
27+
import com.ocpsoft.rewrite.EvaluationContext;
2828
import com.ocpsoft.rewrite.config.Direction;
29-
import com.ocpsoft.rewrite.config.Operation;
3029
import com.ocpsoft.rewrite.config.Rule;
30+
import com.ocpsoft.rewrite.event.Rewrite;
3131
import com.ocpsoft.rewrite.exception.RewriteException;
3232
import com.ocpsoft.rewrite.servlet.config.HttpInboundOperation;
3333
import com.ocpsoft.rewrite.servlet.http.event.HttpInboundServletRewrite;
@@ -46,15 +46,15 @@ public TuckeyRewriteRuleAdaptor(final UrlRewriter urlRewriter)
4646
}
4747

4848
@Override
49-
public Condition getCondition()
49+
public boolean evaluate(final Rewrite event, final EvaluationContext context)
5050
{
51-
return Direction.isInbound();
51+
return Direction.isInbound().evaluate(event, context);
5252
}
5353

5454
@Override
55-
public Operation getOperation()
55+
public void perform(final Rewrite event, final EvaluationContext context)
5656
{
57-
return new HttpInboundOperation() {
57+
new HttpInboundOperation() {
5858

5959
boolean forwarded = false;
6060

@@ -83,7 +83,7 @@ public void doFilter(final ServletRequest request, final ServletResponse respons
8383
throw new RewriteException("Error processing [" + this.getClass().getName() + "]", e);
8484
}
8585
}
86-
};
86+
}.perform(event, context);
8787
}
8888

8989
}

‎impl-servlet/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ TODO's
2525
======
2626

2727
* Continue simplification of Configuration object APIs and convenience classes
28+
* Rule to enable localhost admin/status page
29+
* High level pre-prepared rewrite rules
30+
* Resource.exists(String fileName) to check file existence

0 commit comments

Comments
 (0)