summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-05-25 04:36:35 (EDT)
committerEike Stepper2008-05-25 04:36:35 (EDT)
commitae33a1d13c4765900319178167d35376f0154b4f (patch)
tree907be2e287c93c8d3009a2f9679271e9ad8a774b
parent950c53056cf1f6e316979f33cf1779fdb26a21d3 (diff)
downloadcdo-ae33a1d13c4765900319178167d35376f0154b4f.zip
cdo-ae33a1d13c4765900319178167d35376f0154b4f.tar.gz
cdo-ae33a1d13c4765900319178167d35376f0154b4f.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.launch4
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/http/INet4jTransportServlet.java10
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPAcceptor.java69
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPAcceptorFactory.java28
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPClientConnector.java131
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPConnector.java18
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPServerConnector.java29
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/Net4jTransportServlet.java101
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/tests/HTTPTest.java9
-rw-r--r--plugins/org.eclipse.net4j.tests/.settings/org.eclipse.pde.core.prefs4
-rw-r--r--plugins/org.eclipse.net4j.tests/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.net4j.tests/build.properties3
-rw-r--r--plugins/org.eclipse.net4j.tests/plugin.xml32
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOAdapter.java31
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOHandler.java24
15 files changed, 417 insertions, 78 deletions
diff --git a/plugins/org.eclipse.net4j.http/HTTPServer.launch b/plugins/org.eclipse.net4j.http/HTTPServer.launch
index ecb860b..d64d9c9 100644
--- a/plugins/org.eclipse.net4j.http/HTTPServer.launch
+++ b/plugins/org.eclipse.net4j.http/HTTPServer.launch
@@ -20,8 +20,8 @@
<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@:"/>
+<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.junit*3.8.2.v20080327@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"/>
+<stringAttribute key="workspace_bundles" value="org.eclipse.net4j.http@default:default,org.eclipse.net4j.jvm@default:default,org.eclipse.net4j.tests@default:default,org.eclipse.net4j.tcp@default:default,org.eclipse.net4j@default:default,org.eclipse.net4j.util@default:default"/>
</launchConfiguration>
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 54a7737..fe48f02 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
@@ -19,6 +19,10 @@ public interface INet4jTransportServlet extends Servlet
{
public static final int OPCODE_CONNECT = 1;
+ public static final int OPCODE_OPEN_CHANNEL = 2;
+
+ public static final int OPCODE_SEND_BUFFER = 3;
+
public RequestHandler getRequestHandler();
public void setRequestHandler(RequestHandler handler);
@@ -28,6 +32,10 @@ public interface INet4jTransportServlet extends Servlet
*/
public interface RequestHandler
{
- public String connectRequested(String userID);
+ public IHTTPConnector[] handleList(String connectorID);
+
+ public String handleConnect(String userID);
+
+ public void handleOpenChannel(String connectorID, int channelID, short channelIndex, String protocolType);
}
}
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 0a169dd..9e77a93 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
@@ -10,13 +10,23 @@
**************************************************************************/
package org.eclipse.net4j.internal.http;
+import org.eclipse.net4j.connector.IConnector;
import org.eclipse.net4j.http.IHTTPAcceptor;
+import org.eclipse.net4j.http.IHTTPConnector;
import org.eclipse.net4j.http.INet4jTransportServlet;
import org.eclipse.net4j.internal.http.bundle.OM;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
+import org.eclipse.net4j.util.StringUtil;
import org.eclipse.net4j.util.security.IRandomizer;
import org.eclipse.internal.net4j.acceptor.Acceptor;
+import org.eclipse.internal.net4j.channel.InternalChannel;
+import org.eclipse.internal.net4j.connector.Connector;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
/**
* @author Eike Stepper
@@ -33,6 +43,8 @@ public class HTTPAcceptor extends Acceptor implements IHTTPAcceptor, INet4jTrans
private int connectorIDLength = DEFAULT_CONNECTOR_ID_LENGTH;
+ private Map<String, HTTPConnector> httpConnectors = new HashMap<String, HTTPConnector>();
+
public HTTPAcceptor()
{
}
@@ -73,28 +85,72 @@ public class HTTPAcceptor extends Acceptor implements IHTTPAcceptor, INet4jTrans
this.connectorIDLength = connectorIDLength;
}
- public String connectRequested(String userID)
+ public IHTTPConnector[] handleList(String connectorID)
+ {
+ if (StringUtil.isEmpty(connectorID))
+ {
+ List<IHTTPConnector> result = new ArrayList<IHTTPConnector>();
+ for (IConnector acceptedConnector : getAcceptedConnectors())
+ {
+ IHTTPConnector connector = (IHTTPConnector)acceptedConnector;
+ result.add(connector);
+ }
+
+ return result.toArray(new IHTTPConnector[result.size()]);
+ }
+
+ return new IHTTPConnector[] { httpConnectors.get(connectorID) };
+ }
+
+ public String handleConnect(String userID)
{
String connectorID = createConnectorID(userID);
System.out.println("HELLO " + userID + " (" + connectorID + ")");
- HTTPServerConnector connector = new HTTPServerConnector(this, connectorID);
+ HTTPServerConnector connector = new HTTPServerConnector(this);
prepareConnector(connector);
+ connector.setConnectorID(connectorID);
connector.setUserID(userID);
addConnector(connector);
return connectorID;
}
+ public void handleOpenChannel(String connectorID, int channelID, short channelIndex, String protocolType)
+ {
+ HTTPConnector connector = httpConnectors.get(connectorID);
+ if (connector == null)
+ {
+ throw new IllegalArgumentException("Invalid connectorID: " + connectorID);
+ }
+
+ InternalChannel channel = connector.createChannel(channelID, channelIndex, protocolType);
+ if (channel != null)
+ {
+ channel.activate();
+ }
+ }
+
@Override
public String toString()
{
return "HTTPAcceptor";
}
- protected String createConnectorID(String userID)
+ @Override
+ public void addConnector(Connector connector)
{
- return randomizer.nextString(connectorIDLength, "0123456789ABCDEF");
+ super.addConnector(connector);
+ HTTPConnector httpConnector = (HTTPConnector)connector;
+ httpConnectors.put(httpConnector.getConnectorID(), httpConnector);
+ }
+
+ @Override
+ public void removeConnector(IConnector connector)
+ {
+ HTTPConnector httpConnector = (HTTPConnector)connector;
+ httpConnectors.remove(httpConnector.getConnectorID());
+ super.removeConnector(connector);
}
@Override
@@ -104,4 +160,9 @@ public class HTTPAcceptor extends Acceptor implements IHTTPAcceptor, INet4jTrans
checkState(randomizer, "randomizer");
checkState(connectorIDLength > 0, "Constraint violated: connectorIDLength > 0");
}
+
+ protected String createConnectorID(String userID)
+ {
+ return randomizer.nextString(connectorIDLength, "0123456789ABCDEF");
+ }
}
diff --git a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPAcceptorFactory.java b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPAcceptorFactory.java
index 70e350a..12a830f 100644
--- a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPAcceptorFactory.java
+++ b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPAcceptorFactory.java
@@ -19,8 +19,6 @@ public class HTTPAcceptorFactory extends AcceptorFactory
{
public static final String TYPE = "http";
- private static final String SEPARATOR = ":"; //$NON-NLS-1$
-
public HTTPAcceptorFactory()
{
super(TYPE);
@@ -28,39 +26,13 @@ public class HTTPAcceptorFactory extends AcceptorFactory
public HTTPAcceptor create(String description)
{
- // String address = IHTTPAcceptor.DEFAULT_ADDRESS;
- // int port = IHTTPAcceptor.DEFAULT_PORT;
- //
- // if (!StringUtil.isEmpty(description))
- // {
- // String[] tokens = description.split(SEPARATOR);
- // if (!StringUtil.isEmpty(tokens[0]))
- // {
- // address = tokens[0];
- // }
- //
- // if (tokens.length > 1 && !StringUtil.isEmpty(tokens[1]))
- // {
- // port = Integer.parseInt(tokens[1]);
- // }
- // }
-
HTTPAcceptor acceptor = new HTTPAcceptor();
- // acceptor.setAddress(address);
- // acceptor.setPort(port);
return acceptor;
}
@Override
public String getDescriptionFor(Object object)
{
- // if (object instanceof HTTPAcceptor)
- // {
- // HTTPAcceptor acceptor = (HTTPAcceptor)object;
- // return acceptor.getAddress() + SEPARATOR + acceptor.getPort();
- // }
-
return null;
-
}
}
diff --git a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPClientConnector.java b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPClientConnector.java
index 1ff420e..9858e6e 100644
--- a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPClientConnector.java
+++ b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPClientConnector.java
@@ -10,11 +10,21 @@
**************************************************************************/
package org.eclipse.net4j.internal.http;
+import org.eclipse.net4j.buffer.IBuffer;
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.connector.ConnectorException;
import org.eclipse.net4j.connector.ConnectorLocation;
-import org.eclipse.net4j.http.IHTTPConnector;
import org.eclipse.net4j.http.INet4jTransportServlet;
+import org.eclipse.net4j.internal.http.bundle.OM;
+import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
+import org.eclipse.net4j.protocol.IProtocol;
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.net4j.util.io.IOHandler;
+import org.eclipse.net4j.util.io.IORuntimeException;
+
+import org.eclipse.internal.net4j.buffer.Buffer;
+import org.eclipse.internal.net4j.channel.InternalChannel;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
@@ -24,19 +34,21 @@ import org.apache.commons.httpclient.methods.PostMethod;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.ByteBuffer;
import java.text.MessageFormat;
+import java.util.Queue;
/**
* @author Eike Stepper
*/
-public class HTTPClientConnector extends HTTPConnector implements IHTTPConnector
+public class HTTPClientConnector extends HTTPConnector
{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, HTTPClientConnector.class);
+
private String url;
private HttpClient httpClient;
- private String connectorID;
-
public HTTPClientConnector()
{
}
@@ -46,11 +58,6 @@ public class HTTPClientConnector extends HTTPConnector implements IHTTPConnector
return ConnectorLocation.CLIENT;
}
- public String getConnectorID()
- {
- return connectorID;
- }
-
public String getURL()
{
return url;
@@ -61,6 +68,48 @@ public class HTTPClientConnector extends HTTPConnector implements IHTTPConnector
this.url = url;
}
+ public void multiplexChannel(final IChannel channel)
+ {
+ Queue<IBuffer> localQueue = ((InternalChannel)channel).getSendQueue();
+ final IBuffer buffer = localQueue.poll();
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Multiplexing " + ((Buffer)buffer).formatContent(true));
+ }
+
+ try
+ {
+ request(new IOHandler()
+ {
+ public void handleOut(ExtendedDataOutputStream out) throws IOException
+ {
+ buffer.flip();
+ ByteBuffer byteBuffer = buffer.getByteBuffer();
+ byte[] data = byteBuffer.array();
+
+ out.writeByte(INet4jTransportServlet.OPCODE_SEND_BUFFER);
+ out.writeString(getConnectorID());
+ out.writeShort(channel.getChannelIndex());
+ out.writeByteArray(data);
+
+ buffer.release();
+ }
+
+ public void handleIn(ExtendedDataInputStream in) throws IOException
+ {
+ }
+ });
+ }
+ catch (RuntimeException ex)
+ {
+ throw ex;
+ }
+ catch (IOException ex)
+ {
+ throw new IORuntimeException(ex);
+ }
+ }
+
@Override
public String toString()
{
@@ -94,22 +143,76 @@ public class HTTPClientConnector extends HTTPConnector implements IHTTPConnector
super.doDeactivate();
}
- private void connect() throws IOException, HttpException
+ @Override
+ protected void registerChannelWithPeer(final int channelID, final short channelIndex, final IProtocol protocol)
+ throws ConnectorException
+ {
+ try
+ {
+ request(new IOHandler()
+ {
+ public void handleOut(ExtendedDataOutputStream out) throws IOException
+ {
+ out.writeByte(INet4jTransportServlet.OPCODE_OPEN_CHANNEL);
+ out.writeString(getConnectorID());
+ out.writeInt(channelID);
+ out.writeShort(channelIndex);
+ out.writeString(protocol.getType());
+ }
+
+ public void handleIn(ExtendedDataInputStream in) throws IOException
+ {
+ boolean ok = in.readBoolean();
+ if (!ok)
+ {
+ throw new ConnectorException("Could not open channel");
+ }
+ }
+ });
+ }
+ catch (RuntimeException ex)
+ {
+ throw ex;
+ }
+ catch (IOException ex)
+ {
+ throw new ConnectorException(ex);
+ }
+ }
+
+ private void connect() throws IOException
+ {
+ request(new IOHandler()
+ {
+ public void handleOut(ExtendedDataOutputStream out) throws IOException
+ {
+ out.writeByte(INet4jTransportServlet.OPCODE_CONNECT);
+ out.writeString(getUserID());
+ }
+
+ public void handleIn(ExtendedDataInputStream in) throws IOException
+ {
+ String connectorID = in.readString();
+ setConnectorID(connectorID);
+ leaveConnecting();
+ }
+ });
+ }
+
+ private void request(IOHandler handler) throws IOException, HttpException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ExtendedDataOutputStream out = new ExtendedDataOutputStream(baos);
- out.writeByte(INet4jTransportServlet.OPCODE_CONNECT);
- out.writeString(getUserID());
+ handler.handleOut(out);
out.flush();
byte[] content = baos.toByteArray();
-
PostMethod method = new PostMethod(url);
method.setRequestEntity(new ByteArrayRequestEntity(content));
httpClient.executeMethod(method);
InputStream bodyInputStream = method.getResponseBodyAsStream();
ExtendedDataInputStream in = new ExtendedDataInputStream(bodyInputStream);
- connectorID = in.readString();
+ handler.handleIn(in);
method.releaseConnection();
}
}
diff --git a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPConnector.java b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPConnector.java
index bb699f6..d6f7e1e 100644
--- a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPConnector.java
+++ b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPConnector.java
@@ -10,11 +10,7 @@
**************************************************************************/
package org.eclipse.net4j.internal.http;
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.connector.ConnectorException;
-import org.eclipse.net4j.internal.http.bundle.OM;
-import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
-import org.eclipse.net4j.protocol.IProtocol;
+import org.eclipse.net4j.http.IHTTPConnector;
import org.eclipse.net4j.util.security.INegotiationContext;
import org.eclipse.internal.net4j.connector.Connector;
@@ -22,22 +18,22 @@ import org.eclipse.internal.net4j.connector.Connector;
/**
* @author Eike Stepper
*/
-public abstract class HTTPConnector extends Connector
+public abstract class HTTPConnector extends Connector implements IHTTPConnector
{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, HTTPConnector.class);
+ private String connectorID;
public HTTPConnector()
{
}
- public void multiplexChannel(IChannel channel)
+ public String getConnectorID()
{
+ return connectorID;
}
- @Override
- protected void registerChannelWithPeer(int channelID, short channelIndex, IProtocol protocol)
- throws ConnectorException
+ public void setConnectorID(String connectorID)
{
+ this.connectorID = connectorID;
}
@Override
diff --git a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPServerConnector.java b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPServerConnector.java
index 2add06e..98b4e22 100644
--- a/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPServerConnector.java
+++ b/plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPServerConnector.java
@@ -10,7 +10,10 @@
**************************************************************************/
package org.eclipse.net4j.internal.http;
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.connector.ConnectorException;
import org.eclipse.net4j.connector.ConnectorLocation;
+import org.eclipse.net4j.protocol.IProtocol;
import java.text.MessageFormat;
@@ -21,14 +24,11 @@ public class HTTPServerConnector extends HTTPConnector
{
private HTTPAcceptor acceptor;
- private String connectorID;
-
private long lastTraffic = System.currentTimeMillis();
- public HTTPServerConnector(HTTPAcceptor acceptor, String connectorID)
+ public HTTPServerConnector(HTTPAcceptor acceptor)
{
this.acceptor = acceptor;
- this.connectorID = connectorID;
}
public HTTPAcceptor getAcceptor()
@@ -43,17 +43,17 @@ public class HTTPServerConnector extends HTTPConnector
public String getURL()
{
- return "agent://connector:" + connectorID;
+ return "agent://connector:" + getConnectorID();
}
- public String getConnectorID()
+ public long getLastTraffic()
{
- return connectorID;
+ return lastTraffic;
}
- public long getLastTraffic()
+ public void multiplexChannel(IChannel channel)
{
- return lastTraffic;
+ throw new UnsupportedOperationException();
}
@Override
@@ -61,9 +61,16 @@ public class HTTPServerConnector extends HTTPConnector
{
if (getUserID() == null)
{
- return MessageFormat.format("HTTPServerConnector[{0}]", connectorID); //$NON-NLS-1$
+ return MessageFormat.format("HTTPServerConnector[{0}]", getConnectorID()); //$NON-NLS-1$
}
- return MessageFormat.format("HTTPServerConnector[{1}@{0}]", connectorID, getUserID()); //$NON-NLS-1$
+ return MessageFormat.format("HTTPServerConnector[{1}@{0}]", getConnectorID(), getUserID()); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void registerChannelWithPeer(int channelID, short channelIndex, IProtocol protocol)
+ throws ConnectorException
+ {
+ throw new UnsupportedOperationException();
}
}
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 bff0746..ac326e0 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
@@ -10,7 +10,12 @@
**************************************************************************/
package org.eclipse.net4j.internal.http;
+import org.eclipse.net4j.buffer.IBufferHandler;
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.http.IHTTPConnector;
import org.eclipse.net4j.http.INet4jTransportServlet;
+import org.eclipse.net4j.internal.http.bundle.OM;
+import org.eclipse.net4j.protocol.IProtocol;
import org.eclipse.net4j.util.container.IPluginContainer;
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
@@ -25,6 +30,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
+import java.io.PrintWriter;
/**
* @author Eike Stepper
@@ -68,6 +74,13 @@ public class Net4jTransportServlet extends HttpServlet implements INet4jTranspor
throw new ServletException("No request handler installed");
}
+ String connectorID = req.getParameter("list");
+ if (connectorID != null)
+ {
+ handleList(connectorID, resp);
+ return;
+ }
+
ServletInputStream servletInputStream = req.getInputStream();
ExtendedDataInputStream in = new ExtendedDataInputStream(servletInputStream);
@@ -80,17 +93,99 @@ public class Net4jTransportServlet extends HttpServlet implements INet4jTranspor
case OPCODE_CONNECT:
handleConnect(in, out);
break;
+
+ case OPCODE_OPEN_CHANNEL:
+ handleOpenChannel(in, out);
+ break;
}
out.flush();
}
+ protected void handleList(String connectorID, HttpServletResponse resp) throws IOException
+ {
+ IHTTPConnector[] connectors = requestHandler.handleList(connectorID);
+ PrintWriter writer = resp.getWriter();
+ for (IHTTPConnector connector : connectors)
+ {
+ writer.write(connector.getConnectorID());
+ writer.write(":");
+
+ String userID = connector.getUserID();
+ if (userID != null)
+ {
+ writer.write(" userID=" + userID);
+ }
+
+ if (connector instanceof HTTPServerConnector)
+ {
+ long idleTime = System.currentTimeMillis() - ((HTTPServerConnector)connector).getLastTraffic();
+ writer.write(" idleTime=" + idleTime);
+ }
+
+ writer.write("\n");
+
+ for (IChannel channel : connector.getChannels())
+ {
+ writer.write(" ");
+ writer.write(String.valueOf(channel.getChannelIndex()));
+ writer.write(": ");
+ IBufferHandler receiveHandler = channel.getReceiveHandler();
+ if (receiveHandler instanceof IProtocol)
+ {
+ writer.write(((IProtocol)receiveHandler).getType());
+ }
+ else
+ {
+ String string = receiveHandler.toString();
+ if (string.length() > 256)
+ {
+ string = string.substring(0, 256);
+ }
+
+ writer.write(string);
+ }
+
+ writer.write(" (");
+ writer.write(String.valueOf(channel.getChannelID()));
+ writer.write(")\n");
+ }
+ }
+ }
+
protected void handleConnect(ExtendedDataInputStream in, ExtendedDataOutputStream out) throws ServletException,
IOException
{
- String userID = in.readString();
- String connectorID = requestHandler.connectRequested(userID);
- out.writeString(connectorID);
+ try
+ {
+ String userID = in.readString();
+ String connectorID = requestHandler.handleConnect(userID);
+ out.writeString(connectorID);
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ out.writeString(null);
+ }
+ }
+
+ protected void handleOpenChannel(ExtendedDataInputStream in, ExtendedDataOutputStream out) throws ServletException,
+ IOException
+ {
+ try
+ {
+ String connectorID = in.readString();
+ int channelID = in.readInt();
+ short channelIndex = in.readShort();
+ String protocolType = in.readString();
+ requestHandler.handleOpenChannel(connectorID, channelID, channelIndex, protocolType);
+ out.writeBoolean(true);
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ out.writeBoolean(false);
+ }
}
/**
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
index c6deda7..283a644 100644
--- 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
@@ -10,9 +10,13 @@
**************************************************************************/
package org.eclipse.net4j.internal.http.tests;
+import org.eclipse.net4j.channel.IChannel;
import org.eclipse.net4j.http.HTTPUtil;
import org.eclipse.net4j.http.IHTTPConnector;
import org.eclipse.net4j.tests.AbstractTransportTest;
+import org.eclipse.net4j.tests.signal.IntRequest;
+import org.eclipse.net4j.tests.signal.TestSignalClientProtocolFactory;
+import org.eclipse.net4j.tests.signal.TestSignalProtocol;
import org.eclipse.net4j.util.container.IManagedContainer;
/**
@@ -29,13 +33,18 @@ public class HTTPTest extends AbstractTransportTest
{
IManagedContainer container = super.createContainer();
HTTPUtil.prepareContainer(container);
+ container.registerFactory(new TestSignalClientProtocolFactory());
return container;
}
public void test1() throws Exception
{
IHTTPConnector connector = getHTTPConnector();
+ IChannel channel = connector.openChannel(TestSignalProtocol.PROTOCOL_NAME, null);
+ IntRequest request = new IntRequest(channel, 4711);
+ int result = request.send();
+ assertEquals(4711, result);
}
private IHTTPConnector getHTTPConnector()
diff --git a/plugins/org.eclipse.net4j.tests/.settings/org.eclipse.pde.core.prefs b/plugins/org.eclipse.net4j.tests/.settings/org.eclipse.pde.core.prefs
index 66347c6..e9a6536 100644
--- a/plugins/org.eclipse.net4j.tests/.settings/org.eclipse.pde.core.prefs
+++ b/plugins/org.eclipse.net4j.tests/.settings/org.eclipse.pde.core.prefs
@@ -1,3 +1,3 @@
-#Fri Oct 20 11:53:34 CEST 2006
+#Sun May 25 10:11:03 CEST 2008
eclipse.preferences.version=1
-pluginProject.extensions=false
+pluginProject.extensions=true
diff --git a/plugins/org.eclipse.net4j.tests/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.tests/META-INF/MANIFEST.MF
index 1c594df..b654078 100644
--- a/plugins/org.eclipse.net4j.tests/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j.tests/META-INF/MANIFEST.MF
@@ -1,6 +1,6 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
-Bundle-SymbolicName: org.eclipse.net4j.tests
+Bundle-SymbolicName: org.eclipse.net4j.tests;singleton:=true
Bundle-Version: 0.8.0.qualifier
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
diff --git a/plugins/org.eclipse.net4j.tests/build.properties b/plugins/org.eclipse.net4j.tests/build.properties
index e842be8..3419896 100644
--- a/plugins/org.eclipse.net4j.tests/build.properties
+++ b/plugins/org.eclipse.net4j.tests/build.properties
@@ -22,4 +22,5 @@ bin.includes = META-INF/,\
about.ini,\
about.mappings,\
about.properties,\
- modeling32.png
+ modeling32.png,\
+ plugin.xml
diff --git a/plugins/org.eclipse.net4j.tests/plugin.xml b/plugins/org.eclipse.net4j.tests/plugin.xml
new file mode 100644
index 0000000..f39f451
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tests/plugin.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.3"?>
+<!--
+ <copyright>
+
+ 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
+
+ </copyright>
+-->
+
+<plugin>
+
+ <extension
+ point="org.eclipse.net4j.util.factories">
+ <factory
+ class="org.eclipse.net4j.tests.signal.TestSignalClientProtocolFactory"
+ productGroup="org.eclipse.net4j.clientProtocols"
+ type="signal.protocol"/>
+ <factory
+ class="org.eclipse.net4j.tests.signal.TestSignalServerProtocolFactory"
+ productGroup="org.eclipse.net4j.serverProtocols"
+ type="signal.protocol"/>
+ </extension>
+
+</plugin>
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOAdapter.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOAdapter.java
new file mode 100644
index 0000000..c490433
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOAdapter.java
@@ -0,0 +1,31 @@
+/***************************************************************************
+ * 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.util.io;
+
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public class IOAdapter implements IOHandler
+{
+ public IOAdapter()
+ {
+ }
+
+ public void handleIn(ExtendedDataInputStream in) throws IOException
+ {
+ }
+
+ public void handleOut(ExtendedDataOutputStream out) throws IOException
+ {
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOHandler.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOHandler.java
new file mode 100644
index 0000000..4eba45d
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/IOHandler.java
@@ -0,0 +1,24 @@
+/***************************************************************************
+ * 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.util.io;
+
+
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IOHandler
+{
+ public void handleIn(ExtendedDataInputStream in) throws IOException;
+
+ public void handleOut(ExtendedDataOutputStream out) throws IOException;
+}