mirror of https://github.com/apache/activemq.git
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@906049 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
700f1e45de
commit
568ab1ebe6
|
@ -19,16 +19,16 @@ package org.apache.activemq.transport.http;
|
|||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.activemq.command.Command;
|
||||
import org.apache.activemq.command.WireFormatInfo;
|
||||
import org.apache.activemq.transport.TransportAcceptListener;
|
||||
|
@ -50,9 +50,10 @@ public class HttpTunnelServlet extends HttpServlet {
|
|||
|
||||
private TransportAcceptListener listener;
|
||||
private TextWireFormat wireFormat;
|
||||
private Map<String, BlockingQueueTransport> clients = new HashMap<String, BlockingQueueTransport>();
|
||||
private long requestTimeout = 30000L;
|
||||
private final Map<String, BlockingQueueTransport> clients = new HashMap<String, BlockingQueueTransport>();
|
||||
private final long requestTimeout = 30000L;
|
||||
|
||||
@Override
|
||||
public void init() throws ServletException {
|
||||
super.init();
|
||||
listener = (TransportAcceptListener)getServletContext().getAttribute("acceptListener");
|
||||
|
@ -65,10 +66,12 @@ public class HttpTunnelServlet extends HttpServlet {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doHead(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
createTransportChannel(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
// lets return the next response
|
||||
Command packet = null;
|
||||
|
@ -96,15 +99,19 @@ public class HttpTunnelServlet extends HttpServlet {
|
|||
}
|
||||
}
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
|
||||
IOException {
|
||||
|
||||
// Read the command directly from the reader
|
||||
Command command = (Command)wireFormat.unmarshalText(request.getReader());
|
||||
// Read the command directly from the reader, assuming UTF8 encoding
|
||||
ServletInputStream sis = request.getInputStream();
|
||||
Command command = (Command) wireFormat.unmarshalText(new InputStreamReader(sis, "UTF-8"));
|
||||
|
||||
if (command instanceof WireFormatInfo) {
|
||||
WireFormatInfo info = (WireFormatInfo)command;
|
||||
WireFormatInfo info = (WireFormatInfo) command;
|
||||
if (!canProcessWireFormatVersion(info.getVersion())) {
|
||||
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Cannot process wire format of version: " + info.getVersion());
|
||||
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Cannot process wire format of version: "
|
||||
+ info.getVersion());
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
|
@ -41,11 +41,17 @@ public abstract class TextWireFormat implements WireFormat {
|
|||
public abstract String marshalText(Object command);
|
||||
|
||||
public void marshal(Object command, DataOutput out) throws IOException {
|
||||
out.writeUTF(marshalText(command));
|
||||
String text = marshalText(command);
|
||||
byte[] utf8 = text.getBytes("UTF-8");
|
||||
out.writeInt(utf8.length);
|
||||
out.write(utf8);
|
||||
}
|
||||
|
||||
public Object unmarshal(DataInput in) throws IOException {
|
||||
String text = in.readUTF();
|
||||
int length = in.readInt();
|
||||
byte[] utf8 = new byte[length];
|
||||
in.readFully(utf8);
|
||||
String text = new String(utf8, "UTF-8");
|
||||
return unmarshalText(text);
|
||||
}
|
||||
|
||||
|
@ -63,9 +69,9 @@ public abstract class TextWireFormat implements WireFormat {
|
|||
return unmarshal(dis);
|
||||
}
|
||||
|
||||
public boolean inReceive() {
|
||||
// TODO Implement for inactivity monitor
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean inReceive() {
|
||||
// TODO Implement for inactivity monitor
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue