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:edu.ku.brc.util.WebStoreAttachmentMgr.java

private void testKey() throws WebStoreAttachmentKeyException {
    if (testKeyURLStr == null)
        return; // skip test if there is not test url.

    GetMethod method = new GetMethod(testKeyURLStr);
    String r = "" + (new Random()).nextInt();
    method.setQueryString(new NameValuePair[] { new NameValuePair("random", r),
            new NameValuePair("token", generateToken(r)) });

    HttpClient client = new HttpClient();
    client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);

    try {/*from  w ww .j  a  v a2s . c  om*/
        int status = client.executeMethod(method);
        updateServerTimeDelta(method);
        if (status == HttpStatus.SC_OK) {
            return;
        } else if (status == HttpStatus.SC_FORBIDDEN) {
            throw new WebStoreAttachmentKeyException("Attachment key is invalid.");
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        method.releaseConnection();
    }
    throw new WebStoreAttachmentKeyException("Problem verifying attachment key.");
}

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

public void registerUser(User user) throws ClientException {
    HttpClientParams httpClientParams = new HttpClientParams();
    HttpConnectionManager httpConnectionManager = new SimpleHttpConnectionManager();
    httpClientParams.setSoTimeout(10 * 1000);
    httpConnectionManager.getParams().setConnectionTimeout(10 * 1000);
    httpConnectionManager.getParams().setSoTimeout(10 * 1000);
    HttpClient httpClient = new HttpClient(httpClientParams, httpConnectionManager);

    PostMethod post = new PostMethod(client.getUpdateSettings().getUpdateUrl() + URL_REGISTRATION);
    NameValuePair[] params = { new NameValuePair("serverId", client.getServerId()),
            new NameValuePair("version", client.getVersion()),
            new NameValuePair("user", serializer.toXML(user)) };
    post.setRequestBody(params);/*from   ww  w.j  a  v a  2  s .  c  om*/

    try {
        int statusCode = httpClient.executeMethod(post);

        if ((statusCode != HttpStatus.SC_OK) && (statusCode != HttpStatus.SC_MOVED_TEMPORARILY)) {
            throw new Exception("Failed to connect to update server: " + post.getStatusLine());
        }
    } catch (Exception e) {
        throw new ClientException(e);
    } finally {
        post.releaseConnection();
    }
}

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

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

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

@Test
public void testPublishDeleteComplexShapeZip() throws FileNotFoundException, IOException {
    if (!enabled()) {
        return;//  w  w  w .jav a  2 s.co  m
    }
    deleteAllWorkspacesRecursively();
    //        Assume.assumeTrue(enabled);
    assertTrue(publisher.createWorkspace(DEFAULT_WS));

    String storeName = "resttestshp_complex";
    String datasetName = "cities";

    File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();

    // test insert
    boolean published = publisher.publishShp(DEFAULT_WS, storeName,
            new NameValuePair[] { new NameValuePair("charset", "UTF-8") }, datasetName, UploadMethod.FILE,
            zipFile.toURI(), "EPSG:4326", GSCoverageEncoderTest.WGS84, ProjectionPolicy.REPROJECT_TO_DECLARED,
            "polygon");
    assertTrue("publish() failed", published);
    assertTrue(existsLayer(datasetName));

    RESTLayer layer = reader.getLayer(datasetName);

    LOGGER.info("Layer style is " + layer.getDefaultStyle());

    //test delete
    boolean ok = publisher.unpublishFeatureType(DEFAULT_WS, storeName, datasetName);
    assertTrue("Unpublish() failed", ok);
    assertFalse(existsLayer(datasetName));

    // remove also datastore
    boolean dsRemoved = publisher.removeDatastore(DEFAULT_WS, storeName, false);
    assertTrue("removeDatastore() failed", dsRemoved);
}

From source file:com.sfs.jbtimporter.JBTProcessor.java

/**
 * Gets the Jira security key./* w  w  w .  j  a  v a 2s .  c o m*/
 * 
 * @return the jira security key
 * @throws IOException Signals that an I/O exception has occurred.
 */
public final String getKey() throws IOException {

    String key = "";

    final String jellyUrl = this.getBaseUrl() + this.jiraKeyPath;

    final PostMethod postMethod = new PostMethod(jellyUrl);
    final NameValuePair[] data = { new NameValuePair("os_username", this.getUsername()),
            new NameValuePair("os_password", this.getPassword()) };

    final String raw = postData(postMethod, data);

    // Get the value of the alt_token input field as the key
    if (raw.indexOf("name=\"atl_token\"") > 0) {
        final int charcount = 16;
        final int valuelength = 20;
        // Value returned
        String result = raw.substring(raw.indexOf("name=\"atl_token\"") + charcount, raw.length());
        result = result.substring(result.indexOf("\""), result.indexOf("\"") + valuelength);
        key = result.substring(result.indexOf("\"") + 1, result.lastIndexOf("\""));
    }
    return key;
}

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

public Document createAutoScalePolicy(String action, String conditionIds, int duration,
        HashMap<String, String> optional) throws Exception {
    LinkedList<NameValuePair> arguments = newQueryValues("createAutoScalePolicy", optional);
    arguments.add(new NameValuePair("action", action));
    arguments.add(new NameValuePair("conditionids", conditionIds));
    arguments.add(new NameValuePair("duration", Integer.toString(duration)));
    return Request(arguments);
}

From source file:com.clarkparsia.sbol.editor.sparql.StardogEndpoint.java

@Override
public void addData(RDFInput input, String namedGraph) throws Exception {
    String txId = startTransaction();

    RequestEntity entity = createEntity(input);
    PostMethod post = new PostMethod(url + "/" + txId + "/add");
    if (namedGraph != null) {
        post.setQueryString(new NameValuePair[] { new NameValuePair("graph-uri", namedGraph) });
    }/*from w ww.j ava2 s  .  c om*/
    post.setRequestEntity(entity);

    execute(post);

    commitTransaction(txId);
}

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

@Override
public void modelSetImported(String modelSetId, ModelSetType type) throws LpRestExceptionXWikiImpl {
    HttpClient httpClient = this.getClient();
    String uri = String.format("%s/learnpad/or/bridge/modelsetimported/%s", DefaultRestResource.REST_URI,
            modelSetId);//from  w  ww .j av  a2s.c om
    PostMethod postMethod = new PostMethod(uri);
    postMethod.addRequestHeader("Accept", "application/xml");

    NameValuePair[] queryString = new NameValuePair[1];
    queryString[0] = new NameValuePair("type", type.toString());
    postMethod.setQueryString(queryString);
    try {
        httpClient.executeMethod(postMethod);
    } catch (IOException e) {
        throw new LpRestExceptionXWikiImpl(e.getMessage(), e);
    }
}

From source file:mitm.common.security.ca.handlers.comodo.ApplyCustomClientCert.java

/**
 * Requests a certificate. Returns true if a certificate was successfully requested. 
 * @return true if successful, false if an error occurs
 * @throws CustomClientCertException//w  ww.  j a va2s  .c o m
 */
public boolean apply() throws CustomClientCertException {
    reset();

    if (StringUtils.isEmpty(ap)) {
        throw new CustomClientCertException("ap must be specified.");
    }

    if (StringUtils.isEmpty(pkcs10)) {
        throw new CustomClientCertException("pkcs10 must be specified.");
    }

    PostMethod postMethod = new PostMethod(connectionSettings.getApplyCustomClientCertURL());

    NameValuePair[] data = { new NameValuePair("ap", ap), new NameValuePair("days", Integer.toString(days)),
            new NameValuePair("pkcs10", pkcs10), new NameValuePair("successURL", "none"),
            new NameValuePair("errorURL", "none") };

    if (cACertificateID != null) {
        data = (NameValuePair[]) ArrayUtils.add(data,
                new NameValuePair("caCertificateID", cACertificateID.toString()));
    }

    postMethod.setRequestBody(data);

    HTTPMethodExecutor executor = new HTTPMethodExecutor(connectionSettings.getTotalTimeout(),
            connectionSettings.getProxyInjector());

    executor.setConnectTimeout(connectionSettings.getConnectTimeout());
    executor.setReadTimeout(connectionSettings.getReadTimeout());

    try {
        executor.executeMethod(postMethod, responseHandler);
    } catch (IOException e) {
        throw new CustomClientCertException(e);
    }

    return !error;
}

From source file:com.apifest.oauth20.tests.OAuth20BasicTest.java

public String obtainAccessToken(String grantType, String authCode, String clientId, String clientSecret,
        String uri) {// w  w  w . j  a va  2  s . com
    PostMethod post = new PostMethod(baseOAuth20Uri + TOKEN_ENDPOINT);
    String accessToken = null;
    String response = null;
    try {
        NameValuePair[] requestBody = { new NameValuePair(GRANT_TYPE_PARAM, grantType),
                new NameValuePair(CODE_PARAM, authCode), new NameValuePair(REDIRECT_URI_PARAM, uri),
                new NameValuePair(CLIENT_ID_PARAM, clientId),
                new NameValuePair(CLIENT_SECRET_PARAM, clientSecret) };
        post.setRequestHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
        post.setRequestHeader(HttpHeaders.AUTHORIZATION, createBasicAuthorization(clientId, clientSecret));
        post.setRequestBody(requestBody);
        response = readResponse(post);
        log.info(response);
        if (response != null) {
            accessToken = extractAccessToken(response);
        }
    } catch (IOException e) {
        log.error("cannot obtain access token", e);
    }
    return accessToken;
}