热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

org.apache.thrift.transport.THttpClient类的使用及代码示例

本文整理了Java中org.apache.thrift.transport.THttpClient类的一些代码示例,展示了THttpClient

本文整理了Java中org.apache.thrift.transport.THttpClient类的一些代码示例,展示了THttpClient类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。THttpClient类的具体详情如下:
包路径:org.apache.thrift.transport.THttpClient
类名称:THttpClient

THttpClient介绍

[英]HTTP implementation of the TTransport interface. Used for working with a Thrift web services implementation.
[中]TTTransport接口的HTTP实现。用于使用Thrift web服务实现。

代码示例

代码示例来源:origin: apache/hbase

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

代码示例来源:origin: apache/hbase

@Override
public Pair 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 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);
}
}
}

代码示例来源:origin: apache/hbase

THttpClient httpClient = new THttpClient(url);
httpClient.open();
TProtocol protocol = new TBinaryProtocol(httpClient);
Hbase.Client client = new Hbase.Client(protocol);
httpClient.close();

代码示例来源:origin: apache/hive

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;
}

代码示例来源:origin: cslinmiso/LineAPI4J

public AuthQrcode loginWithQrCode() throws Exception {
// Request QrCode from LINE server.
// Map 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();
}

代码示例来源:origin: line/armeria

@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;
}

代码示例来源:origin: org.wso2.carbon.apimgt/org.wso2.carbon.apimgt.gateway

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;
}

代码示例来源:origin: aatarasoff/spring-thrift-starter

@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
);
}

代码示例来源:origin: apache/hbase

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;
}

代码示例来源:origin: org.wso2.carbon.identity.agent.entitlement.mediator/org.wso2.carbon.identity.entitlement.proxy

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;
}

代码示例来源:origin: apache/hbase

@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 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);
}
}

代码示例来源:origin: org.apache.thrift/libthrift

@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;
}
}
}

代码示例来源:origin: org.wso2.carbon.commons/org.wso2.carbon.databridge.agent.thrift

@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;
}
}

代码示例来源:origin: org.wso2.carbon.appmgt/org.wso2.carbon.appmgt.gateway

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;
}

代码示例来源:origin: com.aliyun.hbase/alihbase-examples

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;
}

代码示例来源:origin: apache/hbase

@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();

代码示例来源:origin: org.wso2.carbon.identity/org.wso2.carbon.identity.entitlement.proxy

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;
}

代码示例来源:origin: cslinmiso/LineAPI4J

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

代码示例来源:origin: stackoverflow.com

// 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");
}

代码示例来源:origin: cslinmiso/LineAPI4J

String encryptString = Hex.encodeHexString(enBytes);
THttpClient transport = new THttpClient(LINE_HTTP_URL, httpClient);
transport.open();
LoginResult result;
TProtocol protocol = new TCompactProtocol(transport);

推荐阅读
  • 本文介绍了一个基本的同步Socket程序,演示了如何实现客户端与服务器之间的简单消息传递。此外,文章还概述了Socket的基本工作流程,并计划在未来探讨同步与异步Socket的区别。 ... [详细]
  • 深入解析Nacos服务自动注册机制
    本文将探讨Nacos服务自动注册的具体实现方法,特别是如何通过Spring事件机制完成服务注册。通过对Nacos源码的详细分析,帮助读者理解其背后的原理。 ... [详细]
  • 本文详细介绍了如何在PHP中使用Memcached进行数据缓存,包括服务器连接、数据操作、高级功能等。 ... [详细]
  • 本文探讨了Java中有效停止线程的多种方法,包括使用标志位、中断机制及处理阻塞I/O操作等,旨在帮助开发者避免使用已废弃的危险方法,确保线程安全和程序稳定性。 ... [详细]
  • 本文详细介绍了如何在本地环境中安装配置Frida及其服务器组件,以及如何通过Frida进行基本的应用程序动态分析,包括获取应用版本和加载的类信息。 ... [详细]
  • 本文介绍了进程的基本概念及其在操作系统中的重要性,探讨了进程与程序的区别,以及如何通过多进程实现并发和并行。文章还详细讲解了Python中的multiprocessing模块,包括Process类的使用方法、进程间的同步与异步调用、阻塞与非阻塞操作,并通过实例演示了进程池的应用。 ... [详细]
  • Kubernetes Services详解
    本文深入探讨了Kubernetes中的服务(Services)概念,解释了如何通过Services实现Pods之间的稳定通信,以及如何管理没有选择器的服务。 ... [详细]
  • 本文探讨了Android系统中联系人数据库的设计,特别是AbstractContactsProvider类的作用与实现。文章提供了对源代码的详细分析,并解释了该类如何支持跨数据库操作及事务处理。源代码可从官方Android网站下载。 ... [详细]
  • 本文详细介绍了在PHP中如何获取和处理HTTP头部信息,包括通过cURL获取请求头信息、使用header函数发送响应头以及获取客户端HTTP头部的方法。同时,还探讨了PHP中$_SERVER变量的使用,以获取客户端和服务器的相关信息。 ... [详细]
  • 本文介绍如何通过Java代码调用阿里云短信服务API来实现短信验证码的发送功能,包括必要的依赖添加和关键代码示例。 ... [详细]
  • 2023年1月28日网络安全热点
    涵盖最新的网络安全动态,包括OpenSSH和WordPress的安全更新、VirtualBox提权漏洞、以及谷歌推出的新证书验证机制等内容。 ... [详细]
  • 本文详细探讨了select和epoll两种I/O多路复用技术的内部实现原理,分析了它们在处理大量文件描述符时的性能差异,并通过具体示例代码展示了select的工作流程。 ... [详细]
  • 本文由chszs撰写,详细介绍了Apache Mina框架的核心开发流程及自定义协议处理方法。文章涵盖从创建IoService实例到协议编解码的具体步骤,适合希望深入了解Mina框架应用的开发者。 ... [详细]
  • 本文分享了作者在使用LaTeX过程中的几点心得,涵盖了从文档编辑、代码高亮、图形绘制到3D模型展示等多个方面的内容。适合希望深入了解LaTeX高级功能的用户。 ... [详细]
  • 2022年4月15日的算法练习题,包括最长公共子序列和线段树的应用。 ... [详细]
author-avatar
小哥脾气
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有