I have a simple Java app that uses Restlet to send messages to a remote server. 
A thread running in the background has these lines of code:

ClientResource resourceHB = new ClientResource ( uri );    
resourceHB.put ( "heartbeat" );    

which works fine. I.e., the message is sent to the desired server.

However, I have copied the same lines to another thread (but using a different 
URI). Two things happened:

    at run time, I get a message that the protocol isn't specified, so, after 
some research, I changed the code to:

    Client client = new Client ( new Context(), Protocol.HTTP );
    ClientResource resourceFault = new ClientResource ( uri );
    resourceFault.setNext ( client );
    resourceFault.put ( "error" );

    that eliminates the protocol error, but the 'put' gets a 'bad request' HTTP 
error; the difference seems to be that in the first case, the HTTP message is 
sent automatically as 'octet_stream' (which is what the remote server expects) 
while in the second it is defaulting to 'html'.

My questions are:

    why do I have to add the extra code in the second case?

    how do I force the content type to be 'octet_stream'? I've tried:

    resourceFault.put ( "error", MediaType.APPLICATION_OCTET_STREAM );

    but Fiddler still shows the header with 'text/html'.

    again, why does the second case need so much extra information? -- the 
first case 'just works'

    is it not possible to have multiple client resources, particularly in 
different threads?

Java 1.6
Restlet version 2.2.1 for Java SE
org.restlet.jar (no extensions)

The main program uses:

import org.restlet.resource.ServerResource;
import org.restlet.Component;
import org.restlet.data.Protocol;
import org.restlet.routing.Router;

The thread containing the first snippet uses:

import org.restlet.resource.ClientResource;

The thread containing the second snippet uses:

import org.restlet.resource.ClientResource;
import org.restlet.data.Protocol;
import org.restlet.Client;
import org.restlet.Context;
import org.restlet.representation.StringRepresentation;
import org.restlet.data.MediaType;

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3084823

Reply via email to