Hi! (my first post to the list)
I've just started looking into Restlet, and have built a minimal
service with accompanying unit tests. (in particular, a job
submission/queue system for running workflows of our workflow
environment)
I also want to use the Restlet API for the client side unit tests, as
Restlet tries to provide such functionality.
My resources have different representations, at this point just text/
plain and text/xml.
However, I cannot find out how to specify which variant I want from
the client code, ie. which Accept header to send. Example:
public static final int PORT = 8977;
public static final String BASE_URL = "http://localhost:" + PORT;
private static Component server;
@BeforeClass
public static void startServer() throws Exception {
stopServer();
server = RestTest.startServer(PORT);
}
@AfterClass
public static void stopServer() throws Exception {
if (server != null && server.isStarted()) {
server.stop();
server = null;
}
}
(.. some kind of junit base class for such set-up that did the port/
URL thing automatically would be great! )
@Test
public void readJustCreatedXML() throws IOException {
if (justCreated == null) {
create();
}
assertNotNull("create() must be run first", justCreated);
Request request = new Request();
Client client = new Client(Protocol.HTTP);
request.setResourceRef(justCreated);
request.setMethod(Method.GET);
Series<Parameter> extraHeaders = new Form();
extraHeaders.add("Accept", "text/xml");
request.getAttributes().put("org.restlet.http.headers",
extraHeaders);
Response response = client.handle(request);
assertTrue(response.getStatus().isSuccess());
assertTrue(response.getEntity().getText().equals(workflow));
}
Now here I've tried to add the Accept header using the magic
org.restlet.http.headers attribute name, but this does not work:
Apr 2, 2007 5:04:14 PM com.noelios.restlet.http.HttpConverter
addAdditionalHeaders
WARNING: Addition of the standard header "Accept" is not allowed.
What is the official way to specify which representation I want?
--
Stian Soiland, myGrid team
School of Computer Science
The University of Manchester
http://www.cs.man.ac.uk/~ssoiland/