use of org.apache.http.message.BasicHttpEntityEnclosingRequest in project android_frameworks_base by ParanoidAndroid.
the class Request method setBodyProvider.
/**
* Supply an InputStream that provides the body of a request. It's
* not great that the caller must also provide the length of the data
* returned by that InputStream, but the client needs to know up
* front, and I'm not sure how to get this out of the InputStream
* itself without a costly readthrough. I'm not sure skip() would
* do what we want. If you know a better way, please let me know.
*/
private void setBodyProvider(InputStream bodyProvider, int bodyLength) {
if (!bodyProvider.markSupported()) {
throw new IllegalArgumentException("bodyProvider must support mark()");
}
// Mark beginning of stream
bodyProvider.mark(Integer.MAX_VALUE);
((BasicHttpEntityEnclosingRequest) mHttpRequest).setEntity(new InputStreamEntity(bodyProvider, bodyLength));
}
use of org.apache.http.message.BasicHttpEntityEnclosingRequest in project XobotOS by xamarin.
the class Request method setBodyProvider.
/**
* Supply an InputStream that provides the body of a request. It's
* not great that the caller must also provide the length of the data
* returned by that InputStream, but the client needs to know up
* front, and I'm not sure how to get this out of the InputStream
* itself without a costly readthrough. I'm not sure skip() would
* do what we want. If you know a better way, please let me know.
*/
private void setBodyProvider(InputStream bodyProvider, int bodyLength) {
if (!bodyProvider.markSupported()) {
throw new IllegalArgumentException("bodyProvider must support mark()");
}
// Mark beginning of stream
bodyProvider.mark(Integer.MAX_VALUE);
((BasicHttpEntityEnclosingRequest) mHttpRequest).setEntity(new InputStreamEntity(bodyProvider, bodyLength));
}
use of org.apache.http.message.BasicHttpEntityEnclosingRequest in project selenium_java by sergueik.
the class App method getIPOfNode.
@SuppressWarnings("deprecation")
private static String getIPOfNode(RemoteWebDriver remoteDriver) {
String hostFound = null;
try {
HttpCommandExecutor ce = (HttpCommandExecutor) remoteDriver.getCommandExecutor();
String hostName = ce.getAddressOfRemoteServer().getHost();
int port = ce.getAddressOfRemoteServer().getPort();
HttpHost host = new HttpHost(hostName, port);
DefaultHttpClient client = new DefaultHttpClient();
URL sessionURL = new URL(String.format("http://%s:%d/grid/api/testsession?session=%s", hostName, port, remoteDriver.getSessionId()));
BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST", sessionURL.toExternalForm());
HttpResponse response = client.execute(host, r);
JSONObject object = extractObject(response);
URL myURL = new URL(object.getString("proxyId"));
if ((myURL.getHost() != null) && (myURL.getPort() != -1)) {
hostFound = myURL.getHost();
}
} catch (Exception e) {
// java.lang.ClassCastException:
// org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor cannot be
// cast to org.openqa.selenium.remote.HttpCommandExecutor
System.err.println(e);
}
return hostFound;
}
use of org.apache.http.message.BasicHttpEntityEnclosingRequest in project selenium_java by sergueik.
the class SessionTest method getIPOfNode.
private static int getIPOfNode(RemoteWebDriver driver) {
// default
int proxyPort = 5555;
try {
HttpCommandExecutor ce = (HttpCommandExecutor) driver.getCommandExecutor();
String hostName = ce.getAddressOfRemoteServer().getHost();
int hubPort = ce.getAddressOfRemoteServer().getPort();
HttpHost host = new HttpHost(hostName, hubPort);
@SuppressWarnings("deprecation") DefaultHttpClient client = new DefaultHttpClient();
URL sessionURL = new URL(String.format("http://%s:%d/grid/api/testsession?session=%s", hostName, hubPort, driver.getSessionId()));
System.err.println(sessionURL);
BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST", sessionURL.toExternalForm());
HttpResponse response = client.execute(host, r);
JSONObject object = extractObject(response);
URL myURL = new URL(object.getString("proxyId"));
if ((myURL.getHost() != null) && (myURL.getPort() != -1)) {
proxyPort = myURL.getPort();
}
} catch (Exception e) {
System.err.println(e);
}
System.err.println(proxyPort);
return proxyPort;
}
use of org.apache.http.message.BasicHttpEntityEnclosingRequest in project selenium_java by sergueik.
the class ActiveNodeDeterminer method getNodeInfoForSession.
/**
* @param sessionId - A {@link SessionId} object that represents a valid session.
* @return - A {@link GridNode} object that represents the node to which the session was routed to.
*/
public GridNode getNodeInfoForSession(SessionId sessionId) {
GridNode node = null;
CloseableHttpClient client = HttpClientBuilder.create().build();
CloseableHttpResponse response = null;
try {
URL url = new URL("http://" + gridHostName + ":" + gridPort + "/grid/api/testsession?session=" + sessionId);
BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST", url.toExternalForm());
response = client.execute(new HttpHost(gridHostName, gridPort), r);
JsonObject object = extractJson(response.getEntity());
URL tempUrl = new URL(object.get("proxyId").getAsString());
node = new GridNode(tempUrl.getHost(), tempUrl.getPort());
} catch (Exception e) {
String errorMsg = "Failed to acquire remote webdriver node and port info. Root cause: " + e.getMessage();
LOGGER.log(Level.SEVERE, errorMsg, e);
throw new RuntimeException(errorMsg, e);
} finally {
try {
if (response != null) {
response.close();
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
}
}
LOGGER.info("Session " + sessionId + " was routed to " + node.toString());
return node;
}
Aggregations