You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ra...@apache.org on 2010/02/03 15:03:42 UTC
svn commit: r906049 - in
/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport:
http/HttpTunnelServlet.java util/TextWireFormat.java
Author: rajdavies
Date: Wed Feb 3 14:03:42 2010
New Revision: 906049
URL: http://svn.apache.org/viewvc?rev=906049&view=rev
Log:
Apply fix for https://issues.apache.org/activemq/browse/AMQ-1308
Modified:
activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTunnelServlet.java
activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/util/TextWireFormat.java
Modified: activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTunnelServlet.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTunnelServlet.java?rev=906049&r1=906048&r2=906049&view=diff
==============================================================================
--- activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTunnelServlet.java (original)
+++ activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTunnelServlet.java Wed Feb 3 14:03:42 2010
@@ -19,16 +19,16 @@
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 @@
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 @@
}
}
+ @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 @@
}
}
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-
- // Read the command directly from the reader
- Command command = (Command)wireFormat.unmarshalText(request.getReader());
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
+ IOException {
+
+ // 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 {
Modified: activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/util/TextWireFormat.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/util/TextWireFormat.java?rev=906049&r1=906048&r2=906049&view=diff
==============================================================================
--- activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/util/TextWireFormat.java (original)
+++ activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/util/TextWireFormat.java Wed Feb 3 14:03:42 2010
@@ -41,11 +41,17 @@
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 @@
return unmarshal(dis);
}
- public boolean inReceive() {
- // TODO Implement for inactivity monitor
- return false;
- }
-
+ public boolean inReceive() {
+ // TODO Implement for inactivity monitor
+ return false;
+ }
+
}