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();
}
}
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();
}
}
}
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);
}
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));
}
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();
}
Aggregations