summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-05-26 03:56:39 (EDT)
committerEike Stepper2008-05-26 03:56:39 (EDT)
commit538dd73622c329ec58145d4f44b07992b2dc722c (patch)
tree2ed9d44fb448c8a397d20b487e8da15e3436db9a
parenta3edc0a7cea000746c390e2bb301aeef928fa067 (diff)
downloadcdo-538dd73622c329ec58145d4f44b07992b2dc722c.zip
cdo-538dd73622c329ec58145d4f44b07992b2dc722c.tar.gz
cdo-538dd73622c329ec58145d4f44b07992b2dc722c.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/INet4jTransportServlet.java10
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPAcceptor.java13
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPClientConnector.java2
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPServerConnector.java13
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/Net4jTransportServlet.java31
5 files changed, 37 insertions, 32 deletions
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 7973daf..14e3347 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
@@ -10,8 +10,13 @@
**************************************************************************/
package org.eclipse.net4j.http;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
import javax.servlet.Servlet;
+import java.io.IOException;
+
/**
* @author Eike Stepper
*/
@@ -23,7 +28,7 @@ public interface INet4jTransportServlet extends Servlet
public static final int OPCODE_CLOSE_CHANNEL = 3;
- public static final int OPCODE_BUFFER = 4;
+ public static final int OPCODE_BUFFERS = 4;
public RequestHandler getRequestHandler();
@@ -42,6 +47,7 @@ public interface INet4jTransportServlet extends Servlet
public void handleCloseChannel(String connectorID, short channelIndex);
- public void handleBuffer(String connectorID, short channelIndex, byte[] data);
+ public void handleBuffers(String connectorID, ExtendedDataInputStream in, ExtendedDataOutputStream out)
+ throws IOException;
}
}
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 84f75a8..a079825 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
@@ -18,12 +18,15 @@ 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.net4j.util.StringUtil;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
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.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
@@ -170,7 +173,8 @@ public class HTTPAcceptor extends Acceptor implements IHTTPAcceptor, INet4jTrans
throw new UnsupportedOperationException();
}
- public void handleBuffer(String connectorID, short channelIndex, byte[] data)
+ public void handleBuffers(String connectorID, ExtendedDataInputStream in, ExtendedDataOutputStream out)
+ throws IOException
{
HTTPServerConnector connector = httpConnectors.get(connectorID);
if (connector == null)
@@ -178,7 +182,12 @@ public class HTTPAcceptor extends Acceptor implements IHTTPAcceptor, INet4jTrans
throw new IllegalArgumentException("Invalid connectorID: " + connectorID);
}
- connector.handleBufferFromMultiplexer(channelIndex, data);
+ short channelIndex = in.readShort();
+ while (channelIndex != -1)
+ {
+ connector.handleBufferFromMultiplexer(channelIndex, in);
+ channelIndex = in.readShort();
+ }
}
@Override
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 449d871..79b21fa 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
@@ -91,7 +91,7 @@ public class HTTPClientConnector extends HTTPConnector
{
public void handleOut(ExtendedDataOutputStream out) throws IOException
{
- out.writeByte(INet4jTransportServlet.OPCODE_BUFFER);
+ out.writeByte(INet4jTransportServlet.OPCODE_BUFFERS);
out.writeString(getConnectorID());
out.writeShort(channel.getChannelIndex());
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 7541c68..73002b7 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
@@ -15,9 +15,11 @@ 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 org.eclipse.net4j.util.io.ExtendedDataInputStream;
import org.eclipse.internal.net4j.channel.InternalChannel;
+import java.io.IOException;
import java.nio.ByteBuffer;
import java.text.MessageFormat;
@@ -72,7 +74,7 @@ public class HTTPServerConnector extends HTTPConnector
throw new UnsupportedOperationException();
}
- public void handleBufferFromMultiplexer(short channelIndex, byte[] data)
+ public void handleBufferFromMultiplexer(short channelIndex, ExtendedDataInputStream in) throws IOException
{
InternalChannel channel = getChannel(channelIndex);
if (channel == null)
@@ -80,12 +82,15 @@ public class HTTPServerConnector extends HTTPConnector
throw new IllegalArgumentException("Invalid channelIndex: " + channelIndex);
}
+ int length = in.readShort();
+
IBuffer buffer = getBufferProvider().provideBuffer();
ByteBuffer byteBuffer = buffer.startPutting(channelIndex);
- for (int i = 0; i < data.length; i++)
+ for (int i = 0; i < length; i++)
{
- System.out.println("Payload: " + data[i]);
- byteBuffer.put(data[i]);
+ byte b = in.readByte();
+ System.out.println("Payload: " + b);
+ byteBuffer.put(b);
}
buffer.flip();
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 2d622c6..c2e97b6 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
@@ -98,9 +98,12 @@ public class Net4jTransportServlet extends HttpServlet implements INet4jTranspor
doOpenChannel(in, out);
break;
- case OPCODE_BUFFER:
- doSendBuffer(in, out);
+ case OPCODE_BUFFERS:
+ doBuffers(in, out);
break;
+
+ default:
+ throw new IOException("Invalid opcaode: " + opcode);
}
out.flush();
@@ -194,29 +197,11 @@ public class Net4jTransportServlet extends HttpServlet implements INet4jTranspor
}
}
- protected void doSendBuffer(ExtendedDataInputStream in, ExtendedDataOutputStream out) throws ServletException,
+ protected void doBuffers(ExtendedDataInputStream in, ExtendedDataOutputStream out) throws ServletException,
IOException
{
- try
- {
- String connectorID = in.readString();
- short channelIndex = in.readShort();
- int length = in.readShort();
- byte[] data = new byte[length];
- for (int i = 0; i < length; i++)
- {
- data[i] = in.readByte();
- }
-
- // TODO Consider passing the stream!
- requestHandler.handleBuffer(connectorID, channelIndex, data);
- out.writeBoolean(true);
- }
- catch (Exception ex)
- {
- OM.LOG.error(ex);
- out.writeBoolean(false);
- }
+ String connectorID = in.readString();
+ requestHandler.handleBuffers(connectorID, in, out);
}
/**