@Override public URLStreamHandler createURLStreamHandler(final String protocol) {
    if (!protocol.equals("http") && !protocol.equals("https")) return null;

    return new URLStreamHandler() {
      @Override protected URLConnection openConnection(URL url) {
        return open(url);
      }

      @Override protected URLConnection openConnection(URL url, Proxy proxy) {
        return open(url, proxy);
      }

      @Override protected int getDefaultPort() {
        if (protocol.equals("http")) return 80;
        if (protocol.equals("https")) return 443;
        throw new AssertionError();
      }
    };
  }
Creates a URLStreamHandler as a {@link java.net.URL#setURLStreamHandlerFactory}.

<p>This code configures OkHttp to handle all HTTP and HTTPS connections
created with {@link java.net.URL#openConnection()}: <pre>   {@code

  OkHttpClient okHttpClient = new OkHttpClient();
  URL.setURLStreamHandlerFactory(new OkUrlFactory(okHttpClient));
}</pre>
gateway/platforms/servlet/src/main/java/io/apiman/gateway/platforms/servlet/connectors/ok/OkUrlFactory.java