I'm experiencing a SocketException everytime I try to send a representation
using PUT.

The error I receive is:

java.net.SocketException: socket closed
        at java.net.SocketInputStream.socketRead0(Native Method)
        at java.net.SocketInputStream.read(SocketInputStream.java:129)
        at java.net.SocketInputStream.read(SocketInputStream.java:182)
        at com.noelios.restlet.http.StreamClientCall.parseResponse(
StreamClientCall.java:120)
        at com.noelios.restlet.http.StreamClientCall.sendRequest(
StreamClientCall.java:232)
        at com.noelios.restlet.http.HttpClientConverter.commit(
HttpClientConverter.java:100)
        at com.noelios.restlet.http.HttpClientHelper.handle(
HttpClientHelper.java:79)
        at org.restlet.Client.handle(Client.java:103)
        at org.restlet.Uniform.handle(Uniform.java:97)
        at PutTest.call(PutTest.java:16)
        at PutTest.main(PutTest.java:10)

Here is a short sample application that will reproduce the error on the
latest 1.1M1 build.  Anyone know whats going on?

Thanks,

Kevin

import org.restlet.*;
import org.restlet.data.*;
import org.restlet.resource.*;

public class PutTest {

    public static void main(String [] args) throws Exception {
        startServer();
        call(null); //Succeeds
        call(new StringRepresentation("Test")); //Fails
    }

    public static void call(Representation entity) {
        String uri = "http://localhost:8000/test/";;
        Request request = new Request(Method.PUT, uri, entity);
        new Client(Protocol.HTTP).handle(request);
    }

    public static void startServer() throws Exception {
        Component component = new Component();
        component.getServers().add(Protocol.HTTP, 8000);

        Application application = new Application(component.getContext()) {
            public Restlet createRoot() {
                Router router = new Router(getContext());
                router.attach("", PutResource.class);
                return router;
            }
        };

        component.getDefaultHost().attach("/test/", application);
        component.start();
    }

    public static class PutResource extends Resource {
        public boolean allowPut() {
            return true;
        }

        public void storeRepresentation(Representation entity) {
            System.out.println("Put called");
        }
    }
}

Reply via email to