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

Attachment: pgpTR6oPWi61D.pgp
Description: PGP signature

Reply via email to