Satto
Satto

Reputation: 51

Restlet client freezing on HTTPS requests

I'm trying to create a client-server application in Java using HTTPS and XML posts with Restlet.

I've followed various tutorials, and managed to run the server side without problems (it responds correctly if I connect to it with a browser), but as soon I start the client they both freeze: the client doesn't complete its request and the server doesn't respond to browser requests anymore.

Right now I'm using version 2.2 Milestone 1, but I also tried with version 2.1.1 with no success. I'm using Eclipse Juno on MacOSX 10.7.5. The two stores have been created using the keytool command (I've created serverKey.jks, exported a self-signed certificate and added it to clientTrust.jks).
The jars that I originally included were:

But I also tried to add the specific connecters (separately, with the dependencies listed in the libs readme.txt):

TestHTTPS class

public class TestHTTPS extends Application{

    public static void main(String[] args) throws Exception{
        TestHTTPS t = new TestHTTPS();
        t.testhttps();
    }

    public void testhttps() throws Exception{
        Component comp = new Component();

        Server server = comp.getServers().add(Protocol.HTTPS, 8183);

        Series<Parameter> servParameters = server.getContext().getParameters();
        servParameters.add("keystorePath", "serverKey.jks");
        servParameters.add("keystorePassword", "password");
        servParameters.add("keystoreType", "JKS");
        servParameters.add("keyPassword", "password");
        servParameters.add("tracing", "true");

        comp.getDefaultHost().attach(new TestHTTPS());      
        server.start();

        Context con = new Context();
        Series<Parameter> clParameters = con.getParameters();

        clParameters.add("truststorePath", "clientTrust.jks");
        clParameters.add("truststoreType", "JKS");
        clParameters.add("truststorePassword", "password");

        Client restletClient = new Client(con, Protocol.HTTPS);
        Reference resourceRef = new Reference("https://localhost:8183/user/myself");

        Request request = new Request(Method.POST, resourceRef);
        request.getClientInfo().getAcceptedMediaTypes().add(new Preference<MediaType>(MediaType.TEXT_XML));

        Response response = restletClient.handle(request);
        System.out.println(response.getEntityAsText());

        restletClient.stop();
        server.stop();
    }

    @Override
    public Restlet createInboundRoot() {
        Router router = new Router(getContext());
        router.attach("/user/{id}", UserResource.class);
        return router;
    }
}

UserResource class

public class UserResource extends ServerResource {
    @Post("xml")
    public Representation sendPostResponse(){
        return new StringRepresentation("<Document>content</Document>", MediaType.APPLICATION_XML);
    }

    @Get("xml")
    public Representation sendGetResponse(){
        return new StringRepresentation("<Document>content</Document>", MediaType.APPLICATION_XML);
    }
}

The only output from the console is:

Starting the internal [HTTPS/1.1] server on port 8183
Starting the internal [HTTPS/1.1] client

Am I doing something wrong?

Upvotes: 1

Views: 2622

Answers (1)

David Torre
David Torre

Reputation: 21

After quite a bit of investigation, I found the following solves the issue of a stalled "Starting the internal [HTTPS/1.1] client" process:

Make sure the following three JARs are in your build path:

org.restlet.ext.net.jar
org.restlet.ext.ssl.jar
org.restlet.jar

Upvotes: 2

Related Questions