Java Code Examples for org.apache.thrift.transport.THttpClient#open()

The following examples show how to use org.apache.thrift.transport.THttpClient#open() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Authenticator.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
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;

}
 
Example 2
Source File: Authenticator.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
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;

}
 
Example 3
Source File: ThriftConnection.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public Pair<THBaseService.Client, TTransport> 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<String, String> 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);
  }

}
 
Example 4
Source File: CrossflowWebTests.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
	transport = new THttpClient("http://localhost:8080/org.eclipse.scava.crossflow.web/thrift");
	transport.open();
	TProtocol protocol = new TJSONProtocol(transport); // JSON transport forma
	client = new Crossflow.Client(protocol);
}
 
Example 5
Source File: LineApiImpl.java    From LineAPI4J with MIT License 5 votes vote down vote up
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);
}
 
Example 6
Source File: ThriftClient.java    From ThriftBook with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) 
        throws IOException, TException {
    THttpClient trans = new THttpClient("http://localhost:8080/thrift-servlet");
    TJSONProtocol proto = new TJSONProtocol(trans);
    TradeHistory.Client client = new TradeHistory.Client(proto);

    for (int i = 0; i < 1000000; i++) {
        trans.open();
        TradeReport tr = client.get_last_sale("AAPL");
        trans.close();
    }
}
 
Example 7
Source File: LineApiImpl.java    From LineAPI4J with MIT License 4 votes vote down vote up
@Override
public LoginResult login(@Nonnull String id,
                         @Nonnull String password,
                         @Nullable String certificate,
                         @Nullable LoginCallback loginCallback)
        throws Exception {
  this.id = id;
  this.password = password;
  this.certificate = certificate;
  IdentityProvider provider;
  JsonNode sessionInfo;
  String sessionKey;
  boolean keepLoggedIn = true;
  String accessLocation = this.ip;

  // Login to LINE server.
  if (id.matches(EMAIL_REGEX)) {
    provider = IdentityProvider.LINE; // LINE
    sessionInfo = getJsonResult(LINE_SESSION_LINE_URL);
  } else {
    provider = IdentityProvider.NAVER_KR; // NAVER
    sessionInfo = getJsonResult(LINE_SESSION_NAVER_URL);
  }

  sessionKey = sessionInfo.get("session_key").asText();
  String message =
      (char) (sessionKey.length()) + sessionKey + (char) (id.length()) + id
          + (char) (password.length()) + password;
  String[] keyArr = sessionInfo.get("rsa_key").asText().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(StandardCharsets.UTF_8));
  String encryptString = Hex.encodeHexString(enBytes);

  THttpClient transport = new THttpClient(LINE_HTTP_URL, httpClient);
  transport.open();
  LoginResult result;
  TProtocol protocol = new TCompactProtocol(transport);
  this.client = new TalkService.Client(protocol);

  result = this.client.loginWithIdentityCredentialForCertificate(provider, keyName, encryptString,
                  keepLoggedIn, accessLocation, this.systemName, this.certificate);

  if (result.getType() == LoginResultType.REQUIRE_DEVICE_CONFIRM) {

    setAuthToken(result.getVerifier());

    if (loginCallback != null) {
      loginCallback.onDeviceConfirmRequired(result.getPinCode());
    } else {
      throw new Exception("Device confirmation is required. Please set " +
              LoginCallback.class.getSimpleName() + " to get the pin code");
    }

    // 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
  loginWithAuthToken(getAuthToken());
  return result;
}
 
Example 8
Source File: LineApiImpl.java    From LineAPI4J with MIT License 4 votes vote down vote up
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, 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();
}
 
Example 9
Source File: HttpDoAsClient.java    From hbase with Apache License 2.0 4 votes vote down vote up
private void run() throws Exception {
  TTransport transport = new TSocket(host, port);

  transport.open();
  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: " + ClientUtils.utf8(name.array()));
    if (ClientUtils.utf8(name.array()).equals(ClientUtils.utf8(t))) {
      if (refresh(client, httpClient).isTableEnabled(name)) {
        System.out.println("    disabling table: " + ClientUtils.utf8(name.array()));
        refresh(client, httpClient).disableTable(name);
      }
      System.out.println("    deleting table: " + ClientUtils.utf8(name.array()));
      refresh(client, httpClient).deleteTable(name);
    }
  }

  //
  // Create the demo table with two column families, entry: and unused:
  //
  ArrayList<ColumnDescriptor> columns = new ArrayList<>(2);
  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: " + ClientUtils.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 " + ClientUtils.utf8(t) + ": ");
  Map<ByteBuffer, ColumnDescriptor> columnMap = refresh(client, httpClient)
      .getColumnDescriptors(ByteBuffer.wrap(t));
  for (ColumnDescriptor col2 : columnMap.values()) {
    System.out.println("  column: " + ClientUtils.utf8(col2.name.array()) + ", maxVer: "
        + col2.maxVersions);
  }

  transport.close();
  httpClient.close();
}