Example usage for com.squareup.okhttp Protocol HTTP_2

List of usage examples for com.squareup.okhttp Protocol HTTP_2

Introduction

In this page you can find the example usage for com.squareup.okhttp Protocol HTTP_2.

Prototype

Protocol HTTP_2

To view the source code for com.squareup.okhttp Protocol HTTP_2.

Click Source Link

Document

The IETF's binary-framed protocol that includes header compression, multiplexing multiple requests on the same socket, and server-push.

Usage

From source file:co.paralleluniverse.fibers.okhttp.CallTest.java

License:Open Source License

@Test
public void patch_HTTP_2() throws Exception {
    enableProtocol(Protocol.HTTP_2);
    patch();
}

From source file:co.paralleluniverse.fibers.okhttp.CallTest.java

License:Open Source License

@Test
public void cancelInFlightBeforeResponseReadThrowsIOE_HTTP_2() throws Exception {
    enableProtocol(Protocol.HTTP_2);
    cancelInFlightBeforeResponseReadThrowsIOE();
}

From source file:co.paralleluniverse.fibers.okhttp.CallTest.java

License:Open Source License

@Test
public void canceledBeforeIOSignalsOnFailure_HTTP_2() throws Exception {
    enableProtocol(Protocol.HTTP_2);
    canceledBeforeIOSignalsOnFailure();
}

From source file:co.paralleluniverse.fibers.okhttp.CallTest.java

License:Open Source License

@Test
public void canceledBeforeResponseReadSignalsOnFailure_HTTP_2() throws Exception {
    enableProtocol(Protocol.HTTP_2);
    canceledBeforeResponseReadSignalsOnFailure();
}

From source file:co.paralleluniverse.fibers.okhttp.CallTest.java

License:Open Source License

@Test
public void canceledAfterResponseIsDeliveredBreaksStreamButSignalsOnce_HTTP_2() throws Exception {
    enableProtocol(Protocol.HTTP_2);
    canceledAfterResponseIsDeliveredBreaksStreamButSignalsOnce();
}

From source file:com.lobobrowser.LoboBrowser.java

License:Open Source License

/**
 * Initializes the global URLStreamHandlerFactory.
 * <p>/*from  w ww. j av a 2s . co  m*/
 * This method is invoked by {@link #init(boolean, boolean)}.
 */
public static void initProtocols(final SSLSocketFactory sslSocketFactory) {
    // Configure URL protocol handlers
    final PlatformStreamHandlerFactory factory = PlatformStreamHandlerFactory.getInstance();
    URL.setURLStreamHandlerFactory(factory);
    final OkHttpClient okHttpClient = new OkHttpClient();

    final ArrayList<Protocol> protocolList = new ArrayList<>(2);
    protocolList.add(Protocol.HTTP_1_1);
    protocolList.add(Protocol.HTTP_2);
    okHttpClient.setProtocols(protocolList);

    okHttpClient.setConnectTimeout(100, TimeUnit.SECONDS);

    // HttpsURLConnection.setDefaultSSLSocketFactory(sslSocketFactory);
    okHttpClient.setSslSocketFactory(sslSocketFactory);
    okHttpClient.setFollowRedirects(false);
    okHttpClient.setFollowSslRedirects(false);
    factory.addFactory(new OkUrlFactory(okHttpClient));
    factory.addFactory(new LocalStreamHandlerFactory());
}

From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.framework.filters.EchoFilter.java

License:Open Source License

@Override
public ListenableFuture<ServiceFilterResponse> handleRequest(ServiceFilterRequest request,
        NextServiceFilterCallback nextServiceFilterCallback) {
    ServiceFilterResponseMock response = new ServiceFilterResponseMock();
    response.setContent(request.getRawContent());
    response.setStatus(new StatusLine(Protocol.HTTP_2, 200, ""));

    ServiceFilterRequestMock requestMock = new ServiceFilterRequestMock(response);
    return nextServiceFilterCallback.onNext(requestMock);

    //return nextServiceFilterCallback.onNext(request);
}

From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.framework.filters.HttpMetaEchoFilter.java

License:Open Source License

@Override
public ListenableFuture<ServiceFilterResponse> handleRequest(ServiceFilterRequest request,
        NextServiceFilterCallback nextServiceFilterCallback) {

    JsonObject jResponse = new JsonObject();

    jResponse.addProperty("method", request.getMethod());

    Headers headers = request.getHeaders();
    if (headers != null && headers.size() > 0) {
        JsonObject jHeaders = new JsonObject();

        for (int i = 0; i < headers.size(); i++) {
            jHeaders.addProperty(headers.name(i), headers.value(i));
        }/*from  w w w. j a v a 2s.  co  m*/

        jResponse.add("headers", jHeaders);
    }

    Uri uri = Uri.parse(request.getUrl());
    String query = uri.getQuery();

    if (query != null && query.trim() != "") {
        JsonObject jParameters = new JsonObject();

        for (String parameter : query.split("&")) {
            jParameters.addProperty(parameter.split("=")[0], parameter.split("=")[1]);
        }
        jResponse.add("parameters", jParameters);
    }

    ServiceFilterResponseMock response = new ServiceFilterResponseMock();
    response.setContent(jResponse.toString());
    response.setStatus(new StatusLine(Protocol.HTTP_2, 200, ""));

    ServiceFilterRequestMock requestMock = new ServiceFilterRequestMock(response);
    return nextServiceFilterCallback.onNext(requestMock);

    //return nextServiceFilterCallback.onNext(request);
}

From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.framework.filters.NullResponseContentFilter.java

License:Open Source License

@Override
public ListenableFuture<ServiceFilterResponse> handleRequest(ServiceFilterRequest request,
        NextServiceFilterCallback nextServiceFilterCallback) {
    ServiceFilterResponseMock response = new ServiceFilterResponseMock();

    response.setContent((String) null);
    response.setStatus(new StatusLine(Protocol.HTTP_2, 200, ""));

    ServiceFilterRequestMock requestMock = new ServiceFilterRequestMock(response);
    return nextServiceFilterCallback.onNext(requestMock);
}

From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.CustomApiClientTests.java

License:Open Source License

public void testResponseWithNon2xxStatusShouldThrowException() throws Throwable {

    final ResultsContainer container = new ResultsContainer();

    MobileServiceClient client = null;// w w  w .j  av  a 2s . c  o  m

    try {
        client = new MobileServiceClient(appUrl, getInstrumentation().getTargetContext());

        client = client.withFilter(new ServiceFilter() {

            @Override
            public ListenableFuture<ServiceFilterResponse> handleRequest(ServiceFilterRequest request,
                    NextServiceFilterCallback nextServiceFilterCallback) {

                ServiceFilterResponseMock mockResponse = new ServiceFilterResponseMock();
                mockResponse.setStatus(new StatusLine(Protocol.HTTP_2, 418, "")); // I'm a
                // teapot
                // status
                // code
                ServiceFilterRequestMock mockRequest = new ServiceFilterRequestMock(mockResponse);

                return nextServiceFilterCallback.onNext(mockRequest);
            }
        });

        List<Pair<String, String>> mockHeaders = new ArrayList<Pair<String, String>>();
        List<Pair<String, String>> mockParameters = new ArrayList<Pair<String, String>>();

        client.invokeApi("myApi", new byte[] { 1, 2, 3, 4 }, HttpConstants.PostMethod, mockHeaders,
                mockParameters).get();

    } catch (Exception exception) {
        if (exception instanceof ExecutionException) {
            container.setException((Exception) exception.getCause());
        } else {
            container.setException(exception);
        }
    }

    // Asserts
    Exception exception = container.getException();
    if (!(exception instanceof MobileServiceException)) {
        fail("Expected Exception MobileServiceException");
    }
}