Search in sources :

Example 1 with ThriftEntitlementServiceImpl

use of org.wso2.carbon.identity.entitlement.thrift.ThriftEntitlementServiceImpl in project carbon-identity-framework by wso2.

the class EntitlementServiceComponent method startThriftEntitlementService.

private void startThriftEntitlementService() throws Exception {
    try {
        // read identity.xml
        IdentityUtil.populateProperties();
        // if thrift based EntitlementService is enabled.
        String thriftEnabled = IdentityUtil.getProperty(ThriftConfigConstants.PARAM_ENABLE_THRIFT_SERVICE);
        if (thriftEnabled != null && Boolean.parseBoolean(thriftEnabled)) {
            TSSLTransportFactory.TSSLTransportParameters transportParam = new TSSLTransportFactory.TSSLTransportParameters();
            // read the keystore and password used for ssl communication from config
            String keystorePath = IdentityUtil.getProperty(ThriftConfigConstants.PARAM_KEYSTORE_LOCATION);
            String keystorePassword = IdentityUtil.getProperty(ThriftConfigConstants.PARAM_KEYSTORE_PASSWORD);
            // set it in parameters
            transportParam.setKeyStore(keystorePath, keystorePassword);
            // int receivePort = 10395;
            int receivePort = readThriftReceivePort();
            // int clientTimeOut = 10000;
            int clientTimeOut = Integer.parseInt(IdentityUtil.getProperty(ThriftConfigConstants.PARAM_CLIENT_TIMEOUT));
            // String ifAddress = "localhost";
            TServerSocket serverTransport = TSSLTransportFactory.getServerSocket(receivePort, clientTimeOut, getHostAddress(readThriftHostName()), transportParam);
            EntitlementService.Processor processor = new EntitlementService.Processor(new ThriftEntitlementServiceImpl());
            // TODO: have to decide on the protocol.
            TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
            // TServer server = new TThreadPoolServer(new TThreadPoolServer.Args())
            /*
                TServer server = new TThreadPoolServer(processor, serverTransport,
                                                   new TCompactProtocol.Factory());*/
            Runnable serverThread = new ServerRunnable(server);
            executor.submit(serverThread);
            if (log.isDebugEnabled()) {
                log.debug("Started thrift entitlement service at port:" + receivePort);
            }
        }
    } catch (TTransportException e) {
        String transportErrorMsg = "Error in initializing thrift transport";
        log.error(transportErrorMsg, e);
        throw new Exception(transportErrorMsg);
    } catch (UnknownHostException e) {
        String hostErrorMsg = "Error in obtaining host name";
        log.error(hostErrorMsg, e);
        throw new Exception(hostErrorMsg);
    }
}
Also used : EntitlementService(org.wso2.carbon.identity.entitlement.thrift.EntitlementService) UnknownHostException(java.net.UnknownHostException) TServer(org.apache.thrift.server.TServer) TTransportException(org.apache.thrift.transport.TTransportException) TSSLTransportFactory(org.apache.thrift.transport.TSSLTransportFactory) ThriftEntitlementServiceImpl(org.wso2.carbon.identity.entitlement.thrift.ThriftEntitlementServiceImpl) TTransportException(org.apache.thrift.transport.TTransportException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) SocketException(java.net.SocketException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) TServerSocket(org.apache.thrift.transport.TServerSocket) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer)

Aggregations

IOException (java.io.IOException)1 SocketException (java.net.SocketException)1 UnknownHostException (java.net.UnknownHostException)1 TServer (org.apache.thrift.server.TServer)1 TThreadPoolServer (org.apache.thrift.server.TThreadPoolServer)1 TSSLTransportFactory (org.apache.thrift.transport.TSSLTransportFactory)1 TServerSocket (org.apache.thrift.transport.TServerSocket)1 TTransportException (org.apache.thrift.transport.TTransportException)1 EntitlementService (org.wso2.carbon.identity.entitlement.thrift.EntitlementService)1 ThriftEntitlementServiceImpl (org.wso2.carbon.identity.entitlement.thrift.ThriftEntitlementServiceImpl)1 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)1