Hello Rémi,

I'm not able to reproduce your problem with Restlet 1.1M4. I send you my sample code. It contains a directory and 2 restlet, one that creates/updates the "test.xml" file, the other the "test2.xml" file. Just hot http://localhost:8182/restletPut1 and http://localhost:8182/restletPut2 to "invoke" them.

Are you using some filter? such as TunnelFilter?

best regards,
Thierry Boileau

Hello,
I have an issue with the implementation of PUT on files.
Let say I have files in a directory :
test.xml
test2.xml
If I make a PUT on test.xml it will modify test2.xml which is not exactilly what I would expect. I don't really catch what I don't understand reading from line 187 to line 219 in FileClientHelper.
If it is not a bug what should I do ?

I am using this line of code :
Response resp = Application.getCurrent().getContext().getClientDispatcher().put(resourceUri,new DomRepresentation(MediaType.TEXT_XML,doc));

I am using Restlet 1.1M4.

Thanks a lot,
Rémi
package testPut;

import org.restlet.Application;
import org.restlet.Component;
import org.restlet.Context;
import org.restlet.Directory;
import org.restlet.Restlet;
import org.restlet.Router;
import org.restlet.data.MediaType;
import org.restlet.data.Protocol;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.resource.DomRepresentation;
import org.restlet.resource.Representation;
import org.restlet.resource.StringRepresentation;

public class TestApplication extends Application {
    public static void main(String[] args) {
        Component component = new Component();
        component.getServers().add(Protocol.HTTP, 8182);
        component.getClients().add(Protocol.HTTP);
        component.getClients().add(Protocol.FILE);
        component.getDefaultHost().attachDefault(
                new TestApplication(component.getContext()));
        try {
            component.start();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public TestApplication(Context parentContext) {
        super(parentContext);
        // TODO Auto-generated constructor stub
    }

    @Override
    public Restlet createRoot() {
        Router router = new Router(getContext());

        // Directory
        Directory directory = new Directory(getContext(), "file:///tmp/thierry");
        directory.setModifiable(true);
        
        // Restlet that puts a representation to file "test.xml"
        Restlet restletPut1 = new Restlet(getContext()) {
            @Override
            public void handle(Request request, Response response) {
                Representation xmlRep = new StringRepresentation("<a>b</a>",
                        MediaType.TEXT_XML);
                DomRepresentation domRepresentation = new DomRepresentation(
                        xmlRep);

                Response resp = getContext().getClientDispatcher()
                        .put("http://localhost:8182/dir/test.xml";,
                                domRepresentation);
                response.setEntity(resp.getEntity());
                response.setStatus(resp.getStatus());
            }
        };

        // Restlet that puts a representation to file "test2.xml"
        Restlet restletPut2 = new Restlet(getContext()) {
            @Override
            public void handle(Request request, Response response) {
                Representation xmlRep = new StringRepresentation("<c>d</c>",
                        MediaType.TEXT_XML);
                DomRepresentation domRepresentation = new DomRepresentation(
                        xmlRep);

                Response resp = getContext().getClientDispatcher().put(
                        "http://localhost:8182/dir/test2.xml";,
                        domRepresentation);
                response.setEntity(resp.getEntity());
                response.setStatus(resp.getStatus());
            }
        };

        router.attach("/dir", directory);
        router.attach("/restletPut1", restletPut1);
        router.attach("/restletPut2", restletPut2);
        return router;
    }

}

Reply via email to