summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-05-25 04:47:20 (EDT)
committerEike Stepper2008-05-25 04:47:20 (EDT)
commit1ea464b36c04f9391b999ae82033eb5a89b98395 (patch)
tree9b188cd1ac5fa53e4ee4cde9e4723728a5eef344
parentae33a1d13c4765900319178167d35376f0154b4f (diff)
downloadcdo-1ea464b36c04f9391b999ae82033eb5a89b98395.zip
cdo-1ea464b36c04f9391b999ae82033eb5a89b98395.tar.gz
cdo-1ea464b36c04f9391b999ae82033eb5a89b98395.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.java4
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPAcceptor.java30
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/HTTPClientConnector.java5
-rw-r--r--plugins/org.eclipse.net4j.http/src/org/eclipse/net4j/internal/http/Net4jTransportServlet.java40
4 files changed, 66 insertions, 13 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 fe48f02..4d223b1 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
@@ -36,6 +36,8 @@ public interface INet4jTransportServlet extends Servlet
public String handleConnect(String userID);
- public void handleOpenChannel(String connectorID, int channelID, short channelIndex, String protocolType);
+ public void handleOpenChannel(String connectorID, short channelIndex, int channelID, String protocolType);
+
+ public void handleSendBuffer(String connectorID, short channelIndex, byte[] data);
}
}
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 9e77a93..ec4a7b0 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,6 +10,7 @@
**************************************************************************/
package org.eclipse.net4j.internal.http;
+import org.eclipse.net4j.buffer.IBuffer;
import org.eclipse.net4j.connector.IConnector;
import org.eclipse.net4j.http.IHTTPAcceptor;
import org.eclipse.net4j.http.IHTTPConnector;
@@ -23,6 +24,7 @@ import org.eclipse.internal.net4j.acceptor.Acceptor;
import org.eclipse.internal.net4j.channel.InternalChannel;
import org.eclipse.internal.net4j.connector.Connector;
+import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -116,7 +118,7 @@ public class HTTPAcceptor extends Acceptor implements IHTTPAcceptor, INet4jTrans
return connectorID;
}
- public void handleOpenChannel(String connectorID, int channelID, short channelIndex, String protocolType)
+ public void handleOpenChannel(String connectorID, short channelIndex, int channelID, String protocolType)
{
HTTPConnector connector = httpConnectors.get(connectorID);
if (connector == null)
@@ -125,10 +127,32 @@ public class HTTPAcceptor extends Acceptor implements IHTTPAcceptor, INet4jTrans
}
InternalChannel channel = connector.createChannel(channelID, channelIndex, protocolType);
- if (channel != null)
+ if (channel == null)
{
- channel.activate();
+ throw new IllegalStateException("Could not open channel");
}
+
+ channel.activate();
+ }
+
+ public void handleSendBuffer(String connectorID, short channelIndex, byte[] data)
+ {
+ HTTPConnector connector = httpConnectors.get(connectorID);
+ if (connector == null)
+ {
+ throw new IllegalArgumentException("Invalid connectorID: " + connectorID);
+ }
+
+ InternalChannel channel = connector.getChannel(channelIndex);
+ if (channel == null)
+ {
+ throw new IllegalArgumentException("Invalid channelIndex: " + channelIndex);
+ }
+
+ IBuffer buffer = getBufferProvider().provideBuffer();
+ ByteBuffer byteBuffer = buffer.startPutting(channelIndex);
+ byteBuffer.put(data);
+ channel.handleBufferFromMultiplexer(buffer);
}
@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 9858e6e..b86f6dd 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
@@ -97,6 +97,11 @@ public class HTTPClientConnector extends HTTPConnector
public void handleIn(ExtendedDataInputStream in) throws IOException
{
+ boolean ok = in.readBoolean();
+ if (!ok)
+ {
+ throw new ConnectorException("Could not send buffer");
+ }
}
});
}
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 ac326e0..fba78a9 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
@@ -64,10 +64,10 @@ public class Net4jTransportServlet extends HttpServlet implements INet4jTranspor
@Override
protected final void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
- handleRequest(req, resp);
+ doRequest(req, resp);
}
- protected void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+ protected void doRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
if (requestHandler == null)
{
@@ -77,7 +77,7 @@ public class Net4jTransportServlet extends HttpServlet implements INet4jTranspor
String connectorID = req.getParameter("list");
if (connectorID != null)
{
- handleList(connectorID, resp);
+ doList(connectorID, resp);
return;
}
@@ -91,18 +91,22 @@ public class Net4jTransportServlet extends HttpServlet implements INet4jTranspor
switch (opcode)
{
case OPCODE_CONNECT:
- handleConnect(in, out);
+ doConnect(in, out);
break;
case OPCODE_OPEN_CHANNEL:
- handleOpenChannel(in, out);
+ doOpenChannel(in, out);
+ break;
+
+ case OPCODE_SEND_BUFFER:
+ doSendBuffer(in, out);
break;
}
out.flush();
}
- protected void handleList(String connectorID, HttpServletResponse resp) throws IOException
+ protected void doList(String connectorID, HttpServletResponse resp) throws IOException
{
IHTTPConnector[] connectors = requestHandler.handleList(connectorID);
PrintWriter writer = resp.getWriter();
@@ -153,7 +157,7 @@ public class Net4jTransportServlet extends HttpServlet implements INet4jTranspor
}
}
- protected void handleConnect(ExtendedDataInputStream in, ExtendedDataOutputStream out) throws ServletException,
+ protected void doConnect(ExtendedDataInputStream in, ExtendedDataOutputStream out) throws ServletException,
IOException
{
try
@@ -169,7 +173,7 @@ public class Net4jTransportServlet extends HttpServlet implements INet4jTranspor
}
}
- protected void handleOpenChannel(ExtendedDataInputStream in, ExtendedDataOutputStream out) throws ServletException,
+ protected void doOpenChannel(ExtendedDataInputStream in, ExtendedDataOutputStream out) throws ServletException,
IOException
{
try
@@ -178,7 +182,25 @@ public class Net4jTransportServlet extends HttpServlet implements INet4jTranspor
int channelID = in.readInt();
short channelIndex = in.readShort();
String protocolType = in.readString();
- requestHandler.handleOpenChannel(connectorID, channelID, channelIndex, protocolType);
+ requestHandler.handleOpenChannel(connectorID, channelIndex, channelID, protocolType);
+ out.writeBoolean(true);
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ out.writeBoolean(false);
+ }
+ }
+
+ protected void doSendBuffer(ExtendedDataInputStream in, ExtendedDataOutputStream out) throws ServletException,
+ IOException
+ {
+ try
+ {
+ String connectorID = in.readString();
+ short channelIndex = in.readShort();
+ byte[] data = in.readByteArray();
+ requestHandler.handleSendBuffer(connectorID, channelIndex, data);
out.writeBoolean(true);
}
catch (Exception ex)