package jalview.rest;
-import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
}
}
- protected String getRequestBody(HttpServletRequest request)
- throws IOException
- {
- StringBuilder sb = new StringBuilder();
- BufferedReader reader = request.getReader();
- try
- {
- String line;
- while ((line = reader.readLine()) != null)
- {
- sb.append(line).append('\n');
- }
- } finally
- {
- reader.close();
- }
- return sb.toString();
- }
-
protected boolean checkParameters(HttpServletRequest request,
HttpServletResponse response, int i)
{
import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.BindException;
import java.util.HashMap;
import java.util.Map;
+import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
* Currently just echoes the request; add helper classes as required to
* process requests
*/
- System.out.println(request.toString());
+ // This "pointless" call to request.getInputStream() seems to preserve the
+ // InputStream for use later in getRequestBody.
+ request.getInputStream();
if (endpoints == null)
{
final String queryString = request.getQueryString();
}
}
- protected String getRequestBody(HttpServletRequest request)
- throws IOException
+ protected String getRequestBody(HttpServletRequest request,
+ HttpServletResponse response) throws IOException
{
StringBuilder sb = new StringBuilder();
- BufferedReader reader = request.getReader();
+ BufferedReader reader = null;
+ Console.debug("REQUEST=" + request.toString());
+ Console.debug("REQUEST.Content-Lenggth=" + request.getContentLength());
try
{
- String line;
- while ((line = reader.readLine()) != null)
+ reader = request.getReader();
+ Console.debug("Using getReader()");
+ } catch (IllegalStateException e)
+ {
+ ServletInputStream is = request.getInputStream();
+ Console.debug("INPUTSTREAM "
+ + (is.isFinished() ? "FINISHED" : "NOT FINISHED"));
+ reader = new BufferedReader(new InputStreamReader(is));
+ Console.debug("Using getInputStream()");
+ }
+ if (reader != null)
+ {
+ try
{
- sb.append(line).append('\n');
+ String line;
+ while ((line = reader.readLine()) != null)
+ {
+ sb.append(line).append('\n');
+ }
+ } finally
+ {
+ reader.close();
}
- } finally
+ }
+ else
{
- reader.close();
+ returnError(request, response, "Error reading body of HTTP request");
}
return sb.toString();
}
-
}
\ No newline at end of file