You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/06/29 19:13:00 UTC
svn commit: r418086 - in /incubator/servicemix/trunk/servicemix-http/src:
main/java/org/apache/servicemix/http/
main/java/org/apache/servicemix/http/jetty/
main/java/org/apache/servicemix/http/processors/
test/java/org/apache/servicemix/http/ test/reso...
Author: gnodet
Date: Thu Jun 29 10:13:00 2006
New Revision: 418086
URL: http://svn.apache.org/viewvc?rev=418086&view=rev
Log:
SM-476: Provide a servlet so that servicemix-http can reuse the web container where servicemix is deployed
Added:
incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ContextManager.java
incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpManagedServlet.java
incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ManagedContextManager.java
incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JettyContextManager.java
incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpManagedTest.java
incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/spring-web.xml
Removed:
incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ServerManager.java
Modified:
incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java
incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpLifeCycle.java
incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpSpringComponent.java
incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java
incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpProviderTest.java
incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/ServerManagerTest.java
Added: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ContextManager.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ContextManager.java?rev=418086&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ContextManager.java (added)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ContextManager.java Thu Jun 29 10:13:00 2006
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2005-2006 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.servicemix.http;
+
+
+public interface ContextManager {
+
+ public void init() throws Exception;
+
+ public void shutDown() throws Exception;
+
+ public void start() throws Exception;
+
+ public void stop() throws Exception;
+
+ public Object createContext(String strUrl,
+ HttpProcessor processor) throws Exception;
+
+ public void remove(Object context) throws Exception;
+
+ public void setConfiguration(HttpConfiguration configuration);
+
+ public HttpProcessor getMainProcessor();
+
+}
Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java?rev=418086&r1=418085&r2=418086&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java (original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java Thu Jun 29 10:13:00 2006
@@ -29,6 +29,8 @@
public static final String DEFAULT_JETTY_CONNECTOR_CLASS_NAME = SelectChannelConnector.class.getName();
+ public static final String MAPPING_DEFAULT = "/jbi";
+
private boolean streamingEnabled = false;
private String jettyConnectorClassName = DEFAULT_JETTY_CONNECTOR_CLASS_NAME;
@@ -65,6 +67,52 @@
* If true, use register jetty mbeans
*/
private boolean jettyManagement;
+
+ /**
+ * If the component is deployed in a web container and uses
+ * a servlet instead of starting its own web server.
+ */
+ private boolean managed = false;
+
+ /**
+ * When managed is true, this is the servlet mapping used
+ * to access the component.
+ */
+ private transient String mapping = MAPPING_DEFAULT;
+
+ /**
+ * @return the mapping
+ */
+ public String getMapping() {
+ return mapping;
+ }
+
+ /**
+ * @param mapping the mapping to set
+ */
+ public void setMapping(String mapping) {
+ if (!mapping.startsWith("/")) {
+ mapping = "/" + mapping;
+ }
+ if (mapping.endsWith("/")) {
+ mapping = mapping.substring(0, mapping.length() - 1);
+ }
+ this.mapping = mapping;
+ }
+
+ /**
+ * @return the managed
+ */
+ public boolean isManaged() {
+ return managed;
+ }
+
+ /**
+ * @param managed the managed to set
+ */
+ public void setManaged(boolean managed) {
+ this.managed = managed;
+ }
/**
* @return the jettyManagement
Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java?rev=418086&r1=418085&r2=418086&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java (original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java Thu Jun 29 10:13:00 2006
@@ -191,12 +191,18 @@
for (int i = 0; i < names.length; i++) {
def.removeBinding(names[i]);
}
+ String location = getLocationURI();
+ HttpLifeCycle lf = (HttpLifeCycle) getServiceUnit().getComponent().getLifeCycle();
+ if (lf.getConfiguration().isManaged()) {
+ // TODO: need to find the port of the web server
+ location = "http://localhost" + lf.getConfiguration().getMapping() + new URI(location).getPath();
+ }
if (portType.getQName().getNamespaceURI().equals(service.getNamespaceURI())) {
if (isSoap()) {
PortTypeDecorator.decorate(
def,
portType,
- getLocationURI(),
+ location,
endpoint + "Binding",
service.getLocalPart(),
endpoint);
@@ -212,7 +218,7 @@
port.setName(endpoint);
port.setBinding(binding);
HTTPAddress address = new HTTPAddressImpl();
- address.setLocationURI(getLocationURI());
+ address.setLocationURI(location);
port.addExtensibilityElement(address);
def.addNamespace("http", "http://schemas.xmlsoap.org/wsdl/http/");
Service svc = def.createService();
@@ -227,7 +233,7 @@
PortTypeDecorator.decorate(
definition,
portType,
- getLocationURI(),
+ location,
endpoint + "Binding",
service.getLocalPart(),
endpoint);
Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpLifeCycle.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpLifeCycle.java?rev=418086&r1=418085&r2=418086&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpLifeCycle.java (original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpLifeCycle.java Thu Jun 29 10:13:00 2006
@@ -31,13 +31,14 @@
import org.apache.servicemix.common.BaseLifeCycle;
import org.apache.servicemix.common.Endpoint;
import org.apache.servicemix.common.ServiceUnit;
+import org.apache.servicemix.http.jetty.JettyContextManager;
import org.apache.servicemix.jbi.security.auth.AuthenticationService;
import org.apache.servicemix.jbi.security.auth.impl.JAASAuthenticationService;
import org.apache.servicemix.jbi.security.keystore.KeystoreManager;
public class HttpLifeCycle extends BaseLifeCycle {
- protected ServerManager server;
+ protected ContextManager server;
protected HttpClient client;
protected MultiThreadedHttpConnectionManager connectionManager;
protected HttpConfiguration configuration = new HttpConfiguration();
@@ -46,11 +47,11 @@
super(component);
}
- public ServerManager getServer() {
+ public ContextManager getServer() {
return server;
}
- public void setServer(ServerManager server) {
+ public void setServer(ContextManager server) {
this.server = server;
}
@@ -114,18 +115,21 @@
client = new HttpClient(connectionManager);
}
// Create serverManager
- if (server == null) {
- server = new ServerManager();
+ if (configuration.isManaged()) {
+ server = new ManagedContextManager();
+ } else {
+ JettyContextManager server = new JettyContextManager();
server.setMBeanServer(context.getMBeanServer());
- server.setConfiguration(configuration);
- server.init();
+ this.server = server;
}
+ server.setConfiguration(configuration);
+ server.init();
}
protected void doShutDown() throws Exception {
super.doShutDown();
if (server != null) {
- ServerManager s = server;
+ ContextManager s = server;
server = null;
s.shutDown();
}
@@ -194,6 +198,16 @@
*/
public void setAuthenticationService(AuthenticationService authenticationService) {
this.configuration.setAuthenticationService(authenticationService);
+ }
+
+ /**
+ * When servicemix-http is embedded inside a web application and configured
+ * to reuse the existing servlet container, this method will create and
+ * return the HTTPProcessor which will handle all servlet calls
+ * @param mappings
+ */
+ public HttpProcessor getMainProcessor() {
+ return server.getMainProcessor();
}
}
Added: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpManagedServlet.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpManagedServlet.java?rev=418086&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpManagedServlet.java (added)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpManagedServlet.java Thu Jun 29 10:13:00 2006
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2005-2006 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.servicemix.http;
+
+import java.io.IOException;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.framework.ComponentMBeanImpl;
+import org.springframework.context.ApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+/**
+ * This servlet is meant to be used when embedding ServiceMix in a web application
+ * so that so servicemix-http component will reuse the web container.
+ *
+ * @author gnodet
+ */
+public class HttpManagedServlet extends javax.servlet.http.HttpServlet {
+
+ public static final String CONTAINER_PROPERTY = "container";
+ public static final String CONTAINER_DEFAULT = "jbi";
+
+ public static final String COMPONENT_PROPERTY = "component";
+ public static final String COMPONENT_DEFAULT = "servicemix-http";
+
+ public static final String MAPPING_PROPERTY = "mapping";
+
+ private HttpProcessor processor;
+
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+
+ // Retrieve spring application context
+ ApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
+
+ // Retrieve
+ String containerName = config.getInitParameter(CONTAINER_PROPERTY);
+ if (containerName == null) {
+ containerName = CONTAINER_DEFAULT;
+ }
+ JBIContainer container = (JBIContainer) applicationContext.getBean(containerName);
+ if (container == null) {
+ throw new IllegalStateException("Unable to find jbi container " + containerName);
+ }
+ String componentName = config.getInitParameter(COMPONENT_PROPERTY);
+ if (componentName == null) {
+ componentName = COMPONENT_DEFAULT;
+ }
+ ComponentMBeanImpl componentMBean = container.getComponent(componentName);
+ if (componentMBean == null) {
+ throw new IllegalStateException("Unable to find component " + componentName);
+ }
+ if (componentMBean.getComponent() instanceof HttpSpringComponent == false) {
+ throw new IllegalStateException("The component is not an instance of HttpSpringComponent");
+ }
+ HttpSpringComponent component = (HttpSpringComponent) componentMBean.getComponent();
+ String mapping = config.getInitParameter(MAPPING_PROPERTY);
+ if (mapping != null) {
+ component.getConfiguration().setMapping(mapping);
+ }
+ processor = component.getMainProcessor();
+ }
+
+ protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ try {
+ processor.process(request, response);
+ } catch (IOException e) {
+ throw e;
+ } catch (ServletException e) {
+ throw e;
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new ServletException("Failed to process request: " + e, e);
+ }
+ }
+}
Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpSpringComponent.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpSpringComponent.java?rev=418086&r1=418085&r2=418086&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpSpringComponent.java (original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpSpringComponent.java Thu Jun 29 10:13:00 2006
@@ -124,4 +124,8 @@
((HttpLifeCycle) getLifeCycle()).setConfiguration(configuration);
}
+ public HttpProcessor getMainProcessor() {
+ return ((HttpLifeCycle) getLifeCycle()).getMainProcessor();
+ }
+
}
Added: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ManagedContextManager.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ManagedContextManager.java?rev=418086&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ManagedContextManager.java (added)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/ManagedContextManager.java Thu Jun 29 10:13:00 2006
@@ -0,0 +1,164 @@
+/*
+ * Copyright 2005-2006 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.servicemix.http;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URI;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.mortbay.jetty.MimeTypes;
+import org.mortbay.util.ByteArrayISO8859Writer;
+import org.mortbay.util.StringUtil;
+
+import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
+
+public class ManagedContextManager implements ContextManager {
+
+ private static final Log logger = LogFactory.getLog(ManagedContextManager.class);
+
+ private HttpConfiguration configuration;
+ private Map managedContexts;
+
+ public void init() throws Exception {
+ if (configuration == null) {
+ configuration = new HttpConfiguration();
+ }
+ managedContexts = new ConcurrentHashMap();
+ }
+
+ public void shutDown() throws Exception {
+ stop();
+ }
+
+ public void start() throws Exception {
+ }
+
+ public void stop() throws Exception {
+ }
+
+ public synchronized Object createContext(String strUrl,
+ HttpProcessor processor) throws Exception {
+ URI uri = new URI(strUrl);
+ String path = uri.getPath();
+ if (!path.startsWith("/")) {
+ path = path + "/";
+ }
+ if (!path.endsWith("/")) {
+ path = path + "/";
+ }
+ managedContexts.put(path, processor);
+ return path;
+ }
+
+ public synchronized void remove(Object context) throws Exception {
+ managedContexts.remove(context);
+ }
+
+ public HttpConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(HttpConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ public HttpProcessor getMainProcessor() {
+ if (!configuration.isManaged()) {
+ throw new IllegalStateException("ServerManager is not managed");
+ }
+ return new MainProcessor();
+ }
+
+ protected class MainProcessor implements HttpProcessor {
+ private String mapping;
+ public MainProcessor() {
+ this.mapping = configuration.getMapping();
+ }
+ public String getAuthMethod() {
+ return null;
+ }
+ public SslParameters getSsl() {
+ return null;
+ }
+ public void process(HttpServletRequest request, HttpServletResponse response) throws Exception {
+ String uri = request.getRequestURI();
+ if ("/".equals(uri) && "GET".equals(request.getMethod())) {
+ displayServices(request, response);
+ return;
+ }
+ Set urls = managedContexts.keySet();
+ for (Iterator iter = urls.iterator(); iter.hasNext();) {
+ String url = (String) iter.next();
+ if (uri.startsWith(mapping + url)) {
+ HttpProcessor proc = (HttpProcessor) managedContexts.get(url);
+ proc.process(request, response);
+ return;
+ }
+ }
+ displayServices(request, response);
+ }
+ public void displayServices(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ response.setStatus(404);
+ response.setContentType(MimeTypes.TEXT_HTML);
+
+ ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(1500);
+
+ String uri = request.getRequestURI();
+ uri = StringUtil.replace(uri, "<", "<");
+ uri = StringUtil.replace(uri, ">", ">");
+
+ writer.write("<HTML>\n<HEAD>\n<TITLE>Error 404 - Not Found");
+ writer.write("</TITLE>\n<BODY>\n<H2>Error 404 - Not Found.</H2>\n");
+ writer.write("No service matched or handled this request.<BR>");
+ writer.write("Known services are: <ul>");
+
+ Set servers = ManagedContextManager.this.managedContexts.keySet();
+ for (Iterator iter = servers.iterator(); iter.hasNext();) {
+ String context = (String) iter.next();
+ if (!context.endsWith("/")) {
+ context += "/";
+ }
+ String protocol = request.isSecure() ? "https" : "http";
+ context = protocol + "://" + request.getLocalName() + ":" + request.getLocalPort() + mapping + context;
+ writer.write("<li><a href=\"");
+ writer.write(context);
+ writer.write("?wsdl\">");
+ writer.write(context);
+ writer.write("</a></li>\n");
+ }
+
+ for (int i=0; i < 10; i++) {
+ writer.write("\n<!-- Padding for IE -->");
+ }
+
+ writer.write("\n</BODY>\n</HTML>\n");
+ writer.flush();
+ response.setContentLength(writer.size());
+ OutputStream out = response.getOutputStream();
+ writer.writeTo(out);
+ out.close();
+ }
+ }
+
+}
Added: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JettyContextManager.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JettyContextManager.java?rev=418086&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JettyContextManager.java (added)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/jetty/JettyContextManager.java Thu Jun 29 10:13:00 2006
@@ -0,0 +1,437 @@
+/*
+ * Copyright 2005-2006 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.servicemix.http.jetty;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.jbi.JBIException;
+import javax.management.MBeanServer;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.http.ContextManager;
+import org.apache.servicemix.http.HttpBridgeServlet;
+import org.apache.servicemix.http.HttpConfiguration;
+import org.apache.servicemix.http.HttpProcessor;
+import org.apache.servicemix.http.SslParameters;
+import org.mortbay.component.AbstractLifeCycle;
+import org.mortbay.jetty.AbstractConnector;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Handler;
+import org.mortbay.jetty.HttpConnection;
+import org.mortbay.jetty.HttpMethods;
+import org.mortbay.jetty.MimeTypes;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.handler.AbstractHandler;
+import org.mortbay.jetty.handler.ContextHandler;
+import org.mortbay.jetty.handler.ContextHandlerCollection;
+import org.mortbay.jetty.handler.HandlerCollection;
+import org.mortbay.jetty.security.Constraint;
+import org.mortbay.jetty.security.ConstraintMapping;
+import org.mortbay.jetty.security.SecurityHandler;
+import org.mortbay.jetty.security.SslSocketConnector;
+import org.mortbay.jetty.servlet.ServletHandler;
+import org.mortbay.jetty.servlet.ServletHolder;
+import org.mortbay.jetty.servlet.ServletMapping;
+import org.mortbay.management.MBeanContainer;
+import org.mortbay.thread.BoundedThreadPool;
+import org.mortbay.thread.ThreadPool;
+import org.mortbay.util.ByteArrayISO8859Writer;
+import org.mortbay.util.LazyList;
+import org.mortbay.util.StringUtil;
+import org.springframework.core.io.ClassPathResource;
+
+public class JettyContextManager implements ContextManager {
+
+ private static final Log logger = LogFactory.getLog(JettyContextManager.class);
+
+ private Map servers;
+ private HttpConfiguration configuration;
+ private ThreadPool threadPool;
+ private Map sslParams;
+ private MBeanServer mbeanServer;
+ private MBeanContainer mbeanContainer;
+
+ /**
+ * @return the mbeanServer
+ */
+ public MBeanServer getMBeanServer() {
+ return mbeanServer;
+ }
+
+ /**
+ * @param mbeanServer the mbeanServer to set
+ */
+ public void setMBeanServer(MBeanServer mbeanServer) {
+ this.mbeanServer = mbeanServer;
+ }
+
+ public void init() throws Exception {
+ if (configuration == null) {
+ configuration = new HttpConfiguration();
+ }
+ if (mbeanServer != null && !configuration.isManaged() && configuration.isJettyManagement()) {
+ mbeanContainer = new MBeanContainer(mbeanServer);
+ }
+ servers = new HashMap();
+ sslParams = new HashMap();
+ BoundedThreadPool btp = new BoundedThreadPool();
+ btp.setMaxThreads(this.configuration.getJettyThreadPoolSize());
+ threadPool = btp;
+ }
+
+ public void shutDown() throws Exception {
+ stop();
+ }
+
+ public void start() throws Exception {
+ threadPool.start();
+ for (Iterator it = servers.values().iterator(); it.hasNext();) {
+ Server server = (Server) it.next();
+ server.start();
+ }
+ }
+
+ public void stop() throws Exception {
+ for (Iterator it = servers.values().iterator(); it.hasNext();) {
+ Server server = (Server) it.next();
+ server.stop();
+ }
+ for (Iterator it = servers.values().iterator(); it.hasNext();) {
+ Server server = (Server) it.next();
+ server.join();
+ Connector[] connectors = server.getConnectors();
+ for (int i = 0; i < connectors.length; i++) {
+ if (connectors[i] instanceof AbstractConnector) {
+ ((AbstractConnector) connectors[i]).join();
+ }
+ }
+ }
+ threadPool.stop();
+ }
+
+ public synchronized Object createContext(String strUrl,
+ HttpProcessor processor) throws Exception {
+ URL url = new URL(strUrl);
+ Server server = getServer(url);
+ if (server == null) {
+ server = createServer(url, processor.getSsl());
+ } else {
+ // Check ssl params
+ SslParameters ssl = (SslParameters) sslParams.get(getKey(url));
+ if (ssl != null && !ssl.equals(processor.getSsl())) {
+ throw new Exception("An https server is already created on port " + url.getPort() + " but SSL parameters do not match");
+ }
+ }
+ String path = url.getPath();
+ if (!path.startsWith("/")) {
+ path = "/" + path;
+ }
+ if (path.endsWith("/")) {
+ path = path.substring(0, path.length() - 1);
+ }
+ // Check that context does not exist yet
+ HandlerCollection handlerCollection = (HandlerCollection) server.getHandler();
+ ContextHandlerCollection contexts = (ContextHandlerCollection) handlerCollection.getHandlers()[0];
+ Handler[] handlers = contexts.getHandlers();
+ if (handlers != null) {
+ for (int i = 0; i < handlers.length; i++) {
+ if (handlers[i] instanceof ContextHandler) {
+ ContextHandler h = (ContextHandler) handlers[i];
+ if (h.getContextPath().startsWith(path) ||
+ path.startsWith(h.getContextPath())) {
+ throw new Exception("The requested context for path '" + path + "' overlaps with an existing context for path: '" + h.getContextPath() + "'");
+ }
+ }
+ }
+ }
+ // Create context
+ ContextHandler context = new ContextHandler();
+ context.setContextPath(path);
+ ServletHolder holder = new ServletHolder();
+ holder.setName("jbiServlet");
+ holder.setClassName(HttpBridgeServlet.class.getName());
+ ServletHandler handler = new ServletHandler();
+ handler.setServlets(new ServletHolder[] { holder });
+ ServletMapping mapping = new ServletMapping();
+ mapping.setServletName("jbiServlet");
+ mapping.setPathSpec("/*");
+ handler.setServletMappings(new ServletMapping[] { mapping });
+ if (processor.getAuthMethod() != null) {
+ SecurityHandler secHandler = new SecurityHandler();
+ ConstraintMapping constraintMapping = new ConstraintMapping();
+ Constraint constraint = new Constraint();
+ constraint.setAuthenticate(true);
+ constraint.setRoles(new String[] { "*" });
+ constraintMapping.setConstraint(constraint);
+ constraintMapping.setPathSpec("/");
+ secHandler.setConstraintMappings(new ConstraintMapping[] { constraintMapping });
+ secHandler.setHandler(handler);
+ secHandler.setAuthMethod(processor.getAuthMethod());
+ secHandler.setUserRealm(new JaasUserRealm());
+ context.setHandler(secHandler);
+ } else {
+ context.setHandler(handler);
+ }
+ context.setAttribute("processor", processor);
+ // add context
+ contexts.addHandler(context);
+ context.start();
+ return context;
+ }
+
+ public synchronized void remove(Object context) throws Exception {
+ ((ContextHandler) context).stop();
+ for (Iterator it = servers.values().iterator(); it.hasNext();) {
+ Server server = (Server) it.next();
+ HandlerCollection handlerCollection = (HandlerCollection) server.getHandler();
+ ContextHandlerCollection contexts = (ContextHandlerCollection) handlerCollection.getHandlers()[0];
+ Handler[] handlers = contexts.getHandlers();
+ if (handlers != null && handlers.length > 0) {
+ contexts.setHandlers((Handler[])LazyList.removeFromArray(handlers, context));
+ }
+ }
+ }
+
+ protected Server getServer(URL url) {
+ Server server = (Server) servers.get(getKey(url));
+ return server;
+ }
+
+ protected String getKey(URL url) {
+ String key = url.getProtocol() + "://" + url.getHost() + ":" + url.getPort();
+ return key;
+ }
+
+ protected Server createServer(URL url, SslParameters ssl) throws Exception {
+ boolean isSsl = false;
+ if (url.getProtocol().equals("https")) {
+ // TODO: put ssl default information on HttpConfiguration
+ if (ssl == null) {
+ throw new IllegalArgumentException("https protocol required but no ssl parameters found");
+ }
+ isSsl = true;
+ } else if (!url.getProtocol().equals("http")) {
+ throw new UnsupportedOperationException("Protocol " + url.getProtocol() + " is not supported");
+ }
+ // Create a new server
+ Connector connector;
+ if (isSsl && ssl.isManaged()) {
+ String keyStore = ssl.getKeyStore();
+ if (keyStore == null) {
+ throw new IllegalArgumentException("keyStore must be set");
+ }
+ ServiceMixSslSocketConnector sslConnector = new ServiceMixSslSocketConnector();
+ sslConnector.setAlgorithm(ssl.getAlgorithm());
+ sslConnector.setProtocol(ssl.getProtocol());
+ sslConnector.setConfidentialPort(url.getPort());
+ sslConnector.setKeystore(keyStore);
+ sslConnector.setKeyAlias(ssl.getKeyAlias());
+ sslConnector.setTrustStore(ssl.getTrustStore());
+ sslConnector.setNeedClientAuth(ssl.isNeedClientAuth());
+ sslConnector.setWantClientAuth(ssl.isWantClientAuth());
+ sslConnector.setKeystoreManager(getConfiguration().getKeystoreManager());
+ connector = sslConnector;
+ } else if (isSsl) {
+ String keyStore = ssl.getKeyStore();
+ if (keyStore == null) {
+ keyStore = System.getProperty("javax.net.ssl.keyStore", "");
+ if (keyStore == null) {
+ throw new IllegalArgumentException("keyStore or system property javax.net.ssl.keyStore must be set");
+ }
+ }
+ if (keyStore.startsWith("classpath:")) {
+ try {
+ String res = keyStore.substring(10);
+ URL resurl = new ClassPathResource(res).getURL();
+ keyStore = resurl.toString();
+ } catch (IOException e) {
+ throw new JBIException("Unable to find keystore " + keyStore, e);
+ }
+ }
+ String keyStorePassword = ssl.getKeyStorePassword();
+ if (keyStorePassword == null) {
+ keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword");
+ if (keyStorePassword == null) {
+ throw new IllegalArgumentException("keyStorePassword or system property javax.net.ssl.keyStorePassword must be set");
+ }
+ }
+ SslSocketConnector sslConnector = new SslSocketConnector();
+ sslConnector.setAlgorithm(ssl.getAlgorithm());
+ sslConnector.setProtocol(ssl.getProtocol());
+ sslConnector.setConfidentialPort(url.getPort());
+ sslConnector.setPassword(ssl.getKeyStorePassword());
+ sslConnector.setKeyPassword(ssl.getKeyPassword() != null ? ssl.getKeyPassword() : keyStorePassword);
+ sslConnector.setKeystore(keyStore);
+ sslConnector.setKeystoreType(ssl.getKeyStoreType());
+ sslConnector.setNeedClientAuth(ssl.isNeedClientAuth());
+ sslConnector.setWantClientAuth(ssl.isWantClientAuth());
+ connector = sslConnector;
+ } else {
+ String connectorClassName = configuration.getJettyConnectorClassName();
+ try {
+ connector = (Connector) Class.forName(connectorClassName).newInstance();
+ } catch (Exception e) {
+ logger.warn("Could not create a jetty connector of class '" + connectorClassName + "'. Defaulting to " + HttpConfiguration.DEFAULT_JETTY_CONNECTOR_CLASS_NAME);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Reason: " + e.getMessage(), e);
+ }
+ connector = (Connector) Class.forName(HttpConfiguration.DEFAULT_JETTY_CONNECTOR_CLASS_NAME).newInstance();
+ }
+ }
+ connector.setHost(url.getHost());
+ connector.setPort(url.getPort());
+ Server server = new Server();
+ server.setThreadPool(new ThreadPoolWrapper());
+ server.setConnectors(new Connector[] { connector });
+ ContextHandlerCollection contexts = new ContextHandlerCollection();
+ HandlerCollection handlers = new HandlerCollection();
+ handlers.setHandlers(new Handler[] { contexts, new DisplayServiceHandler() });
+ server.setHandler(handlers);
+ server.start();
+ servers.put(getKey(url), server);
+ sslParams.put(getKey(url), isSsl ? ssl : null);
+ if (mbeanContainer != null) {
+ server.getContainer().addEventListener(mbeanContainer);
+ }
+ return server;
+ }
+
+ public HttpConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(HttpConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ public ThreadPool getThreadPool() {
+ return threadPool;
+ }
+
+ protected class DisplayServiceHandler extends AbstractHandler {
+
+ public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException {
+ if (response.isCommitted() || HttpConnection.getCurrentConnection().getRequest().isHandled())
+ return;
+
+ String method = request.getMethod();
+
+ if (!method.equals(HttpMethods.GET) || !request.getRequestURI().equals("/")) {
+ response.sendError(404);
+ return;
+ }
+
+ response.setStatus(404);
+ response.setContentType(MimeTypes.TEXT_HTML);
+
+ ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(1500);
+
+ String uri = request.getRequestURI();
+ uri = StringUtil.replace(uri, "<", "<");
+ uri = StringUtil.replace(uri, ">", ">");
+
+ writer.write("<HTML>\n<HEAD>\n<TITLE>Error 404 - Not Found");
+ writer.write("</TITLE>\n<BODY>\n<H2>Error 404 - Not Found.</H2>\n");
+ writer.write("No service matched or handled this request.<BR>");
+ writer.write("Known services are: <ul>");
+
+ Set servers = JettyContextManager.this.servers.keySet();
+ for (Iterator iter = servers.iterator(); iter.hasNext();) {
+ String serverUri = (String) iter.next();
+ Server server = (Server) JettyContextManager.this.servers.get(serverUri);
+ Handler[] handlers = server.getChildHandlersByClass(ContextHandler.class);
+ for (int i = 0; handlers != null && i < handlers.length; i++) {
+ if (!(handlers[i] instanceof ContextHandler)) {
+ continue;
+ }
+ ContextHandler context = (ContextHandler) handlers[i];
+ if (context.isStarted()) {
+ writer.write("<li><a href=\"");
+ writer.write(serverUri);
+ if (!context.getContextPath().startsWith("/")) {
+ writer.write("/");
+ }
+ writer.write(context.getContextPath());
+ if (!context.getContextPath().endsWith("/")) {
+ writer.write("/");
+ }
+ writer.write("?wsdl\">");
+ writer.write(serverUri);
+ writer.write(context.getContextPath());
+ writer.write("</a></li>\n");
+ } else {
+ writer.write("<li>");
+ writer.write(serverUri);
+ writer.write(context.getContextPath());
+ writer.write(" [Stopped]</li>\n");
+ }
+ }
+ }
+
+ for (int i=0; i < 10; i++) {
+ writer.write("\n<!-- Padding for IE -->");
+ }
+
+ writer.write("\n</BODY>\n</HTML>\n");
+ writer.flush();
+ response.setContentLength(writer.size());
+ OutputStream out = response.getOutputStream();
+ writer.writeTo(out);
+ out.close();
+ }
+
+ }
+
+ protected class ThreadPoolWrapper extends AbstractLifeCycle implements ThreadPool {
+
+ public boolean dispatch(Runnable job) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Dispatching job: " + job);
+ }
+ return threadPool.dispatch(job);
+ }
+
+ public int getIdleThreads() {
+ return threadPool.getIdleThreads();
+ }
+
+ public int getThreads() {
+ return threadPool.getThreads();
+ }
+
+ public void join() throws InterruptedException {
+ }
+
+ public boolean isLowOnThreads() {
+ return threadPool.isLowOnThreads();
+ }
+ }
+
+ public HttpProcessor getMainProcessor() {
+ throw new IllegalStateException("ServerManager is not managed");
+ }
+
+}
Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java?rev=418086&r1=418085&r2=418086&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java (original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java Thu Jun 29 10:13:00 2006
@@ -18,7 +18,9 @@
import java.net.URI;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
import javax.jbi.component.ComponentContext;
import javax.jbi.messaging.DeliveryChannel;
@@ -40,7 +42,7 @@
import org.apache.servicemix.http.HttpEndpoint;
import org.apache.servicemix.http.HttpLifeCycle;
import org.apache.servicemix.http.HttpProcessor;
-import org.apache.servicemix.http.ServerManager;
+import org.apache.servicemix.http.ContextManager;
import org.apache.servicemix.http.SslParameters;
import org.apache.servicemix.http.jetty.JaasJettyPrincipal;
import org.apache.servicemix.jbi.jaxp.SourceTransformer;
@@ -50,7 +52,6 @@
import org.apache.servicemix.soap.marshalers.JBIMarshaler;
import org.apache.servicemix.soap.marshalers.SoapMessage;
import org.apache.servicemix.soap.marshalers.SoapWriter;
-import org.mortbay.jetty.handler.ContextHandler;
import org.mortbay.util.ajax.Continuation;
import org.mortbay.util.ajax.ContinuationSupport;
import org.w3c.dom.Element;
@@ -64,7 +65,7 @@
public static final URI ROBUST_IN_ONLY = URI.create("http://www.w3.org/2004/08/wsdl/robust-in-only");
protected HttpEndpoint endpoint;
- protected ContextHandler httpContext;
+ protected Object httpContext;
protected ComponentContext context;
protected DeliveryChannel channel;
protected SoapHelper soapHelper;
@@ -99,14 +100,12 @@
public void start() throws Exception {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
String url = endpoint.getLocationURI();
- httpContext = getServerManager().createContext(url, this);
- httpContext.start();
context = endpoint.getServiceUnit().getComponent().getComponentContext();
channel = context.getDeliveryChannel();
+ httpContext = getServerManager().createContext(url, this);
}
public void stop() throws Exception {
- httpContext.stop();
getServerManager().remove(httpContext);
}
@@ -123,8 +122,8 @@
return;
}
String path = request.getPathInfo();
- if (path.startsWith("/")) {
- path = path.substring(1);
+ if (path.lastIndexOf('/') >= 0) {
+ path = path.substring(path.lastIndexOf('/') + 1);
}
if (path.endsWith(".wsdl")) {
Definition def = (Definition) endpoint.getWsdls().get(path);
@@ -247,7 +246,7 @@
return headers;
}
- protected ServerManager getServerManager() {
+ protected ContextManager getServerManager() {
HttpLifeCycle lf = (HttpLifeCycle) endpoint.getServiceUnit().getComponent().getLifeCycle();
return lf.getServer();
}
Added: incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpManagedTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpManagedTest.java?rev=418086&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpManagedTest.java (added)
+++ incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpManagedTest.java Thu Jun 29 10:13:00 2006
@@ -0,0 +1,73 @@
+package org.apache.servicemix.http;
+
+import java.util.EventListener;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.servicemix.components.http.InvalidStatusResponseException;
+import org.apache.servicemix.xbean.XmlWebApplicationContext;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Handler;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.handler.ContextHandler;
+import org.mortbay.jetty.handler.ContextHandlerCollection;
+import org.mortbay.jetty.handler.HandlerCollection;
+import org.mortbay.jetty.nio.SelectChannelConnector;
+import org.mortbay.jetty.servlet.ServletHandler;
+import org.mortbay.jetty.servlet.ServletHolder;
+import org.mortbay.jetty.servlet.ServletMapping;
+import org.springframework.web.context.ContextLoaderListener;
+
+public class HttpManagedTest extends TestCase {
+
+ public void test() throws Exception {
+ ContextHandler context = new ContextHandler();
+ context.setContextPath("/");
+ context.setEventListeners(new EventListener[] { new ContextLoaderListener() });
+ Map initParams = new HashMap();
+ initParams.put("contextConfigLocation", "classpath:org/apache/servicemix/http/spring-web.xml");
+ initParams.put("contextClass", XmlWebApplicationContext.class.getName());
+ context.setInitParams(initParams);
+ ServletHolder holder = new ServletHolder();
+ holder.setName("jbiServlet");
+ holder.setClassName(HttpManagedServlet.class.getName());
+ ServletHandler handler = new ServletHandler();
+ handler.setServlets(new ServletHolder[] { holder });
+ ServletMapping mapping = new ServletMapping();
+ mapping.setServletName("jbiServlet");
+ mapping.setPathSpec("/*");
+ handler.setServletMappings(new ServletMapping[] { mapping });
+ context.setHandler(handler);
+
+ ContextHandlerCollection contexts = new ContextHandlerCollection();
+ HandlerCollection handlers = new HandlerCollection();
+ handlers.setHandlers(new Handler[] { contexts });
+ contexts.addHandler(context);
+
+ SelectChannelConnector connector = new SelectChannelConnector();
+ connector.setHost("localhost");
+ connector.setPort(8080);
+
+ Server server = new Server();
+ server.setConnectors(new Connector[] { connector });
+ server.setHandler(handlers);
+ server.start();
+
+ System.err.println("Started");
+
+ PostMethod post = new PostMethod("http://localhost:8080/jbi/Service/");
+ post.setRequestEntity(new StringRequestEntity("<hello>world</hello>"));
+ new HttpClient().executeMethod(post);
+ if (post.getStatusCode() != 200) {
+ throw new InvalidStatusResponseException(post.getStatusCode());
+ }
+ System.err.println(post.getResponseBodyAsString());
+
+ }
+}
Modified: incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpProviderTest.java?rev=418086&r1=418085&r2=418086&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpProviderTest.java (original)
+++ incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpProviderTest.java Thu Jun 29 10:13:00 2006
@@ -1,19 +1,5 @@
-/*
- * Copyright 2005-2006 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.servicemix.http;
+
import java.io.ByteArrayInputStream;
import java.io.File;
Modified: incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/ServerManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/ServerManagerTest.java?rev=418086&r1=418085&r2=418086&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/ServerManagerTest.java (original)
+++ incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/ServerManagerTest.java Thu Jun 29 10:13:00 2006
@@ -32,20 +32,20 @@
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.servicemix.components.http.InvalidStatusResponseException;
+import org.apache.servicemix.http.jetty.JettyContextManager;
import org.apache.servicemix.jbi.util.FileUtil;
-import org.mortbay.jetty.handler.ContextHandler;
import org.mortbay.thread.BoundedThreadPool;
public class ServerManagerTest extends TestCase {
- protected ServerManager server;
+ protected JettyContextManager server;
protected HttpConfiguration configuration;
protected void setUp() throws Exception {
System.setProperty("DEBUG", "true");
System.setProperty("java.protocol.handler.pkgs", "HTTPClient");
configuration = new HttpConfiguration();
- server = new ServerManager();
+ server = new JettyContextManager();
server.setConfiguration(configuration);
}
@@ -59,23 +59,23 @@
// Test first context
checkFail("http://localhost:8192/Service1/echo", null);
- ContextHandler ctx1 = server.createContext("http://localhost:8192/Service1", new TestHttpProcessor());
+ Object ctx1 = server.createContext("http://localhost:8192/Service1", new TestHttpProcessor());
request("http://localhost:8192/Service1/echo", null);
- ctx1.stop();
+ server.remove(ctx1);
checkFail("http://localhost:8192/Service1/echo", null);
// Test second context on the same host/port
checkFail("http://localhost:8192/Service2/echo", null);
- ContextHandler ctx2 = server.createContext("http://localhost:8192/Service2", new TestHttpProcessor());
+ Object ctx2 = server.createContext("http://localhost:8192/Service2", new TestHttpProcessor());
request("http://localhost:8192/Service2/echo", null);
- ctx2.stop();
+ server.remove(ctx2);
checkFail("http://localhost:8192/Service2/echo", null);
// Test third context on another port
checkFail("http://localhost:8193/echo", null);
- ContextHandler ctx3 = server.createContext("http://localhost:8193", new TestHttpProcessor());
+ Object ctx3 = server.createContext("http://localhost:8193", new TestHttpProcessor());
request("http://localhost:8193/echo", null);
- ctx3.stop();
+ server.remove(ctx3);
checkFail("http://localhost:8193/echo", null);
}
Added: incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/spring-web.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/spring-web.xml?rev=418086&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/spring-web.xml (added)
+++ incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/spring-web.xml Thu Jun 29 10:13:00 2006
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:http="http://servicemix.apache.org/http/1.0"
+ xmlns:test="http://servicemix.org/test/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- output using a POJO -->
+ <sm:activationSpec componentName="servicemix-http">
+ <sm:component>
+ <http:component>
+ <http:configuration managed="true" />
+ <http:endpoints>
+
+ <http:endpoint service="test:Hello"
+ endpoint="testService"
+ role="consumer"
+ locationURI="http://localhost:8193/Service/"
+ defaultMep="http://www.w3.org/2004/08/wsdl/in-out"
+ wsdlResource="classpath:org/apache/servicemix/http/test.wsdl"
+ soap="true" />
+
+ </http:endpoints>
+ </http:component>
+ </sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec service="test:Hello" endpoint="testService">
+ <sm:component>
+ <bean class="org.apache.servicemix.components.util.EchoComponent" />
+ </sm:component>
+ </sm:activationSpec>
+
+ </sm:activationSpecs>
+ </sm:container>
+
+</beans>