Example usage for org.apache.commons.httpclient NameValuePair NameValuePair

List of usage examples for org.apache.commons.httpclient NameValuePair NameValuePair

Introduction

In this page you can find the example usage for org.apache.commons.httpclient NameValuePair NameValuePair.

Prototype

public NameValuePair(String name, String value) 

Source Link

Document

Constructor.

Usage

From source file:net.neurowork.cenatic.centraldir.workers.XMLPusher.java

private void pushOrganization(RestUrlManager restUrl, String token) {
    HttpClient httpclient = XMLRestWorker.getHttpClient();
    PostMethod post = new PostMethod(restUrl.getPushOrganizationUrl());

    NameValuePair tokenParam = new NameValuePair("token", token);
    NameValuePair[] params = new NameValuePair[] { tokenParam };

    post.addRequestHeader("Accept", "application/xml");
    post.setQueryString(params);/*  w  ww  .  ja v  a 2  s .  c o m*/

    String content = XmlPushCreator.getInstance().getPushXml(organizacion);
    try {
        RequestEntity entity = new StringRequestEntity(content, PostMethod.FORM_URL_ENCODED_CONTENT_TYPE, null);
        post.setRequestEntity(entity);

        int result = httpclient.executeMethod(post);

        logger.info("Response status code: " + result);
        logger.info("Response body: ");
        logger.info(post.getResponseBodyAsString());

    } catch (UnsupportedEncodingException e) {
        logger.error(e.getMessage());
    } catch (HttpException e) {
        logger.error(e.getMessage());
    } catch (IOException e) {
        logger.error(e.getMessage());
    } finally {
        post.releaseConnection();
    }

}

From source file:com.mirth.connect.client.core.MessageListHandler.java

public void removeFilterTables() throws ClientException {
    NameValuePair[] params = { new NameValuePair("op", Operations.MESSAGE_FILTER_TABLES_REMOVE.getName()),
            new NameValuePair("uid", uid) };
    connection.executePostMethod(Client.MESSAGE_SERVLET, params);
}

From source file:eu.learnpad.core.impl.qm.XwikiBridgeInterfaceRestResource.java

@Override
public void importModelSet(String modelSetId, ModelSetType type, InputStream modelContent)
        throws LpRestExceptionXWikiImpl {
    // Notify QM about a new model set imported
    HttpClient httpClient = this.getClient();
    String uri = String.format("%s/learnpad/qm/bridge/importmodel/%s", DefaultRestResource.REST_URI,
            modelSetId);//from w  ww. j ava2  s  .  c o  m
    PutMethod putMethod = new PutMethod(uri);
    putMethod.addRequestHeader("Accept", "application/xml");

    NameValuePair[] queryString = new NameValuePair[1];
    queryString[0] = new NameValuePair("type", type.toString());
    putMethod.setQueryString(queryString);

    RequestEntity requestEntity = new InputStreamRequestEntity(modelContent);
    putMethod.setRequestEntity(requestEntity);

    try {
        httpClient.executeMethod(putMethod);
    } catch (IOException e) {
        throw new LpRestExceptionXWikiImpl(e.getMessage(), e);
    }

}

From source file:net.datapipe.CloudStack.CloudStackAPI.java

public Document enableAutoScaleVMGroup(String autoScaleVMGroupId) throws Exception {
    LinkedList<NameValuePair> arguments = newQueryValues("enableAutoScaleVmGroup", null);
    arguments.add(new NameValuePair("id", autoScaleVMGroupId));
    return Request(arguments);
}

From source file:edu.ku.brc.services.biogeomancer.BioGeomancer.java

/**
 * Sends a georeferencing request to the BioGeomancer web service.
 * //from   www  .  j av a  2  s.co m
 * @param id id
 * @param country country
 * @param adm1 country
 * @param adm2 adm2
 * @param localityArg locality
 * @return returns the response body content (as XML)
 * @throws IOException a network error occurred while contacting the BioGeomancer service
 */
public static String getBioGeomancerResponse(final String id, final String country, final String adm1,
        final String adm2, final String localityArg) throws IOException {
    HttpClient httpClient = new HttpClient();
    PostMethod postMethod = new PostMethod("http://130.132.27.130/cgi-bin/bgm-0.2/batch_test.pl"); //$NON-NLS-1$
    StringBuilder strBuf = new StringBuilder(128);
    strBuf.append("\"" + id + "\","); //$NON-NLS-1$ //$NON-NLS-2$
    strBuf.append("\"" + country + "\","); //$NON-NLS-1$ //$NON-NLS-2$
    strBuf.append("\"" + adm1 + "\","); //$NON-NLS-1$ //$NON-NLS-2$
    strBuf.append("\"" + (adm2 != null ? adm2 : "") + "\","); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    strBuf.append("\"" + localityArg + "\"\r\n"); //$NON-NLS-1$ //$NON-NLS-2$

    NameValuePair[] postData = {
            //new NameValuePair("batchtext", "\"12931\",\"Mexico\",\"Veracruz\",\"\",\"12 km NW of Catemaco\"\r\n"),
            new NameValuePair("batchtext", strBuf.toString()), //$NON-NLS-1$
            new NameValuePair("format", "xml") }; //$NON-NLS-1$ //$NON-NLS-2$

    // the 2.0 beta1 version has a
    // PostMethod.setRequestBody(NameValuePair[])
    // method, as addParameters is deprecated
    postMethod.addParameters(postData);

    httpClient.executeMethod(postMethod);

    InputStream iStream = postMethod.getResponseBodyAsStream();

    StringBuilder sb = new StringBuilder();
    byte[] bytes = new byte[8196];
    int numBytes = 0;
    do {
        numBytes = iStream.read(bytes);
        if (numBytes > 0) {
            sb.append(new String(bytes, 0, numBytes));
        }

    } while (numBytes > 0);

    //release the connection used by the method
    postMethod.releaseConnection();

    return sb.toString();
}

From source file:com.ohalo.baidu.map.BaiduMapTest.java

/**
 * /*from ww  w. ja  v  a 2  s .co m*/
 * <pre>
 * ??
 * 
 * 2013-10-8
 * </pre>
 * 
 * @throws IllegalArgumentException
 * @throws IOException
 */
public void testSearchCompanyBaseInfo() throws IllegalArgumentException, IOException {
    HttpClient client = new HttpClient();
    PostMethod method = new PostMethod("http://www.sgs.gov.cn/lz/etpsInfo.do?method=doSearch");
    method.setRequestBody(new NameValuePair[] {
            new NameValuePair("keyWords",
                    new String("??".getBytes(), "ISO8859-1")),
            new NameValuePair("searchType", "1") });
    client.executeMethod(method);
    String response = new String(method.getResponseBody());
    System.out.println(response);
}

From source file:com.ltasks.LtasksNameFinderClient.java

/**
 * Annotate a normalized text from a URL
 * //from  w  w w .ja  v a2  s . c  om
 * @param aUrl
 *            the URL
 * @return the annotation object
 * @throws HttpException
 *             Got a protocol error.
 * @throws IOException
 *             Failed to communicate or to read the result.
 * @throws IllegalArgumentException
 *             The data received from server was invalid.
 */
public LtasksObject processUrl(URL aUrl) throws HttpException, IOException, IllegalArgumentException {
    return post(Collections.singletonList(new NameValuePair("url", aUrl.toString())));
}

From source file:com.owncloud.android.lib.resources.files.UpdateMetadataOperation.java

/**
 * @param client Client object//from w  ww . jav  a  2 s.  c  om
 */
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    PutMethod putMethod = null;
    RemoteOperationResult result;

    try {
        // remote request
        putMethod = new PutMethod(client.getBaseUri() + METADATA_URL + fileId);
        putMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
        putMethod.addRequestHeader(CONTENT_TYPE, FORM_URLENCODED);

        NameValuePair[] putParams = new NameValuePair[2];
        putParams[0] = new NameValuePair(TOKEN, token);
        putParams[1] = new NameValuePair(FORMAT, "json");
        putMethod.setQueryString(putParams);

        StringRequestEntity data = new StringRequestEntity("metaData=" + encryptedMetadataJson,
                "application/json", "UTF-8");
        putMethod.setRequestEntity(data);

        int status = client.executeMethod(putMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);

        if (status == HttpStatus.SC_OK) {
            String response = putMethod.getResponseBodyAsString();

            // Parse the response
            JSONObject respJSON = new JSONObject(response);
            String metadata = (String) respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA)
                    .get(NODE_META_DATA);

            result = new RemoteOperationResult(true, putMethod);
            ArrayList<Object> keys = new ArrayList<>();
            keys.add(metadata);
            result.setData(keys);
        } else {
            result = new RemoteOperationResult(false, putMethod);
            client.exhaustResponse(putMethod.getResponseBodyAsStream());
        }
    } catch (Exception e) {
        result = new RemoteOperationResult(e);
        Log_OC.e(TAG, "Storing of metadata for folder " + fileId + " failed: " + result.getLogMessage(),
                result.getException());
    } finally {
        if (putMethod != null)
            putMethod.releaseConnection();
    }
    return result;
}

From source file:eu.learnpad.rest.utils.internal.DefaultCWRestUtils.java

@Override
public boolean putXWikiPackage(String packagePath) {
    HttpClient httpClient = getClient();

    String uri = REST_URI + "/learnpad/cw/package";
    PutMethod putMethod = new PutMethod(uri);
    putMethod.addRequestHeader("Accept", "application/xml");
    putMethod.addRequestHeader("Accept-Ranges", "bytes");

    NameValuePair[] queryString = new NameValuePair[1];
    queryString[0] = new NameValuePair("path", packagePath);
    putMethod.setQueryString(queryString);

    try {//w  w w .  j a  v  a  2 s  .  co m
        httpClient.executeMethod(putMethod);
        return true;
    } catch (HttpException e) {
        logger.error("Unable to process the PUT request for XWiki package '" + packagePath
                + "' onto the Collaborative Workspace.", e);
        return false;
    } catch (IOException e) {
        logger.error("Unable to PUT XWiki package '" + packagePath + "' to the Collaborative Workspace.", e);
        return false;
    }
}

From source file:it.geosolutions.geoserver.rest.publisher.GeoserverRESTWorldImageTest.java

@Test
public void testPublishWorldImage() throws IOException {

    if (!enabled()) {
        return;//w ww  . j a  va2  s  .c o  m
    }
    deleteAll();
    String storeName = "testWorldimage";

    assertTrue(reader.getWorkspaces().isEmpty());

    assertTrue(publisher.createWorkspace(DEFAULT_WS));

    File worldImageFile = new ClassPathResource("testdata/sw.zip").getFile();

    // test publish

    boolean wp = publisher.publishWorldImage(DEFAULT_WS, storeName, worldImageFile, ParameterConfigure.NONE,
            null);

    assertTrue("Publish worldfile with no layer configured, failed.", wp);

    assertTrue("Unpublish() failed", publisher.removeCoverageStore(DEFAULT_WS, storeName, true));

    // create default style
    File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
    assertTrue(publisher.publishStyle(sldFile, "raster"));

    wp = publisher.publishWorldImage(DEFAULT_WS, storeName, worldImageFile, ParameterConfigure.FIRST,
            new NameValuePair("coverageName", "worldImage_test"));

    assertTrue("Publish worldfile configuring layer name, failed.", wp);

    assertTrue("Unpublish() failed", publisher.removeCoverageStore(DEFAULT_WS, storeName, true));

    wp = publisher.publishWorldImage(DEFAULT_WS, storeName, worldImageFile, ParameterConfigure.ALL, null);

    assertTrue("Publish worldfile configuring all available layers, failed.", wp);

    assertTrue("Unpublish() failed", publisher.removeCoverageStore(DEFAULT_WS, storeName, true));
}