use of org.apache.thrift.transport.TServerSocket in project yyl_example by Relucent.
the class HelloServer method getSimpleServer.
/**
* 简单的单线程服务模型,一般用于测试
*/
public static TServer getSimpleServer(int port, HelloService.Processor<HelloServiceHandler> processor) throws TTransportException {
TServerTransport transport = new TServerSocket(port);
TServer server = new TSimpleServer(new TServer.Args(transport).processor(processor));
return server;
}
use of org.apache.thrift.transport.TServerSocket in project hive by apache.
the class SecurityUtils method getServerSSLSocket.
public static TServerSocket getServerSSLSocket(String hiveHost, int portNum, String keyStorePath, String keyStorePassWord, String keyStoreType, String keyStoreAlgorithm, List<String> sslVersionBlacklist) throws TTransportException, UnknownHostException {
TSSLTransportFactory.TSSLTransportParameters params = new TSSLTransportFactory.TSSLTransportParameters();
String kStoreType = keyStoreType.isEmpty() ? KeyStore.getDefaultType() : keyStoreType;
String kStoreAlgorithm = keyStoreAlgorithm.isEmpty() ? KeyManagerFactory.getDefaultAlgorithm() : keyStoreAlgorithm;
params.setKeyStore(keyStorePath, keyStorePassWord, kStoreAlgorithm, kStoreType);
InetSocketAddress serverAddress;
if (hiveHost == null || hiveHost.isEmpty()) {
// Wildcard bind
serverAddress = new InetSocketAddress(portNum);
} else {
serverAddress = new InetSocketAddress(hiveHost, portNum);
}
TServerSocket thriftServerSocket = TSSLTransportFactory.getServerSocket(portNum, 0, serverAddress.getAddress(), params);
if (thriftServerSocket.getServerSocket() instanceof SSLServerSocket) {
List<String> sslVersionBlacklistLocal = new ArrayList<>();
for (String sslVersion : sslVersionBlacklist) {
sslVersionBlacklistLocal.add(sslVersion.trim().toLowerCase());
}
SSLServerSocket sslServerSocket = (SSLServerSocket) thriftServerSocket.getServerSocket();
List<String> enabledProtocols = new ArrayList<>();
for (String protocol : sslServerSocket.getEnabledProtocols()) {
if (sslVersionBlacklistLocal.contains(protocol.toLowerCase())) {
LOG.debug("Disabling SSL Protocol: " + protocol);
} else {
enabledProtocols.add(protocol);
}
}
sslServerSocket.setEnabledProtocols(enabledProtocols.toArray(new String[0]));
LOG.info("SSL Server Socket Enabled Protocols: " + Arrays.toString(sslServerSocket.getEnabledProtocols()));
}
return thriftServerSocket;
}
use of org.apache.thrift.transport.TServerSocket in project dubbo by alibaba.
the class ServiceMethodNotFoundTest method init.
protected void init() throws Exception {
TServerTransport serverTransport = new TServerSocket(PORT);
DubboDemoImpl impl = new DubboDemoImpl();
$__DemoStub.Processor processor = new $__DemoStub.Processor(impl);
// for test
Field field = processor.getClass().getSuperclass().getDeclaredField("processMap");
ReflectUtils.makeAccessible(field);
Object obj = field.get(processor);
if (obj instanceof Map) {
((Map) obj).remove("echoString");
}
// ~
TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();
MultiServiceProcessor wrapper = new MultiServiceProcessor();
wrapper.addProcessor(Demo.class, processor);
server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).inputProtocolFactory(bFactory).outputProtocolFactory(bFactory).inputTransportFactory(getTransportFactory()).outputTransportFactory(getTransportFactory()).processor(wrapper));
Thread startTread = new Thread() {
@Override
public void run() {
server.serve();
}
};
startTread.start();
while (!server.isServing()) {
Thread.sleep(100);
}
}
use of org.apache.thrift.transport.TServerSocket in project tech by ffyyhh995511.
the class Test1 method main.
/**
* 编写服务端,发布(阻塞式IO + 多线程处理)服务
*
* @param args
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void main(String[] args) {
try {
// 设置传输通道,普通通道
TServerTransport serverTransport = new TServerSocket(7911);
// 使用高密度二进制协议
TProtocolFactory proFactory = new TCompactProtocol.Factory();
// 设置处理器HelloImpl
TProcessor processor = new Hello.Processor(new HelloImpl());
// 创建服务器
Args args2 = new Args(serverTransport);
args2.protocolFactory(proFactory);
args2.processor(processor);
TServer server = new TThreadPoolServer(args2);
System.out.println("Start server on port 7911...");
server.serve();
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations