use of org.apache.thrift.transport.THttpClient in project hbase by apache.
the class TestThrift2HttpServer method talkToThriftServer.
@Override
protected void talkToThriftServer(String url, int customHeaderSize) throws Exception {
THttpClient httpClient = new THttpClient(url);
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);
THBaseService.Client client = new THBaseService.Client(prot);
TTableName tTableName = new TTableName();
tTableName.setNs(Bytes.toBytes(""));
tTableName.setQualifier(Bytes.toBytes(TABLENAME));
if (!tableCreated) {
Assert.assertTrue(!client.tableExists(tTableName));
TTableDescriptor tTableDescriptor = new TTableDescriptor();
tTableDescriptor.setTableName(tTableName);
TColumnFamilyDescriptor columnFamilyDescriptor = new TColumnFamilyDescriptor();
columnFamilyDescriptor.setName(Bytes.toBytes(TABLENAME));
tTableDescriptor.addToColumns(columnFamilyDescriptor);
client.createTable(tTableDescriptor, new ArrayList<>());
tableCreated = true;
}
Assert.assertTrue(client.tableExists(tTableName));
} finally {
httpClient.close();
}
}
use of org.apache.thrift.transport.THttpClient in project hive by apache.
the class TestHs2ConnectionMetricsHttp method getHttpClient.
private TCLIService.Client getHttpClient() throws Exception {
DefaultHttpClient httpClient = new DefaultHttpClient();
Map<String, String> headers = new HashMap<>();
headers.put("Connection", "close");
httpClient.addRequestInterceptor(new BasicHttpRequestInterceptor(USERNAME, PASSWORD, null, null, false, headers));
TTransport transport = new THttpClient(getHttpUrl(), httpClient);
TProtocol protocol = new TBinaryProtocol(transport);
return new TCLIService.Client(protocol);
}
use of org.apache.thrift.transport.THttpClient in project hive by apache.
the class TestHttpCookieAuthenticationTest method getCookieStoreFromConnection.
// ((InternalHttpClient) ((THttpClient) ((HiveConnection) connection).transport).client).cookieStore.getCookies()
private CookieStore getCookieStoreFromConnection(Connection connection) throws Exception {
CookieStore cookieStore = null;
if (connection instanceof HiveConnection) {
HiveConnection hiveConnection = (HiveConnection) connection;
Field transportField = hiveConnection.getClass().getDeclaredField("transport");
transportField.setAccessible(true);
TTransport transport = (TTransport) transportField.get(hiveConnection);
if (transport instanceof THttpClient) {
THttpClient httpTransport = (THttpClient) transport;
Field clientField = httpTransport.getClass().getDeclaredField("client");
clientField.setAccessible(true);
HttpClient httpClient = (HttpClient) clientField.get(httpTransport);
Field cookieStoreField = httpClient.getClass().getDeclaredField("cookieStore");
cookieStoreField.setAccessible(true);
cookieStore = (CookieStore) cookieStoreField.get(httpClient);
}
}
return cookieStore;
}
use of org.apache.thrift.transport.THttpClient in project hive by apache.
the class TestThriftHttpCLIServiceFeatures method testCustomCookies.
/**
* Test additional http headers passed to request interceptor.
* @throws Exception
*/
@Test
public void testCustomCookies() throws Exception {
TTransport transport;
DefaultHttpClient hClient = new DefaultHttpClient();
String httpUrl = getHttpUrl();
Map<String, String> additionalHeaders = new HashMap<String, String>();
Map<String, String> cookieHeaders = new HashMap<String, String>();
cookieHeaders.put("key1", "value1");
cookieHeaders.put("key2", "value2");
HttpBasicAuthInterceptorWithLogging authInt = new HttpBasicAuthInterceptorWithLogging(ThriftCLIServiceTest.USERNAME, ThriftCLIServiceTest.PASSWORD, null, null, false, additionalHeaders, cookieHeaders);
hClient.addRequestInterceptor(authInt);
transport = new THttpClient(httpUrl, hClient);
TCLIService.Client httpClient = getClient(transport);
// Create a new open session request object
TOpenSessionReq openReq = new TOpenSessionReq();
httpClient.OpenSession(openReq).getSessionHandle();
String cookieHeader = authInt.getCookieHeader();
assertTrue(cookieHeader.contains("key1=value1"));
assertTrue(cookieHeader.contains("key2=value2"));
}
use of org.apache.thrift.transport.THttpClient in project hive by apache.
the class TestThriftHttpCLIServiceFeatures method testAdditionalHttpHeaders.
/**
* Test additional http headers passed to request interceptor.
* @throws Exception
*/
@Test
public void testAdditionalHttpHeaders() throws Exception {
TTransport transport;
DefaultHttpClient hClient = new DefaultHttpClient();
String httpUrl = getHttpUrl();
Map<String, String> additionalHeaders = new HashMap<String, String>();
additionalHeaders.put("key1", "value1");
additionalHeaders.put("key2", "value2");
HttpBasicAuthInterceptorWithLogging authInt = new HttpBasicAuthInterceptorWithLogging(ThriftCLIServiceTest.USERNAME, ThriftCLIServiceTest.PASSWORD, null, null, false, additionalHeaders, null);
hClient.addRequestInterceptor(authInt);
transport = new THttpClient(httpUrl, hClient);
TCLIService.Client httpClient = getClient(transport);
// Create a new open session request object
TOpenSessionReq openReq = new TOpenSessionReq();
httpClient.OpenSession(openReq).getSessionHandle();
ArrayList<String> headers = authInt.getRequestHeaders();
for (String h : headers) {
assertTrue(h.contains("key1:value1"));
assertTrue(h.contains("key2:value2"));
}
}
Aggregations