Skip to content

Commit 4265063

Browse files
committed
Added some nicer messaging for multi-domain example
1 parent 7d2974c commit 4265063

3 files changed

Lines changed: 18 additions & 23 deletions

File tree

‎showcase/multi-domain/src/main/java/com/ocpsoft/rewrite/showcase/domain/DomainRewriteConfiguration.java‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.ocpsoft.rewrite.servlet.config.Domain;
2626
import com.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider;
2727
import com.ocpsoft.rewrite.servlet.config.QueryString;
28+
import com.ocpsoft.rewrite.servlet.config.rule.Join;
2829

2930
/**
3031
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
@@ -38,13 +39,21 @@ public Configuration getConfiguration(final ServletContext context)
3839
return ConfigurationBuilder
3940
.begin()
4041

42+
/**
43+
* When a known sub-domain of example.com is accessed, it will be loaded by the application.
44+
*/
4145
.defineRule()
4246
.when(Domain.matches("{domain}.example.com").where("domain")
4347
.bindsTo(El.property("#{domains.currentName}"))
4448
.and(DispatchType.isRequest())
4549
.andNot(QueryString.parameterExists("disableDomainRewrite")))
46-
.perform(Invoke.binding(El.retrievalMethod("#{domains.load}")));
50+
.perform(Invoke.binding(El.retrievalMethod("#{domains.load}")))
4751

52+
/**
53+
* Access http://{domain}.example.com:8080/context/literal and you should see a FileNotFoundException or
54+
* * 404 for "/{domain}.xhtml", where "{domain}" matches the sub-domain of example.com
55+
*/
56+
.addRule(Join.path("/literal").to("/{domain}.xhtml").when(Domain.matches("{domain}.example.com")));
4857
}
4958

5059
@Override

‎showcase/multi-domain/src/main/java/com/ocpsoft/rewrite/showcase/domain/Domains.java‎

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@
2323
import javax.persistence.PersistenceContextType;
2424
import javax.persistence.TypedQuery;
2525

26-
import com.ocpsoft.rewrite.config.Operation;
27-
import com.ocpsoft.rewrite.context.EvaluationContext;
28-
import com.ocpsoft.rewrite.servlet.config.HttpOperation;
29-
import com.ocpsoft.rewrite.servlet.http.event.HttpInboundServletRewrite;
30-
import com.ocpsoft.rewrite.servlet.http.event.HttpServletRewrite;
31-
import com.ocpsoft.rewrite.servlet.util.URLBuilder;
32-
3326
/**
3427
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
3528
*
@@ -45,7 +38,7 @@ public class Domains
4538
@PersistenceContext(type = PersistenceContextType.EXTENDED)
4639
private EntityManager em;
4740

48-
public Operation load()
41+
public void load()
4942
{
5043
if (current == null)
5144
{
@@ -57,25 +50,13 @@ public Operation load()
5750
current = result;
5851
}
5952
catch (Exception e) {
60-
6153
/*
62-
* For the purposes of this example, let's just disable this so we
54+
* For the purposes of this example, let's just keep going so we
6355
* can keep working
6456
*/
65-
return new HttpOperation() {
66-
@Override
67-
public void performHttp(final HttpServletRewrite event, final EvaluationContext context)
68-
{
69-
URLBuilder url = URLBuilder.begin().addPathSegments(event.getRequestPath())
70-
.addQueryParameters(event.getRequestQueryString())
71-
.addQueryParameters("disableDomainRewrite");
72-
((HttpInboundServletRewrite) event).redirectTemporary(url.toURL());
73-
}
74-
};
7557
}
7658
System.out.println("Loaded settings for domain [" + current + "]");
7759
}
78-
return null;
7960
}
8061

8162
public DomainEntity getCurrent()

‎showcase/multi-domain/src/main/webapp/index.xhtml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
value="Welcome to #{domains.current.name}'s subdomain" />
1111

1212
<ui:define name="header">
13-
Welcome to #{domains.current.name}'s sub-domain
13+
<h:panelGroup rendered="#{domains.current != null}">
14+
Welcome to #{domains.current.name}'s sub-domain
15+
</h:panelGroup>
16+
<h:panelGroup rendered="#{domains.current == null}">
17+
Let's get started
18+
</h:panelGroup>
1419
</ui:define>
1520

1621
<ui:define name="subheader">

0 commit comments

Comments
 (0)