Skip to content

Commit 7f0342f

Browse files
committed
JSF deploys on Jetty
1 parent 3d7d0b7 commit 7f0342f

8 files changed

Lines changed: 124 additions & 19 deletions

File tree

‎integration-faces/pom.xml‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,11 @@
3535
<version>2.0.0.Beta1</version>
3636
<scope>provided</scope>
3737
</dependency>
38-
39-
<dependency>
40-
<groupId>com.sun.faces</groupId>
41-
<artifactId>jsf-api</artifactId>
42-
<version>2.1.7</version>
43-
<scope>test</scope>
44-
</dependency>
45-
38+
4639
<dependency>
47-
<groupId>com.sun.faces</groupId>
48-
<artifactId>jsf-impl</artifactId>
40+
<groupId>org.glassfish</groupId>
41+
<artifactId>javax.faces</artifactId>
4942
<version>2.1.7</version>
50-
<scope>test</scope>
5143
</dependency>
5244

5345
<dependency>

‎integration-faces/src/test/java/com/ocpsoft/rewrite/faces/PhaseOperationTest.java‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,27 @@ public class PhaseOperationTest extends RewriteTestBase
3939
public static WebArchive getDeployment()
4040
{
4141
WebArchive deployment = RewriteTestBase
42-
.getDeployment()
42+
.getDeploymentNoWebXml()
43+
.setWebXML("faces-web.xml")
4344
.addPackages(true, ADFRoot.class.getPackage())
45+
.addAsLibraries(resolveDependencies("org.glassfish:javax.faces:jar:2.1.7"))
46+
.addAsWebInfResource("META-INF/faces-config.xml","faces-config.xml")
47+
.addAsWebResource("empty-view.xhtml","empty.xhtml")
4448
.addAsResource(
45-
new StringAsset("com.ocpsoft.rewrite.faces.OperationTestConfigurationProvider"),
49+
new StringAsset("com.ocpsoft.rewrite.faces.PhaseOperationTestConfigurationProvider"),
4650
"/META-INF/services/com.ocpsoft.rewrite.config.ConfigurationProvider");
51+
52+
System.out.println(deployment.toString(true));
53+
4754
return deployment;
4855
}
4956

5057
@Test
5158
public void testUrlMappingConfiguration()
5259
{
53-
HttpAction<HttpGet> action = get("/?adf=blah");
60+
HttpAction<HttpGet> action = get("/faces/empty.xhtml?adf=blah");
61+
String content = action.getResponseContent();
62+
Assert.assertTrue(content.contains(">Empty"));
5463
Assert.assertEquals(203, action.getResponse().getStatusLine().getStatusCode());
5564
}
5665

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version='1.0' encoding='UTF-8' ?>
2+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3+
<html xmlns="http://www.w3.org/1999/xhtml"
4+
xmlns:h="http://java.sun.com/jsf/html"
5+
xmlns:ui="http://java.sun.com/jsf/facelets">
6+
7+
<h:outputText value="Empty" />
8+
9+
</html>
10+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
version="3.0"
4+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
5+
6+
<env-entry>
7+
<env-entry-name>name</env-entry-name>
8+
<env-entry-type>java.lang.String</env-entry-type>
9+
<env-entry-value>Jetty</env-entry-value>
10+
</env-entry>
11+
<!-- Should be overridden by jetty-env.xml -->
12+
<env-entry>
13+
<env-entry-name>type</env-entry-name>
14+
<env-entry-type>java.lang.String</env-entry-type>
15+
<env-entry-value>Remote</env-entry-value>
16+
</env-entry>
17+
18+
<listener>
19+
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
20+
</listener>
21+
22+
<!-- JSF Config -->
23+
<listener>
24+
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
25+
</listener>
26+
<servlet>
27+
<servlet-name>Faces Servlet</servlet-name>
28+
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
29+
<load-on-startup>1</load-on-startup>
30+
</servlet>
31+
<servlet-mapping>
32+
<servlet-name>Faces Servlet</servlet-name>
33+
<url-pattern>*.xhtml</url-pattern>
34+
</servlet-mapping>
35+
<servlet-mapping>
36+
<servlet-name>Faces Servlet</servlet-name>
37+
<url-pattern>/faces/*</url-pattern>
38+
</servlet-mapping>
39+
<context-param>
40+
<param-name>javax.faces.PROJECT_STAGE</param-name>
41+
<param-value>Development</param-value>
42+
</context-param>
43+
44+
</web-app>

‎test-harness/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<dependency>
7878
<groupId>org.jboss.weld.servlet</groupId>
7979
<artifactId>weld-servlet</artifactId>
80-
<version>1.1.1.Final</version>
80+
<version>1.1.6.Final</version>
8181
</dependency>
8282
<dependency>
8383
<groupId>javax.enterprise</groupId>

‎test-harness/src/main/java/com/ocpsoft/rewrite/test/HttpAction.java‎

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

18+
import java.io.IOException;
19+
import java.io.InputStream;
20+
import java.io.InputStreamReader;
21+
import java.io.Reader;
22+
import java.io.UnsupportedEncodingException;
1823
import java.util.ArrayList;
1924
import java.util.List;
2025

@@ -27,6 +32,9 @@
2732
import org.apache.http.protocol.ExecutionContext;
2833
import org.apache.http.protocol.HttpContext;
2934

35+
import com.ocpsoft.common.util.Streams;
36+
import com.ocpsoft.rewrite.exception.RewriteException;
37+
3038
/**
3139
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
3240
*
@@ -133,4 +141,41 @@ public int getStatusCode()
133141
{
134142
return response.getStatusLine().getStatusCode();
135143
}
144+
145+
public String getResponseContent()
146+
{
147+
try {
148+
return toString(getResponse().getEntity().getContent());
149+
}
150+
catch (Exception e) {
151+
throw new RewriteException("Could not stringify response InputStream", e);
152+
}
153+
}
154+
155+
/**
156+
* Return a {@link String} containing the contents of the given {@link InputStream}
157+
*/
158+
public static String toString(final InputStream stream)
159+
{
160+
StringBuilder out = new StringBuilder();
161+
try {
162+
final char[] buffer = new char[0x10000];
163+
Reader in = new InputStreamReader(stream, "UTF-8");
164+
int read;
165+
do {
166+
read = in.read(buffer, 0, buffer.length);
167+
if (read > 0) {
168+
out.append(buffer, 0, read);
169+
}
170+
}
171+
while (read >= 0);
172+
}
173+
catch (UnsupportedEncodingException e) {
174+
throw new RuntimeException(e);
175+
}
176+
catch (IOException e) {
177+
throw new RuntimeException(e);
178+
}
179+
return out.toString();
180+
}
136181
}

‎test-harness/src/main/java/com/ocpsoft/rewrite/test/RewriteTestBase.java‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,18 @@ public class RewriteTestBase
7272
{
7373
@Deployment(testable = false)
7474
public static WebArchive getDeployment()
75+
{
76+
return getDeploymentNoWebXml()
77+
.setWebXML("jetty-web.xml");
78+
}
79+
80+
public static WebArchive getDeploymentNoWebXml()
7581
{
7682

7783
return ShrinkWrap
7884
.create(WebArchive.class, "rewrite-test.war")
7985
.addAsLibraries(getRewriteArchive())
80-
.addAsLibraries(resolveDependencies("org.jboss.weld.servlet:weld-servlet:1.1.2.Final"))
86+
.addAsLibraries(resolveDependencies("org.jboss.weld.servlet:weld-servlet:1.1.6.Final"))
8187

8288
/*
8389
* Set the EL implementation
@@ -88,7 +94,6 @@ public static WebArchive getDeployment()
8894
/*
8995
* Set up container configuration
9096
*/
91-
.setWebXML("jetty-web.xml")
9297
.addAsWebResource(new StringAsset("<beans/>"), ArchivePaths.create("WEB-INF/beans.xml"))
9398
.addAsWebResource("jetty-env.xml", ArchivePaths.create("WEB-INF/jetty-env.xml"))
9499
.addAsResource("jetty-log4j.xml", ArchivePaths.create("WEB-INF/classes/log4j.xml"));

‎test-harness/src/main/resources/jetty-env.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
33
"http://www.eclipse.org/jetty/configure.dtd">
44
<Configure id="webAppCtx" class="org.eclipse.jetty.webapp.WebAppContext">
5-
<!-- Third argument to EnvEntry constructor (overrideWebXml) required for Jetty <= 6.1.14 -->
6-
<!-- EnvEntry scope not implemented until Jetty 6.1.12 -->
5+
6+
<Set class="org.eclipse.jetty.util.resource.Resource" name="defaultUseCaches">false</Set>
77
<New class="org.eclipse.jetty.plus.jndi.EnvEntry">
88
<Arg><Ref id="webAppCtx"/></Arg>
99
<Arg>type</Arg>

0 commit comments

Comments
 (0)