jetty服务器,okhttp客户端和SPDY

时间:2015-03-10 16:53:52

标签: java jetty okhttp jetty-9

我试图通过SPDY协议使用okhttp客户端从我的码头测试服务器下载文件。 首先,我启动了支持spdy的服务器,看起来没问题。

2015-03-10 12:37:36.623:INFO::main: Logging initialized @112ms
2015-03-10 12:37:37.074:INFO:oejs.Server:main: jetty-9.2.9.v20150224
2015-03-10 12:37:37.101:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:/home/ialan/jetty/jetty9/mybase/webapps/] at interval 1
2015-03-10 12:37:37.806:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@2e88aace{/,file:/home/ialan/jetty/jetty9/mybase/webapps/ROOT/,AVAILABLE}{/ROOT}
2015-03-10 12:37:37.842:INFO:oejs.ServerConnector:main: Started ServerConnector@5d79653{HTTP/1.1}{0.0.0.0:8080}
2015-03-10 12:37:38.022:INFO:oejs.ServerConnector:main: Started ServerConnector@5f6cf858{SSL-alpn}{0.0.0.0:443}
2015-03-10 12:37:38.023:INFO:oejs.Server:main: Started @1517ms

然后我正在运行我的okhttp客户端,如下所示,但我无法建立SPDY连接它总是转发我http 1.1但是当我尝试连接google.com时我可以得到spdy3.1。可能是什么问题?

import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import java.io.IOException;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;

public class GetExample {
    OkHttpClient client = new OkHttpClient();
    String run(String url) throws IOException {

        client.setHostnameVerifier(new HostnameVerifier() {
            public boolean verify1(String hostname, SSLSession session) {
                //TODO: Make this more restrictive
                return true;
            }
            @Override
            public boolean verify(String hostname, SSLSession session) {
                // TODO Auto-generated method stub
                return true;
            }
        });
        Request request = new Request.Builder()
        .url(url)
        .build();
        Response response = client.newCall(request).execute();
        System.out.println(response.protocol());
        return response.body().string();
    }

    public static void main(String[] args) throws IOException {
        GetOrginal example = new GetOrginal();
        String response = example.run("https://localhost/");
    //  String response = example.run("https://google.com");
        System.out.println(response.length());
    }
}

0 个答案:

没有答案