Search in sources :

Example 1 with Handler

use of libcore.java.net.customstreamhandler.http.Handler in project j2objc by google.

the class URLStreamHandlerFactoryTest method testFirstUseIsCached.

public void testFirstUseIsCached() throws Exception {
    // clear cached protocol handlers if they exist
    factoryField.set(null, null);
    URL.setURLStreamHandlerFactory(oldFactory);
    // creating a connection should use the platform's default stream handler
    URLConnection connection1 = new URL("http://android.com/").openConnection();
    assertFalse(connection1 instanceof Handler.HandlerURLConnection);
    try {
        // set the property and get another connection. The property should not be honored
        System.setProperty("java.protocol.handler.pkgs", getHandlerPackageName());
        URLConnection connection2 = new URL("http://android.com/").openConnection();
        assertFalse(connection2 instanceof Handler.HandlerURLConnection);
    } finally {
        System.clearProperty("java.protocol.handler.pkgs");
    }
}
Also used : URLStreamHandler(java.net.URLStreamHandler) Handler(libcore.java.net.customstreamhandler.http.Handler) URLConnection(java.net.URLConnection) URL(java.net.URL)

Example 2 with Handler

use of libcore.java.net.customstreamhandler.http.Handler in project robovm by robovm.

the class URLStreamHandlerFactoryTest method testFirstUseIsCached.

public void testFirstUseIsCached() throws Exception {
    // clear cached protocol handlers if they exist
    factoryField.set(null, null);
    URL.setURLStreamHandlerFactory(oldFactory);
    // creating a connection should use the platform's default stream handler
    URLConnection connection1 = new URL("http://android.com/").openConnection();
    assertFalse(connection1 instanceof Handler.HandlerURLConnection);
    try {
        // set the property and get another connection. The property should not be honored
        System.setProperty("java.protocol.handler.pkgs", getHandlerPackageName());
        URLConnection connection2 = new URL("http://android.com/").openConnection();
        assertFalse(connection2 instanceof Handler.HandlerURLConnection);
    } finally {
        System.clearProperty("java.protocol.handler.pkgs");
    }
}
Also used : URLStreamHandler(java.net.URLStreamHandler) Handler(libcore.java.net.customstreamhandler.http.Handler) URLConnection(java.net.URLConnection) URL(java.net.URL)

Aggregations

URL (java.net.URL)2 URLConnection (java.net.URLConnection)2 URLStreamHandler (java.net.URLStreamHandler)2 Handler (libcore.java.net.customstreamhandler.http.Handler)2