public void run() throws Exception { File socketFile = new File("/tmp/ClientAndServer.sock"); socketFile.delete(); // Clean up from previous runs. MockWebServer server = new MockWebServer(); server.setServerSocketFactory(new UnixDomainServerSocketFactory(socketFile)); server.setProtocols(Collections.singletonList(Protocol.H2_PRIOR_KNOWLEDGE)); server.enqueue(new MockResponse().setBody("hello")); server.start(); OkHttpClient client = new OkHttpClient.Builder() .socketFactory(new UnixDomainSocketFactory(socketFile)) .protocols(Collections.singletonList(Protocol.H2_PRIOR_KNOWLEDGE)) .build(); Request request = new Request.Builder() .url("http://publicobject.com/helloworld.txt") .build(); try (Response response = client.newCall(request).execute()) { System.out.println(response.body().string()); } server.shutdown(); socketFile.delete(); }
public void connect(OkHttpClient client) { client = client.newBuilder() .eventListener(EventListener.NONE) .protocols(ONLY_HTTP1) .build(); final Request request = originalRequest.newBuilder()
public void connect(OkHttpClient client) { client = client.newBuilder() .eventListener(EventListener.NONE) .protocols(ONLY_HTTP1) .build(); final Request request = originalRequest.newBuilder()
.protocols(Arrays.asList(Protocol.HTTP_1_1)) .readTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS) .writeTimeout(HttpConstants.DEFAULT_DATA_TIMEOUT, TimeUnit.MILLISECONDS)
public void connect(OkHttpClient client) { client = client.newBuilder() .eventListener(EventListener.NONE) .protocols(ONLY_HTTP1) .build(); final int pingIntervalMillis = client.pingIntervalMillis();
public void connect(OkHttpClient client) { client = client.newBuilder() .eventListener(EventListener.NONE) .protocols(ONLY_HTTP1) .build(); final Request request = originalRequest.newBuilder()
static NamespacedKubernetesClient getKubernetesClient(Config rootConfig, String id, Container gke, KubernetesClientFactory clientFactory) { try { final Config config = rootConfig .getConfig(GKE_CLUSTER_PATH) .getConfig(id); final Cluster cluster = gke.projects().locations().clusters() .get(String.format("projects/%s/locations/%s/clusters/%s", config.getString(GKE_CLUSTER_PROJECT_ID), config.getString(GKE_CLUSTER_ZONE), config.getString(GKE_CLUSTER_ID))).execute(); final io.fabric8.kubernetes.client.Config kubeConfig = new ConfigBuilder() .withMasterUrl("https://" + cluster.getEndpoint()) .withCaCertData(cluster.getMasterAuth().getClusterCaCertificate()) .withClientCertData(cluster.getMasterAuth().getClientCertificate()) .withClientKeyData(cluster.getMasterAuth().getClientKey()) .withNamespace(config.getString(GKE_CLUSTER_NAMESPACE)) .withRequestTimeout(get(rootConfig, rootConfig::getInt, KUBERNETES_REQUEST_TIMEOUT) .orElse(DEFAULT_KUBERNETES_REQUEST_TIMEOUT_MILLIS)) .build(); final OkHttpClient httpClient = HttpClientUtils.createHttpClient(kubeConfig).newBuilder() .protocols(Collections.singletonList(Protocol.HTTP_1_1)) .build(); return clientFactory.apply(httpClient, kubeConfig); } catch (IOException e) { throw Throwables.propagate(e); } }
private void setupClient(int count, boolean h2) throws Exception { clients = IntStream.range(0, count) .mapToObj( index -> { try { if (h2) { return OkHttpUnsafe.getUnsafeClient() .newBuilder() .protocols(Arrays.asList(HTTP_2, HTTP_1_1)) .build(); } else { return OkHttpUnsafe.getUnsafeClient() .newBuilder() .protocols(Collections.singletonList(HTTP_1_1)) .build(); } } catch (Exception e) { return null; } }) .collect(Collectors.toList()); }
public static OkHttpClient getUnsafeClient(Protocol... protocols) throws Exception { X509TrustManager trustManager = unsafeTrustManager(); final SSLSocketFactory sslSocketFactory = getUnsafeSSLSocketFactory(null, trustManager); final List<Protocol> protocolList; if (protocols.length == 0) { protocolList = Collections.singletonList(Protocol.HTTP_1_1); } else { protocolList = Arrays.asList(protocols); } return new OkHttpClient.Builder() .sslSocketFactory(sslSocketFactory, trustManager) .hostnameVerifier( new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } }) .protocols(protocolList) .build(); }
/** * Make a synchronous http request. * * @param address the request address. * @param protocols the protocol(s) to support. * @return a response. */ public static Response http(InetSocketAddress address, Protocol... protocols) { final List<Protocol> protocolList; if (protocols.length == 0) { protocolList = Collections.singletonList(Protocol.HTTP_1_1); } else { protocolList = Arrays.asList(protocols); } String url = buildUrl("http://", address); return request(url, new OkHttpClient.Builder().protocols(protocolList).build()); }
WebSocketCall(OkHttpClient client, Request request, Random random) { if (!"GET".equals(request.method())) { throw new IllegalArgumentException("Request must be GET: " + request.method()); } this.random = random; byte[] nonce = new byte[16]; random.nextBytes(nonce); key = ByteString.of(nonce).base64(); client = client.newBuilder() .protocols(Collections.singletonList(Protocol.HTTP_1_1)) .build(); request = request.newBuilder() .header("Upgrade", "websocket") .header("Connection", "Upgrade") .header("Sec-WebSocket-Key", key) .header("Sec-WebSocket-Version", "13") .build(); call = client.newCall(request); }
@Before public void setUp() throws Exception { log.debug("Test: " + testName.getMethodName()); client = OkHttpUnsafe.getUnsafeClient() .newBuilder() .protocols(Arrays.asList(Protocol.HTTP_2, Protocol.HTTP_1_1)) .build(); TlsConfig tlsConfig = TlsConfig.builderFrom(ConfigFactory.load().getConfig("xio.h2BackendServer.settings.tls")) .build(); server = OkHttpUnsafe.getSslMockWebServer(getKeyManagers(tlsConfig)); server.setProtocols(Arrays.asList(Protocol.HTTP_2, Protocol.HTTP_1_1)); server.start(); }
public FastHttpClientBuilder protocols(List<Protocol> protocols) { builder.protocols(protocols); return this; }