Author: djencks
Date: Sun Sep 17 14:30:10 2006
New Revision: 447149
URL: http://svn.apache.org/viewvc?view=rev&rev=447149
Log:
Fix the jetty 6 integration enough so tests pass, modulo JETTY-119
Modified:
geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/pom.xml
geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty/JettyEJBWebServiceContext.java
geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty/JettySecurityHandler.java
geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty/JettyWebAppContext.java
geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty/ContainerTest.java
geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty/SecurityTest.java
geronimo/sandbox/javaee5/pom.xml
Modified: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/pom.xml?view=diff&rev=447149&r1=447148&r2=447149
==============================================================================
--- geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/pom.xml (original)
+++ geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/pom.xml Sun Sep 17 14:30:10 2006
@@ -29,7 +29,7 @@
</parent>
<artifactId>geronimo-jetty6</artifactId>
- <name>Geronimo :: Jetty</name>
+ <name>Geronimo :: Jetty 6</name>
<dependencies>
Modified: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty/JettyEJBWebServiceContext.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty/JettyEJBWebServiceContext.java?view=diff&rev=447149&r1=447148&r2=447149
==============================================================================
--- geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty/JettyEJBWebServiceContext.java
(original)
+++ geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty/JettyEJBWebServiceContext.java
Sun Sep 17 14:30:10 2006
@@ -24,6 +24,10 @@
import java.util.HashMap;
import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+
import org.apache.geronimo.security.ContextManager;
import org.apache.geronimo.webservices.WebServiceContainer;
import org.mortbay.jetty.HttpException;
@@ -74,11 +78,11 @@
this.contextPath = contextPath;
this.webServiceContainer = webServiceContainer;
if (internalJAASJettyRealm != null) {
- JAASJettyRealm realm = new JAASJettyRealm(realmName, internalJAASJettyRealm);
+ realm = new JAASJettyRealm(realmName, internalJAASJettyRealm);
//TODO
//not used???
//setUserRealm(realm);
- this.realm = realm;
+// this.realm = realm;
if ("NONE".equals(transportGuarantee)) {
isConfidentialTransportGuarantee = false;
isIntegralTransportGuarantee = false;
@@ -116,21 +120,27 @@
return contextPath;
}
- public boolean handle(Request req, Response res) throws HttpException, IOException {
+ public void handle(String target, HttpServletRequest req, HttpServletResponse res, int
dispatch)
+ throws IOException, ServletException
+ {
//TODO
//shouldn't set this on the request !
//req.setContentType("text/xml");
//TODO
//do we need to check that this request should be handled by this handler?
- RequestAdapter request = new RequestAdapter(req);
- ResponseAdapter response = new ResponseAdapter(res);
+ if (! target.startsWith(contextPath)) {
+ return;
+ }
+ Request jettyRequest = (Request) req;
+ Response jettyResponse = (Response) res;
+ RequestAdapter request = new RequestAdapter(jettyRequest);
+ ResponseAdapter response = new ResponseAdapter(jettyResponse);
if (req.getParameter("wsdl") != null) {
try {
webServiceContainer.getWsdl(request, response);
//WHO IS RESPONSIBLE FOR CLOSING OUT?
- return true;
} catch (IOException e) {
throw e;
} catch (Exception e) {
@@ -142,7 +152,7 @@
throw new HttpException(403, null);
}
} else if (isIntegralTransportGuarantee) {
- if (!req.getConnection().isIntegral(req)) {
+ if (!jettyRequest.getConnection().isIntegral(jettyRequest)) {
throw new HttpException(403, null);
}
}
@@ -154,7 +164,7 @@
try {
if (authenticator != null) {
String pathInContext = org.mortbay.util.URIUtil.canonicalPath(req.getContextPath());
- if (authenticator.authenticate(realm, pathInContext, req, res) == null)
{
+ if (authenticator.authenticate(realm, pathInContext, jettyRequest, jettyResponse)
== null) {
throw new HttpException(403, null);
}
} else {
@@ -165,7 +175,7 @@
}
try {
webServiceContainer.invoke(request, response);
- return true;
+ jettyRequest.setHandled(true);
} catch (IOException e) {
throw e;
} catch (Exception e) {
@@ -238,7 +248,7 @@
}
public Map getParameters() {
- return request.getParameters();
+ return request.getParameterMap();
}
public Object getAttribute(String name) {
@@ -294,7 +304,7 @@
public int getStatusCode() {
return response.getStatus();
- }
+ }
public void setContentType(String type) {
response.setContentType(type);
Modified: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty/JettySecurityHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty/JettySecurityHandler.java?view=diff&rev=447149&r1=447148&r2=447149
==============================================================================
--- geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty/JettySecurityHandler.java
(original)
+++ geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty/JettySecurityHandler.java
Sun Sep 17 14:30:10 2006
@@ -63,6 +63,10 @@
public JettySecurityHandler() {
}
+ public boolean hasConstraints() {
+ return true;
+ }
+
public void init(String policyContextID,
DefaultPrincipal defaultPrincipal,
PermissionCollection checkedPermissions,
@@ -173,13 +177,9 @@
} else {
transportType = "NONE";
}
- WebUserDataPermission wudp = new WebUserDataPermission(request
- .getServletPath(), new String[] { request.getMethod() },
- transportType);
- WebResourcePermission webResourcePermission = new WebResourcePermission(
- request);
- Principal user = obtainUser(pathInContext, request, response,
- webResourcePermission, wudp);
+ WebUserDataPermission wudp = new WebUserDataPermission(pathInContext, new String[]
{ request.getMethod() }, transportType);
+ WebResourcePermission webResourcePermission = new WebResourcePermission(request);
+ Principal user = obtainUser(pathInContext, request, response, webResourcePermission,
wudp);
if (user == null) {
return false;
@@ -232,10 +232,8 @@
private Principal obtainUser(String pathInContext, Request request,
Response response, WebResourcePermission resourcePermission,
WebUserDataPermission dataPermission) throws IOException {
- boolean unauthenticated = !(checked.implies(resourcePermission) || checked
- .implies(dataPermission));
- boolean forbidden = excludedPermissions.implies(resourcePermission)
- || excludedPermissions.implies(dataPermission);
+ boolean unauthenticated = !(checked.implies(resourcePermission) || checked.implies(dataPermission));
+ boolean forbidden = excludedPermissions.implies(resourcePermission) || excludedPermissions.implies(dataPermission);
Authenticator authenticator = getAuthenticator();
if (!unauthenticated && !forbidden) {
Modified: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty/JettyWebAppContext.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty/JettyWebAppContext.java?view=diff&rev=447149&r1=447148&r2=447149
==============================================================================
--- geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty/JettyWebAppContext.java
(original)
+++ geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty/JettyWebAppContext.java
Sun Sep 17 14:30:10 2006
@@ -64,6 +64,7 @@
import org.mortbay.jetty.servlet.ServletHolder;
import org.mortbay.jetty.servlet.ServletMapping;
import org.mortbay.jetty.servlet.SessionHandler;
+import org.mortbay.jetty.servlet.ErrorPageErrorHandler;
import org.mortbay.jetty.webapp.WebAppContext;
/**
@@ -159,7 +160,21 @@
//TODO get the SessionHandler from some clustering factory.
SessionHandler sessionHandler = null;
//TODO construct an interceptor chain inside one of the Handlers.
- this.webAppContext = new WebAppContext(new JettySecurityHandler(), sessionHandler,
null, null);
+ //TODO determine if we should construct a JettySecurityHandler if there is no security
+ JettySecurityHandler securityHandler = null;
+//JACC
+
+ if (securityRealmName != null) {
+ securityHandler = new JettySecurityHandler();
+ InternalJAASJettyRealm internalJAASJettyRealm = jettyContainer.addRealm(securityRealmName);
+ //wrap jetty realm with something that knows the dumb realmName
+ JAASJettyRealm realm = new JAASJettyRealm(realmName, internalJAASJettyRealm);
+ securityHandler.setUserRealm(realm);
+
+ securityHandler.init(policyContextID, defaultPrincipal, checkedPermissions, excludedPermissions,
classLoader);
+ }
+// end JACC
+ this.webAppContext = new WebAppContext(securityHandler, sessionHandler, null, null);
this.server = server;
this.application = application;
@@ -208,18 +223,6 @@
BeforeAfter interceptor = new InstanceContextBeforeAfter(null, index++, unshareableResources,
applicationManagedSecurityResources, trackedConnectionAssociator);
interceptor = new ComponentContextBeforeAfter(interceptor, index++, enc);
interceptor = new ThreadClassloaderBeforeAfter(interceptor, index++, index++, this.webClassLoader);
-//JACC
-
- if (securityRealmName != null) {
- InternalJAASJettyRealm internalJAASJettyRealm = jettyContainer.addRealm(securityRealmName);
- //wrap jetty realm with something that knows the dumb realmName
- JAASJettyRealm realm = new JAASJettyRealm(realmName, internalJAASJettyRealm);
- SecurityHandler security_handler = this.webAppContext.getSecurityHandler();
- security_handler.setUserRealm(realm);
-
- ((JettySecurityHandler) this.webAppContext.getSecurityHandler()).init(policyContextID,
defaultPrincipal, checkedPermissions, excludedPermissions, classLoader);
- }
-// end JACC
chain = interceptor;
contextLength = index;
}
@@ -401,7 +404,7 @@
public void setErrorPages(Map errorPageMap) {
if (errorPageMap != null) {
- ((WebAppContext.WebAppErrorHandler) this.webAppContext.getErrorHandler()).setErrorPages(errorPageMap);
+ ((ErrorPageErrorHandler)this.webAppContext.getErrorHandler()).setErrorPages(errorPageMap);
}
}
Modified: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty/ContainerTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty/ContainerTest.java?view=diff&rev=447149&r1=447148&r2=447149
==============================================================================
--- geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty/ContainerTest.java
(original)
+++ geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty/ContainerTest.java
Sun Sep 17 14:30:10 2006
@@ -42,11 +42,40 @@
}
}
- public void XtestWebServiceHandler() throws Exception {
+ public void testWebServiceHandler() throws Exception {
String contextPath = "/foo/webservice.ws";
MockWebServiceContainer webServiceInvoker = new MockWebServiceContainer();
container.addWebService(contextPath, null, webServiceInvoker, null, null, null, null,cl);
+
+ HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:5678"
+ contextPath).openConnection();
+ try {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
+ assertEquals("Hello World", reader.readLine());
+ } finally {
+ connection.disconnect();
+ }
+ container.removeWebService(contextPath);
+ connection = (HttpURLConnection) new URL("http://localhost:5678" + contextPath).openConnection();
+ try {
+ connection.getInputStream();
+ fail();
+ } catch (Exception e) {
+ // see if we removed the ws.
+ assertEquals(HttpURLConnection.HTTP_NOT_FOUND, connection.getResponseCode());
+ connection.disconnect();
+ }
+ }
+ public void test2WebServiceHandlers() throws Exception {
+
+ String contextPath = "/foo/webservice.ws";
+ MockWebServiceContainer webServiceInvoker = new MockWebServiceContainer();
+ container.addWebService(contextPath, null, webServiceInvoker, null, null, null, null,cl);
+
+ String contextPath2 = "/bar/webservice.ws";
+ MockWebServiceContainer webServiceInvoker2 = new MockWebServiceContainer();
+ container.addWebService(contextPath2, null, webServiceInvoker2, null, null, null,
null,cl);
HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:5678"
+ contextPath).openConnection();
try {
Modified: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty/SecurityTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty/SecurityTest.java?view=diff&rev=447149&r1=447148&r2=447149
==============================================================================
--- geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty/SecurityTest.java
(original)
+++ geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/test/java/org/apache/geronimo/jetty/SecurityTest.java
Sun Sep 17 14:30:10 2006
@@ -95,17 +95,12 @@
HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:5678/test/protected/hello.txt").openConnection();
connection.setInstanceFollowRedirects(false);
- //TODO jetty 6 this assertEquals should still be there!
-// assertEquals(HttpURLConnection.HTTP_MOVED_TEMP, connection.getResponseCode());
+ assertEquals(HttpURLConnection.HTTP_MOVED_TEMP, connection.getResponseCode());
String cookie = connection.getHeaderField("Set-Cookie");
cookie = cookie == null? "": cookie.substring(0, cookie.lastIndexOf(';'));
String location = connection.getHeaderField("Location");
- if (location == null) {
- //TODO this means test failed
- return;
- }
connection = (HttpURLConnection) new URL(location).openConnection();
connection.setInstanceFollowRedirects(false);
assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
Modified: geronimo/sandbox/javaee5/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/pom.xml?view=diff&rev=447149&r1=447148&r2=447149
==============================================================================
--- geronimo/sandbox/javaee5/pom.xml (original)
+++ geronimo/sandbox/javaee5/pom.xml Sun Sep 17 14:30:10 2006
@@ -78,8 +78,7 @@
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
- <version>6.0.0
- </version>
+ <version>6.0-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
|