summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-05-25 02:42:25 (EDT)
committerEike Stepper2008-05-25 02:42:25 (EDT)
commit950c53056cf1f6e316979f33cf1779fdb26a21d3 (patch)
tree1c669feaab33d037cce606f27942829be1c1b0b2
parentf12610fcdb199cfeb16de0068d3788a2bc607cb9 (diff)
downloadcdo-950c53056cf1f6e316979f33cf1779fdb26a21d3.zip
cdo-950c53056cf1f6e316979f33cf1779fdb26a21d3.tar.gz
cdo-950c53056cf1f6e316979f33cf1779fdb26a21d3.tar.bz2
[232648] Provide an HTTPConnector
https://bugs.eclipse.org/bugs/show_bug.cgi?id=232648
-rw-r--r--plugins/org.eclipse.net4j.http/HTTPServer.launch27
-rw-r--r--plugins/org.eclipse.net4j.http/HTTPTest.launch19
-rw-r--r--plugins/org.eclipse.net4j.http/META-INF/MANIFEST.MF5
-rw-r--r--plugins/org.eclipse.net4j.http/plugin.xml9
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/HTTPUtil.java9
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/IHTTPAcceptor.java2
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPAcceptor.java25
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPConnectorFactory.java58
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/Net4jTransportServlet.java45
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/RandomizerInjector.java47
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/tests/HTTPTest.java46
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/Lifecycle.java2
12 files changed, 233 insertions, 61 deletions
diff --git a/plugins/org.eclipse.net4j.http/HTTPServer.launch b/plugins/org.eclipse.net4j.http/HTTPServer.launch
new file mode 100644
index 0000000..ecb860b
--- /dev/null
+++ b/plugins/org.eclipse.net4j.http/HTTPServer.launch
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="org.eclipse.pde.ui.EquinoxLauncher">
+<booleanAttribute key="append.args" value="true"/>
+<booleanAttribute key="automaticAdd" value="false"/>
+<booleanAttribute key="automaticValidate" value="true"/>
+<stringAttribute key="bootstrap" value=""/>
+<stringAttribute key="checked" value="org.eclipse.net4j,org.eclipse.net4j.http,org.eclipse.net4j.util"/>
+<booleanAttribute key="clearConfig" value="false"/>
+<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/HTTPServer"/>
+<booleanAttribute key="default_auto_start" value="true"/>
+<intAttribute key="default_start_level" value="4"/>
+<booleanAttribute key="includeOptional" value="true"/>
+<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
+<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
+<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
+</listAttribute>
+<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -console"/>
+<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Declipse.ignoreApp=true -Dosgi.noShutdown=true&#13;&#10;-Dorg.osgi.service.http.port=8080"/>
+<stringAttribute key="pde.version" value="3.3"/>
+<stringAttribute key="selectedPlugin" value="org.eclipse.net4j"/>
+<booleanAttribute key="show_selected_only" value="false"/>
+<stringAttribute key="target_bundles" value="org.eclipse.equinox.http.jetty@default:default,org.eclipse.osgi.services@default:default,org.eclipse.core.contenttype@default:default,org.eclipse.equinox.common@default:default,org.eclipse.equinox.http.registry@default:default,org.eclipse.core.runtime@default:default,org.eclipse.equinox.http.servlet@default:default,org.apache.commons.codec*1.3.0.v200803061910@default:default,org.apache.commons.httpclient*3.1.0.v200803061910@default:default,org.eclipse.core.runtime.compatibility.registry@default:false,org.eclipse.core.runtime.compatibility.auth@default:default,org.eclipse.equinox.preferences@default:default,org.apache.commons.logging*1.1.1.v200803061910@default:default,org.eclipse.core.jobs@default:default,org.mortbay.jetty*5.1.14.v200804221617@default:default,org.eclipse.equinox.app@default:default,javax.servlet*2.5.0.v200804152124@default:default,org.eclipse.equinox.registry@default:default,org.eclipse.osgi@:"/>
+<booleanAttribute key="tracing" value="true"/>
+<booleanAttribute key="useDefaultConfigArea" value="true"/>
+<stringAttribute key="workspace_bundles" value="org.eclipse.net4j.http@default:default,org.eclipse.net4j@default:default,org.eclipse.net4j.util@default:default"/>
+</launchConfiguration>
diff --git a/plugins/org.eclipse.net4j.http/HTTPTest.launch b/plugins/org.eclipse.net4j.http/HTTPTest.launch
new file mode 100644
index 0000000..dad840b
--- /dev/null
+++ b/plugins/org.eclipse.net4j.http/HTTPTest.launch
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/tests/HTTPTest.java"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="1"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
+<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
+<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
+</listAttribute>
+<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
+<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
+<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
+<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.net4j.internal.http.tests.HTTPTest"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.net4j.http"/>
+</launchConfiguration>
diff --git a/plugins/org.eclipse.net4j.http/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.http/META-INF/MANIFEST.MF
index 25c1270..d62e1e6 100644
--- a/plugins/org.eclipse.net4j.http/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j.http/META-INF/MANIFEST.MF
@@ -12,7 +12,10 @@ Bundle-ClassPath: .
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.3.0,4.0.0)";resolution:=optional,
org.eclipse.net4j;bundle-version="[0.8.0,0.9.0)";visibility:=reexport,
org.eclipse.equinox.http.registry;bundle-version="[1.0.0,2.0.0)";resolution:=optional,
- org.eclipse.equinox.http.servlet;bundle-version="[1.0.0,2.0.0)";resolution:=optional
+ org.eclipse.equinox.http.servlet;bundle-version="[1.0.0,2.0.0)";resolution:=optional,
+ org.eclipse.net4j.tests;bundle-version="[0.8.0,0.9.0)";resolution:=optional,
+ org.apache.commons.logging;bundle-version="[1.0.0,2.0.0)";resolution:=optional,
+ org.apache.commons.codec;bundle-version="[1.0.0,2.0.0)";resolution:=optional
Import-Package: javax.servlet;version="2.4.0";resolution:=optional,
javax.servlet.http;version="2.4.0";resolution:=optional,
org.apache.commons.httpclient;version="3.0.1";resolution:=optional,
diff --git a/plugins/org.eclipse.net4j.http/plugin.xml b/plugins/org.eclipse.net4j.http/plugin.xml
index 9db2275..5289704 100644
--- a/plugins/org.eclipse.net4j.http/plugin.xml
+++ b/plugins/org.eclipse.net4j.http/plugin.xml
@@ -30,10 +30,17 @@
</extension>
<extension
+ point="org.eclipse.net4j.util.elementProcessors">
+ <elementProcessor
+ class="org.eclipse.net4j.internal.http.RandomizerInjector">
+ </elementProcessor>
+ </extension>
+
+ <extension
point="org.eclipse.equinox.http.registry.servlets">
<servlet
alias="/net4j"
- class="org.eclipse.net4j.internal.http.Net4jTransportServlet">
+ class="org.eclipse.net4j.internal.http.Net4jTransportServlet$ContainerAware">
</servlet>
</extension>
diff --git a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/HTTPUtil.java b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/HTTPUtil.java
index d466a3b..25a09f2 100644
--- a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/HTTPUtil.java
+++ b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/HTTPUtil.java
@@ -12,6 +12,7 @@ package org.eclipse.net4j.http;
import org.eclipse.net4j.internal.http.HTTPAcceptorFactory;
import org.eclipse.net4j.internal.http.HTTPConnectorFactory;
+import org.eclipse.net4j.internal.http.RandomizerInjector;
import org.eclipse.net4j.util.container.IManagedContainer;
/**
@@ -27,16 +28,18 @@ public final class HTTPUtil
{
container.registerFactory(new HTTPAcceptorFactory());
container.registerFactory(new HTTPConnectorFactory());
+ container.addPostProcessor(new RandomizerInjector());
}
public static IHTTPAcceptor getAcceptor(IManagedContainer container, String description)
{
- return (IHTTPAcceptor)container.getElement(HTTPAcceptorFactory.PRODUCT_GROUP, HTTPAcceptorFactory.TYPE, description);
+ return (IHTTPAcceptor)container
+ .getElement(HTTPAcceptorFactory.PRODUCT_GROUP, HTTPAcceptorFactory.TYPE, description);
}
public static IHTTPConnector getConnector(IManagedContainer container, String description)
{
- return (IHTTPConnector)container
- .getElement(HTTPConnectorFactory.PRODUCT_GROUP, HTTPConnectorFactory.TYPE, description);
+ return (IHTTPConnector)container.getElement(HTTPConnectorFactory.PRODUCT_GROUP, HTTPConnectorFactory.TYPE,
+ description);
}
}
diff --git a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/IHTTPAcceptor.java b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/IHTTPAcceptor.java
index b11f936..9f761b2 100644
--- a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/IHTTPAcceptor.java
+++ b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/IHTTPAcceptor.java
@@ -18,4 +18,6 @@ import org.eclipse.net4j.acceptor.IAcceptor;
public interface IHTTPAcceptor extends IAcceptor
{
public INet4jTransportServlet getServlet();
+
+ public void setServlet(INet4jTransportServlet servlet);
}
diff --git a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPAcceptor.java b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPAcceptor.java
index 8f957af..0a169dd 100644
--- a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPAcceptor.java
+++ b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPAcceptor.java
@@ -54,7 +54,13 @@ public class HTTPAcceptor extends Acceptor implements IHTTPAcceptor, INet4jTrans
public void setServlet(INet4jTransportServlet servlet)
{
+ if (this.servlet != null)
+ {
+ this.servlet.setRequestHandler(null);
+ }
+
this.servlet = servlet;
+ servlet.setRequestHandler(this);
}
public int getConnectorIDLength()
@@ -95,22 +101,7 @@ public class HTTPAcceptor extends Acceptor implements IHTTPAcceptor, INet4jTrans
protected void doBeforeActivate() throws Exception
{
super.doBeforeActivate();
- checkArg(randomizer, "randomizer == null");
- checkArg(servlet, "servlet == null");
- checkArg(connectorIDLength > 0, "Constraint violated: connectorIDLength > 0");
- }
-
- @Override
- protected void doActivate() throws Exception
- {
- super.doActivate();
- servlet.setRequestHandler(this);
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- servlet.setRequestHandler(null);
- super.doDeactivate();
+ checkState(randomizer, "randomizer");
+ checkState(connectorIDLength > 0, "Constraint violated: connectorIDLength > 0");
}
}
diff --git a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPConnectorFactory.java b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPConnectorFactory.java
index a54f60b..a37fcc8 100644
--- a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPConnectorFactory.java
+++ b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPConnectorFactory.java
@@ -12,6 +12,9 @@ package org.eclipse.net4j.internal.http;
import org.eclipse.internal.net4j.connector.ConnectorFactory;
+import java.net.MalformedURLException;
+import java.net.URL;
+
/**
* @author Eike Stepper
*/
@@ -19,8 +22,6 @@ public class HTTPConnectorFactory extends ConnectorFactory
{
public static final String TYPE = "http";
- private static final String URL_SCHEME = "http://";
-
public HTTPConnectorFactory()
{
super(TYPE);
@@ -28,50 +29,31 @@ public class HTTPConnectorFactory extends ConnectorFactory
public HTTPClientConnector create(String description)
{
- // try
- // {
- // URL url = new URL(URL_SCHEME + description);
- // String userID = url.getUserInfo();
- // String host = url.getHost();
- // int port = url.getPort();
- // if (port == -1)
- // {
- // port = IHTTPConnector.DEFAULT_PORT;
- // }
+ String userID = null;
+ try
+ {
+ URL url = new URL(description);
+ userID = url.getUserInfo();
+ }
+ catch (MalformedURLException ex)
+ {
+ ex.printStackTrace();
+ }
HTTPClientConnector connector = new HTTPClientConnector();
- // connector.setUserID(userID);
- // connector.setHost(host);
- // connector.setPort(port);
+ connector.setURL(description);
+ connector.setUserID(userID);
return connector;
- // }
- // catch (MalformedURLException ex)
- // {
- // throw new ProductCreationException(ex);
- // }
}
@Override
public String getDescriptionFor(Object object)
{
- // if (object instanceof HTTPClientConnector)
- // {
- // HTTPClientConnector connector = (HTTPClientConnector)object;
- // String description = connector.getHost();
- // String userID = connector.getUserID();
- // if (!StringUtil.isEmpty(userID))
- // {
- // description = userID + "@" + description;
- // }
- //
- // int port = connector.getPort();
- // if (port != IHTTPConnector.DEFAULT_PORT)
- // {
- // description = description + ":" + port;
- // }
- //
- // return description;
- // }
+ if (object instanceof HTTPClientConnector)
+ {
+ HTTPClientConnector connector = (HTTPClientConnector)object;
+ return connector.getURL();
+ }
return null;
}
diff --git a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/Net4jTransportServlet.java b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/Net4jTransportServlet.java
index d153ec5..bff0746 100644
--- a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/Net4jTransportServlet.java
+++ b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/Net4jTransportServlet.java
@@ -11,9 +11,12 @@
package org.eclipse.net4j.internal.http;
import org.eclipse.net4j.http.INet4jTransportServlet;
+import org.eclipse.net4j.util.container.IPluginContainer;
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.internal.net4j.acceptor.AcceptorFactory;
+
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
@@ -89,4 +92,46 @@ public class Net4jTransportServlet extends HttpServlet implements INet4jTranspor
String connectorID = requestHandler.connectRequested(userID);
out.writeString(connectorID);
}
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class ContainerAware extends Net4jTransportServlet
+ {
+ private static final String ACCEPTORS_GROUP = AcceptorFactory.PRODUCT_GROUP;
+
+ private static final String HTTP_TYPE = HTTPAcceptorFactory.TYPE;
+
+ private static final long serialVersionUID = 1L;
+
+ private HTTPAcceptor acceptor;
+
+ public ContainerAware()
+ {
+ }
+
+ @Override
+ public void init() throws ServletException
+ {
+ super.init();
+
+ acceptor = (HTTPAcceptor)IPluginContainer.INSTANCE.getElement(ACCEPTORS_GROUP, HTTP_TYPE, null);
+ if (acceptor == null)
+ {
+ throw new ServletException("Acceptor not found");
+ }
+
+ acceptor.setServlet(this);
+ setRequestHandler(acceptor);
+ }
+
+ @Override
+ public void destroy()
+ {
+ setRequestHandler(null);
+ acceptor.setServlet(null);
+ acceptor = null;
+ super.destroy();
+ }
+ }
}
diff --git a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/RandomizerInjector.java b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/RandomizerInjector.java
new file mode 100644
index 0000000..ac89791
--- /dev/null
+++ b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/RandomizerInjector.java
@@ -0,0 +1,47 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.internal.http;
+
+import org.eclipse.net4j.util.container.IElementProcessor;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.security.IRandomizer;
+
+/**
+ * @author Eike Stepper
+ */
+public class RandomizerInjector implements IElementProcessor
+{
+ public static final String TYPE = null;
+
+ public RandomizerInjector()
+ {
+ }
+
+ public Object process(IManagedContainer container, String productGroup, String factoryType, String description,
+ Object element)
+ {
+ if (element instanceof HTTPAcceptor)
+ {
+ HTTPAcceptor acceptor = (HTTPAcceptor)element;
+ if (acceptor.getRandomizer() == null)
+ {
+ acceptor.setRandomizer(getRandomizer(container));
+ }
+ }
+
+ return element;
+ }
+
+ protected IRandomizer getRandomizer(IManagedContainer container)
+ {
+ return (IRandomizer)container.getElement("org.eclipse.net4j.randomizers", "default", TYPE);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/tests/HTTPTest.java b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/tests/HTTPTest.java
new file mode 100644
index 0000000..c6deda7
--- /dev/null
+++ b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/tests/HTTPTest.java
@@ -0,0 +1,46 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.internal.http.tests;
+
+import org.eclipse.net4j.http.HTTPUtil;
+import org.eclipse.net4j.http.IHTTPConnector;
+import org.eclipse.net4j.tests.AbstractTransportTest;
+import org.eclipse.net4j.util.container.IManagedContainer;
+
+/**
+ * @author Eike Stepper
+ */
+public class HTTPTest extends AbstractTransportTest
+{
+ public HTTPTest()
+ {
+ }
+
+ @Override
+ protected IManagedContainer createContainer()
+ {
+ IManagedContainer container = super.createContainer();
+ HTTPUtil.prepareContainer(container);
+ return container;
+ }
+
+ public void test1() throws Exception
+ {
+ IHTTPConnector connector = getHTTPConnector();
+
+ }
+
+ private IHTTPConnector getHTTPConnector()
+ {
+ return (IHTTPConnector)container.getElement("org.eclipse.net4j.connectors", "http",
+ "http://eike@localhost:8080/net4j");
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/Lifecycle.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/Lifecycle.java
index 7d6409e..50e68f3 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/Lifecycle.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/Lifecycle.java
@@ -173,7 +173,7 @@ public class Lifecycle extends Notifier implements ILifecycle.Introspection
protected final void checkArg(Object handle, String handleName) throws IllegalArgumentException
{
- CheckUtil.checkArg(handle, handleName);
+ CheckUtil.checkState(handle, handleName);
}
protected final void checkState(boolean expr, String msg) throws IllegalStateException