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

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

Introduction

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

Prototype

public static RequestBuilder put() 

Source Link

Usage

From source file:org.keycloak.authorization.client.util.Http.java

public <R> HttpMethod<R> put(String path) {
    return method(RequestBuilder.put().setUri(path));
}

From source file:org.dasein.cloud.qingcloud.util.requester.QingCloudRequestBuilder.java

public static QingCloudRequestBuilder put(QingCloud qingCloud) {
    return new QingCloudRequestBuilder(qingCloud, RequestBuilder.put());
}

From source file:cf.spring.servicebroker.ServiceBrokerErrorHandlingTest.java

@Test
public void returnsErrorMessage() throws Exception {
    final ServiceBrokerHandler.ProvisionBody provisionBody = new ServiceBrokerHandler.ProvisionBody(BROKER_ID,
            PLAN_ID, UUID.randomUUID(), UUID.randomUUID());
    final HttpUriRequest provisionRequest = RequestBuilder.put()
            .setUri("http://localhost:8080/v2/service_instances/" + UUID.randomUUID())
            .setEntity(new StringEntity(mapper.writeValueAsString(provisionBody), ContentType.APPLICATION_JSON))
            .build();//www.  ja  va 2s .c  om
    final CloseableHttpResponse provisionResponse = client.execute(provisionRequest);
    assertEquals(provisionResponse.getStatusLine().getStatusCode(), HTTP_RESPONSE_CODE);
    final JsonNode responseJson = mapper.readTree(provisionResponse.getEntity().getContent());

    assertTrue(responseJson.has("description"));
    assertEquals(responseJson.get("description").asText(), HTTP_RESPONSE_MESSAGE);
}

From source file:edu.mit.scratch.ScratchProjectManager.java

@NotWorking
public void toggleCommentsEnabled() throws ScratchProjectException {
    final RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.DEFAULT).build();

    final CookieStore cookieStore = new BasicCookieStore();
    final BasicClientCookie lang = new BasicClientCookie("scratchlanguage", "en");
    final BasicClientCookie sessid = new BasicClientCookie("scratchsessionsid", this.session.getSessionID());
    final BasicClientCookie token = new BasicClientCookie("scratchcsrftoken", this.session.getCSRFToken());
    final BasicClientCookie debug = new BasicClientCookie("DEBUG", "true");
    lang.setDomain(".scratch.mit.edu");
    lang.setPath("/");
    sessid.setDomain(".scratch.mit.edu");
    sessid.setPath("/");
    token.setDomain(".scratch.mit.edu");
    token.setPath("/");
    debug.setDomain(".scratch.mit.edu");
    debug.setPath("/");
    cookieStore.addCookie(lang);/* w ww. jav a  2s  . c o  m*/
    cookieStore.addCookie(sessid);
    cookieStore.addCookie(token);
    cookieStore.addCookie(debug);

    final CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(globalConfig)
            .setUserAgent(Scratch.USER_AGENT).setDefaultCookieStore(cookieStore).build();
    CloseableHttpResponse resp;

    final HttpUriRequest update = RequestBuilder.put()
            .setUri("https://scratch.mit.edu/site-api/comments/project/" + this.getProjectID()
                    + "/toggle-comments/")
            .addHeader("Accept", "*/*")
            .addHeader("Referer", "https://scratch.mit.edu/projects/" + this.getProjectID() + "/")
            .addHeader("Origin", "https://scratch.mit.edu/").addHeader("Accept-Encoding", "gzip, deflate, sdch")
            .addHeader("Accept-Language", "en-US,en;q=0.8").addHeader("Content-Type", "application/json")
            .addHeader("X-Requested-With", "XMLHttpRequest")
            .addHeader("Cookie",
                    "scratchsessionsid=" + this.session.getSessionID() + "; scratchcsrftoken="
                            + this.session.getCSRFToken())
            .addHeader("X-CSRFToken", this.session.getCSRFToken()).build();
    try {
        resp = httpClient.execute(update);
        System.out.println("current status:" + resp.getStatusLine().getStatusCode());
        if (resp.getStatusLine().getStatusCode() != 200)
            throw new ScratchProjectException();
        final BufferedReader rd = new BufferedReader(new InputStreamReader(resp.getEntity().getContent()));

        final StringBuffer result = new StringBuffer();
        String line = "";
        while ((line = rd.readLine()) != null)
            result.append(line);

        System.out.println(result);
    } catch (final IOException e) {
        e.printStackTrace();
        throw new ScratchProjectException();
    }
}

From source file:cf.spring.servicebroker.ServiceBrokerErrorHandlingTest.java

@Test
public void handlesUnexpectedException() throws Exception {
    final ServiceBrokerHandler.BindBody bindBody = new ServiceBrokerHandler.BindBody(BROKER_ID, PLAN_ID,
            UUID.randomUUID());//from  w  w  w.  ja v  a 2  s.c om
    final HttpUriRequest bindRequest = RequestBuilder.put()
            .setUri("http://localhost:8080/v2/service_instances/" + UUID.randomUUID() + "/service_bindings/"
                    + UUID.randomUUID())
            .setEntity(new StringEntity(mapper.writeValueAsString(bindBody), ContentType.APPLICATION_JSON))
            .build();
    final CloseableHttpResponse bindResponse = client.execute(bindRequest);
    assertEquals(bindResponse.getStatusLine().getStatusCode(), 500);
    final JsonNode responseJson = mapper.readTree(bindResponse.getEntity().getContent());

    assertTrue(responseJson.has("description"));
    assertEquals(responseJson.get("description").asText(), BINDING_ERROR);
}

From source file:org.eclipse.vorto.repository.RestClient.java

@SuppressWarnings("restriction")
public void executePut(String query) throws ClientProtocolException, IOException {
    CloseableHttpClient client = HttpClients.custom().build();

    HttpUriRequest request = RequestBuilder.put().setConfig(createProxyConfiguration())
            .setUri(createQuery(query)).addHeader(createSecurityHeader()).build();
    client.execute(request);//from w  w  w  .j a  v  a2 s. com
}

From source file:edu.mit.scratch.ScratchUser.java

public void setFollowing(final ScratchSession session, final boolean following) throws ScratchUserException {
    try {/*from  w ww  .ja  v a 2s .c o  m*/
        final RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.DEFAULT).build();

        final BasicCookieStore cookieStore = new BasicCookieStore();
        final BasicClientCookie lang = new BasicClientCookie("scratchlanguage", "en");
        final BasicClientCookie sessionid = new BasicClientCookie("scratchsessionsid", session.getSessionID());
        final BasicClientCookie token = new BasicClientCookie("scratchcsrftoken", session.getCSRFToken());
        final BasicClientCookie debug = new BasicClientCookie("DEBUG", "true");
        lang.setDomain(".scratch.mit.edu");
        lang.setPath("/");
        sessionid.setDomain(".scratch.mit.edu");
        sessionid.setPath("/");
        token.setDomain(".scratch.mit.edu");
        token.setPath("/");
        debug.setDomain(".scratch.mit.edu");
        debug.setPath("/");
        cookieStore.addCookie(lang);
        cookieStore.addCookie(sessionid);
        cookieStore.addCookie(token);
        cookieStore.addCookie(debug);

        final CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(globalConfig)
                .setUserAgent(Scratch.USER_AGENT).setDefaultCookieStore(cookieStore).build();
        CloseableHttpResponse resp;

        final HttpUriRequest update = RequestBuilder.put()
                .setUri("https://scratch.mit.edu/site-api/users/followers/" + this.getUsername() + "/"
                        + ((following) ? "add" : "remove") + "/?usernames=" + session.getUsername())
                .addHeader("Accept", "application/json, text/javascript, */*; q=0.01")
                .addHeader("Referer", "https://scratch.mit.edu/users/" + this.getUsername() + "/")
                .addHeader("Origin", "https://scratch.mit.edu")
                .addHeader("Accept-Encoding", "gzip, deflate, sdch")
                .addHeader("Accept-Language", "en-US,en;q=0.8").addHeader("Content-Type", "application/json")
                .addHeader("Content-Encoding", "gzip").addHeader("X-Requested-With", "XMLHttpRequest")
                .addHeader("Cookie",
                        "scratchsessionsid=" + session.getSessionID() + "; scratchcsrftoken="
                                + session.getCSRFToken())
                .addHeader("X-CSRFToken", session.getCSRFToken()).build();
        try {
            resp = httpClient.execute(update);
            if (resp.getStatusLine().getStatusCode() != 200)
                throw new ScratchUserException();
        } catch (final Exception e) {
            e.printStackTrace();
            throw new ScratchUserException();
        }

        BufferedReader rd;
        try {
            rd = new BufferedReader(new InputStreamReader(resp.getEntity().getContent()));
        } catch (UnsupportedOperationException | IOException e) {
            e.printStackTrace();
            throw new ScratchUserException();
        }

        final StringBuffer result = new StringBuffer();
        String line = "";
        while ((line = rd.readLine()) != null)
            result.append(line);
        // result = your json data
    } catch (final UnsupportedEncodingException e) {
        e.printStackTrace();
        throw new ScratchUserException();
    } catch (final IOException e) {
        e.printStackTrace();
        throw new ScratchUserException();
    }
}

From source file:com.esri.geoevent.test.performance.provision.GeoEventProvisioner.java

private void uploadConfiguration() throws IOException {
    System.out.print(ImplMessages.getMessage("PROVISIONER_UPLOADING_CONFIG_MSG"));
    // String url = "https://"+hostname+":"+6143+"/geoevent/admin/configuration/install/.json";
    String url = "https://" + hostName + ":" + 6143 + "/geoevent/admin/configuration/.json";

    File configAsFile = new File(configFile);

    CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(getSSLSocketFactory()).build();
    FileEntity file = new FileEntity(configAsFile, ContentType.APPLICATION_XML);
    HttpUriRequest post = RequestBuilder.put().setUri(url).addHeader("GeoEventAuthorization", token)
            .addHeader("referer", referer).setEntity(file).build();

    HttpResponse response = httpClient.execute(post);
    HttpEntity entity = response.getEntity();
    ObjectMapper mapper = new ObjectMapper();
    @SuppressWarnings("unused")
    JsonNode jsonResponse = mapper.readTree(entity.getContent());
    sleep(10 * 1000);/*from www. ja  v a  2s. c  o m*/
    System.out.println(ImplMessages.getMessage("DONE"));
}

From source file:cf.spring.servicebroker.ServiceBrokerTest.java

@Test
public void bind() throws Exception {
    final AtomicInteger bindCounter = context.getBean("bindCounter", AtomicInteger.class);
    assertEquals(bindCounter.get(), 0);//from  www.j a va 2  s .  c  o m
    // Do bind
    final ServiceBrokerHandler.BindBody bindBody = new ServiceBrokerHandler.BindBody(BROKER_ID_STATIC, PLAN_ID,
            APPLICATION_GUID);
    final HttpUriRequest bindRequest = RequestBuilder.put().setUri(bindingUri)
            .setEntity(new StringEntity(mapper.writeValueAsString(bindBody), ContentType.APPLICATION_JSON))
            .build();
    final CloseableHttpResponse bindResponse = client.execute(bindRequest);
    assertEquals(bindResponse.getStatusLine().getStatusCode(), 201);
    assertEquals(bindCounter.get(), 1);
    final JsonNode bindResponseJson = mapper.readTree(bindResponse.getEntity().getContent());
    assertTrue(bindResponseJson.has("credentials"));
    assertFalse(bindResponseJson.has("syslog_drain_url"));

    final JsonNode credentials = bindResponseJson.get("credentials");
    assertEquals(credentials.get("username").asText(), SOME_USERNAME);
    assertEquals(credentials.get("password").asText(), SOME_PASSWORD);
}

From source file:edu.mit.scratch.ScratchProject.java

public void setLoved(final ScratchSession session, final boolean loved) throws ScratchProjectException {
    final RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.DEFAULT).build();

    final CookieStore cookieStore = new BasicCookieStore();
    final BasicClientCookie lang = new BasicClientCookie("scratchlanguage", "en");
    final BasicClientCookie sessid = new BasicClientCookie("scratchsessionsid", session.getSessionID());
    final BasicClientCookie token = new BasicClientCookie("scratchcsrftoken", session.getCSRFToken());
    final BasicClientCookie debug = new BasicClientCookie("DEBUG", "true");
    lang.setDomain(".scratch.mit.edu");
    lang.setPath("/");
    sessid.setDomain(".scratch.mit.edu");
    sessid.setPath("/");
    token.setDomain(".scratch.mit.edu");
    token.setPath("/");
    debug.setDomain(".scratch.mit.edu");
    debug.setPath("/");
    cookieStore.addCookie(lang);/* www.j av  a2 s.c o  m*/
    cookieStore.addCookie(sessid);
    cookieStore.addCookie(token);
    cookieStore.addCookie(debug);

    final CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(globalConfig)
            .setUserAgent("Mozilla/5.0 (Windows NT 6.1; WOW64)"
                    + " AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/" + "537.36")
            .setDefaultCookieStore(cookieStore).build();
    CloseableHttpResponse resp;

    final HttpUriRequest update = RequestBuilder.put()
            .setUri("https://scratch.mit.edu/site-api/users/lovers/" + this.getProjectID() + "/"
                    + (loved ? "add" : "remove") + "/?usernames=" + session.getUsername())
            .addHeader("Accept", "application/json, text/javascript, */*; q=0.01").addHeader("DNT", "1")
            .addHeader("Referer", "https://scratch.mit.edu/projects/" + this.getProjectID() + "/")
            .addHeader("Origin", "https://scratch.mit.edu/").addHeader("Accept-Encoding", "gzip, deflate, sdch")
            .addHeader("Accept-Language", "en-US,en;q=0.8").addHeader("Content-Type", "application/json")
            .addHeader("X-Requested-With", "XMLHttpRequest").addHeader("Cookie", "scratchsessionsid="
                    + session.getSessionID() + "; scratchcsrftoken=" + session.getCSRFToken())
            .addHeader("X-CSRFToken", session.getCSRFToken()).build();
    try {
        resp = httpClient.execute(update);
        if (resp.getStatusLine().getStatusCode() != 200)
            throw new ScratchProjectException();
        final BufferedReader rd = new BufferedReader(new InputStreamReader(resp.getEntity().getContent()));

        final StringBuffer result = new StringBuffer();
        String line = "";
        while ((line = rd.readLine()) != null)
            result.append(line);
    } catch (final IOException e) {
        e.printStackTrace();
        throw new ScratchProjectException();
    }

    BufferedReader rd;
    try {
        rd = new BufferedReader(new InputStreamReader(resp.getEntity().getContent()));
    } catch (UnsupportedOperationException | IOException e) {
        e.printStackTrace();
        throw new ScratchProjectException();
    }
}