Christopher Schultz wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Aryeh,
On 3/2/2010 4:12 PM, Aryeh M. Friedman wrote:
Also forgot to mention I already refactored the servlet to use pure
hex encoding (namely we convert the entire request into a hex string
so for example a old format message of
"call=default.Session.getSession()" gets translated into
"63616c6c3d64656661756c742e53657373696f6e2e67657453657373696f6e2829"
If that string above is your entire POST request body, then it's not
properly formatted. Instead, it should be:
call=8347812459870132405987234985023450987
or whatever. The parameter has to have a name :)
Design decision for two reasons:
1. If we are already decoding the request from hex to plain text
mightiest use getReader()
2. Our app needs to support several frontends (not just the web via a
servlet)
Just for reference here is the refactored servlet with any trade secret
code removed (all the tomcat<-->servlet logic is kept)
// src/backend/servlet/Servlet.java
package backend.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Reader;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import backend.util.StringUtil; // hex encoding/decoding
public class Servlet extends HttpServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException
{
handleRequest(request,response);
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException
{
handleRequest(request,response);
}
private void handleRequest(HttpServletRequest request,
HttpServletResponse response)
throws IOException
{
// not possible to do custom error reporting yet
because we have no writer to write to
PrintWriter pw=new PrintWriter(response.getWriter());
String call=null;
try {
call=StringUtil.hexToString(
readRequest(request)).substring(5);
} catch(IOException e) {
write out error in custom format
}
code to do something with the request
}
private String readRequest(HttpServletRequest request)
throws IOException
{
if(request.getMethod().equals("GET"))
return request.getQueryString();
String out="";
Reader reader=request.getReader();
// reading all the content in one read causes problems
sometimes so we read it char by char
for(int i=0;i<request.getContentLength();i++)
out+=(char) reader.read();
return out;
}
private static final long serialVersionUID=0L;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org