use of org.apache.hive.service.rpc.thrift.TOpenSessionReq 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"));
}
}
use of org.apache.hive.service.rpc.thrift.TOpenSessionReq in project hive by apache.
the class TestThriftCLIServiceSecurity method testPasswordNotInLogs.
/**
* Ensures password isn't printed to logs from TOpenSessionReq.toString().
* See maven-replacer-plugin code in service-rpc/pom.xml.
*
* @throws Exception
*/
@Test
public void testPasswordNotInLogs() throws Exception {
String PASSWORD = "testpassword";
TOpenSessionReq tOpenSessionReq = new TOpenSessionReq();
tOpenSessionReq.setPassword(PASSWORD);
assertFalse(tOpenSessionReq.toString().contains(PASSWORD));
}
use of org.apache.hive.service.rpc.thrift.TOpenSessionReq in project hive by apache.
the class TestThriftCliServiceWithInfoMessage method testExecuteReturnWithInfoMessage.
@Test
public void testExecuteReturnWithInfoMessage() throws Exception {
TTransport transport = HiveAuthUtils.getSocketTransport(host, cliPort, 0);
try {
transport.open();
TCLIService.Iface client = new TCLIService.Client(new TBinaryProtocol(transport));
TOpenSessionReq openReq = new TOpenSessionReq();
openReq.setClient_protocol(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V11);
TOpenSessionResp sessionResp = client.OpenSession(openReq);
Map<String, String> serverHiveConf = sessionResp.getConfiguration();
assertNotNull(serverHiveConf);
assertTrue(Boolean.parseBoolean(serverHiveConf.get(ConfVars.HIVE_DEFAULT_NULLS_LAST.varname)));
TSessionHandle sessHandle = sessionResp.getSessionHandle();
TExecuteStatementReq execReq = new TExecuteStatementReq(sessHandle, "select 1");
execReq.setRunAsync(true);
TExecuteStatementResp execResp = client.ExecuteStatement(execReq);
TStatus status = execResp.getStatus();
assertTrue(status.getStatusCode() == TStatusCode.SUCCESS_WITH_INFO_STATUS);
assertNotNull(status.getInfoMessages());
assertTrue(status.getInfoMessages().size() > 0);
Pattern pattern = Pattern.compile("http://.*:(\\d+)/query_page\\.html\\?operationId=(.+)$");
Matcher matcher = pattern.matcher(status.getInfoMessages().get(0));
assertTrue(matcher.find());
assertEquals(webuiPort + "", matcher.group(1));
OperationHandle operationHandle = new OperationHandle(execResp.getOperationHandle());
assertEquals(operationHandle.getHandleIdentifier().toString(), matcher.group(2));
// Cancel the operation
TCancelOperationReq cancelReq = new TCancelOperationReq();
cancelReq.setOperationHandle(execResp.getOperationHandle());
client.CancelOperation(cancelReq);
// Disable showing the link
Map<String, String> overlayConf = new HashMap<>();
overlayConf.put(ConfVars.HIVE_SERVER2_SHOW_OPERATION_DRILLDOWN_LINK.varname, "false");
execReq = new TExecuteStatementReq(sessHandle, "select 1");
execReq.setRunAsync(true);
execReq.setConfOverlay(overlayConf);
execResp = client.ExecuteStatement(execReq);
status = execResp.getStatus();
assertTrue(status.getStatusCode() == TStatusCode.SUCCESS_STATUS);
assertTrue(status.getInfoMessages() == null);
} finally {
transport.close();
}
}
use of org.apache.hive.service.rpc.thrift.TOpenSessionReq in project hive by apache.
the class ThriftCLIServiceClient method openSession.
/* (non-Javadoc)
* @see org.apache.hive.service.cli.ICLIService#openSession(java.lang.String, java.lang.String, java.util.Map)
*/
@Override
public SessionHandle openSession(String username, String password, Map<String, String> configuration) throws HiveSQLException {
try {
TOpenSessionReq req = new TOpenSessionReq();
req.setUsername(username);
req.setPassword(password);
req.setConfiguration(configuration);
TOpenSessionResp resp = cliService.OpenSession(req);
checkStatus(resp.getStatus());
return new SessionHandle(resp.getSessionHandle(), resp.getServerProtocolVersion());
} catch (HiveSQLException e) {
throw e;
} catch (Exception e) {
throw new HiveSQLException(e);
}
}
Aggregations