Java 类org.apache.thrift.transport.THttpClient 实例源码

项目:CodeCheckerEclipsePlugin    文件:ThriftTransportFactory.java   
protected TProtocol requestTransport(String url) throws TTransportException {

        // probably not thread safe, but we need it? Not atm.

        TTransport act;

        if (!activeTransports.containsKey(url)) {
            logger.log(Level.DEBUG ,"Creating new transport for: " + url);
            activeTransports.put(url, new THttpClient(url));
        }

        act = activeTransports.get(url);

        if (!act.isOpen()) {
            act.open();
        }
        // THINK: always create new protocol?
        return new TJSONProtocol(act);
    }
项目:providence    文件:ProvidenceServlet_ThriftClientTest.java   
@Test
public void testThriftClient() throws TException, IOException, Failure {
    ApacheHttpTransport transport = new ApacheHttpTransport();
    THttpClient httpClient = new THttpClient(endpoint().toString(), transport.getHttpClient());
    TBinaryProtocol protocol = new TBinaryProtocol(httpClient);
    net.morimekta.test.thrift.service.TestService.Iface client =
            new net.morimekta.test.thrift.service.TestService.Client(protocol);

    doAnswer(i -> new Response("reply"))
            .when(impl)
            .test(any(Request.class));

    net.morimekta.test.thrift.service.Response response =
            client.test(new net.morimekta.test.thrift.service.Request("call"));
    assertThat(response.getText(), is("reply"));

    verify(impl).test(any(Request.class));
    verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), any(PServiceCall.class));
    verifyNoMoreInteractions(impl, instrumentation);
}
项目:providence    文件:ProvidenceServlet_ThriftClientTest.java   
@Test
public void testThriftClient_void() throws TException, IOException, Failure {
    ApacheHttpTransport transport = new ApacheHttpTransport();
    THttpClient httpClient = new THttpClient(endpoint().toString(), transport.getHttpClient());
    TBinaryProtocol protocol = new TBinaryProtocol(httpClient);
    net.morimekta.test.thrift.service.TestService.Iface client =
            new net.morimekta.test.thrift.service.TestService.Client(protocol);

    AtomicBoolean called = new AtomicBoolean();
    doAnswer(i -> {
        called.set(true);
        return null;
    }).when(impl).voidMethod(55);

    client.voidMethod(55);

    waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);

    verify(impl).voidMethod(55);
    verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), any(PServiceCall.class));
    verifyNoMoreInteractions(impl, instrumentation);
}
项目:providence    文件:ProvidenceServlet_ThriftClientTest.java   
@Test
public void testThriftClient_oneway() throws TException, IOException, Failure {
    ApacheHttpTransport transport = new ApacheHttpTransport();
    THttpClient httpClient = new THttpClient(endpoint().toString(), transport.getHttpClient());
    TBinaryProtocol protocol = new TBinaryProtocol(httpClient);
    net.morimekta.test.thrift.service.TestService.Iface client =
            new net.morimekta.test.thrift.service.TestService.Client(protocol);

    AtomicBoolean called = new AtomicBoolean();
    doAnswer(i -> {
        called.set(true);
        return null;
    }).when(impl).ping();

    client.ping();

    waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);

    verify(impl).ping();
    verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), isNull());
    verifyNoMoreInteractions(impl, instrumentation);
}
项目:providence    文件:ProvidenceServlet_ThriftClientTest.java   
@Test
public void testThriftClient_failure() throws TException, IOException, Failure {
    ApacheHttpTransport transport = new ApacheHttpTransport();
    THttpClient httpClient = new THttpClient(endpoint().toString(), transport.getHttpClient());
    TBinaryProtocol protocol = new TBinaryProtocol(httpClient);
    net.morimekta.test.thrift.service.TestService.Iface client =
            new net.morimekta.test.thrift.service.TestService.Client(protocol);

    AtomicBoolean called = new AtomicBoolean();
    doAnswer(i -> {
        called.set(true);
        throw new Failure("test");
    }).when(impl).voidMethod(55);

    try {
        client.voidMethod(55);
    } catch (net.morimekta.test.thrift.service.Failure e) {
        assertEquals("test", e.getText());
    }

    waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);

    verify(impl).voidMethod(55);
    verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), any(PServiceCall.class));
    verifyNoMoreInteractions(impl, instrumentation);
}
项目:armeria    文件:ThriftOverHttp1Test.java   
@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()
                                  .setSSLContext(sslContext)
                                  .build());
    client.setCustomHeaders(
            headers.names().stream()
                   .collect(toImmutableMap(AsciiString::toString,
                                           name -> String.join(", ", headers.getAll(name)))));
    return client;
}
项目:carbon-identity    文件:Authenticator.java   
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;

}
项目:hbase    文件:TestThriftHttpServer.java   
private void talkToThriftServer(int customHeaderSize) throws Exception {
  THttpClient httpClient = new THttpClient(
      "http://"+ HConstants.LOCALHOST + ":" + port);
  httpClient.open();

  if (customHeaderSize > 0) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < customHeaderSize; 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();
  }
}
项目:ditb    文件:HttpDoAsClient.java   
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;
}
项目:ikasoa    文件:HttpThriftClientImpl.java   
@Override
protected TTransport getTransport(String serverHost, int serverPort) throws STException {
    try {
        return new THttpClient(serverHost);
    } catch (TTransportException e) {
        throw new STException("Get http transport failed !", e);
    }
}
项目:spring-thrift-api-gateway    文件:TGreetingServiceHandlerTests.java   
@Before
public void setUp() throws Exception {
    TTransport transport = new THttpClient("http://localhost:" + port + "/api");

    TProtocol protocol = protocolFactory.getProtocol(transport);

    client = new TGreetingService.Client(protocol);
}
项目:spring-thrift-integration    文件:Client.java   
public static void main(String[] args) throws Exception {

        THttpClient transport = new THttpClient("http://localhost:8080/api");
        transport.open();
        TProtocol protocol = new TBinaryProtocol(transport);
        PingPongService.Client client = new PingPongService.Client(new TMultiplexedProtocol(protocol, "PingPongService"));

        Ping ping = new Ping();
        ping.setMessage("Hello");
        Pong pong = client.knock(ping);

        LoggerFactory.getLogger(Client.class).info("Got answer: "+pong.getAnswer());
    }
项目:Blitz-2015    文件:ThriftHttpTest.java   
private AwesomeService.Client createClient() throws TTransportException
{
    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setScheme("http");
    uriBuilder.setHost("localhost");
    uriBuilder.setPort(SERVER_PORT);

    TTransport transport = new THttpClient(uriBuilder.toString());
    transport.open();
    TProtocol protocol = new TJSONProtocol(transport);

    return new AwesomeService.Client(protocol);
}
项目:pbase    文件:HttpDoAsClient.java   
private Hbase.Client refresh(Hbase.Client client, THttpClient httpClient) {
  if(secure) {
    httpClient.setCustomHeader("doAs", "hbase");
    try {
      httpClient.setCustomHeader("Authorization", generateTicket());
    } catch (GSSException e) {
      e.printStackTrace();
    }
  }
  return client;
}
项目:diqube    文件:DefaultConnectionFactory.java   
private TTransport openTransport(RNodeAddress addr, SocketListener socketListener) throws ConnectionException {
  if (addr.isSetHttpAddr()) {
    try {
      // TODO #32: Integrate SocketListener into HTTP connections.
      return new THttpClient(addr.getHttpAddr().getUrl());
    } catch (TTransportException e) {
      throw new ConnectionException("Could not open connection to " + addr, e);
    }
  }

  TTransport transport = new DiqubeClientSocket(addr.getDefaultAddr().getHost(), addr.getDefaultAddr().getPort(),
      socketTimeout, socketListener);
  return new TFramedTransport(transport);
}
项目:hbase    文件:HttpDoAsClient.java   
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;
}
项目:ThriftBook    文件:ThriftClient.java   
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();
    }
}
项目:airavata    文件:AuroraSchedulerClientFactory.java   
/**
 * Gets the t protocol.
 *
 * @param connectionUrl the connection url
 * @param connectionTimeout the connection timeout
 * @return the t protocol
 * @throws Exception the exception
 */
private static TProtocol getTProtocol(String connectionUrl, int connectionTimeout) throws Exception {
    try {
        THttpClient client = new THttpClient(connectionUrl);
        client.setConnectTimeout(connectionTimeout);

        TTransport transport = client;
        transport.open();
        TProtocol protocol = new TJSONProtocol(transport);
        return protocol;
    } catch(Exception ex) {
        logger.error(ex.getMessage(), ex);
        throw ex;
    }
}
项目:framework    文件:ThriftClientInterceptor.java   
protected TTransport getTransport() throws TTransportException {
    return new THttpClient(getServiceUrl(), httpClientUtil.getHttpClient());
}
项目:Mastering-Mesos    文件:HttpSecurityIT.java   
private AuroraAdmin.Client getClient(HttpClient httpClient) throws TTransportException {
  final TTransport httpClientTransport = new THttpClient(formatUrl(API_PATH), httpClient);
  addTearDown(httpClientTransport::close);
  return new AuroraAdmin.Client(new TJSONProtocol(httpClientTransport));
}
项目:sw360rest    文件:Sw360ProjectService.java   
private ProjectService.Iface getThriftProjectClient() throws TTransportException {
    THttpClient thriftClient = new THttpClient(thriftServerUrl + "/projects/thrift");
    TProtocol protocol = new TCompactProtocol(thriftClient);
    return new ProjectService.Client(protocol);
}
项目:sw360rest    文件:Sw360LicenseService.java   
private LicenseService.Iface getThriftLicenseClient() throws TTransportException {
    THttpClient thriftClient = new THttpClient(thriftServerUrl + "/licenses/thrift");
    TProtocol protocol = new TCompactProtocol(thriftClient);
    return new LicenseService.Client(protocol);
}
项目:sw360rest    文件:Sw360ReleaseService.java   
private ComponentService.Iface getThriftComponentClient() throws TTransportException {
    THttpClient thriftClient = new THttpClient(thriftServerUrl + "/components/thrift");
    TProtocol protocol = new TCompactProtocol(thriftClient);
    return new ComponentService.Client(protocol);
}
项目:sw360rest    文件:Sw360UserService.java   
private UserService.Iface getThriftUserClient() throws TTransportException {
    THttpClient thriftClient = new THttpClient(thriftServerUrl + "/users/thrift");
    TProtocol protocol = new TCompactProtocol(thriftClient);
    return new UserService.Client(protocol);
}
项目:sw360rest    文件:Sw360AttachmentService.java   
private ComponentService.Iface getThriftComponentClient() throws TTransportException {
    THttpClient thriftClient = new THttpClient(thriftServerUrl + "/components/thrift");
    TProtocol protocol = new TCompactProtocol(thriftClient);
    return new ComponentService.Client(protocol);
}
项目:sw360rest    文件:Sw360ComponentService.java   
private ComponentService.Iface getThriftComponentClient() throws TTransportException {
    THttpClient thriftClient = new THttpClient(thriftServerUrl + "/components/thrift");
    TProtocol protocol = new TCompactProtocol(thriftClient);
    return new ComponentService.Client(protocol);
}
项目:sw360rest    文件:Sw360VendorService.java   
private VendorService.Iface getThriftVendorClient() throws TTransportException {
    THttpClient thriftClient = new THttpClient(thriftServerUrl + "/vendors/thrift");
    TProtocol protocol = new TCompactProtocol(thriftClient);
    return new VendorService.Client(protocol);
}
项目:spring-remoting-thrift    文件:ThriftClientInterceptor.java   
protected TTransport getTransport() throws TTransportException {
    return new THttpClient(getServiceUrl(), httpClientUtil.getHttpClient());
}
项目:LineAPI4J    文件:LineApiImpl.java   
@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;
}
项目:LineAPI4J    文件:LineApiImpl.java   
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);
}
项目:LineAPI4J    文件:LineApiImpl.java   
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();
}
项目:mondo-collab-framework    文件:OfflineLensLocalDaemonInvoker.java   
public static TTransport openTransportForClient(String portAndAlias) throws TTransportException {
    final THttpClient transport = new THttpClient(getURLForPortAndAlias(portAndAlias));
    transport.open();       
    return transport;
}
项目:spring-thrift-api-gateway    文件:TGreetingServiceHandlerTests.java   
public void setUp() throws Exception {
    TTransport transport = new THttpClient("http://localhost:" + port + "/greetings/api");

    TProtocol protocol = protocolFactory.getProtocol(transport);

    client = new TGreetingExternalService.Client(protocol);
}