Search in sources :

Example 1 with BasicHttpEntityEnclosingRequest

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));
}
Also used : BasicHttpEntityEnclosingRequest(org.apache.http.message.BasicHttpEntityEnclosingRequest) InputStreamEntity(org.apache.http.entity.InputStreamEntity)

Example 2 with BasicHttpEntityEnclosingRequest

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));
}
Also used : BasicHttpEntityEnclosingRequest(org.apache.http.message.BasicHttpEntityEnclosingRequest) InputStreamEntity(org.apache.http.entity.InputStreamEntity)

Example 3 with BasicHttpEntityEnclosingRequest

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;
}
Also used : HttpCommandExecutor(org.openqa.selenium.remote.HttpCommandExecutor) JSONObject(org.json.JSONObject) HttpHost(org.apache.http.HttpHost) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) URL(java.net.URL) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) JSONException(org.json.JSONException) TimeoutException(org.openqa.selenium.TimeoutException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BindException(java.net.BindException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) BasicHttpEntityEnclosingRequest(org.apache.http.message.BasicHttpEntityEnclosingRequest)

Example 4 with BasicHttpEntityEnclosingRequest

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;
}
Also used : HttpCommandExecutor(org.openqa.selenium.remote.HttpCommandExecutor) JSONObject(org.json.JSONObject) HttpHost(org.apache.http.HttpHost) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) URL(java.net.URL) JSONException(org.json.JSONException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) BasicHttpEntityEnclosingRequest(org.apache.http.message.BasicHttpEntityEnclosingRequest)

Example 5 with BasicHttpEntityEnclosingRequest

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;
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpHost(org.apache.http.HttpHost) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException) BasicHttpEntityEnclosingRequest(org.apache.http.message.BasicHttpEntityEnclosingRequest)

Aggregations

BasicHttpEntityEnclosingRequest (org.apache.http.message.BasicHttpEntityEnclosingRequest)23 IOException (java.io.IOException)13 HttpHost (org.apache.http.HttpHost)10 URL (java.net.URL)8 JSONException (org.json.JSONException)8 JSONObject (org.json.JSONObject)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 GeneralSecurityException (java.security.GeneralSecurityException)6 HttpResponse (org.apache.http.HttpResponse)6 InetSocketAddress (java.net.InetSocketAddress)5 Socket (java.net.Socket)5 SSLContext (javax.net.ssl.SSLContext)5 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)5 InputStreamEntity (org.apache.http.entity.InputStreamEntity)5 Calendar (java.util.Calendar)4 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)4 DefaultHttpClientConnection (org.apache.http.impl.DefaultHttpClientConnection)4 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)4 BasicHttpParams (org.apache.http.params.BasicHttpParams)4 HttpParams (org.apache.http.params.HttpParams)4