Example usage for org.apache.http.client.methods RequestBuilder post

List of usage examples for org.apache.http.client.methods RequestBuilder post

Introduction

In this page you can find the example usage for org.apache.http.client.methods RequestBuilder post.

Prototype

public static RequestBuilder post() 

Source Link

Usage

From source file:org.bonitasoft.connectors.rest.RESTConnector.java

/**
 * Generate a request builder based on the given method
 * /*from w w w .j  av a 2  s.c  o  m*/
 * @param method The method
 * @return The request builder
 */
private RequestBuilder getRequestBuilderFromMethod(final HTTPMethod method) {
    switch (method) {
    case GET:
        return RequestBuilder.get();
    case POST:
        return RequestBuilder.post();
    case PUT:
        return RequestBuilder.put();
    case DELETE:
        return RequestBuilder.delete();
    default:
        throw new IllegalStateException(
                "Impossible to get the RequestBuilder from the \"" + method.name() + "\" name.");
    }
}

From source file:org.apache.hadoop.yarn.server.resourcemanager.security.TestHopsworksRMAppSecurityActions.java

private Pair<String, String[]> loginAndGetJWT() throws Exception {
    CloseableHttpClient client = null;//from  w  w  w. j av a 2s.c  o m
    try {
        SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
        sslContextBuilder.loadTrustMaterial(new TrustStrategy() {
            @Override
            public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
                return true;
            }
        });
        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContextBuilder.build(),
                NoopHostnameVerifier.INSTANCE);

        client = HttpClients.custom().setSSLSocketFactory(sslSocketFactory).build();
        URL loginURL = new URL(new URL(HOPSWORKS_ENDPOINT), HOPSWORKS_LOGIN_PATH);
        HttpUriRequest login = RequestBuilder.post().setUri(loginURL.toURI())
                .addParameter("email", HOPSWORKS_USER).addParameter("password", HOPSWORKS_PASSWORD).build();
        CloseableHttpResponse response = client.execute(login);
        Assert.assertNotNull(response);
        Assert.assertEquals(200, response.getStatusLine().getStatusCode());
        Header[] authHeaders = response.getHeaders(HttpHeaders.AUTHORIZATION);

        String masterJWT = null;
        for (Header h : authHeaders) {
            Matcher matcher = HopsworksRMAppSecurityActions.JWT_PATTERN.matcher(h.getValue());
            if (matcher.matches()) {
                masterJWT = matcher.group(1);
            }
        }
        JsonParser jsonParser = new JsonParser();
        JsonObject json = jsonParser.parse(EntityUtils.toString(response.getEntity())).getAsJsonObject();
        JsonArray array = json.getAsJsonArray("renewTokens");
        String[] renewTokens = new String[array.size()];
        boolean renewalTokensFound = false;
        for (int i = 0; i < renewTokens.length; i++) {
            renewTokens[i] = array.get(i).getAsString();
            renewalTokensFound = true;
        }
        if (masterJWT != null && renewalTokensFound) {
            return new Pair<>(masterJWT, renewTokens);
        }

        throw new IOException("Could not get JWT from Hopsworks");
    } finally {
        if (client != null) {
            client.close();
        }
    }
}

From source file:org.jboss.javadoc.PostFile.java

public PostFile(final String fullUrl, final File file, final String username, final String password) {
    this.httppost = new HttpPost(fullUrl);
    this.filePath = file;
    this.mpEntityBuilder = MultipartEntityBuilder.create();
    this.username = username;
    this.password = password;

    requestBuilderPost = RequestBuilder.post();
    requestBuilderPost.setUri(fullUrl);//w w  w .ja  v a  2  s .  c  o  m

}