>> I tried to receive/handle a POST request via HttpService.doService >> (extending the "GET" of the ElementalHttpServer example)
>Many thanks for tracking this bug down. I have applied a fix for the >problem it in the SVN trunk. Please get the latest SVN snapshot off the >SVN trunk and let me know if that solves the problem for you. Yes it works now, but it is a little hard to get the content (see attached patch how i tried this). It would be nice to have not only the getContent() -> InputStream, but something like getContentAsString(). But dont expect too much from my feedback because i am absolutely unexperienced und stumbled over httpcore accidently. What i can say is that in my tests it worked out of the box and (in contrast to httpclient) without any dependies. Having a more convenient method - or write one myself, which would not bee to hard with the given interface - to get the content of a posted entity would fit my needs. In the meantime i decited that the minimal needs that i have could be satified without any tool outside the core java language, but if my needs grows than httcore will be the first choice that i would try. gerhard -- .''`. gerhard oettl on Debian/Gnu Linux : :' : `. `'` gpg key: 1024D/D59131AA 2002-06-18 `-
--- ElementalHttpServer.java.ori 2006-04-15 20:59:53.000000000 +0200 +++ ElementalHttpServer.java 2006-05-26 15:20:21.350176896 +0200 @@ -38,12 +38,14 @@ import org.apache.http.HttpException; import org.apache.http.HttpRequest; +import org.apache.http.HttpEntityEnclosingRequest; import org.apache.http.HttpResponse; import org.apache.http.HttpServerConnection; import org.apache.http.HttpStatus; import org.apache.http.MethodNotSupportedException; import org.apache.http.entity.FileEntity; import org.apache.http.entity.StringEntity; +import org.apache.http.entity.BasicHttpEntity; import org.apache.http.impl.DefaultHttpParams; import org.apache.http.impl.DefaultHttpServerConnection; import org.apache.http.params.HttpConnectionParams; @@ -83,9 +85,8 @@ protected void doService(final HttpRequest request, final HttpResponse response) throws HttpException, IOException { String method = request.getRequestLine().getMethod(); - if (!method.equalsIgnoreCase("GET") && !method.equalsIgnoreCase("HEAD")) { - throw new MethodNotSupportedException(method + " method not supported"); - } + + if (method.equalsIgnoreCase("GET") || method.equalsIgnoreCase("HEAD")) { String docroot = (String) request.getParams().getParameter("server.docroot"); String target = request.getRequestLine().getUri(); File file = new File(docroot, URLDecoder.decode(target)); @@ -105,6 +106,20 @@ response.setEntity(body); System.out.println("Serving file " + file.getPath()); } + } + else if (method.equalsIgnoreCase("POST")) { + System.out.println("***reached POST method."); + response.setStatusCode(HttpStatus.SC_OK); + StringEntity body = new StringEntity("*** reached POST method", "UTF-8"); + response.setEntity(body); + BasicHttpEntity ent = (BasicHttpEntity)((HttpEntityEnclosingRequest)request).getEntity(); + System.out.println(ent.toString()); + System.out.println("len=" + ent.getContentLength()); + System.out.println("***finished POST method."); + } + else { + throw new MethodNotSupportedException(method + " method not supported"); + } } protected void logMessage(final String s) { @@ -130,7 +145,7 @@ this.serversocket = new ServerSocket(port); this.params = new DefaultHttpParams(null); this.params - .setIntParameter(HttpConnectionParams.SO_TIMEOUT, 5000) + .setIntParameter(HttpConnectionParams.SO_TIMEOUT, 50000) .setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false) .setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true)
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]