Example usage for org.apache.http.entity ContentType APPLICATION_FORM_URLENCODED

List of usage examples for org.apache.http.entity ContentType APPLICATION_FORM_URLENCODED

Introduction

In this page you can find the example usage for org.apache.http.entity ContentType APPLICATION_FORM_URLENCODED.

Prototype

ContentType APPLICATION_FORM_URLENCODED

To view the source code for org.apache.http.entity ContentType APPLICATION_FORM_URLENCODED.

Click Source Link

Usage

From source file:dk.dbc.DevelMain.java

@Override
public void initialize(Bootstrap<OaiSetMatcherConfiguration> bootstrap) {
    try {/* w w  w.j  ava2 s  .  c  om*/
        CloseableHttpClient client = new HttpClientBuilder(bootstrap.getMetricRegistry()).build("client");
        String killUrl = findAdminUrl(YAML_FILE_NAME) + "tasks/terminate";
        HttpPost post = new HttpPost(killUrl);
        post.setEntity(new StringEntity("", ContentType.APPLICATION_FORM_URLENCODED));
        try (CloseableHttpResponse resp = client.execute(post);
                InputStream is = resp.getEntity().getContent()) {
            String content = readInputStream(is);
            log.debug(content);
        }
        Thread.sleep(100);
    } catch (InterruptedException | IOException ex) {
        log.info(ex.getMessage());
    }
    super.initialize(bootstrap);
}

From source file:brooklyn.rest.BrooklynPropertiesSecurityFilterTest.java

@Test(groups = "Integration")
public void testInteractionOfSecurityFilterAndFormMapProvider() throws Exception {
    Stopwatch stopwatch = Stopwatch.createStarted();
    try {/*from  w  w  w  .j  a  va 2  s  .co m*/
        Server server = useServerForTest(
                BrooklynRestApiLauncher.launcher().securityProvider(AnyoneSecurityProvider.class)
                        .forceUseOfDefaultCatalogWithJavaClassPath(true).withoutJsgui().start());
        String appId = startAppAtNode(server);
        String entityId = getTestEntityInApp(server, appId);
        HttpClient client = HttpTool.httpClientBuilder().uri(getBaseUri(server)).build();
        List<? extends NameValuePair> nvps = Lists.newArrayList(new BasicNameValuePair("arg", "bar"));
        String effector = String.format("/v1/applications/%s/entities/%s/effectors/identityEffector", appId,
                entityId);
        HttpToolResponse response = HttpTool.httpPost(client, URI.create(getBaseUri() + effector),
                ImmutableMap.of(HttpHeaders.CONTENT_TYPE,
                        ContentType.APPLICATION_FORM_URLENCODED.getMimeType()),
                URLEncodedUtils.format(nvps, Charsets.UTF_8).getBytes());

        LOG.info("Effector response: {}", response.getContentAsString());
        assertTrue(HttpTool.isStatusCodeHealthy(response.getResponseCode()),
                "response code=" + response.getResponseCode());
    } finally {
        LOG.info("testInteractionOfSecurityFilterAndFormMapProvider complete in "
                + Time.makeTimeStringRounded(stopwatch));
    }
}

From source file:com.loyalty.service.RemoteService.java

@Override
public List<PromotionDTO> getPromotions() throws KioskException, IOException {
    try (CloseableHttpResponse result = getHttpClient().post("/public-api/promotions",
            ContentType.APPLICATION_FORM_URLENCODED)) {
        if (result.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            throw new KioskException(result.getStatusLine().getStatusCode(), "Can't find receive promotions");
        }//from  www  .  j  a  va2s .com
        final List<PromotionDTO> promotionDTOs = getMapper().readValue(EntityUtils.toString(result.getEntity()),
                getMapper().getTypeFactory().constructCollectionType(List.class, PromotionDTO.class));
        return promotionDTOs;
    }
}

From source file:org.smallmind.web.oauth.v1.ClientResource.java

@Path("/exchange")
@GET//from w  w  w.j  a va2s .c o m
public String exchange(@QueryParam("code") String code) throws Exception {

    HttpPost httpPost = new HttpPost(restUri + "/v1/oauth/token");
    String jsonTokenPostEntity = ClientAccessTokenFromCodeRequest.instance().setClientId(clientId)
            .setGrantType(GrantType.AUTHORIZATION_CODE.getParameter()).setCode(code)
            .setRedirectUri(restUri + "/spoof/exchange").setClientSecret("monkeys eat smores").build();

    httpPost.setEntity(new StringEntity(jsonTokenPostEntity, ContentType.APPLICATION_FORM_URLENCODED));
    try (CloseableHttpResponse httpResponse = HttpClients.createDefault().execute(httpPost)) {

        HttpEntity responseEntity = httpResponse.getEntity();

        return EntityUtils.toString(responseEntity);
    }
}

From source file:eu.over9000.cathode.resources.implementations.UsersImpl.java

@Override
public Result<Follow> putFollows(final String userName, final String targetName,
        final PutFollowsOptions options) {
    return dispatcher.performPut(Follow.class, Users.PATH + "/" + userName + "/follows/channels/" + targetName,
            options == null ? null//from   w w  w  .j  a  v a 2  s  .c  o  m
                    : new StringEntity(options.encode(), ContentType.APPLICATION_FORM_URLENCODED));
}

From source file:org.wisdom.test.http.MultipartBody.java

/**
 * Computes the request payload.//from  www.  j a  v a 2 s.  c  om
 *
 * @return the payload containing the declared fields and files.
 */
public HttpEntity getEntity() {
    if (hasFile) {
        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        for (Entry<String, Object> part : parameters.entrySet()) {
            if (part.getValue() instanceof File) {
                hasFile = true;
                builder.addPart(part.getKey(), new FileBody((File) part.getValue()));
            } else {
                builder.addPart(part.getKey(),
                        new StringBody(part.getValue().toString(), ContentType.APPLICATION_FORM_URLENCODED));
            }
        }
        return builder.build();
    } else {
        try {
            return new UrlEncodedFormEntity(getList(parameters), UTF_8);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:com.offbytwo.jenkins.JenkinsServerTest.java

@Test
public void testScriptPosts() throws IOException, URISyntaxException {
    given(client.post_text("/scriptText", "script=script", ContentType.APPLICATION_FORM_URLENCODED, false))
            .willReturn("result");
    String result = server.runScript("script");
    verify(client).post_text("/scriptText", "script=script", ContentType.APPLICATION_FORM_URLENCODED, false);
    assertEquals("result", result);
}

From source file:eu.over9000.cathode.resources.implementations.ChannelsImpl.java

@Override
public Result<Void> postCommercial(final String channelName, final CommercialOption options) {
    return dispatcher.performPost(Void.class, Channels.PATH + "/" + channelName + "/commercial",
            new StringEntity(options.encode(), ContentType.APPLICATION_FORM_URLENCODED));
}

From source file:net.ychron.unirestinst.request.body.MultipartBody.java

public MultipartBody field(String name, Object value, boolean file, String contentType) {
    List<Object> list = parameters.get(name);
    if (list == null)
        list = new LinkedList<Object>();
    list.add(value);/* ww  w  .  j a  va 2s  .  com*/
    parameters.put(name, list);

    ContentType type = null;
    if (contentType != null && contentType.length() > 0) {
        type = ContentType.parse(contentType);
    } else if (file) {
        type = ContentType.APPLICATION_OCTET_STREAM;
    } else {
        type = ContentType.APPLICATION_FORM_URLENCODED.withCharset(UTF_8);
    }
    contentTypes.put(name, type);

    if (!hasFile && file) {
        hasFile = true;
    }

    return this;
}

From source file:org.craftercms.studio.impl.v1.web.http.MultiReadHttpServletRequestWrapper.java

private Iterable<NameValuePair> decodeParams(String body) {
    List<NameValuePair> params = new ArrayList<>(URLEncodedUtils.parse(body, UTF8_CHARSET));
    try {//from  w w w  .  j av  a 2s.co  m
        String cts = getContentType();
        if (cts != null) {
            ContentType ct = ContentType.parse(cts);
            if (ct.getMimeType().equals(ContentType.APPLICATION_FORM_URLENCODED.getMimeType())) {
                List<NameValuePair> postParams = URLEncodedUtils.parse(IOUtils.toString(getReader()),
                        UTF8_CHARSET);
                CollectionUtils.addAll(params, postParams);
            }
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return params;
}