List of usage examples for org.apache.thrift.transport THttpClient THttpClient
public THttpClient(String url) throws TTransportException
From source file:MapDExample.java
License:Apache License
public static MapD.Client get_client(String host_or_uri, int port, boolean http) { THttpClient httpTransport;//from w w w .java 2 s . c o m TTransport transport; 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 {/* w w w . j a va2 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:com.facebook.buck.distributed.ThriftOverHttp.java
License:Apache License
public ThriftOverHttp(String uri, Encoding type) throws TTransportException { transport = new THttpClient(uri); transport.setReadTimeout(READ_TIMEOUT_MS); transport.setCustomHeader("X-Thrift-Protocol", type.toString()); transport.open();/* w w w.jav a 2 s . c om*/ switch (type) { case json: proto = new TJSONProtocol(transport); break; case compact: proto = new TCompactProtocol(transport); break; case binary: default: proto = new TBinaryProtocol(transport); break; } }
From source file:com.mapd.jdbc.MapDConnection.java
License:Apache License
public MapDConnection(String url, Properties info) throws SQLException { //logger.debug("Entered"); this.url = url; this.properties = info; this.user = info.getProperty("user"); boolean http_session = false; //logger.debug("We got to here " + url + " info: " + info.toString()); String[] temp = url.split(":"); //for (int i = 0; i < temp.length; i++) { // logger.debug("temp " + i + " " + temp[i].toString()); //}/* w ww. j a v a 2 s . c om*/ String machine = temp[2]; // deal with requirement that there may be double // before the machine if (machine.startsWith("//")) { machine = machine.substring(2); } //logger.debug("machine : " + machine); int port = Integer.valueOf(temp[3]); this.catalog = temp[4]; //test for http protocol request (we could consider using properties) if (temp.length == 6) { if (temp[5].equals("http")) { http_session = true; } else { throw new SQLException("Connection failed invalid protocol option- " + temp[5]); } } try { TProtocol protocol = null; if (http_session) { transport = new THttpClient("http://" + machine + ":" + port); transport.open(); protocol = new TJSONProtocol(transport); } else { transport = new TSocket(machine, port); transport.open(); protocol = new TBinaryProtocol(transport); } client = new MapD.Client(protocol); session = client.connect(info.getProperty("user"), info.getProperty("password"), this.catalog); logger.debug("Connected session is " + session); } catch (TTransportException ex) { throw new SQLException("Connection failed - " + ex.toString()); } catch (TMapDException ex) { throw new SQLException("Connection failed - " + ex.toString()); } catch (TException ex) { throw new SQLException("Connection failed - " + ex.toString()); } }
From source file:com.mapd.logrunner.LogRunner.java
License:Apache License
private MapD.Client getClient(String hostname, int port) throws TTransportException { TTransport transport = null;//w w w .j a va 2 s . c o m //transport = new TSocket("localhost", 9091); transport = new THttpClient("http://" + hostname + ":" + port); transport.open(); //TProtocol protocol = new TBinaryProtocol(transport); TProtocol protocol = new TJSONProtocol(transport); //TProtocol protocol = new TProtocol(transport); return new MapD.Client(protocol); }
From source file:com.navercorp.pinpoint.plugin.thrift.common.client.HttpEchoTestClient.java
License:Apache License
public static HttpEchoTestClient create(TestEnvironment environment) throws TTransportException { return new HttpEchoTestClient(environment, new THttpClient(environment.getHttpUrl())); }
From source file:com.rubenlaguna.en4j.sync.EvernoteProtocolUtil.java
License:Open Source License
private NoteStore.Client getValidNoteStore() throws TTransportException, EDAMUserException, EDAMSystemException, TException { if (isAboutToExpire()) { // Set up the NoteStore AuthenticationResult authResult = getValidAuthenticationResult(); if (null == noteStoreUrl.get()) { //noteStoreUrl must be cached because we don't get a User in //from refreshAuthentication User user = authResult.getUser(); noteStoreUrl.set(noteStoreUrlBase + user.getShardId()); }/*from w ww . ja v a2 s. co m*/ THttpClient noteStoreTrans = new THttpClient(noteStoreUrl.get()); noteStoreTrans.setConnectTimeout(30000); //30s noteStoreTrans.setReadTimeout(180 * 1000);//180s TBinaryProtocol noteStoreProt = new TBinaryProtocol(noteStoreTrans); currentNoteStore.set(new NoteStore.Client(noteStoreProt, noteStoreProt)); } return currentNoteStore.get(); }
From source file:com.rubenlaguna.en4j.sync.EvernoteProtocolUtil.java
License:Open Source License
private UserStore.Client getUserStore() throws TTransportException { if (null == currentUserStore.get()) { THttpClient userStoreTrans = new THttpClient(userStoreUrl); TBinaryProtocol userStoreProt = new TBinaryProtocol(userStoreTrans); currentUserStore.set(new UserStore.Client(userStoreProt, userStoreProt)); }//from w ww . ja va 2 s .c o m return currentUserStore.get(); }
From source file:com.siemens.sw360.attachments.TestAttachmentClient.java
License:Open Source License
public static void main(String[] args) throws TException, IOException { THttpClient thriftClient = new THttpClient("http://127.0.0.1:8080/attachmentservice/thrift"); TProtocol protocol = new TCompactProtocol(thriftClient); AttachmentService.Iface client = new AttachmentService.Client(protocol); System.out.println(client.getDatabaseAddress().toString()); }
From source file:com.siemens.sw360.components.TestComponentClient.java
License:Open Source License
public static void main(String[] args) throws TException, IOException { THttpClient thriftClient = new THttpClient("http://127.0.0.1:8080/components/thrift"); TProtocol protocol = new TCompactProtocol(thriftClient); ComponentService.Iface client = new ComponentService.Client(protocol); // List<Component> components = client.getComponentSummary(user); // List<Component> recentComponents = client.getRecentComponents(); // List<Release> releases = client.getReleaseSummary(user); ////from w w w . j a va2 s . c o m // System.out.println("Fetched " + components.size() + " components from license service"); // System.out.println("Fetched " + releases.size() + " releases from license service"); // System.out.println("Fetched " + recentComponents.size() + " recent components from license service"); // // String referenceId =null; // for (Component component : recentComponents) { // if(referenceId==null) referenceId=component.getId(); // System.out.println(component.getId() + ": " + component.getName()); // } // // if(referenceId!=null) { // System.out.println(client.getComponentById(referenceId, user).toString()); // Component component = new ComponentHandler("http://localhost:5984", "sw360db", "sw360attachments").getComponentById(referenceId, user); // System.out.println(component.toString()); // System.out.println(client.getComponentById(referenceId, user).toString()); // } // // for(Release release : releases) { // System.out.println(release.toString()); // } // // This fails with a thrift error... debug! // if(releases.size()>0) { // String releaseNameStart = releases.get(0).getName().substring(0,1); // System.out.println("The following releases start with " + releaseNameStart ); // // List<Release> releases1 = client.searchReleaseByName(releaseNameStart); // for(Release release : releases1) { // System.out.println(release.toString()); // } // // } // final Component cpe = client.getComponentForReportFromCPEId("cpe"); // System.out.println(cpe.toString()); }