Activating tracing mode in Restlet

In a previous post, I described how to programmatically use TcpMon as a proxy to see the HTTP trafic between a client and a server. Obviously this approach can be used to see which requests Restlet builds and sends and display what the corresponding responses are.

Another solution can also be chosen. Its advantage is that there is no external tool to implement since it relies on the tracing mode of Restlet itself. Enabling this feature in Restlet can be done using context parameters.

On the client side, this can be done using the context instance provided in the Client constructor, as described below:

String url = "(...)";
Request request = new Request(Method.POST, url);
Context context = new Context();
context.getParameters().add("tracing", "true");
Client client = new Client(context, Protocol.HTTP);
Response response = client.handle(request);

This allows displaying raw contents of requests and responses:

GET /accounts/accountId/mails/mailId HTTP/1.1
Date: Tue, 17 May 2011 07:28:47 GMT
Accept: */*
Host: localhost:8084
User-Agent: Restlet-Framework/2.0.5
Content-Length: 27
Content-Type: text/plain; charset=UTF-8

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Tue, 17 May 2011 07:28:47 GMT
Accept-Ranges: bytes
Server: Restlet-Framework/2.0.5
Content-Type: text/xml; charset=UTF-8

My content...

If you choose to use the ClientResource class, you can configure this aspect, as described below:

String url = "(...)";
Context context = new Context();
ClientResource clientResource = new ClientResource(context, url);
Context context = clientResource.getContext();
context.getParameters().add("tracing", "true");

This entry was posted in Restlet. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s