Re: Setting Content-length in http client request?
Hello Erik, your code seems ok, I just wonder if your classpath is correctly set. I am able to reproduce your problem (with same post request with netcat) when my classpath does not contain the httpclient extension archive. best regards, Thierry Boileau Hi all, I am having trouble sending a request to a restlet 1.0.2 service from another restlet. In brief, using a file representation is not setting the Content-Length, and if the Content-Length is not set, the Restlet gives me an empty entity in the request. Here is some sample code for the client side: import org.restlet.*; import org.restlet.data.*; import org.restlet.resource.*; import org.restlet.util.*; public class Test { public static void main (String[] args) { try { Client client = new Client(Protocol.HTTP); client.start(); // not sure if this is necessary Request req = new Request(Method.POST, http://localhost:8001/jobs/;, new FileRepresentation(/tmp/test, MediaType.APPLICATION_XML, 60)); org.restlet.data.Response resp = client.handle(req); System.out.println(resp.getStatus().getCode()); System.out.println(resp.getEntity().getText()); } catch (Exception e) { System.out.println(Exception: + e); } } } This is run with all the necessary jars (commons httpclient, restlet httpclient, etc.) If /tmp/test is an xml file, here is our request, as captured by netcat: C: POST /jobs/ HTTP/1.1 C: Host:localhost:8001 C: User-Agent:Noelios-Restlet-Engine/1.0.2 C: Accept:*/* C: Content-Type:application/xml C: Connection:close C: C: ?xml version=1.0 encoding=UTF-8? C: [...] The request object, as sent to my restlet, has an empty entity. If I add Content-Length and send it using netcat, it goes through fine. Ditto for using curl. Additionally, my response in the client has a status of 1001, and an empty entity, when it should be 400, with an error message as the entity. Am I doing something wrong with my setting up of an http client? best, Erik Hetzner ;; Erik Hetzner, California Digital Library ;; gnupg key id: 1024D/01DB07E3
Re: Setting Content-length in http client request?
Hi Erik great! Actually, release 1.0.2 contains an inner http client planned to be released with Restlet 1.1. As the development of this client is not achieved, it has been decided to remove this useless code from release 1.0.3. Thus, when providing no client extensions, this inner client is detected when using release 1.0.2 (which leads to some bugs...) and is not detected with release 1.0.3 which leads to a correct error message stating that no client supports the HTTP protocol. best regards, Thierry Boileau Hello Erik, your code seems ok, I just wonder if your classpath is correctly set. I am able to reproduce your problem (with same post request with netcat) when my classpath does not contain the httpclient extension archive. Hi Thierry, Excellent, thank you! I’d thought I was including the extension; but it seems it is a bad idea to upgrade to a new version while trying to solve a problem. In 1.0.3 not including the extension gives you an error, so I think I was using 1.0.2 expecting an error message, not a silent problem. Many thanks. best, Erik Hetzner ;; Erik Hetzner, California Digital Library ;; gnupg key id: 1024D/01DB07E3
Re: Setting Content-length in http client request?
At Mon, 16 Jul 2007 20:23:08 +0200, Thierry Boileau [EMAIL PROTECTED] wrote: Hi Erik great! Actually, release 1.0.2 contains an inner http client planned to be released with Restlet 1.1. As the development of this client is not achieved, it has been decided to remove this useless code from release 1.0.3. Thus, when providing no client extensions, this inner client is detected when using release 1.0.2 (which leads to some bugs...) and is not detected with release 1.0.3 which leads to a correct error message stating that no client supports the HTTP protocol. This makes sense. Thanks again for your help. And thanks as well for everybody’s work on Restlet. best, Erik Hetzner ;; Erik Hetzner, California Digital Library ;; gnupg key id: 1024D/01DB07E3 pgpKB0SdOUZyf.pgp Description: PGP signature
Setting Content-length in http client request?
Hi all, I am having trouble sending a request to a restlet 1.0.2 service from another restlet. In brief, using a file representation is not setting the Content-Length, and if the Content-Length is not set, the Restlet gives me an empty entity in the request. Here is some sample code for the client side: import org.restlet.*; import org.restlet.data.*; import org.restlet.resource.*; import org.restlet.util.*; public class Test { public static void main (String[] args) { try { Client client = new Client(Protocol.HTTP); client.start(); // not sure if this is necessary Request req = new Request(Method.POST, http://localhost:8001/jobs/;, new FileRepresentation(/tmp/test, MediaType.APPLICATION_XML, 60)); org.restlet.data.Response resp = client.handle(req); System.out.println(resp.getStatus().getCode()); System.out.println(resp.getEntity().getText()); } catch (Exception e) { System.out.println(Exception: + e); } } } This is run with all the necessary jars (commons httpclient, restlet httpclient, etc.) If /tmp/test is an xml file, here is our request, as captured by netcat: C: POST /jobs/ HTTP/1.1 C: Host:localhost:8001 C: User-Agent:Noelios-Restlet-Engine/1.0.2 C: Accept:*/* C: Content-Type:application/xml C: Connection:close C: C: ?xml version=1.0 encoding=UTF-8? C: [...] The request object, as sent to my restlet, has an empty entity. If I add Content-Length and send it using netcat, it goes through fine. Ditto for using curl. Additionally, my response in the client has a status of 1001, and an empty entity, when it should be 400, with an error message as the entity. Am I doing something wrong with my setting up of an http client? best, Erik Hetzner ;; Erik Hetzner, California Digital Library ;; gnupg key id: 1024D/01DB07E3 pgpTR6oPWi61D.pgp Description: PGP signature