热门标签 | 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);

推荐阅读
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社区 版权所有