Hi,
I try to adopt the sample restlet application as seen in the code below.
If I run the client I get null for the report object without any errors:
INFO: Starting the default HTTP client
null
Server started without any errors
INFO: Starting the Simple [HTTP/1.1] server on port 8080
I thing I missed something... any clues would be very appreciated.
labtrax
public class Client {
public static void main(String[] args) {
ClientResource cr = new ClientResource(
"http://localhost:8080/reportservice");
IReportResourceProxy resource =
cr.wrap(IReportResourceProxy.class);
resource.getClientResource().getClientInfo().getAcceptedMediaTypes().add(
new Preference<MediaType>(
MediaType.APPLICATION_JAVA_OBJECT));
Report report = resource.generate(new Result<Report>() {
public void onFailure(Throwable caught) {
System.out.println("test");
}
public void onSuccess(Report result) {
System.out.println(result.getConfig().getType());
}
});
System.out.println(report);
}
}
public class Server extends Application {
public Server() {
super();
}
public Server(Context context) {
super(context);
}
public static void main(String[] args) throws Exception {
Component component = new Component();
component.getClients().add(Protocol.FILE);
component.getServers().add(Protocol.HTTP, 8080);
component.getDefaultHost().attach(new Server());
component.start();
}
@Override
public Restlet createInboundRoot() {
Router router = new Router(getContext());
getConnectorService().getClientProtocols().add(Protocol.FILE);
router.attach("/reportservice/1", ReportResource.class);
return router;
}
}
import org.restlet.resource.Put;
public interface IReportResource {
@Put
public Report generate();
}
public interface IReportResourceProxy extends ClientProxy {
@Put
public Report generate(Result<Report> callback);
}
public class Report implements Serializable {
private static final long serialVersionUID = -7802486304707483586L;
private ReportConfig config;
public ReportConfig getConfig() {
return config;
}
public void setConfig(ReportConfig config) {
this.config = config;
}
}
public class ReportConfig implements Serializable{
private static final long serialVersionUID = 5650631967758314454L;
private String type;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
public class ReportResource extends ServerResource implements IReportResource {
@Put
public Report generate() {
Report report = new Report();
ReportConfig config = new ReportConfig();
config.setType("server");
report.setConfig(config);
return report;
}
}
public class Server extends Application {
public Server() {
super();
}
public Server(Context context) {
super(context);
}
public static void main(String[] args) throws Exception {
Component component = new Component();
component.getClients().add(Protocol.FILE);
component.getServers().add(Protocol.HTTP, 8080);
component.getDefaultHost().attach(new Server());
component.start();
}
@Override
public Restlet createInboundRoot() {
Router router = new Router(getContext());
getConnectorService().getClientProtocols().add(Protocol.FILE);
router.attach("/reportservice", ReportResource.class);
return router;
}
}
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2703599