List of usage examples for org.apache.thrift.transport THttpClient open
public void open()
From source file:MapDExample.java
License:Apache License
public static MapD.Client get_client(String host_or_uri, int port, boolean http) { THttpClient httpTransport; TTransport transport;/*from w w w . j a va2s .com*/ TBinaryProtocol protocol; TJSONProtocol jsonProtocol; TSocket socket; MapD.Client client; try { if (http) { httpTransport = new THttpClient(host_or_uri); jsonProtocol = new TJSONProtocol(httpTransport); client = new MapD.Client(jsonProtocol); httpTransport.open(); return client; } else { transport = new TSocket(host_or_uri, port); protocol = new TBinaryProtocol(transport); client = new MapD.Client(protocol); transport.open(); return client; } } catch (TException x) { x.printStackTrace(); } return null; }
From source file:boxalino.client.SDK.BxClient.java
private Client getP13n(int timeout, boolean useCurlIfAvailable) throws IOException, UnsupportedEncodingException, TTransportException, URISyntaxException, MalformedURLException { try {//from w w w . ja v a 2 s . co m //default start if (timeout == 0) { timeout = 2; } //default end useCurlIfAvailable = false; THttpClient transport = null; if (useCurlIfAvailable) { } else { try { transport = new THttpClient( new URI(String.format("%s://%s%s", this.schema, this.host, this.uri)).toURL() .toString()); } catch (TTransportException ex) { throw ex; } } transport.setCustomHeader("Authorization", "Basic " + Base64.getEncoder() .encodeToString((this.p13n_username + ':' + this.p13n_password).getBytes("UTF-8"))); Client client = new Client(new TCompactProtocol(transport)); transport.open(); return client; } catch (UncheckedIOException ex) { throw ex.getCause(); } }
From source file:io.cslinmiso.line.api.impl.LineApiImpl.java
License:Open Source License
/** * Ready./*from w w w .ja va2 s . c o m*/ * * @return the talk service. client * @throws TTransportException */ public Client ready() throws TTransportException { THttpClient transport = new THttpClient(LINE_HTTP_IN_URL); transport.setCustomHeaders(headers); transport.open(); TProtocol protocol = new TCompactProtocol(transport); return new TalkService.Client(protocol); }
From source file:io.cslinmiso.line.api.impl.LineApiImpl.java
License:Open Source License
public LoginResult login(String id, String password, String certificate) throws Exception { IdentityProvider provider = null;//from w w w .j a va 2s . c o m Map<String, String> json = null; String sessionKey = null; boolean keepLoggedIn = true; String accessLocation = this.ip; // Login to LINE server. if (id.matches(EMAIL_REGEX)) { provider = IdentityProvider.LINE; // LINE json = getCertResult(LINE_SESSION_LINE_URL); } else { provider = IdentityProvider.NAVER_KR; // NAVER json = getCertResult(LINE_SESSION_NAVER_URL); } if (id != null) { this.id = id; } if (password != null) { this.password = password; } if (StringUtils.isNotEmpty(certificate)) { setCertificate(certificate); } else { // read the certificate file if it exists try { List<String> readFile = Utility.readFile(LineApiImpl.CERT_FILE); String tmpCert = readFile != null ? readFile.get(0) : ""; if (tmpCert != null) { setCertificate(tmpCert); } } catch (Exception ex) { setCertificate(""); } } sessionKey = json.get("session_key"); String tmpMsg = (char) (sessionKey.length()) + sessionKey + (char) (id.length()) + id + (char) (password.length()) + password; String message = new String(tmpMsg.getBytes(), java.nio.charset.StandardCharsets.UTF_8); String[] keyArr = json.get("rsa_key").split(","); String keyName = keyArr[0]; String n = keyArr[1]; String e = keyArr[2]; BigInteger modulus = new BigInteger(n, 16); BigInteger pubExp = new BigInteger(e, 16); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(modulus, pubExp); RSAPublicKey publicKey = (RSAPublicKey) keyFactory.generatePublic(pubKeySpec); Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); cipher.init(Cipher.ENCRYPT_MODE, publicKey); byte[] enBytes = cipher.doFinal(message.getBytes()); String encryptString = Hex.encodeHexString(enBytes); THttpClient transport = new THttpClient(LINE_HTTP_URL); transport.setCustomHeaders(headers); transport.open(); TProtocol protocol = new TCompactProtocol(transport); this.client = new TalkService.Client(protocol); LoginResult result = this.client.loginWithIdentityCredentialForCertificate(provider, keyName, encryptString, keepLoggedIn, accessLocation, this.systemName, this.certificate); if (result.getType() == LoginResultType.REQUIRE_DEVICE_CONFIRM) { headers.put("X-Line-Access", result.getVerifier()); String pinCode = result.getPinCode(); System.out.printf("Enter PinCode '%s' to your mobile phone in 2 minutes.\n", pinCode); // await for pinCode to be certified, it will return a verifier afterward. loginWithVerifierForCertificate(); } else if (result.getType() == LoginResultType.SUCCESS) { // if param certificate has passed certification setAuthToken(result.getAuthToken()); } // Once the client passed the verification, switch connection to HTTP_IN_URL this.client = ready(); return result; }
From source file:io.cslinmiso.line.api.impl.LineApiImpl.java
License:Open Source License
public void loginWithAuthToken(String authToken) throws Exception { if (StringUtils.isNotEmpty(authToken)) { setAuthToken(authToken);/*from www . j a va 2 s . com*/ } THttpClient transport = new THttpClient(LINE_HTTP_URL); transport.setCustomHeaders(headers); transport.open(); TProtocol protocol = new TCompactProtocol(transport); setClient(new TalkService.Client(protocol)); }
From source file:io.cslinmiso.line.api.impl.LineApiImpl.java
License:Open Source License
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); transport.setCustomHeaders(headers); transport.open(); TProtocol protocol = new TCompactProtocol(transport); this.client = new TalkService.Client(protocol); AuthQrcode result = this.client.getAuthQrcode(keepLoggedIn, systemName); headers.put("X-Line-Access", result.getVerifier()); System.out.println("Retrieved QR Code."); return result; // await for QR code to be certified, it will return a verifier afterward. // loginWithVerifier(); }
From source file:org.apache.hadoop.hbase.thrift.HttpDoAsClient.java
License:Apache License
private void run() throws Exception { TTransport transport = new TSocket(host, port); transport.open();//w ww . ja v a 2 s . c o m String url = "http://" + host + ":" + port; THttpClient httpClient = new THttpClient(url); httpClient.open(); TProtocol protocol = new TBinaryProtocol(httpClient); Hbase.Client client = new Hbase.Client(protocol); byte[] t = bytes("demo_table"); // // Scan all tables, look for the demo table and delete it. // System.out.println("scanning tables..."); for (ByteBuffer name : refresh(client, httpClient).getTableNames()) { System.out.println(" found: " + utf8(name.array())); if (utf8(name.array()).equals(utf8(t))) { if (refresh(client, httpClient).isTableEnabled(name)) { System.out.println(" disabling table: " + utf8(name.array())); refresh(client, httpClient).disableTable(name); } System.out.println(" deleting table: " + utf8(name.array())); refresh(client, httpClient).deleteTable(name); } } // // Create the demo table with two column families, entry: and unused: // ArrayList<ColumnDescriptor> columns = new ArrayList<ColumnDescriptor>(); ColumnDescriptor col; col = new ColumnDescriptor(); col.name = ByteBuffer.wrap(bytes("entry:")); col.timeToLive = Integer.MAX_VALUE; col.maxVersions = 10; columns.add(col); col = new ColumnDescriptor(); col.name = ByteBuffer.wrap(bytes("unused:")); col.timeToLive = Integer.MAX_VALUE; columns.add(col); System.out.println("creating table: " + utf8(t)); try { refresh(client, httpClient).createTable(ByteBuffer.wrap(t), columns); } catch (AlreadyExists ae) { System.out.println("WARN: " + ae.message); } System.out.println("column families in " + utf8(t) + ": "); Map<ByteBuffer, ColumnDescriptor> columnMap = refresh(client, httpClient) .getColumnDescriptors(ByteBuffer.wrap(t)); for (ColumnDescriptor col2 : columnMap.values()) { System.out.println( " column: " + utf8(col2.name.array()) + ", maxVer: " + Integer.toString(col2.maxVersions)); } transport.close(); httpClient.close(); }
From source file:org.apache.hadoop.hbase.thrift.TestThriftHttpServer.java
License:Apache License
private void talkToThriftServer() throws Exception { THttpClient httpClient = new THttpClient("http://" + HConstants.LOCALHOST + ":" + port); httpClient.open(); try {//from w ww. j av a 2s . c o m 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(); } }
From source file:org.apache.hadoop.hbase.thrift2.TestThrift2HttpServer.java
License:Apache License
@Override 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"); }//from w w w . j av a 2s . c o m httpClient.setCustomHeader("User-Agent", sb.toString()); } try { TProtocol prot; prot = new TBinaryProtocol(httpClient); THBaseService.Client client = new THBaseService.Client(prot); TTableName tTableName = new TTableName(); tTableName.setNs(Bytes.toBytes("")); tTableName.setQualifier(Bytes.toBytes(TABLENAME)); if (!tableCreated) { Assert.assertTrue(!client.tableExists(tTableName)); TTableDescriptor tTableDescriptor = new TTableDescriptor(); tTableDescriptor.setTableName(tTableName); TColumnFamilyDescriptor columnFamilyDescriptor = new TColumnFamilyDescriptor(); columnFamilyDescriptor.setName(Bytes.toBytes(TABLENAME)); tTableDescriptor.addToColumns(columnFamilyDescriptor); client.createTable(tTableDescriptor, new ArrayList<>()); tableCreated = true; } Assert.assertTrue(client.tableExists(tTableName)); } finally { httpClient.close(); } }
From source file:org.wso2.carbon.databridge.agent.thrift.internal.pool.client.secure.SecureClientPoolFactory.java
License:Open Source License
@Override public ThriftSecureEventTransmissionService.Client makeObject(Object key) throws AgentSecurityException, TTransportException { String[] keyElements = key.toString().split(AgentConstants.SEPARATOR); if (keyElements[2].equals(ReceiverConfiguration.Protocol.TCP.toString())) { if (params == null) { if (trustStore == null) { trustStore = System.getProperty("javax.net.ssl.trustStore"); if (trustStore == null) { throw new AgentSecurityException("No trustStore found"); }/*from w w w .ja v a2 s . c om*/ // trustStore = "/home/suho/projects/wso2/trunk/carbon/distribution/product/modules/distribution/target/wso2carbon-4.0.0-SNAPSHOT/repository/resources/security/client-truststore.jks"; } if (trustStorePassword == null) { trustStorePassword = System.getProperty("javax.net.ssl.trustStorePassword"); if (trustStorePassword == null) { throw new AgentSecurityException("No trustStore password found"); } //trustStorePassword = "wso2carbon"; } params = new TSSLTransportFactory.TSSLTransportParameters(); params.setTrustStore(trustStore, trustStorePassword); } String[] hostNameAndPort = keyElements[3].split(AgentConstants.HOSTNAME_AND_PORT_SEPARATOR); TTransport receiverTransport = null; try { receiverTransport = TSSLTransportFactory.getClientSocket( HostAddressFinder.findAddress(hostNameAndPort[0]), Integer.parseInt(hostNameAndPort[1]), 0, params); } catch (SocketException ignored) { //already checked } TProtocol protocol = new TBinaryProtocol(receiverTransport); return new ThriftSecureEventTransmissionService.Client(protocol); } else { try { TrustManager easyTrustManager = new X509TrustManager() { public void checkClientTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws java.security.cert.CertificateException { } public void checkServerTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws java.security.cert.CertificateException { } public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } }; String[] hostNameAndPort = keyElements[3].split(AgentConstants.HOSTNAME_AND_PORT_SEPARATOR); SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, new TrustManager[] { easyTrustManager }, null); SSLSocketFactory sf = new SSLSocketFactory(sslContext); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme httpsScheme = new Scheme("https", sf, Integer.parseInt(hostNameAndPort[1])); DefaultHttpClient client = new DefaultHttpClient(); client.getConnectionManager().getSchemeRegistry().register(httpsScheme); THttpClient tclient = new THttpClient("https://" + keyElements[3] + "/securedThriftReceiver", client); TProtocol protocol = new TCompactProtocol(tclient); ThriftSecureEventTransmissionService.Client authClient = new ThriftSecureEventTransmissionService.Client( protocol); tclient.open(); return authClient; } catch (Exception e) { throw new AgentSecurityException("Cannot create Secure client for " + keyElements[3], e); } } }