Example usage for org.apache.thrift.transport THttpClient setCustomHeader

List of usage examples for org.apache.thrift.transport THttpClient setCustomHeader

Introduction

In this page you can find the example usage for org.apache.thrift.transport THttpClient setCustomHeader.

Prototype

public void setCustomHeader(String key, String value) 

Source Link

Usage

From source file:boxalino.client.SDK.BxClient.java

private Client getP13n(int timeout, boolean useCurlIfAvailable) throws IOException,
        UnsupportedEncodingException, TTransportException, URISyntaxException, MalformedURLException {
    try {/*  w  w w  .  ja v  a2s .c  om*/
        //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:com.sudios714.cfevernote.CFEvernote.java

License:Open Source License

/************************************************
 *                methods                       *
 ***********************************************/
private boolean initialize() throws Exception {

    //setup the userstore
    THttpClient userStoreTrans = new THttpClient(this.userStoreURL);

    userStoreTrans.setCustomHeader("User-Agent", this.userAgent);

    TBinaryProtocol userStoreProt = new TBinaryProtocol(userStoreTrans);

    setUserStore(new UserStore.Client(userStoreProt, userStoreProt));

    // Check that we can talk to the server
    boolean versionOk = userStore.checkVersion(this.userAgent, VERSION_MAJOR, VERSION_MINOR);

    if (!versionOk) {
        return false;
    }/*from   www.j av a2  s .  c  o  m*/

    // Set up the NoteStore client 
    String noteStoreUrl = this.noteStoreURLBase + this.getShard();

    THttpClient noteStoreTrans = new THttpClient(noteStoreUrl);
    noteStoreTrans.setCustomHeader("User-Agent", this.userAgent);

    TBinaryProtocol noteStoreProt = new TBinaryProtocol(noteStoreTrans);

    this.setNoteStore(new NoteStore.Client(noteStoreProt, noteStoreProt));

    return true;
}

From source file:org.apache.hadoop.hbase.thrift.HttpDoAsClient.java

License:Apache License

private Hbase.Client refresh(Hbase.Client client, THttpClient httpClient) {
    httpClient.setCustomHeader("doAs", doAsUser);
    if (secure) {
        try {//  w  w  w. j a  v  a2s. c o  m
            httpClient.setCustomHeader("Authorization", generateTicket());
        } catch (GSSException e) {
            e.printStackTrace();
        }
    }
    return client;
}

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();//from  w w w  .  jav a  2  s .  c  om

    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);
        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.simbasecurity.manager.service.rest.BaseRESTService.java

License:Apache License

T cl(String ssoToken) throws TException {
    THttpClient tHttpClient = new THttpClient(serviceURL);
    tHttpClient.setCustomHeader("Cookie", SIMBA_SSO_TOKEN + "=" + ssoToken);
    TProtocol tProtocol = new TJSONProtocol(tHttpClient);
    return clientFactory.getClient(tProtocol);
}