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); Hbase.Client client = new Hbase.Client(prot); if (!tableCreated){ TestThriftServer.createTestTables(client); tableCreated = true; } TestThriftServer.checkTableList(client); } finally { httpClient.close(); } }
@Override public Pair<THBaseService.Client, TTransport> getClient() throws IOException { Preconditions.checkArgument(connection.getHost().startsWith("http"), "http client host must start with http or https"); String url = connection.getHost() + ":" + connection.getPort(); try { THttpClient httpClient = new THttpClient(url, connection.getHttpClient()); for (Map.Entry<String, String> header : customHeader.entrySet()) { httpClient.setCustomHeader(header.getKey(), header.getValue()); } httpClient.open(); TProtocol prot = new TBinaryProtocol(httpClient); THBaseService.Client client = new THBaseService.Client(prot); return new Pair<>(client, httpClient); } catch (TTransportException e) { throw new IOException(e); } } }
THttpClient httpClient = new THttpClient(url); httpClient.open(); TProtocol protocol = new TBinaryProtocol(httpClient); Hbase.Client client = new Hbase.Client(protocol); httpClient.close();
private TTransport createHttpTransport() throws SQLException, TTransportException { CloseableHttpClient httpClient; boolean useSsl = isSslConnection(); // Create an http client from the configs httpClient = getHttpClient(useSsl); transport = new THttpClient(getServerHttpUrl(useSsl), httpClient); return transport; }
public AuthQrcode loginWithQrCode() throws Exception { // Request QrCode from LINE server. // Map<String, String> json = null; boolean keepLoggedIn = false; THttpClient transport = new THttpClient(LINE_HTTP_URL, httpClient); transport.open(); TProtocol protocol = new TCompactProtocol(transport); this.client = new TalkService.Client(protocol); AuthQrcode result = this.client.getAuthQrcode(keepLoggedIn, systemName); setAuthToken(result.getVerifier()); System.out.println("Retrieved QR Code."); return result; // await for QR code to be certified, it will return a verifier afterward. // loginWithVerifier(); }
@Override protected TTransport newTransport(String uri, HttpHeaders headers) throws TTransportException { final SSLContext sslContext; try { sslContext = SSLContextBuilder.create() .loadTrustMaterial((TrustStrategy) (chain, authType) -> true) .build(); } catch (GeneralSecurityException e) { throw new TTransportException("failed to initialize an SSL context", e); } final THttpClient client = new THttpClient( uri, HttpClientBuilder.create() .setSSLHostnameVerifier((hostname, session) -> true) .setSSLContext(sslContext) .build()); client.setCustomHeaders( headers.names().stream() .collect(toImmutableMap(AsciiString::toString, name -> String.join(", ", headers.getAll(name))))); return client; }
public String getSessionId(String userName, String password) throws AuthenticationException { String sessionId = null; try { TProtocol protocol = new TCompactProtocol(client); AuthenticatorService.Client authClient = new AuthenticatorService.Client(protocol); client.open(); sessionId = authClient.authenticate(userName, password); client.close(); } catch (TTransportException e) { throw new AuthenticationException("Error in authenticating with thrift client..", e); } catch (TException e) { throw new AuthenticationException("Error in authenticating with thrift client..", e); } catch (AuthenticationException e) { throw new AuthenticationException("Error in authenticating with thrift client..", e); } finally { if (client != null) { client.close(); } } return sessionId; }
@Override public TServiceClient create(ThriftClientKey key) throws Exception { String serviceName = key.getServiceName(); String endpoint = propertyResolver.getProperty(serviceName + ".endpoint"); int connectTimeout = propertyResolver.getProperty(serviceName + ".connectTimeout", Integer.class, DEFAULT_CONNECTION_TIMEOUT); int readTimeout = propertyResolver.getProperty(serviceName + ".readTimeout", Integer.class, DEFAULT_READ_TIMEOUT); int maxRetries = propertyResolver.getProperty(serviceName + ".maxRetries", Integer.class, DEFAULT_MAX_RETRIES); TProtocol protocol; if (StringUtils.isEmpty(endpoint)) { final TLoadBalancerClient loadBalancerClient = new TLoadBalancerClient( this.loadBalancerClient, serviceName, propertyResolver.getProperty(serviceName + ".path", "") + key.getPath() ); loadBalancerClient.setConnectTimeout(connectTimeout); loadBalancerClient.setReadTimeout(readTimeout); loadBalancerClient.setMaxRetries(maxRetries); protocol = protocolFactory.getProtocol(loadBalancerClient); } else { final THttpClient httpClient = new THttpClient(endpoint); httpClient.setConnectTimeout(connectTimeout); httpClient.setReadTimeout(readTimeout); protocol = protocolFactory.getProtocol(httpClient); } return BeanUtils.instantiateClass( key.getClazz().getConstructor(TProtocol.class), (TProtocol) protocol ); }
private Hbase.Client refresh(Hbase.Client client, THttpClient httpClient) { httpClient.setCustomHeader("doAs", doAsUser); if(secure) { try { httpClient.setCustomHeader("Authorization", generateTicket()); } catch (GSSException e) { LOG.error("Kerberos authentication failed", e); } } return client; }
private boolean authenticate() throws EntitlementProxyException { boolean isAuthenticated; try { THttpClient client = new THttpClient(serverUrl); TProtocol protocol = new TCompactProtocol(client); AuthenticatorService.Client authClient = new AuthenticatorService.Client(protocol); client.open(); sessionId = authClient.authenticate(userName, password); client.close(); isAuthenticated = true; } catch (Exception e) { throw new EntitlementProxyException("Error while authenticating with ThriftAuthenticator", e); } return isAuthenticated; }
@Override protected void talkToThriftServer(String url, int customHeaderSize) throws Exception { // Close httpClient and THttpClient automatically on any failures try ( CloseableHttpClient httpClient = createHttpClient(); THttpClient tHttpClient = new THttpClient(url, httpClient) ) { tHttpClient.open(); if (customHeaderSize > 0) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < customHeaderSize; i++) { sb.append("a"); } tHttpClient.setCustomHeader(HttpHeaders.USER_AGENT, sb.toString()); } TProtocol prot = new TBinaryProtocol(tHttpClient); Hbase.Client client = new Hbase.Client(prot); if (!tableCreated) { TestThriftServer.createTestTables(client); tableCreated = true; } TestThriftServer.checkTableList(client); } }
@Override public TTransport getTransport(TTransport trans) { try { if (null != client) { return new THttpClient(url, client); } else { return new THttpClient(url); } } catch (TTransportException tte) { return null; } } }
@Override public ThriftEventTransmissionService.Client makeObject(Object key) throws TTransportException { String[] keyElements = key.toString().split(AgentConstants.SEPARATOR); if (keyElements[0].equals(ReceiverConfiguration.Protocol.TCP.toString())) { String[] hostNameAndPort = keyElements[1].split(AgentConstants.HOSTNAME_AND_PORT_SEPARATOR); TTransport receiverTransport = null; try { receiverTransport = new TSocket(HostAddressFinder.findAddress(hostNameAndPort[0]), Integer.parseInt(hostNameAndPort[1])); } catch (SocketException ignored) { //already checked } TProtocol protocol = new TBinaryProtocol(receiverTransport); ThriftEventTransmissionService.Client client = new ThriftEventTransmissionService.Client(protocol); receiverTransport.open(); return client; } else { THttpClient client = new THttpClient("http://" + keyElements[1] + "/thriftReceiver"); TProtocol protocol = new TCompactProtocol(client); ThriftEventTransmissionService.Client publisherClient = new ThriftEventTransmissionService.Client(protocol); client.open(); return publisherClient; } }
public String getSessionId(String userName, String password) throws AuthenticationException { try { //if (sessionId == null) { TProtocol protocol = new TCompactProtocol(client); AuthenticatorService.Client authClient = new AuthenticatorService.Client( protocol); client.open(); sessionId = authClient.authenticate(userName, password); client.close(); //} } catch (TTransportException e) { throw new AuthenticationException("Error in authenticating with thrift client.."); } catch (TException e) { throw new AuthenticationException("Error in authenticating with thrift client.."); } catch (AuthenticationException e) { throw new AuthenticationException("Error in authenticating with thrift client.."); } finally { if (client != null) { client.close(); } } return sessionId; }
private Hbase.Client refresh(Hbase.Client client, THttpClient httpClient) { httpClient.setCustomHeader("doAs", doAsUser); if(secure) { try { httpClient.setCustomHeader("Authorization", generateTicket()); } catch (GSSException e) { e.printStackTrace(); } } return client; }
@Override protected void talkToThriftServer(String url, int customHeaderSize) throws Exception { THttpClient httpClient = new THttpClient(url); httpClient.open(); sb.append("a"); httpClient.setCustomHeader("User-Agent", sb.toString()); httpClient.close();
private boolean authenticate() throws EntitlementProxyException { boolean isAuthenticated; try { THttpClient client = new THttpClient(serverUrl); TProtocol protocol = new TCompactProtocol(client); AuthenticatorService.Client authClient = new AuthenticatorService.Client(protocol); client.open(); sessionId = authClient.authenticate(userName, password); client.close(); isAuthenticated = true; } catch (Exception e) { throw new EntitlementProxyException("Error while authenticating with ThriftAuthenticator", e); } return isAuthenticated; }
public void loginWithAuthToken(String authToken) throws Exception { THttpClient transport = new THttpClient(LINE_HTTP_IN_URL, httpClient); transport.setCustomHeader(X_LINE_ACCESS, authToken); transport.open(); TProtocol protocol = new TCompactProtocol(transport); setClient(new TalkService.Client(protocol)); setAuthToken(authToken); }
// Java Thrift Client Using HTTP Transport public static void main(String[] args) throws InvalidRequestException, AuthenticationException, TException, UnavailableException { THttpClient transport = new THttpClient("http://localhost:9000/application/api"); TProtocol protocol = new TBinaryProtocol(transport); MyThriftService.Client client = new MyThriftService.Client(protocol); client.RPCMethod("some string"); }
String encryptString = Hex.encodeHexString(enBytes); THttpClient transport = new THttpClient(LINE_HTTP_URL, httpClient); transport.open(); LoginResult result; TProtocol protocol = new TCompactProtocol(transport);