Hello,
I have a very simple example that is very similar to the application tutorial 
on restlet that works using the 2.0 and doesn't work using 2.1RC1. Maybe I've 
missing something, or maybe this already answered in the thread, if this is the 
case, pleas point me to the right direction. Thank you.
My clases:

ObjectsResource.java


public interface ObjectResource {
    
    @Get("xml")
    public  String retrieveXml();
    
    @Get("object")
    public EnvObject retrieveObject();
      
}


ObjectsServerResource.java

public class ObjectServerResource extends ServerResource implements 
ObjectResource{
    private static volatile EnvObject envObject;
    String name;
        
    @Override
    public void doInit() {                    
        name =(String)getRequest().getAttributes().get("name");
        envObject = EnvObjectPersistence.getObject(name);                   
        System.out.println("Init Resource: "+ envObject.toString());
    }

    @Override
    public String retrieveXml() {
        String ret = "";
        XStream xstream =FreedomXStream.getXstream(); 
        ret = xstream.toXML(envObject);
        return ret;
    }
    @Override   
    public EnvObject retrieveObject() {
        System.out.println("Retrieve Object: "+ envObject.toString());
       return ObjectServerResource.envObject;
    }
              
}


The RestletServer:

public class FreedomRestServer extends Application{
    
    
    public FreedomRestServer() 
    {
        setName("Freedom API WebServer");
        setDescription("Restfull API server for the freedom enviroment");
        setOwner("freedom");
        setAuthor("Freedom dev team");
        getMetadataService().addExtension("object", 
MediaType.APPLICATION_JAVA_OBJECT);    
    }
    
    
    
    public static void main(String[] args) throws Exception {
    
        Component component = new Component();
        component.getClients().add(Protocol.FILE);        
        component.getServers().add(Protocol.HTTP, 8112);
        component.getDefaultHost().attach(new FreedomRestServer());
        component.start();                    
    }
    
/**
     * Returns the root Restlet of this application.
     */
    @Override
    public Restlet createInboundRoot() {
        Router router = new Router(getContext());                       
        router.attach("/v1/enviroment/objects/{name}", 
ObjectServerResource.class);                              

        return router;
    }
        
    
}

With this code, the explorer clients show me the xml when I point to the url's
And this is my J2SE client:

public class RestTestClient {

    public static void main(String[] args) {               
                     
        //One object
        ClientResource cr = new 
ClientResource("http://localhost:8111/v1/enviroment/objects/TV";);
        ObjectResource resource = cr.wrap(ObjectResource.class);
        String objectXml = resource.retrieveXml();
        System.out.println("EnvObject as XML: " +objectXml);
        EnvObject object = (EnvObject)resource.retrieveObject();        
        System.out.println("EnvObject as object: " +object.toString());
}

}

This client when I use the 2.0 restlet library works well and I could use the 
object and the representation.
However when I use the 2.1 restlet library the line:

 EnvObject object = (EnvObject)resource.retrieveObject(); 

Object is always null (Although objectXml has the data correct).
So there is any problem in the proxy mechanism that tries to retrieve the 
Object.
Do I miss something? this is turning me crazy :)

Thank you very much and congratulations for the great work.
Gabriel

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

Reply via email to