Simple HTTPS-Connector does not start anymore #702

Open
waywaaard opened this Issue Jan 7, 2013 · 20 comments

Projects

None yet

5 participants

@waywaaard

In Version 2.1.1 and 2.2-M1 and 2.2-Snapshot using HTTPS with the simple framework does not work. I get always a timeout when trying to access my files. Normal HTTP starts via simple-server https does not.

Though also the internal https-connector does not work for me --> always timeouts. See this stackoverflow-post for code details:

http://stackoverflow.com/questions/14187399/restlet-2-1-1-internal-https-connector

@waywaaard

here some testcode

        Component compHttps = new Component();
        compHttps.getServers().add(Protocol.HTTPS, 8443);
        compHttps.getClients().add(Protocol.FILE);
        Series<Parameter> parametersHTTPS = compHttps.getContext()
                .getParameters();

        parametersHTTPS.add("maxThreads", "40");
        parametersHTTPS.add("sslContextFactory",
                "org.restlet.ext.ssl.PkixSslContextFactory");
        parametersHTTPS.add("keystorePath", "ssl/keystore.jks");
        parametersHTTPS.add("keystorePassword", "test");
        parametersHTTPS.add("keystoreType", "JKS");
        parametersHTTPS.add("keyPassword", "test");


        // create Component (as ever for Restlet)
        Component comp = new Component();
        comp.getServers().add(Protocol.HTTP, 8182);
        comp.getClients().add(Protocol.FILE);

        // create JAX-RS runtime environment
        JaxRsApplication application = new JaxRsApplication(comp.getContext()
                .createChildContext());

        // attach Application
        application.add(new PlatformApplication());

        StaticDirectoryApplication staticApplication = new StaticDirectoryApplication();

        // Attach the application to the component and start it
        comp.getDefaultHost().attach("/api", application);
        comp.getDefaultHost().attach("/", staticApplication);

        compHttps.getDefaultHost().attach("/", staticApplication);

        comp.start();
        compHttps.start();
@thboileau thboileau was assigned Jan 15, 2013
@jlouvel
Member
jlouvel commented Jan 15, 2013

Could you list your classpath entries and their order?

2013/1/7 Michael notifications@github.com

here some testcode

    Component compHttps = new Component();
    compHttps.getServers().add(Protocol.HTTPS, 8443);
    compHttps.getClients().add(Protocol.FILE);
    Series<Parameter> parametersHTTPS = compHttps.getContext()
            .getParameters();

    parametersHTTPS.add("maxThreads", "40");
    parametersHTTPS.add("sslContextFactory",
            "org.restlet.ext.ssl.PkixSslContextFactory");
    parametersHTTPS.add("keystorePath", "ssl/keystore.jks");
    parametersHTTPS.add("keystorePassword", "test");
    parametersHTTPS.add("keystoreType", "JKS");
    parametersHTTPS.add("keyPassword", "test");


    // create Component (as ever for Restlet)
    Component comp = new Component();
    comp.getServers().add(Protocol.HTTP, 8182);
    comp.getClients().add(Protocol.FILE);

    // create JAX-RS runtime environment
    JaxRsApplication application = new JaxRsApplication(comp.getContext()
            .createChildContext());

    // attach Application
    application.add(new PlatformApplication());

    StaticDirectoryApplication staticApplication = new StaticDirectoryApplication();

    // Attach the application to the component and start it
    comp.getDefaultHost().attach("/api", application);
    comp.getDefaultHost().attach("/", staticApplication);

    compHttps.getDefaultHost().attach("/", staticApplication);

    comp.start();
    compHttps.start();


Reply to this email directly or view it on GitHubhttps://github.com/restlet/restlet-framework-java/issues/702#issuecomment-11971792.

@waywaaard

Does this help you?

image

@waywaaard

Hello,

did somebody dig into this or could anyone reproduce this error?

@lhanusiak

Today, I experienced same issue in android version. Connection is timed out both in 2.1.1 and 2.2-M1.
When I tested against 2.2-SNAPSHOT only first request receives valid response, all other attempts are timed out by the server. Is there any workaround for this issue?

@lhanusiak

I tested my andorid setup against version 2.1.2 and I am still having troubles with HTTPS requests. Same as before, first request returns with valid response all other requests are timed out by a server. Is there any hope for quick fix or workaround or should I consider using another framework

@lhanusiak

Today, I was testing restlet for android (version 2.1.4) and I am still having troubles with HTTPS requests. Same as before, first request returns with valid response all other requests are timed out by a server.

I have prepared sample project where error can be reproduced: https://db.tt/c5k3bD1l

I did some digging in debug mode and find out that after processing first request my app falls into infinit loop in org.restlet.engine.connector.Connection class, method onSelected(SelectionRegistration registration) lines 640 - 672

           boolean readyFound = false;
           do {
           readyFound = false;

            synchronized (getInboundWay().getBuffer().getLock()) {
                if (getInboundWay().getIoState() == IoState.READY) {
                    readyFound = true;

                    if (getLogger().isLoggable(Level.FINEST)) {
                        getLogger().finest(
                                "Entering into a connection READY loop");
                    }

                    getInboundWay().onSelected(
                            getInboundWay().getRegistration());
                }
            }

            synchronized (getOutboundWay().getBuffer().getLock()) {
                if (getOutboundWay().getIoState() == IoState.READY) {
                    readyFound = true;

                    if (getLogger().isLoggable(Level.FINEST)) {
                        getLogger().finest(
                                "Entering into a connection READY loop");
                    }

                    getOutboundWay().onSelected(
                            getOutboundWay().getRegistration());
                }
            }
        } while (readyFound);

In my log consol I can see following output after first request

11-20 08:31:25.444: W/System.err(1249): Handling SSL result: OK
11-20 08:31:25.444: W/System.err(1249): Handling SSL handshake: NOT_HANDSHAKING
11-20 08:31:25.444: W/System.err(1249): Closing connection to /127.0.0.1:56385 gracefully
11-20 08:31:25.444: W/System.err(1249): Ending process of buffer java.nio.ReadWriteHeapByteBuffer, status: capacity=16384 position=0 limit=16384, FILLING, true. Result: -1, try again: false, can loop: true, total filled: 0
11-20 08:31:25.444: W/System.err(1249): Handling SSL result: OK
11-20 08:31:25.444: W/System.err(1249): Handling SSL handshake: NOT_HANDSHAKING
11-20 08:31:25.444: W/System.err(1249): Inbound way selected. Done for : READY, START, java.nio.ReadWriteHeapByteBuffer, status: capacity=16384 position=0 limit=16384, FILLING, true
11-20 08:31:25.444: W/System.err(1249): Entering into a connection READY loop
11-20 08:31:25.444: W/System.err(1249): Processing IO for inbound way: READY, START, java.nio.ReadWriteHeapByteBuffer, status: capacity=16384 position=0 limit=16384, FILLING, true
11-20 08:31:25.444: W/System.err(1249): Beginning process of buffer java.nio.ReadWriteHeapByteBuffer, status: capacity=16384 position=0 limit=16384, FILLING, true
11-20 08:31:25.444: W/System.err(1249): 0 bytes drained from buffer at pre-processing, 16384 remaining bytes
11-20 08:31:25.444: W/System.err(1249): Filling buffer java.nio.ReadWriteHeapByteBuffer, status: capacity=16384 position=0 limit=16384, FILLING, true
11-20 08:31:25.444: W/System.err(1249): Beginning process of buffer java.nio.ReadWriteHeapByteBuffer, status: capacity=18437 position=0 limit=18437, FILLING, true
11-20 08:31:25.444: W/System.err(1249): 0 bytes drained from buffer at pre-processing, 18437 remaining bytes
11-20 08:31:25.444: W/System.err(1249): Filling buffer java.nio.ReadWriteHeapByteBuffer, status: capacity=18437 position=0 limit=18437, FILLING, true
11-20 08:31:25.444: W/System.err(1249): Ending process of buffer java.nio.ReadWriteHeapByteBuffer, status: capacity=18437 position=0 limit=18437, FILLING, true. Result: -1, try again: false, can loop: true, total filled: 0
11-20 08:31:25.454: W/System.err(1249): Handling SSL result: OK
11-20 08:31:25.454: W/System.err(1249): Handling SSL handshake: NOT_HANDSHAKING
11-20 08:31:25.454: W/System.err(1249): Closing connection to /127.0.0.1:56385 gracefully
11-20 08:31:25.454: W/System.err(1249): Ending process of buffer java.nio.ReadWriteHeapByteBuffer, status: capacity=16384 position=0 limit=16384, FILLING, true. Result: -1, try again: false, can loop: true, total filled: 0
11-20 08:31:25.454: W/System.err(1249): Handling SSL result: OK
11-20 08:31:25.454: W/System.err(1249): Handling SSL handshake: NOT_HANDSHAKING
11-20 08:31:25.454: W/System.err(1249): Inbound way selected. Done for : READY, START, java.nio.ReadWriteHeapByteBuffer, status: capacity=16384 position=0 limit=16384, FILLING, true
11-20 08:31:25.454: W/System.err(1249): Entering into a connection READY loop
11-20 08:31:25.454: W/System.err(1249): Processing IO for inbound way: READY, START, java.nio.ReadWriteHeapByteBuffer, status: capacity=16384 position=0 limit=16384, FILLING, true
11-20 08:31:25.454: W/System.err(1249): Beginning process of buffer java.nio.ReadWriteHeapByteBuffer, status: capacity=16384 position=0 limit=16384, FILLING, true
11-20 08:31:25.454: W/System.err(1249): 0 bytes drained from buffer at pre-processing, 16384 remaining bytes
11-20 08:31:25.454: W/System.err(1249): Filling buffer java.nio.ReadWriteHeapByteBuffer, status: capacity=16384 position=0 limit=16384, FILLING, true
11-20 08:31:25.454: W/System.err(1249): Beginning process of buffer java.nio.ReadWriteHeapByteBuffer, status: capacity=18437 position=0 limit=18437, FILLING, true
11-20 08:31:25.454: W/System.err(1249): 0 bytes drained from buffer at pre-processing, 18437 remaining bytes
11-20 08:31:25.454: W/System.err(1249): Filling buffer java.nio.ReadWriteHeapByteBuffer, status: capacity=18437 position=0 limit=18437, FILLING, true
11-20 08:31:25.454: W/System.err(1249): Ending process of buffer java.nio.ReadWriteHeapByteBuffer, status: capacity=18437 position=0 limit=18437, FILLING, true. Result: -1, try again: false, can loop: true, total filled: 0
11-20 08:31:25.454: W/System.err(1249): Handling SSL result: OK
11-20 08:31:25.454: W/System.err(1249): Handling SSL handshake: NOT_HANDSHAKING
11-20 08:31:25.454: W/System.err(1249): Closing connection to /127.0.0.1:56385 gracefully
11-20 08:31:25.454: W/System.err(1249): Ending process of buffer java.nio.ReadWriteHeapByteBuffer, status: capacity=16384 position=0 limit=16384, FILLING, true. Result: -1, try again: false, can loop: true, total filled: 0
11-20 08:31:25.454: W/System.err(1249): Handling SSL result: OK
11-20 08:31:25.454: W/System.err(1249): Handling SSL handshake: NOT_HANDSHAKING
11-20 08:31:25.454: W/System.err(1249): Inbound way selected. Done for : READY, START, java.nio.ReadWriteHeapByteBuffer, status: capacity=16384 position=0 limit=16384, FILLING, true
11-20 08:31:25.454: W/System.err(1249): Entering into a connection READY loop
11-20 08:31:25.454: W/System.err(1249): Processing IO for inbound way: READY, START, java.nio.ReadWriteHeapByteBuffer, status: capacity=16384 position=0 limit=16384, FILLING, true
11-20 08:31:25.454: W/System.err(1249): Beginning process of buffer java.nio.ReadWriteHeapByteBuffer, status: capacity=16384 position=0 limit=16384, FILLING, true
11-20 08:31:25.454: W/System.err(1249): 0 bytes drained from buffer at pre-processing, 16384 remaining bytes
11-20 08:31:25.454: W/System.err(1249): Filling buffer java.nio.ReadWriteHeapByteBuffer, status: capacity=16384 position=0 limit=16384, FILLING, true
11-20 08:31:25.454: W/System.err(1249): Beginning process of buffer java.nio.ReadWriteHeapByteBuffer, status: capacity=18437 position=0 limit=18437, FILLING, true
11-20 08:31:25.454: W/System.err(1249): 0 bytes drained from buffer at pre-processing, 18437 remaining bytes
11-20 08:31:25.454: W/System.err(1249): Filling buffer java.nio.ReadWriteHeapByteBuffer, status: capacity=18437 position=0 limit=18437, FILLING, true
11-20 08:31:25.454: W/System.err(1249): Ending process of buffer java.nio.ReadWriteHeapByteBuffer, status: capacity=18437 position=0 limit=18437, FILLING, true. Result: -1, try again: false, can loop: true, total filled: 0

Since I am developing for android I cannot use any other connector supporting SSL. Please let me know how can I work around this issue. Without SSL support my project will be discontinued.

@jlouvel jlouvel modified the milestone: Unplanned issues, 2.1.5 Feb 6, 2014
@jlouvel jlouvel modified the milestone: 2.2.0, Unplanned Feb 7, 2014
@jlouvel
Member
jlouvel commented Feb 7, 2014

@lhanusiak: your problem is different than the original issue (related to the Simple HTTP server extension) . FYI, we have replaced the internal HTTP client connector so using 2.2 RC1 (due tomorrow), you shouldn't have this issue anymore.

@waywaaard: do you still experiment this issue with Simple?

@lhanusiak

I successfully workaround the problem using Java SE Simple Extension. Currently I have working Simple based https server (with client certificate auth) on my android device. In spare time I will gladly try to test new release.

Here is my dependency configuration:

        <dependency>
            <!-- Apache License 2.0 -->
            <groupId>org.restlet.android</groupId>
            <artifactId>org.restlet</artifactId>
            <version>${restlet.version}</version>
        </dependency>

        <dependency>
            <!-- Apache License 2.0 -->
            <groupId>org.restlet.android</groupId>
            <artifactId>org.restlet.ext.ssl</artifactId>
            <version>${restlet.version}</version>
        </dependency>

        <dependency>
            <!-- Apache License 2.0 -->
            <groupId>org.restlet.jse</groupId>
            <artifactId>org.restlet.ext.fileupload</artifactId>
            <version>${restlet.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>commons-fileupload</artifactId>
                    <groupId>commons-fileupload</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>org.restlet</artifactId>
                    <groupId>org.restlet.jse</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <!-- Apache License 2.0 -->
            <groupId>org.restlet.jse</groupId>
            <artifactId>org.restlet.ext.simple</artifactId>
            <version>${restlet.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>org.restlet</artifactId>
                    <groupId>org.restlet.jse</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>org.restlet.ext.ssl</artifactId>
                    <groupId>org.restlet.jse</groupId>
                </exclusion>
            </exclusions>
        </dependency>
@jlouvel jlouvel modified the milestone: 2.2 RC4, 2.2.0 Mar 6, 2014
@jlouvel
Member
jlouvel commented Mar 6, 2014

Moved to 2.2 RC4

@jlouvel
Member
jlouvel commented Mar 17, 2014

Moved to 2.2.0

@jlouvel jlouvel modified the milestone: 2.2.0, 2.2 RC4 Mar 17, 2014
@jlouvel
Member
jlouvel commented Mar 20, 2014

@lhanusiak The original issue you had with the NIO connector (now part of org.restlet.ext.nio.jar) should have been fixed in the recent 2.2 RC4 release.

@waywaaard Our tests suite including Simple HTTPS test does work fine, so we are wondering how to further help. Can you confirm that you still have an issue?

@jlouvel jlouvel modified the milestone: 2.x - Maintenance, 2.2.0 Mar 20, 2014
@jlouvel
Member
jlouvel commented Mar 20, 2014

Moved to 2.x maintenance.

@lhanusiak

I was unable to test against 2.2 RC4 beacouse of missing org.restlet.ext.ssl dependency for android.
When I decided to execute my code against 2.2-SNAPSHOT I received following error

java.lang.NoSuchMethodError: org.restlet.engine.connector.HttpServerHelper.<init>
at org.restlet.ext.ssl.HttpsServerHelper.<init>(HttpsServerHelper.java:93)
at pl.com.mcg.hermes.android.mdm.rest.RestServerService.onCreate(RestServerService.java:49)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2253)
at android.app.ActivityThread.access$1600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)

@jlouvel
Member
jlouvel commented Mar 27, 2014

You should update the pl.com.mcg.hermes.android.mdm.rest.RestServerService.onCreate() method to invoke org.restlet.ext.nio.HttpsServerHelper instead of org.restlet.ext.ssl.HttpsServerHelper and remove the org.restlet.ext.ssl.jar dependency altogether from your project.

This org.restlet.ext.ssl extension no longer exist in 2.2 RC4 (part of org.restlet.ext.jsslutils, org.restlet.ext.nio and org.restlet).

@lhanusiak

After updating my dependencies I was able to test sample application against 2.2 RC4. Unfortunately I have run into similar problem as before, first request returns with valid response all other requests after a while return ERR_EMPTY_RESPONSE instead of valid data.

I posted updated version of sample application that I use for testing purposes (https://db.tt/JJVprIe3).

Any ideas what I might be doing wrong?

@jlouvel jlouvel modified the milestone: 2.2.2, 2.x - Maintenance May 1, 2014
@jlouvel
Member
jlouvel commented May 1, 2014

Set milestone to 2.2.2

@jlouvel jlouvel modified the milestone: Unplanned Nov 2, 2014
@maroofsaeed

Hi,

I am using restlet framework 2.2.2 for android. I have created just simple app and after installing app each time its giving an error saying:

No available server connector supports the required protocols: 'HTTP' . Please add the JAR of a matching connector to your classpath. Then, register this connector helper manually.

Any help plzzzzz

@lhanusiak

In order to use http/https you need to register server beforehand so for for https it goes something like thisEngine.getInstance().getRegisteredServers().add(new HttpsServerHelper(null));
Engine.setLogLevel(Level.FINEST);

And when writing client you also need to register client helper. For more details please review this page http://restlet.com/learn/guide/2.2/editions/android/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment