Search in sources :

Example 6 with RestEchoClient

use of com.linkedin.r2.sample.echo.rest.RestEchoClient in project rest.li by linkedin.

the class TestHttpsEcho method testHttpEcho.

/**
 * Test that https-enabled server and client can speak plain HTTP as well.
 */
@Test
public void testHttpEcho() throws Exception {
    final EchoService client = new RestEchoClient(Bootstrap.createURI(SslContextUtil.getHttpPortFromHttps(_port), Bootstrap.getEchoURI(), false), createClient());
    final String msg = "This is a simple http echo message";
    final FutureCallback<String> callback = new FutureCallback<>();
    client.echo(msg, callback);
    Assert.assertEquals(callback.get(), msg);
}
Also used : EchoService(com.linkedin.r2.sample.echo.EchoService) RestEchoClient(com.linkedin.r2.sample.echo.rest.RestEchoClient) FutureCallback(com.linkedin.common.callback.FutureCallback) AbstractEchoServiceTest(test.r2.integ.clientserver.providers.AbstractEchoServiceTest) Test(org.testng.annotations.Test)

Example 7 with RestEchoClient

use of com.linkedin.r2.sample.echo.rest.RestEchoClient in project rest.li by linkedin.

the class TestAlpnUpgradePromise method testAlpnFailure.

public void testAlpnFailure() throws Exception {
    final EchoService client = new RestEchoClient(Bootstrap.createURI(_port, Bootstrap.getEchoURI(), _serverProvider.isSsl()), _client);
    final String msg = "This is a simple http echo message";
    final FutureCallback<String> callback = new FutureCallback<>();
    try {
        client.echo(msg, callback);
        Assert.assertEquals(callback.get(), msg);
        Assert.fail("Should not have reached here !");
    } catch (Exception ex) {
        Throwable throwable = ExceptionUtils.getRootCause(ex);
        Assert.assertTrue(throwable instanceof IllegalStateException);
        Assert.assertEquals(throwable.getMessage(), "Unsupported protocol 'http/1.1' is negotiated.");
    }
}
Also used : EchoService(com.linkedin.r2.sample.echo.EchoService) RestEchoClient(com.linkedin.r2.sample.echo.rest.RestEchoClient) FutureCallback(com.linkedin.common.callback.FutureCallback)

Example 8 with RestEchoClient

use of com.linkedin.r2.sample.echo.rest.RestEchoClient in project rest.li by linkedin.

the class TestAlpnUpgradePromise method testClientMessageEcho.

public void testClientMessageEcho() throws Exception {
    final EchoService client = new RestEchoClient(Bootstrap.createURI(_port, Bootstrap.getEchoURI(), _serverProvider.isSsl()), _client);
    final String msg = "This is a simple http echo message";
    final FutureCallback<String> callback = new FutureCallback<>();
    client.echo(msg, callback);
    Assert.assertEquals(callback.get(), msg);
}
Also used : EchoService(com.linkedin.r2.sample.echo.EchoService) RestEchoClient(com.linkedin.r2.sample.echo.rest.RestEchoClient) FutureCallback(com.linkedin.common.callback.FutureCallback)

Example 9 with RestEchoClient

use of com.linkedin.r2.sample.echo.rest.RestEchoClient in project rest.li by linkedin.

the class TestHttpsCheckCertificate method testHttpsEchoWithSessionValidator.

private void testHttpsEchoWithSessionValidator(SslSessionValidator sslSessionValidator) throws Exception {
    final RestEchoClient client = getEchoClient(_client, Bootstrap.getEchoURI());
    final String msg = "This is a simple echo message";
    final FutureCallback<String> callback = new FutureCallback<>();
    RequestContext requestContext = new RequestContext();
    requestContext.putLocalAttr(R2Constants.REQUESTED_SSL_SESSION_VALIDATOR, sslSessionValidator);
    client.echo(msg, requestContext, callback);
    String actual = callback.get(20, TimeUnit.SECONDS);
    Assert.assertEquals(actual, msg);
}
Also used : RestEchoClient(com.linkedin.r2.sample.echo.rest.RestEchoClient) RequestContext(com.linkedin.r2.message.RequestContext) FutureCallback(com.linkedin.common.callback.FutureCallback)

Aggregations

FutureCallback (com.linkedin.common.callback.FutureCallback)9 RestEchoClient (com.linkedin.r2.sample.echo.rest.RestEchoClient)9 EchoService (com.linkedin.r2.sample.echo.EchoService)8 Test (org.testng.annotations.Test)5 AbstractEchoServiceTest (test.r2.integ.clientserver.providers.AbstractEchoServiceTest)3 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)2 RequestContext (com.linkedin.r2.message.RequestContext)2 RestException (com.linkedin.r2.message.rest.RestException)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimingContext (com.linkedin.r2.message.timing.TimingContextUtil.TimingContext)1 TimingKey (com.linkedin.r2.message.timing.TimingKey)1 Map (java.util.Map)1