Example usage for com.google.common.net MediaType FORM_DATA

List of usage examples for com.google.common.net MediaType FORM_DATA

Introduction

In this page you can find the example usage for com.google.common.net MediaType FORM_DATA.

Prototype

MediaType FORM_DATA

To view the source code for com.google.common.net MediaType FORM_DATA.

Click Source Link

Usage

From source file:io.rebolt.http.converters.FormToJsonConverter.java

@Override
public String getContentType() {
    return MediaType.FORM_DATA.toString();
}

From source file:google.registry.tools.CreateOrUpdatePremiumListCommandTestCase.java

void verifySentParams(Connection connection, String path, ImmutableMap<String, String> parameterMap)
        throws Exception {
    verify(connection).send(eq(path), urlParamCaptor.capture(), eq(MediaType.FORM_DATA),
            requestBodyCaptor.capture());
    assertThat(new ImmutableMap.Builder<String, String>().putAll(urlParamCaptor.getValue())
            .putAll(UriParameters.parse(new String(requestBodyCaptor.getValue(), UTF_8)).entries()).build())
                    .containsExactlyEntriesIn(parameterMap);
}

From source file:google.registry.tools.EppToolVerifier.java

void verifySent(String... xmlToMatch) throws Exception {
    ArgumentCaptor<byte[]> params = ArgumentCaptor.forClass(byte[].class);
    verify(connection, times(xmlToMatch.length)).send(eq("/_dr/epptool"), eq(ImmutableMap.<String, Object>of()),
            eq(MediaType.FORM_DATA), params.capture());
    List<byte[]> capturedParams = params.getAllValues();
    assertThat(capturedParams).hasSize(xmlToMatch.length);
    for (int i = 0; i < xmlToMatch.length; i++) {
        String xml = xmlToMatch[i];
        byte[] capturedParam = capturedParams.get(i);
        Map<String, String> map = Splitter.on('&').withKeyValueSeparator('=')
                .split(new String(capturedParam, UTF_8));
        assertThat(map).hasSize(4);/*w  ww. jav  a 2s  . c  om*/
        assertXmlEquals(readResourceUtf8(getClass(), "testdata/" + xml),
                URLDecoder.decode(map.get("xml"), UTF_8.toString()));
        assertThat(map).containsEntry("dryRun", Boolean.toString(dryRun));
        assertThat(map).containsEntry("clientId", clientId);
        assertThat(map).containsEntry("superuser", Boolean.toString(superuser));
    }
}

From source file:io.rebolt.http.HttpRequest.java

public HttpRequest method(HttpMethod method) {
    this.method = method;
    if (Get != method && ObjectUtil.isEmpty(header.getContentType())) {
        header.addContentType(MediaType.FORM_DATA);
    }//from   w w  w . j a va  2 s  . c  o  m
    return this;
}

From source file:google.registry.tools.CreateOrUpdatePremiumListCommand.java

@Override
public String execute() throws Exception {
    ImmutableMap.Builder<String, Object> params = new ImmutableMap.Builder<>();
    params.put(NAME_PARAM, name);/*w ww .  j  a v a2s  .  co m*/
    String inputFileContents = new String(Files.readAllBytes(inputFile), UTF_8);
    String requestBody = Joiner.on('&').withKeyValueSeparator("=")
            .join(ImmutableMap.of(INPUT_PARAM, URLEncoder.encode(inputFileContents, UTF_8.toString())));

    ImmutableMap<String, ?> extraParams = getParameterMap();
    if (extraParams != null) {
        params.putAll(extraParams);
    }

    // Call the server and get the response data
    String response = connection.send(getCommandPath(), params.build(), MediaType.FORM_DATA,
            requestBody.getBytes());

    return extractServerResponse(response);
}

From source file:google.registry.tools.EppToolCommand.java

private List<String> processCommands(boolean dryRun) throws IOException {
    ImmutableList.Builder<String> responses = new ImmutableList.Builder<>();
    for (XmlEppParameters command : commands) {
        Map<String, Object> params = new HashMap<>();
        params.put("dryRun", dryRun);
        params.put("clientId", command.clientId);
        params.put("superuser", superuser);
        params.put("xml", URLEncoder.encode(command.xml, UTF_8.toString()));
        String requestBody = Joiner.on('&').withKeyValueSeparator("=").join(filterValues(params, notNull()));
        responses.add(nullToEmpty(connection.send("/_dr/epptool", ImmutableMap.<String, String>of(),
                MediaType.FORM_DATA, requestBody.getBytes(UTF_8))));
    }/*from   w w w . j  a  va 2  s.  c om*/
    return responses.build();
}

From source file:brooklyn.entity.nosql.couchbase.CouchbaseNodeImpl.java

protected void renameServerToPublicHostname() {
    // http://docs.couchbase.com/couchbase-manual-2.5/cb-install/#couchbase-getting-started-hostnames
    URI apiUri = null;//  w  w  w  . j a  va 2 s  . com
    try {
        HostAndPort accessible = BrooklynAccessUtils.getBrooklynAccessibleAddress(this,
                getAttribute(COUCHBASE_WEB_ADMIN_PORT));
        apiUri = URI.create(String.format("http://%s:%d/node/controller/rename", accessible.getHostText(),
                accessible.getPort()));
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(
                getConfig(COUCHBASE_ADMIN_USERNAME), getConfig(COUCHBASE_ADMIN_PASSWORD));
        HttpToolResponse response = HttpTool.httpPost(
                // the uri is required by the HttpClientBuilder in order to set the AuthScope of the credentials
                HttpTool.httpClientBuilder().uri(apiUri).credentials(credentials).build(), apiUri,
                MutableMap.of(HttpHeaders.CONTENT_TYPE, MediaType.FORM_DATA.toString(), HttpHeaders.ACCEPT,
                        "*/*",
                        // this appears needed; without it we get org.apache.http.NoHttpResponseException !?
                        HttpHeaders.AUTHORIZATION, HttpTool.toBasicAuthorizationValue(credentials)),
                Charsets.UTF_8.encode("hostname=" + Urls.encode(accessible.getHostText())).array());
        log.debug("Renamed Couchbase server " + this + " via " + apiUri + ": " + response);
        if (!HttpTool.isStatusCodeHealthy(response.getResponseCode())) {
            log.warn("Invalid response code, renaming " + apiUri + ": " + response);
        }
    } catch (Exception e) {
        Exceptions.propagateIfFatal(e);
        log.warn("Error renaming server, using " + apiUri + ": " + e, e);
    }
}

From source file:org.apache.brooklyn.entity.nosql.couchbase.CouchbaseNodeImpl.java

protected void renameServerToPublicHostname() {
    // http://docs.couchbase.com/couchbase-manual-2.5/cb-install/#couchbase-getting-started-hostnames
    URI apiUri = null;//from www .  ja  va 2s.  com
    try {
        HostAndPort accessible = BrooklynAccessUtils.getBrooklynAccessibleAddress(this,
                getAttribute(COUCHBASE_WEB_ADMIN_PORT));
        apiUri = URI.create(String.format("http://%s:%d/node/controller/rename", accessible.getHostText(),
                accessible.getPort()));
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(
                getConfig(COUCHBASE_ADMIN_USERNAME), getConfig(COUCHBASE_ADMIN_PASSWORD));
        HttpToolResponse response = HttpTool.httpPost(
                // the uri is required by the HttpClientBuilder in order to set the AuthScope of the credentials
                HttpTool.httpClientBuilder().uri(apiUri).credentials(credentials).build(), apiUri,
                MutableMap.of(HttpHeaders.CONTENT_TYPE, MediaType.FORM_DATA.toString(), HttpHeaders.ACCEPT,
                        "*/*",
                        // this appears needed; without it we get org.apache.http.NoHttpResponseException !?
                        HttpHeaders.AUTHORIZATION, HttpTool.toBasicAuthorizationValue(credentials)),
                Charsets.UTF_8.encode("hostname=" + Urls.encode(accessible.getHostText())).array());
        log.debug("Renamed Couchbase server " + this + " via " + apiUri + ": " + response);
        if (!HttpTool.isStatusCodeHealthy(response.getResponseCode())) {
            log.warn("Invalid response code, renaming {} ({}): {}",
                    new Object[] { apiUri, response.getResponseCode(), response.getContentAsString() });
        }
    } catch (Exception e) {
        Exceptions.propagateIfFatal(e);
        log.warn("Error renaming server, using " + apiUri + ": " + e, e);
    }
}