Author: jgenender
Date: Wed Jun 15 09:27:58 2005
New Revision: 190774
URL: http://svn.apache.org/viewcvs?rev=190774&view=rev
Log:
Added EJB Webservice Support for Tomcat. Does not yet support virtual hosts until GERONIMO-666
is resolved. All EJB webservices will be applied to the default host
Added:
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatEJBWebServiceContext.java
geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/ContainerTest.java
geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/app/
geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/app/MockWebServiceContainer.java
Modified:
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContainer.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatGeronimoEmbedded.java
geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
Modified: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContainer.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContainer.java?rev=190774&r1=190773&r2=190774&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContainer.java
(original)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatContainer.java
Wed Jun 15 09:27:58 2005
@@ -16,6 +16,9 @@
*/
package org.apache.geronimo.tomcat;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.catalina.Container;
import org.apache.catalina.Context;
import org.apache.catalina.Engine;
@@ -27,6 +30,8 @@
import org.apache.geronimo.gbean.GBeanLifecycle;
import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
import org.apache.geronimo.system.serverinfo.ServerInfo;
+import org.apache.geronimo.webservices.SoapHandler;
+import org.apache.geronimo.webservices.WebServiceContainer;
/**
* Apache Tomcat GBean
@@ -36,7 +41,7 @@
*
* @version $Rev: 46019 $ $Date: 2004-09-14 11:56:06 +0200 (Tue, 14 Sep 2004) $
*/
-public class TomcatContainer implements GBeanLifecycle {
+public class TomcatContainer implements SoapHandler, GBeanLifecycle {
private static final Log log = LogFactory.getLog(TomcatContainer.class);
@@ -72,6 +77,8 @@
*/
private ServerInfo serverInfo;
+ private final Map webServices = new HashMap();
+
// Required as it's referenced by deployed webapps
public TomcatContainer() {
setCatalinaHome(DEFAULT_CATALINA_HOME);
@@ -213,6 +220,37 @@
public void removeConnector(Connector connector) {
embedded.removeConnector(connector);
}
+
+ public void addWebService(String contextPath, WebServiceContainer webServiceContainer,
String securityRealmName, String realmName, String transportGuarantee, String authMethod,
ClassLoader classLoader) throws Exception {
+ Context webServiceContext = embedded.createEJBWebServiceContext(contextPath, webServiceContainer,
securityRealmName, realmName, transportGuarantee, authMethod, classLoader);
+
+ //TODO When OpenEJB supports virtual hosts, remove the next line
+ String virtualServer = engine.getDefaultHost();
+
+ //TODO When OpenEJB supports virtual hosts, uncomment the code below. The
+ //virtualServer variable should be a String parameter from this function call
+ //if (virtualServer == null)
+ // virtualServer = engine.getDefaultHost();
+
+ Container host = engine.findChild(virtualServer);
+ if (host == null){
+ throw new IllegalArgumentException("Invalid virtual host '" + virtualServer +"'.
Do you have a matchiing Host entry in the plan?");
+ }
+
+ host.addChild(webServiceContext);
+ webServices.put(contextPath, webServiceContext);
+ }
+
+ public void removeWebService(String contextPath) {
+ TomcatEJBWebServiceContext context = (TomcatEJBWebServiceContext) webServices.get(contextPath);
+ try{
+ context.destroy();
+ } catch (Exception e){
+ throw new RuntimeException(e);
+ }
+ embedded.removeContext(context);
+ webServices.remove(contextPath);
+ }
public static final GBeanInfo GBEAN_INFO;
@@ -235,10 +273,13 @@
infoFactory.addOperation("addConnector", new Class[] { Connector.class });
infoFactory.addOperation("removeConnector", new Class[] { Connector.class });
+ infoFactory.addInterface(SoapHandler.class);
+
GBEAN_INFO = infoFactory.getBeanInfo();
}
public static GBeanInfo getGBeanInfo() {
return GBEAN_INFO;
}
+
}
Added: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatEJBWebServiceContext.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatEJBWebServiceContext.java?rev=190774&view=auto
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatEJBWebServiceContext.java
(added)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatEJBWebServiceContext.java
Wed Jun 15 09:27:58 2005
@@ -0,0 +1,277 @@
+/**
+*
+* Copyright 2003-2004 The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.geronimo.tomcat;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.ServletException;
+
+import org.apache.catalina.authenticator.BasicAuthenticator;
+import org.apache.catalina.authenticator.DigestAuthenticator;
+import org.apache.catalina.authenticator.SSLAuthenticator;
+import org.apache.catalina.connector.Request;
+import org.apache.catalina.connector.Response;
+import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.deploy.LoginConfig;
+import org.apache.catalina.deploy.SecurityCollection;
+import org.apache.catalina.deploy.SecurityConstraint;
+import org.apache.catalina.valves.ValveBase;
+import org.apache.geronimo.tomcat.realm.TomcatJAASRealm;
+import org.apache.geronimo.webservices.WebServiceContainer;
+
+public class TomcatEJBWebServiceContext extends StandardContext{
+ private final String contextPath;
+ private final WebServiceContainer webServiceContainer;
+ private final boolean isSecureTransportGuarantee;
+ private final ClassLoader classLoader;
+
+ public TomcatEJBWebServiceContext(String contextPath, WebServiceContainer webServiceContainer,
String securityRealmName, String realmName, String transportGuarantee, String authMethod,
ClassLoader classLoader) {
+
+ super();
+
+ this.contextPath = contextPath;
+ this.webServiceContainer = webServiceContainer;
+ this.setPath(contextPath);
+ this.setDocBase("");
+
+ if (securityRealmName != null) {
+
+ TomcatJAASRealm realm = new TomcatJAASRealm();
+ realm.setAppName(securityRealmName);
+ realm.setUserClassNames("org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal");
+ realm.setRoleClassNames("org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal");
+ setRealm(realm);
+ this.realm = realm;
+
+ if ("NONE".equals(transportGuarantee)) {
+ isSecureTransportGuarantee = false;
+ } else if ("INTEGRAL".equals(transportGuarantee) ||
+ "CONFIDENTIAL".equals(transportGuarantee)) {
+ isSecureTransportGuarantee = true;
+ } else {
+ throw new IllegalArgumentException("Invalid transport-guarantee: " + transportGuarantee);
+ }
+
+ if ("BASIC".equals(authMethod) ||
+ "DIGEST".equals(authMethod) ||
+ "CLIENT-CERT".equals(authMethod)) {
+
+ //Setup a login configuration
+ LoginConfig loginConfig = new LoginConfig();
+ loginConfig.setAuthMethod(authMethod);
+ loginConfig.setRealmName(realmName);
+ this.setLoginConfig(loginConfig);
+
+ //Setup a default Security Constraint
+ SecurityCollection collection = new SecurityCollection();
+ collection.addMethod("GET");
+ collection.addMethod("POST");
+ collection.addPattern("/*");
+ collection.setName("default");
+ SecurityConstraint sc = new SecurityConstraint();
+ sc.addAuthRole("*");
+ sc.addCollection(collection);
+ sc.setAuthConstraint(true);
+ sc.setUserConstraint(transportGuarantee);
+ this.addConstraint(sc);
+ this.addSecurityRole("default");
+
+ //Set the proper authenticator
+ if ("BASIC".equals(authMethod) ){
+ this.addValve(new BasicAuthenticator());
+ } else if ("DIGEST".equals(authMethod) ){
+ this.addValve(new DigestAuthenticator());
+ } else if ("CLIENT-CERT".equals(authMethod) ){
+ this.addValve(new SSLAuthenticator());
+ }
+
+ } else {
+ throw new IllegalArgumentException("Invalid authMethod: " + authMethod);
+ }
+ } else {
+ isSecureTransportGuarantee = false;
+ }
+ this.classLoader = classLoader;
+ this.addValve(new EJBWebServiceValve());
+
+ }
+
+ public class EJBWebServiceValve extends ValveBase{
+
+ public void invoke(Request req, Response res) throws IOException, ServletException
{
+ req.setContentType("text/xml");
+ RequestAdapter request = new RequestAdapter(req);
+ ResponseAdapter response = new ResponseAdapter(res);
+ req.finishRequest();
+ if (req.getParameter("wsdl") != null) {
+ try {
+ webServiceContainer.getWsdl(request, response);
+ //WHO IS RESPONSIBLE FOR CLOSING OUT?
+ } catch (IOException e) {
+ throw e;
+ } catch (Exception e) {
+ res.sendError(500,"Could not fetch wsdl!");
+ return;
+ }
+ } else {
+ if (isSecureTransportGuarantee) {
+ if (!req.isSecure()) {
+ res.sendError(403);
+ return;
+ }
+ }
+ Thread currentThread = Thread.currentThread();
+ ClassLoader oldClassLoader = currentThread.getContextClassLoader();
+ currentThread.setContextClassLoader(classLoader);
+ try {
+ try {
+ webServiceContainer.invoke(request, response);
+ req.finishRequest();
+ } catch (IOException e) {
+ throw e;
+ } catch (Exception e) {
+ res.sendError(500, "Could not process message!");
+ }
+ } finally {
+ currentThread.setContextClassLoader(oldClassLoader);
+ }
+ }
+ }
+
+ }
+
+ public static class RequestAdapter implements WebServiceContainer.Request {
+ private final Request request;
+ private URI uri;
+
+ public RequestAdapter(Request request) {
+ this.request = request;
+ }
+
+ public String getHeader(String name) {
+ return request.getHeader(name);
+ }
+
+ public java.net.URI getURI() {
+ if (uri == null) {
+ try {
+ String uriString = request.getScheme() + "://" + request.getHost() +
":" + request.getLocalPort() + request.getRequestURI();
+ //return new java.net.URI(uri.getScheme(),uri.getHost(),uri.getPath(),uri.);
+ uri = new java.net.URI(uriString);
+ } catch (URISyntaxException e) {
+ throw new IllegalStateException(e.getMessage());
+ }
+ }
+ return uri;
+ }
+
+ public int getContentLength() {
+ return request.getContentLength();
+ }
+
+ public String getContentType() {
+ return request.getContentType();
+ }
+
+ public InputStream getInputStream() throws IOException {
+ return request.getInputStream();
+ }
+
+ public int getMethod() {
+ Integer method = (Integer) methods.get(request.getMethod());
+ return method == null ? UNSUPPORTED : method.intValue();
+ }
+
+ public String getParameter(String name) {
+ return request.getParameter(name);
+ }
+
+ public Map getParameters() {
+ return request.getParameterMap();
+ }
+
+ public Object getAttribute(String name) {
+ return request.getAttribute(name);
+ }
+
+ public void setAttribute(String name, Object value) {
+ request.setAttribute(name, value);
+ }
+
+
+ private static final Map methods = new HashMap();
+
+ static {
+ methods.put("OPTIONS", new Integer(OPTIONS));
+ methods.put("GET", new Integer(GET));
+ methods.put("HEAD", new Integer(HEAD));
+ methods.put("POST", new Integer(POST));
+ methods.put("PUT", new Integer(PUT));
+ methods.put("DELETE", new Integer(DELETE));
+ methods.put("TRACE", new Integer(TRACE));
+ methods.put("CONNECT", new Integer(CONNECT));
+ }
+
+ }
+
+ public static class ResponseAdapter implements WebServiceContainer.Response {
+ private final Response response;
+
+ public ResponseAdapter(Response response) {
+ this.response = response;
+ }
+
+ public void setHeader(String name, String value) {
+ response.setHeader(name, value);
+ }
+
+ public String getHeader(String name) {
+ return response.getHeader(name);
+ }
+
+ public OutputStream getOutputStream() {
+ return response.getStream();
+ }
+
+ public void setStatusCode(int code) {
+ response.setStatus(code);
+ }
+
+ public int getStatusCode() {
+ return response.getStatus();
+ }
+
+ public void setContentType(String type) {
+ response.setContentType(type);
+ }
+
+ public String getContentType() {
+ return response.getContentType();
+ }
+
+ public void setStatusMessage(String responseString) {
+ response.setStatus(response.getStatus(), responseString);
+ }
+ }
+
+}
Modified: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatGeronimoEmbedded.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatGeronimoEmbedded.java?rev=190774&r1=190773&r2=190774&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatGeronimoEmbedded.java
(original)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatGeronimoEmbedded.java
Wed Jun 15 09:27:58 2005
@@ -22,6 +22,7 @@
import org.apache.catalina.startup.Embedded;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.webservices.WebServiceContainer;
public class TomcatGeronimoEmbedded extends Embedded{
@@ -39,6 +40,27 @@
context.setPath(path);
context.setParentClassLoader(cl);
+ ContextConfig config = new ContextConfig();
+ config.setCustomAuthenticators(authenticators);
+ ((Lifecycle) context).addLifecycleListener(config);
+
+ return (context);
+
+ }
+
+ public Context createEJBWebServiceContext(String contextPath,
+ WebServiceContainer webServiceContainer,
+ String securityRealmName,
+ String realmName,
+ String transportGuarantee,
+ String authMethod,
+ ClassLoader classLoader) {
+
+ if( log.isDebugEnabled() )
+ log.debug("Creating EJBWebService context '" + contextPath + "'.");
+
+ TomcatEJBWebServiceContext context = new TomcatEJBWebServiceContext(contextPath,
webServiceContainer, securityRealmName, realmName, transportGuarantee, authMethod, classLoader);
+
ContextConfig config = new ContextConfig();
config.setCustomAuthenticators(authenticators);
((Lifecycle) context).addLifecycleListener(config);
Modified: geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java?rev=190774&r1=190773&r2=190774&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
(original)
+++ geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
Wed Jun 15 09:27:58 2005
@@ -231,9 +231,6 @@
propertiesRealmGBean = new GBeanData(propertiesRealmName, GenericSecurityRealm.GBEAN_INFO);
propertiesRealmGBean.setReferencePattern("ServerInfo", serverInfoName);
propertiesRealmGBean.setAttribute("realmName", "Geronimo");
-// Properties config = new Properties();
-// config.setProperty("LoginModule.1.REQUIRED", propertiesLMName.getCanonicalName());
-// propertiesRealmGBean.setAttribute("loginModuleConfiguration", config);
propertiesRealmGBean.setReferencePattern("LoginModuleConfiguration", testUseName);
Principal.PrincipalEditor principalEditor = new Principal.PrincipalEditor();
principalEditor.setAsText("metro=org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal");
Added: geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/ContainerTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/ContainerTest.java?rev=190774&view=auto
==============================================================================
--- geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/ContainerTest.java (added)
+++ geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/ContainerTest.java Wed
Jun 15 09:27:58 2005
@@ -0,0 +1,301 @@
+/**
+*
+* Copyright 2003-2004 The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.geronimo.tomcat;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import javax.management.ObjectName;
+
+import junit.framework.TestCase;
+import org.apache.geronimo.gbean.GBeanData;
+import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContext;
+import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContextImpl;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.kernel.KernelFactory;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.management.State;
+import org.apache.geronimo.security.SecurityServiceImpl;
+import org.apache.geronimo.security.deploy.Principal;
+import org.apache.geronimo.security.jaas.GeronimoLoginConfiguration;
+import org.apache.geronimo.security.jaas.JaasLoginModuleUse;
+import org.apache.geronimo.security.jaas.JaasLoginService;
+import org.apache.geronimo.security.jaas.LoginModuleGBean;
+import org.apache.geronimo.security.realm.GenericSecurityRealm;
+import org.apache.geronimo.system.serverinfo.ServerInfo;
+import org.apache.geronimo.tomcat.app.MockWebServiceContainer;
+import org.apache.geronimo.webservices.WebServiceContainer;
+
+import sun.misc.BASE64Encoder;
+
+/**
+* @version $Rev: 170494 $ $Date: 2005-05-16 18:28:28 -0600 (Mon, 16 May 2005) $
+*/
+public class ContainerTest extends TestCase {
+ private ClassLoader cl = this.getClass().getClassLoader();
+ private Kernel kernel;
+ private GBeanData container;
+ private ObjectName containerName;
+ private Set containerPatterns;
+ private ObjectName connectorName;
+ private GBeanData connector;
+ private ObjectName engineName;
+ private GBeanData engine;
+ private ObjectName hostName;
+ private GBeanData host;
+ private J2eeContext moduleContext = new J2eeContextImpl("tomcat.test", "test", "null",
NameFactory.WEB_MODULE, "tomcatTest", null, null);
+ private ObjectName serverInfoName;
+ private GBeanData serverInfoGBean;
+ private GBeanData securityServiceGBean;
+ private ObjectName securityServiceName;
+ private ObjectName loginServiceName;
+ private GBeanData loginServiceGBean;
+ private GBeanData loginConfigurationGBean;
+ private ObjectName loginConfigurationName;
+ private GBeanData propertiesLMGBean;
+ private ObjectName propertiesLMName;
+ private ObjectName propertiesRealmName;
+ private GBeanData propertiesRealmGBean;
+
+
+ public void testWebServiceHandler() throws Exception {
+
+ setUpWeb();
+
+ assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(connectorName));
+ assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(containerName));
+
+ String contextPath = "/foo/webservice.ws";
+ MockWebServiceContainer webServiceInvoker = new MockWebServiceContainer();
+ kernel.invoke(containerName, "addWebService", new Object[] {contextPath, webServiceInvoker,
null, null, null, null, cl}, new String[] {String.class.getName(), WebServiceContainer.class.getName(),
String.class.getName(), String.class.getName(), String.class.getName(), String.class.getName(),
ClassLoader.class.getName()});
+
+ HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:8080"
+ 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();
+ }
+ kernel.invoke(containerName, "removeWebService", new Object[] {contextPath}, new String[]
{String.class.getName()});
+ connection = (HttpURLConnection) new URL("http://localhost:8080" + contextPath).openConnection();
+ try {
+ connection.getInputStream();
+ fail();
+ } catch (Exception e) {
+ // see if we removed the ws.
+ assertEquals(HttpURLConnection.HTTP_NOT_FOUND, connection.getResponseCode());
+ connection.disconnect();
+ }
+
+ tearDownWeb();
+ }
+
+ public void testSecureWebServiceHandler() throws Exception {
+
+ setUpWeb();
+
+ assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(connectorName));
+ assertEquals(State.RUNNING_INDEX, kernel.getGBeanState(containerName));
+
+ setUpSecurity();
+
+ String contextPath = "/foo/webservice.ws";
+ MockWebServiceContainer webServiceInvoker = new MockWebServiceContainer();
+ kernel.invoke(containerName, "addWebService", new Object[] {contextPath, webServiceInvoker,
"Geronimo", "Geronimo", "NONE", "BASIC",cl}, new String[] {String.class.getName(), WebServiceContainer.class.getName(),
String.class.getName(), String.class.getName(), String.class.getName(), String.class.getName(),
ClassLoader.class.getName()});
+
+ //Veryify its secured
+ HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:8080"
+ contextPath).openConnection();
+ try {
+ connection.getInputStream();
+ fail();
+ } catch (Exception e) {
+ assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, connection.getResponseCode());
+ } finally {
+ connection.disconnect();
+ }
+
+ //Authenticate
+ connection = (HttpURLConnection) new URL("http://localhost:8080" + contextPath).openConnection();
+ String authentication = (new BASE64Encoder()).encode(("alan:starcraft").getBytes());
+ connection.setRequestProperty("Authorization", "Basic " + authentication);
+ try {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
+ assertEquals("Hello World", reader.readLine());
+ } finally {
+ connection.disconnect();
+ }
+ kernel.invoke(containerName, "removeWebService", new Object[] {contextPath}, new String[]
{String.class.getName()});
+ connection = (HttpURLConnection) new URL("http://localhost:8080" + contextPath).openConnection();
+ try {
+ connection.getInputStream();
+ fail();
+ } catch (Exception e) {
+ // see if we removed the ws.
+ assertEquals(HttpURLConnection.HTTP_NOT_FOUND, connection.getResponseCode());
+ connection.disconnect();
+ }
+
+ tearDownSecurity();
+ tearDownWeb();
+ }
+
+ private void start(GBeanData instance) throws Exception {
+ kernel.loadGBean(instance, cl);
+ kernel.startGBean(instance.getName());
+ }
+
+ private void stop(ObjectName name) throws Exception {
+ kernel.stopGBean(name);
+ kernel.unloadGBean(name);
+ }
+
+ protected void setUpSecurity() throws Exception {
+
+ loginConfigurationName = new ObjectName("geronimo.security:type=LoginConfiguration");
+ loginConfigurationGBean = new GBeanData(loginConfigurationName, GeronimoLoginConfiguration.getGBeanInfo());
+ Set configurations = new HashSet();
+ configurations.add(new ObjectName("geronimo.server:j2eeType=SecurityRealm,*"));
+ configurations.add(new ObjectName("geronimo.server:j2eeType=ConfigurationEntry,*"));
+ loginConfigurationGBean.setReferencePatterns("Configurations", configurations);
+
+ securityServiceName = new ObjectName("geronimo.server:j2eeType=SecurityService");
+ securityServiceGBean = new GBeanData(securityServiceName, SecurityServiceImpl.GBEAN_INFO);
+ securityServiceGBean.setReferencePattern("ServerInfo", serverInfoName);
+ securityServiceGBean.setAttribute("policyConfigurationFactory", "org.apache.geronimo.security.jacc.GeronimoPolicyConfigurationFactory");
+ securityServiceGBean.setAttribute("policyProvider", "org.apache.geronimo.security.jacc.GeronimoPolicy");
+
+ loginServiceName = JaasLoginService.OBJECT_NAME;
+ loginServiceGBean = new GBeanData(loginServiceName, JaasLoginService.GBEAN_INFO);
+ loginServiceGBean.setReferencePattern("Realms", new ObjectName("geronimo.server:j2eeType=SecurityRealm,*"));
+ loginServiceGBean.setAttribute("algorithm", "HmacSHA1");
+ loginServiceGBean.setAttribute("password", "secret");
+
+ propertiesLMName = new ObjectName("geronimo.security:type=LoginModule,name=Geronimo");
+ propertiesLMGBean = new GBeanData(propertiesLMName, LoginModuleGBean.GBEAN_INFO);
+ propertiesLMGBean.setAttribute("loginModuleClass", "org.apache.geronimo.security.realm.providers.PropertiesFileLoginModule");
+ propertiesLMGBean.setAttribute("serverSide", Boolean.TRUE);
+ Properties options = new Properties();
+ options.setProperty("usersURI", "src/test-resources/data/users.properties");
+ options.setProperty("groupsURI", "src/test-resources/data/groups.properties");
+ propertiesLMGBean.setAttribute("options", options);
+ propertiesLMGBean.setAttribute("loginDomainName", "geronimo-properties-realm");
+
+ ObjectName testUseName = new ObjectName("geronimo.security:type=LoginModuleUse,name=properties");
+ GBeanData lmUseGBean = new GBeanData(testUseName, JaasLoginModuleUse.getGBeanInfo());
+ lmUseGBean.setAttribute("controlFlag", "REQUIRED");
+ lmUseGBean.setReferencePattern("LoginModule", propertiesLMName);
+
+ propertiesRealmName = new ObjectName("geronimo.server:j2eeType=SecurityRealm,name=geronimo-properties-realm");
+ propertiesRealmGBean = new GBeanData(propertiesRealmName, GenericSecurityRealm.GBEAN_INFO);
+ propertiesRealmGBean.setReferencePattern("ServerInfo", serverInfoName);
+ propertiesRealmGBean.setAttribute("realmName", "Geronimo");
+ propertiesRealmGBean.setReferencePattern("LoginModuleConfiguration", testUseName);
+ Principal.PrincipalEditor principalEditor = new Principal.PrincipalEditor();
+ principalEditor.setAsText("metro=org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal");
+ propertiesRealmGBean.setAttribute("defaultPrincipal", principalEditor.getValue());
+
+ start(loginConfigurationGBean);
+ start(securityServiceGBean);
+ start(loginServiceGBean);
+ start(propertiesLMGBean);
+ start(lmUseGBean);
+ start(propertiesRealmGBean);
+
+ }
+
+ protected void tearDownSecurity() throws Exception {
+ stop(propertiesRealmName);
+ stop(propertiesLMName);
+ stop(loginServiceName);
+ stop(securityServiceName);
+ stop(loginConfigurationName);
+ }
+
+ private void setUpWeb() throws Exception{
+ containerName = NameFactory.getWebComponentName(null, null, null, null, "tomcatContainer",
"WebResource", moduleContext);
+ connectorName = NameFactory.getWebComponentName(null, null, null, null, "tomcatConnector",
"WebResource", moduleContext);
+ containerPatterns = new HashSet();
+ containerPatterns.add(containerName);
+ connectorName = new ObjectName("geronimo.tomcat:role=Connector");
+ connectorName = NameFactory.getWebComponentName(null, null, null, null, "tomcatConnector",
"WebResource", moduleContext);
+ engineName = NameFactory.getWebComponentName(null, null, null, null, "tomcatEngine",
"WebResource", moduleContext);
+ hostName = NameFactory.getWebComponentName(null, null, null, null, "tomcatHost", "WebResource",
moduleContext);
+ kernel = KernelFactory.newInstance().createKernel("test.kernel");
+ kernel.boot();
+
+ //ServerInfo
+ serverInfoName = new ObjectName("geronimo.system:role=ServerInfo");
+ serverInfoGBean = new GBeanData(serverInfoName, ServerInfo.GBEAN_INFO);
+ serverInfoGBean.setAttribute("baseDirectory", ".");
+ start(serverInfoGBean);
+
+ Map initParams = new HashMap();
+
+ //Default Engine
+ initParams.clear();
+ initParams.put("name","Geronimo");
+ initParams.put("defaultHost","localhost");
+ engine = new GBeanData(engineName, EngineGBean.GBEAN_INFO);
+ engine.setAttribute("className", "org.apache.geronimo.tomcat.TomcatEngine");
+ engine.setAttribute("initParams", initParams);
+ start(engine);
+
+ //Default Host
+ initParams.clear();
+ initParams.put("workDir","work");
+ initParams.put("name","localhost");
+ initParams.put("appBase","");
+ host = new GBeanData(hostName, HostGBean.GBEAN_INFO);
+ host.setAttribute("className", "org.apache.catalina.core.StandardHost");
+ host.setAttribute("initParams", initParams);
+ host.setReferencePattern("engineGBean", engineName);
+ start(host);
+
+ container = new GBeanData(containerName, TomcatContainer.GBEAN_INFO);
+ container.setAttribute("classLoader", cl);
+ container.setAttribute("catalinaHome", "target/var/catalina");
+ container.setReferencePattern("engineGBean", engineName);
+ container.setReferencePattern("ServerInfo", serverInfoName);
+ start(container);
+
+ initParams.clear();
+ initParams.put("port","8080");
+ connector = new GBeanData(connectorName, ConnectorGBean.GBEAN_INFO);
+ connector.setAttribute("initParams", initParams);
+ connector.setReferencePattern("TomcatContainer", containerName);
+ start(connector);
+ }
+
+ private void tearDownWeb() throws Exception {
+ stop(connectorName);
+ stop(containerName);
+ stop(hostName);
+ stop(engineName);
+ stop(serverInfoName);
+ kernel.shutdown();
+ }
+
+}
Added: geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/app/MockWebServiceContainer.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/app/MockWebServiceContainer.java?rev=190774&view=auto
==============================================================================
--- geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/app/MockWebServiceContainer.java
(added)
+++ geronimo/trunk/modules/tomcat/src/test/org/apache/geronimo/tomcat/app/MockWebServiceContainer.java
Wed Jun 15 09:27:58 2005
@@ -0,0 +1,33 @@
+/**
+*
+* Copyright 2003-2004 The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.geronimo.tomcat.app;
+
+import org.apache.geronimo.webservices.WebServiceContainer;
+
+/**
+* @version $Rev: $ $Date: $
+*/
+public class MockWebServiceContainer implements WebServiceContainer {
+ public void invoke(Request request, Response response) throws Exception {
+ response.getOutputStream().write("Hello World".getBytes());
+ }
+
+ public void getWsdl(Request req, Response res) throws Exception {
+
+ }
+
+}
|