summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-05-24 04:19:27 (EDT)
committerEike Stepper2008-05-24 04:19:27 (EDT)
commit3c4108a5b57541e826dfc6a6c57323067449c545 (patch)
treed5de78b9212d2cd0f77662861f563f9dd94b51bd
parente64161817af5ba48bb7019e24b10edf8ef6ef65d (diff)
downloadcdo-3c4108a5b57541e826dfc6a6c57323067449c545.zip
cdo-3c4108a5b57541e826dfc6a6c57323067449c545.tar.gz
cdo-3c4108a5b57541e826dfc6a6c57323067449c545.tar.bz2
[232648] Provide an HTTPConnector
https://bugs.eclipse.org/bugs/show_bug.cgi?id=232648
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/IHTTPAcceptor.java4
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/IHTTPConnector.java2
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/INet4jTransportServlet.java4
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPAcceptor.java68
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/Net4jTransportServlet.java24
5 files changed, 31 insertions, 71 deletions
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 9740016..b11f936 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
@@ -17,7 +17,5 @@ import org.eclipse.net4j.acceptor.IAcceptor;
*/
public interface IHTTPAcceptor extends IAcceptor
{
- public static final int DEFAULT_PORT = 80;
-
- public int getPort();
+ public INet4jTransportServlet getServlet();
}
diff --git a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/IHTTPConnector.java b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/IHTTPConnector.java
index e78c088..08f6fd6 100644
--- a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/IHTTPConnector.java
+++ b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/IHTTPConnector.java
@@ -17,7 +17,5 @@ import org.eclipse.net4j.connector.IConnector;
*/
public interface IHTTPConnector extends IConnector
{
- public static final int DEFAULT_PORT = IHTTPAcceptor.DEFAULT_PORT;
-
public String getURL();
}
diff --git a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/INet4jTransportServlet.java b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/INet4jTransportServlet.java
index 56dddc7..e05fe29 100644
--- a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/INet4jTransportServlet.java
+++ b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/INet4jTransportServlet.java
@@ -17,6 +17,8 @@ import javax.servlet.Servlet;
*/
public interface INet4jTransportServlet extends Servlet
{
+ public static final int OPCODE_CONNECT = 1;
+
public RequestHandler getRequestHandler();
public void setRequestHandler(RequestHandler handler);
@@ -26,6 +28,6 @@ public interface INet4jTransportServlet extends Servlet
*/
public interface RequestHandler
{
- public void connectRequested(String user);
+ public void connectRequested(String userID);
}
}
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 27e0775..7aa544a 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
@@ -13,108 +13,62 @@ package org.eclipse.net4j.internal.http;
import org.eclipse.net4j.http.IHTTPAcceptor;
import org.eclipse.net4j.http.INet4jTransportServlet;
import org.eclipse.net4j.internal.http.bundle.OM;
-import org.eclipse.net4j.internal.util.lifecycle.Worker;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.internal.net4j.acceptor.Acceptor;
-import java.io.IOException;
-import java.text.MessageFormat;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
/**
* @author Eike Stepper
*/
public class HTTPAcceptor extends Acceptor implements IHTTPAcceptor, INet4jTransportServlet.RequestHandler
{
- public static final boolean DEFAULT_START_SYNCHRONOUSLY = true;
-
- public static final long DEFAULT_SYNCHRONOUS_START_TIMEOUT = 2 * Worker.DEFAULT_TIMEOUT;
-
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, HTTPAcceptor.class);
- private boolean startSynchronously = DEFAULT_START_SYNCHRONOUSLY;
-
- private long synchronousStartTimeout = DEFAULT_SYNCHRONOUS_START_TIMEOUT;
-
- private CountDownLatch startLatch;
-
- private int port = DEFAULT_PORT;
+ private INet4jTransportServlet servlet;
public HTTPAcceptor()
{
}
- public int getPort()
+ public INet4jTransportServlet getServlet()
{
- return port;
+ return servlet;
}
- public void setPort(int port)
+ public void setServlet(INet4jTransportServlet servlet)
{
- this.port = port;
+ this.servlet = servlet;
}
- public boolean isStartSynchronously()
- {
- return startSynchronously;
- }
-
- public void setStartSynchronously(boolean startSynchronously)
- {
- this.startSynchronously = startSynchronously;
- }
-
- public long getSynchronousStartTimeout()
- {
- return synchronousStartTimeout;
- }
-
- public void setSynchronousStartTimeout(long synchronousStartTimeout)
- {
- this.synchronousStartTimeout = synchronousStartTimeout;
- }
-
- public void connectRequested(String user)
+ public void connectRequested(String userID)
{
+ System.out.println("HELLO " + userID);
}
@Override
public String toString()
{
- return MessageFormat.format("HTTPAcceptor[{0}]", port); //$NON-NLS-1$
+ return "HTTPAcceptor";
}
@Override
protected void doBeforeActivate() throws Exception
{
super.doBeforeActivate();
- if (startSynchronously)
- {
- startLatch = new CountDownLatch(1);
- }
+ checkArg(servlet, "servlet == null");
}
@Override
protected void doActivate() throws Exception
{
super.doActivate();
-
- if (startLatch != null)
- {
- if (!startLatch.await(synchronousStartTimeout, TimeUnit.MILLISECONDS))
- {
- startLatch = null;
- // IOUtil.closeSilent(serverSocketChannel);
- throw new IOException("Registration with selector timed out after " + synchronousStartTimeout + " millis");
- }
- }
+ servlet.setRequestHandler(this);
}
@Override
protected void doDeactivate() throws Exception
{
+ servlet.setRequestHandler(null);
super.doDeactivate();
}
}
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 611fd5e..c68b55b 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,13 +11,14 @@
package org.eclipse.net4j.internal.http;
import org.eclipse.net4j.http.INet4jTransportServlet;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
import javax.servlet.ServletException;
+import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.io.BufferedReader;
import java.io.IOException;
/**
@@ -57,18 +58,25 @@ public class Net4jTransportServlet extends HttpServlet implements INet4jTranspor
protected void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
- BufferedReader reader = req.getReader();
- String op = reader.readLine();
- if ("connect".equals(op))
+ ServletInputStream servletInputStream = req.getInputStream();
+ ExtendedDataInputStream in = new ExtendedDataInputStream(servletInputStream);
+ int opcode = servletInputStream.read();
+ switch (opcode)
{
- handleConnect(reader, req, resp);
+ case OPCODE_CONNECT:
+ handleConnect(in, req, resp);
+
+ break;
+
+ default:
+ break;
}
}
- protected void handleConnect(BufferedReader reader, HttpServletRequest req, HttpServletResponse resp)
+ protected void handleConnect(ExtendedDataInputStream in, HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
- String user = reader.readLine();
- requestHandler.connectRequested(user);
+ String userID = in.readString();
+ requestHandler.connectRequested(userID);
}
}