Note that there are some explanatory texts on larger screens.

plurals
  1. POintercepting http file upload using TCP/IP
    primarykey
    data
    text
    <p>I have written one proxy for intercepting the http requests for my tomcat.</p> <p>every request would go through my proxy and do some checking before it reaches the tomcat server. i am doing it by binding the port using TCP/IP written in java.</p> <p>All the requests(GET and POST) are successfully able to route to tomcat server except the file upload (multipart POST form) submissions.</p> <p>even though i am able to get all the bytes in the TCP/IP and able to flush the data back to tomcat server, somehow the data is getting truncated/lost </p> <p>is there any special things like encoding etc.. that i need to do when dealing with file stream content??</p> <p>below is my sample code...</p> <pre> <code> protected void processData(InputStream input, OutputStream output) throws IOException { // reads a line of text from an InputStream StringBuffer data = new StringBuffer(""); StringBuffer data2 = new StringBuffer(""); StringBuffer data3 = new StringBuffer(""); StringBuffer data4 = new StringBuffer(""); int c; try { while ((c = input.read()) >= 0) { data.append((char) c); // check for an end-of-line character if ((c == 0) || (c == 10) || (c == 13)) { output.write(data.toString().getBytes(), 0, data.length()); data4.append(data.toString()); data = new StringBuffer(); count = 0; } else { if (count > 6) { if (input.available() == 1) { data.append((char) input.read()); } data2.append(data.toString()); data4.append(data.toString()); output.write(data.toString().getBytes(), 0, data .toString().length()); data = new StringBuffer(); } else { if (count == 6) { if (data.toString().toLowerCase() .indexOf("get /") == 0 || data.toString().toLowerCase() .indexOf("post /") == 0) { count = 0; contentLength = -1; // continue read data(header info) while ((line = readLine(input, data)) != null) { data = new StringBuffer(); // do my own stuff here dealing with headers if (StringUtils.isBlank(line)) { data4.append(line); output.write(line.getBytes(), 0, line.length()); break; } line += "\r\n"; output.write(line.getBytes(), 0, line.length()); data4.append(line); output.flush(); } } else { if (input.available() == 1) { data.append((char) input.read()); } } } else { if (input.available() == 1) { data.append((char) input.read()); output.write(data.toString().getBytes(), 0, data.toString().length()); data4.append(data.toString()); data3.append(data.toString()); data = new StringBuffer(); } } } count++; } if (processbody) total++; if (contentLength > 0 && contentLength == total) { log.debug("post data2: " + (data2.toString() != null ? data2.toString() : " ")); log.debug("post data3: " + (data3.toString() != null ? data3.toString() : " ")); log.debug("post data4: " + (data4.toString() != null ? data4.toString() : " ")); output.flush(); } } } catch (Exception e) { log.error("Error ", e); } finally { } } </code> </pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload