Search in sources :

Example 1 with THttpClient

use of org.apache.thrift.transport.THttpClient in project hbase by apache.

the class TestThriftHttpServer method talkToThriftServer.

private void talkToThriftServer(int customHeaderSize) throws Exception {
    THttpClient httpClient = new THttpClient("http://" + HConstants.LOCALHOST + ":" + port);
    httpClient.open();
    if (customHeaderSize > 0) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < customHeaderSize; i++) {
            sb.append("a");
        }
        httpClient.setCustomHeader("User-Agent", sb.toString());
    }
    try {
        TProtocol prot;
        prot = new TBinaryProtocol(httpClient);
        Hbase.Client client = new Hbase.Client(prot);
        if (!tableCreated) {
            TestThriftServer.createTestTables(client);
            tableCreated = true;
        }
        TestThriftServer.checkTableList(client);
    } finally {
        httpClient.close();
    }
}
Also used : TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) THttpClient(org.apache.thrift.transport.THttpClient) THttpClient(org.apache.thrift.transport.THttpClient) Hbase(org.apache.hadoop.hbase.thrift.generated.Hbase)

Example 2 with THttpClient

use of org.apache.thrift.transport.THttpClient in project simba-os by cegeka.

the class SimbaFilter method doFilter.

private void doFilter(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws ServletException, IOException {
    if (isUrlExcluded(request)) {
        chain.doFilter(request, response);
        return;
    }
    RequestData requestData = RequestUtil.createRequestData(request, simbaWebURL, simbeEidSuccessUrl);
    FilterActionFactory actionFactory = new FilterActionFactory(request, response, chain);
    THttpClient tHttpClient = null;
    try {
        tHttpClient = new THttpClient(SimbaConfiguration.getSimbaAuthenticationURL());
        TProtocol tProtocol = new TJSONProtocol(tHttpClient);
        AuthenticationFilterService.Client authenticationClient = new AuthenticationFilterService.Client(tProtocol);
        ActionDescriptor actionDescriptor = authenticationClient.processRequest(requestData, authenticationChainName);
        actionFactory.execute(actionDescriptor);
    } catch (Exception e) {
        throw new ServletException(e);
    } finally {
        if (tHttpClient != null) {
            tHttpClient.close();
        }
    }
}
Also used : FilterActionFactory(org.simbasecurity.client.filter.action.FilterActionFactory) TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) AuthenticationFilterService(org.simbasecurity.api.service.thrift.AuthenticationFilterService) TProtocol(org.apache.thrift.protocol.TProtocol) RequestData(org.simbasecurity.api.service.thrift.RequestData) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) THttpClient(org.apache.thrift.transport.THttpClient) THttpClient(org.apache.thrift.transport.THttpClient) IOException(java.io.IOException)

Example 3 with THttpClient

use of org.apache.thrift.transport.THttpClient in project simba-os by cegeka.

the class BaseRESTService method cl.

T cl() throws TException {
    THttpClient tHttpClient = new THttpClient(serviceURL);
    TProtocol tProtocol = new TJSONProtocol(tHttpClient);
    return clientFactory.getClient(tProtocol);
}
Also used : TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) THttpClient(org.apache.thrift.transport.THttpClient)

Example 4 with THttpClient

use of org.apache.thrift.transport.THttpClient in project simba-os by cegeka.

the class SimbaGatewayTest method createAuthenticationService_WhenTHttpClientIsNotOpen_ReturnsClientByEstablishingANewConnection.

@Test
public void createAuthenticationService_WhenTHttpClientIsNotOpen_ReturnsClientByEstablishingANewConnection() throws Exception {
    Client originalClient = mock(Client.class);
    THttpClient tHttpClientMock = mock(THttpClient.class);
    Whitebox.setInternalState(simbaGateway, "tHttpClient", tHttpClientMock);
    Whitebox.setInternalState(simbaGateway, "authenticationFilterService", originalClient);
    THttpClient newlyCreatedTHttpClient = new THttpClient(SIMBA_WEB_URL);
    when(simbaServiceFactoryMock.createTHttpClient(SIMBA_WEB_URL + "/" + SIMBA_AUTHENTICATION_SERVICE)).thenReturn(newlyCreatedTHttpClient);
    Client expectedClient = new Client(null);
    when(simbaServiceFactoryMock.createJSONAuthenticationFilterService(newlyCreatedTHttpClient)).thenReturn(expectedClient);
    when(tHttpClientMock.isOpen()).thenReturn(false);
    Client actual = simbaGateway.createAuthenticationService();
    assertThat(actual).isEqualTo(expectedClient);
    verify(simbaServiceFactoryMock, times(1)).createTHttpClient(SIMBA_WEB_URL + "/" + SIMBA_AUTHENTICATION_SERVICE);
    verify(simbaServiceFactoryMock, times(1)).createJSONAuthenticationFilterService(any(THttpClient.class));
}
Also used : THttpClient(org.apache.thrift.transport.THttpClient) Client(org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client) THttpClient(org.apache.thrift.transport.THttpClient) Test(org.junit.Test)

Example 5 with THttpClient

use of org.apache.thrift.transport.THttpClient in project simba-os by cegeka.

the class SimbaGatewayTest method authenticate_THttpClientEvenGetsClosedAfterAnExceptionOccurred.

@Test
public void authenticate_THttpClientEvenGetsClosedAfterAnExceptionOccurred() throws Exception {
    Client expectedClient = mock(Client.class);
    THttpClient tHttpClientMock = mock(THttpClient.class);
    when(simbaServiceFactoryMock.createTHttpClient(SIMBA_WEB_URL + SIMBA_AUTHENTICATION_SERVICE)).thenReturn(tHttpClientMock);
    when(simbaServiceFactoryMock.createJSONAuthenticationFilterService(tHttpClientMock)).thenReturn(expectedClient);
    Client authenticationServiceMock = expectedClient;
    when(authenticationServiceMock.processRequest(any(RequestData.class), any(String.class))).thenThrow(new TException());
    expectedException.expect(SimbaUnavailableException.class);
    simbaGateway.authenticate(new SimbaCredentialsBuilderForTests().build());
    verify(tHttpClientMock, times(1)).close();
}
Also used : TException(org.apache.thrift.TException) RequestData(org.simbasecurity.api.service.thrift.RequestData) SimbaCredentialsBuilderForTests(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests) THttpClient(org.apache.thrift.transport.THttpClient) Client(org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client) THttpClient(org.apache.thrift.transport.THttpClient) Test(org.junit.Test)

Aggregations

THttpClient (org.apache.thrift.transport.THttpClient)51 TProtocol (org.apache.thrift.protocol.TProtocol)34 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)18 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)12 TJSONProtocol (org.apache.thrift.protocol.TJSONProtocol)9 Test (org.junit.Test)9 TTransport (org.apache.thrift.transport.TTransport)8 Hbase (org.apache.hadoop.hbase.thrift.generated.Hbase)5 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)5 RequestData (org.simbasecurity.api.service.thrift.RequestData)5 ApacheHttpTransport (com.google.api.client.http.apache.ApacheHttpTransport)4 IOException (java.io.IOException)4 PServiceCall (net.morimekta.providence.PServiceCall)4 TestService (net.morimekta.test.providence.service.TestService)4 Client (org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client)4 HashMap (java.util.HashMap)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 TCLIService (org.apache.hive.service.rpc.thrift.TCLIService)3 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)3 ActionDescriptor (org.simbasecurity.api.service.thrift.ActionDescriptor)3