Example usage for org.apache.commons.httpclient.methods GetMethod setQueryString

List of usage examples for org.apache.commons.httpclient.methods GetMethod setQueryString

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods GetMethod setQueryString.

Prototype

public void setQueryString(String queryString) 

Source Link

Usage

From source file:org.sakaiproject.kernel.mailman.impl.MailmanManagerImpl.java

public boolean listHasMember(String listName, String listPassword, String memberEmail) throws MailmanException {
    HttpClient client = new HttpClient(proxyClientService.getHttpConnectionManager());
    GetMethod get = new GetMethod(getMailmanUrl("/admin/" + listName + "members"));
    NameValuePair[] parameters = new NameValuePair[] { new NameValuePair("findmember", memberEmail),
            new NameValuePair("setmemberopts_btn", ""), new NameValuePair("adminpw", listPassword) };
    get.setQueryString(parameters);
    try {//from  w  ww . j a  va2s .  c o m
        int result = client.executeMethod(get);
        if (result != HttpServletResponse.SC_OK) {
            throw new MailmanException("Unable to search for member");
        }
        Document dom = parseHtml(get);
        NodeList inputs = dom.getElementsByTagName("INPUT");
        String unsubString = URLEncoder.encode(memberEmail, "utf8") + "_unsub";
        for (int i = 0; i < inputs.getLength(); i++) {
            Node input = inputs.item(i);
            try {
                if (input.getAttributes().getNamedItem("name").getTextContent().equals(unsubString)) {
                    return true;
                }
            } catch (NullPointerException npe) {
            }
        }
    } catch (SAXException e) {
        throw new MailmanException("Error parsing mailman response", e);
    } catch (HttpException e) {
        throw new MailmanException("HTTP Exception communicating with mailman server", e);
    } catch (IOException e) {
        throw new MailmanException("IOException communicating with mailman server", e);
    } finally {
        get.releaseConnection();
    }
    return false;
}

From source file:org.sakaiproject.kernel.mailman.impl.MailmanManagerImpl.java

public boolean addMember(String listName, String listPassword, String memberEmail) throws MailmanException {
    HttpClient client = new HttpClient(proxyClientService.getHttpConnectionManager());
    GetMethod get = new GetMethod(getMailmanUrl("/admin/" + listName + "/members/add"));
    NameValuePair[] parameters = new NameValuePair[] { new NameValuePair("subscribe_or_invite", "0"),
            new NameValuePair("send_welcome_msg_to_this_batch", "0"),
            new NameValuePair("notification_to_list_owner", "0"),
            new NameValuePair("subscribees_upload", memberEmail), new NameValuePair("adminpw", listPassword) };
    get.setQueryString(parameters);
    try {//from   w w w . ja va2 s  .co m
        int result = client.executeMethod(get);
        if (result != HttpServletResponse.SC_OK) {
            throw new MailmanException("Unable to add member");
        }
        Document dom = parseHtml(get);
        NodeList inputs = dom.getElementsByTagName("h5");
        if (inputs.getLength() == 0) {
            throw new MailmanException("Unable to read result status");
        }
        return "Successfully subscribed:".equals(inputs.item(0).getTextContent());
    } catch (SAXException e) {
        throw new MailmanException("Error parsing mailman response", e);
    } catch (HttpException e) {
        throw new MailmanException("HTTP Exception communicating with mailman server", e);
    } catch (IOException e) {
        throw new MailmanException("IOException communicating with mailman server", e);
    } finally {
        get.releaseConnection();
    }
}

From source file:org.sakaiproject.kernel.mailman.impl.MailmanManagerImpl.java

public boolean removeMember(String listName, String listPassword, String memberEmail) throws MailmanException {
    HttpClient client = new HttpClient(proxyClientService.getHttpConnectionManager());
    GetMethod get = new GetMethod(getMailmanUrl("/admin/" + listName + "/members/remove"));
    NameValuePair[] parameters = new NameValuePair[] { new NameValuePair("send_unsub_ack_to_this_batch", "0"),
            new NameValuePair("send_unsub_notifications_to_list_owner", "0"),
            new NameValuePair("unsubscribees_upload", memberEmail),
            new NameValuePair("adminpw", listPassword) };
    get.setQueryString(parameters);
    try {/*from w w w.j a  v a  2 s.  c  o m*/
        int result = client.executeMethod(get);
        if (result != HttpServletResponse.SC_OK) {
            throw new MailmanException("Unable to add member");
        }
        Document dom = parseHtml(get);
        NodeList inputs = dom.getElementsByTagName("h5");
        if (inputs.getLength() == 0) {
            inputs = dom.getElementsByTagName("h3");
            if (inputs.getLength() == 0) {
                throw new MailmanException("Unable to read result status");
            }
        }
        return "Successfully Unsubscribed:".equals(inputs.item(0).getTextContent());
    } catch (HttpException e) {
        throw new MailmanException("HTTP Exception communicating with mailman server", e);
    } catch (IOException e) {
        throw new MailmanException("IOException communicating with mailman server", e);
    } catch (SAXException e) {
        throw new MailmanException("Error parsing mailman response", e);
    } finally {
        get.releaseConnection();
    }
}

From source file:org.sakaiproject.nakamura.mailman.impl.MailmanManagerImpl.java

public boolean listHasMember(String listName, String listPassword, String memberEmail) throws MailmanException {
    HttpClient client = new HttpClient(proxyClientService.getHttpConnectionManager());
    GetMethod get = new GetMethod(getMailmanUrl("/admin/" + listName + "/members"));
    NameValuePair[] parameters = new NameValuePair[] { new NameValuePair("findmember", memberEmail),
            new NameValuePair("setmemberopts_btn", ""), new NameValuePair("adminpw", listPassword) };
    get.setQueryString(parameters);
    try {//w  ww  . ja va 2 s  . c o m
        int result = client.executeMethod(get);
        if (result != HttpServletResponse.SC_OK) {
            throw new MailmanException("Unable to search for member");
        }
        Document dom = parseHtml(get);
        NodeList inputs = dom.getElementsByTagName("INPUT");
        String unsubString = URLEncoder.encode(memberEmail, "utf8") + "_unsub";
        for (int i = 0; i < inputs.getLength(); i++) {
            Node input = inputs.item(i);
            try {
                if (input.getAttributes().getNamedItem("name").getTextContent().equals(unsubString)) {
                    return true;
                }
            } catch (NullPointerException npe) {
            }
        }
    } catch (SAXException e) {
        throw new MailmanException("Error parsing mailman response", e);
    } catch (HttpException e) {
        throw new MailmanException("HTTP Exception communicating with mailman server", e);
    } catch (IOException e) {
        throw new MailmanException("IOException communicating with mailman server", e);
    } finally {
        get.releaseConnection();
    }
    return false;
}

From source file:org.svenk.redmine.core.client.RedmineRestfulClient.java

public List<Integer> getChangedTicketId(Integer projectId, Date changedSince, IProgressMonitor monitor)
        throws RedmineException {
    GetMethod method = new GetMethod(PATH_GET_CHANGED_TICKETS.replace(PLACEHOLDER, projectId.toString()));
    method.setQueryString(new NameValuePair[] {
            new NameValuePair(PATH_GET_CHANGED_TICKETS_PARAM, "" + changedSince.getTime() / 1000) });

    return executeMethod(method, updatedTicketsParser, monitor);
}

From source file:org.wings.recorder.Script.java

public String send(GET request) throws IOException {
    GetMethod get = new GetMethod(url + request.getResource());
    addHeaders(request, get);/*from   w  w w.  j a  v  a 2s  .c om*/

    NameValuePair[] nvps = eventsAsNameValuePairs(request);
    get.setQueryString(nvps);

    int result = client.executeMethod(get);
    return get.getResponseBodyAsString();
}

From source file:org.wso2.appfactory.dynamicslave.JenkinsClient.java

private GetMethod createGetMethod(String path, NameValuePair[] queryParameters) {
    GetMethod method = new GetMethod(this.url + path);
    if (queryParameters != null) {
        method.setQueryString(queryParameters);
    }// w  w w  .j a va 2s.c  o  m
    return method;
}

From source file:org.wso2.carbon.appfactory.jenkins.api.JenkinsBuildStatusProvider.java

public Map<String, String> getLastBuildInformation(String applicationId, String version, String userName,
        String repoFrom) throws BuildStatusProviderException {
    String jobName = JenkinsUtility.getJobName(applicationId, version, userName, repoFrom);
    String url = null;//  w  ww .  j  a  v a  2s  .  c  o  m
    try {
        url = AppFactoryUtil.getAppfactoryConfiguration()
                .getFirstProperty(AppFactoryConstants.JENKINS_PROPERTYBASE_URL);
    } catch (AppFactoryException e) {
        String msg = "Error occuered while calling the API";
        throw new BuildStatusProviderException(msg);
    }
    String tenantDomain = Utils.getEnvironmentVariable("TENANT_DOMAIN");
    url += "/t/" + tenantDomain + "/webapps/jenkins/" + "job/" + jobName + "/api/json";
    log.info("Calling jenkins api : " + url);
    GetMethod get = new GetMethod(url);
    NameValuePair valuePair = new NameValuePair("tree", "builds[number,status,timestamp,id,result]");
    get.setQueryString(new org.apache.commons.httpclient.NameValuePair[] { valuePair });

    try {
        getHttpClient().getState().setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials(
                        AppFactoryUtil.getAppfactoryConfiguration()
                                .getFirstProperty(Constants.JENKINS_ADMIN_USERNAME_PATH),
                        AppFactoryUtil.getAppfactoryConfiguration()
                                .getFirstProperty(Constants.JENKINS_ADMIN_PASSWORD_PATH)));
    } catch (AppFactoryException e) {
        String msg = "Error occuered while calling the API";
        throw new BuildStatusProviderException(msg);
    }
    getHttpClient().getParams().setAuthenticationPreemptive(true);

    Map<String, String> buildInformarion = null;

    try {
        log.debug("Retrieving last build information for job : " + jobName);
        getHttpClient().executeMethod(get);
        log.info("Retrieving last build information for job : " + jobName + " status received : "
                + get.getStatusCode());
        if (get.getStatusCode() == HttpStatus.SC_OK) {
            String response = get.getResponseBodyAsString();
            log.debug("Returns build information for job : " + jobName + " - " + response);
            buildInformarion = extractBuildInformarion(response);
        } else {
            String msg = "Error while retrieving  build information for job : " + jobName
                    + " Jenkins returned status code : " + get.getStatusCode();
            log.error(msg);
            throw new BuildStatusProviderException(msg, BuildStatusProviderException.INVALID_RESPONSE);
        }

    } catch (HttpException e) {
        String msg = "Error occuered while calling the API";
        throw new BuildStatusProviderException(msg);

    } catch (IOException e) {
        String msg = "Error occuered while calling the API";
        throw new BuildStatusProviderException(msg);
    } finally {
        get.releaseConnection();
    }
    return buildInformarion;
}

From source file:org.wso2.carbon.appfactory.webdavsvn.svn.repository.provider.Apache2WebDAVSVNRepositoryProvider.java

/**
 * {@inheritDoc}/*from w  w w .j  a v a 2 s. co  m*/
 */
@Override
public String createRepository(String applicationKey, String tenantDomain) throws RepositoryMgtException {
    /*String fullRepositoryPath=configuration.getFirstProperty(getPropertyKey(REMOTE_PARENT_REPO_LOCATION))+"/"+applicationKey;
    String username=configuration.getFirstProperty(getPropertyKey(REMOTE_USER_NAME));
    String password=configuration.getFirstProperty(getPropertyKey(REMOTE_USER_PASSWORD));
    String hostName=configuration.getFirstProperty(getPropertyKey(HOST_NAME));
    client=new SSHClient();
    client.createRepositoryRemotely(fullRepositoryPath,configuration.getFirstProperty(getPropertyKey(REMOTE_HOST_SUPER_USER_PASSWORD)),username,password,hostName);
    return getAppRepositoryURL(applicationKey);*/

    HttpClient client = getClient();
    GetMethod get = new GetMethod(getBackendUrl() + CREATE_REPO_EPR);
    NameValuePair[] repositoryName = new NameValuePair[1];
    repositoryName[0] = new NameValuePair();
    repositoryName[0].setName(CREATE_REPO_REQUEST_REPO_NAME_PARAMETER_NAME);
    repositoryName[0].setValue(applicationKey);
    get.setQueryString(repositoryName);
    get.setDoAuthentication(true);
    try {
        client.executeMethod(get);
        if (get.getStatusCode() == HttpStatus.SC_CREATED) {
            return getAppRepositoryURL(applicationKey, tenantDomain);
        } else {
            String msg = "Repository creation is failed for " + applicationKey + " server returned status "
                    + get.getStatusText();
            log.error(msg);
            throw new RepositoryMgtException(msg);
        }
    } catch (IOException e) {
        String msg = "Error while invoking the web service";
        log.error(msg, e);
        throw new RepositoryMgtException(msg, e);
    } finally {
        get.releaseConnection();
    }
}

From source file:org.wso2.carbon.appmgt.mdm.wso2mdm.MDMOperationsImpl.java

/**
 *
 * @param tenantId tenantId//from  w  w w .ja  v  a2 s  .c o m
 * @param type type of the resource. Eg: role, user, device
 * @param params ids of the resources which belong to type
 * @param platform platform of the devices
 * @param platformVersion platform version of the devices
 * @param isSampleDevicesEnabled if MDM is not connected, enable this to display sample devices.
 * @return
 */

public List<Device> getDevices(User currentUser, int tenantId, String type, String[] params, String platform,
        String platformVersion, boolean isSampleDevicesEnabled, HashMap<String, String> configProperties) {

    String tokenApiURL = configProperties.get(Constants.PROPERTY_TOKEN_API_URL);
    String clientKey = configProperties.get(Constants.PROPERTY_CLIENT_KEY);
    String clientSecret = configProperties.get(Constants.PROPERTY_CLIENT_SECRET);
    String authUser = configProperties.get(Constants.PROPERTY_AUTH_USER);
    String authPass = configProperties.get(Constants.PROPERTY_AUTH_PASS);

    JSONArray jsonArray = null;

    if (isSampleDevicesEnabled) {
        return Sample.getSampleDevices();
    } else {

        HttpClient httpClient = new HttpClient();

        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId);
        String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);

        String deviceListAPI = String.format(Constants.API_DEVICE_LIST, params[0], tenantDomain);
        String requestURL = configProperties.get(Constants.PROPERTY_SERVER_URL) + deviceListAPI;
        GetMethod getMethod = new GetMethod(requestURL);

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        //nameValuePairs.add(new NameValuePair("tenantId", String.valueOf(tenantId)));

        if (platform != null)
            nameValuePairs.add(new NameValuePair("platform", platform));

        if (platformVersion != null)
            nameValuePairs.add(new NameValuePair("platformVersion", platform));

        getMethod.setQueryString(
                (NameValuePair[]) nameValuePairs.toArray(new NameValuePair[nameValuePairs.size()]));
        getMethod.setRequestHeader("Accept", "application/json");

        if (executeMethod(tokenApiURL, clientKey, clientSecret, authUser, authPass, httpClient, getMethod)) {
            try {
                jsonArray = (JSONArray) new JSONValue().parse(new String(getMethod.getResponseBody()));
                if (jsonArray != null) {
                    if (log.isDebugEnabled())
                        log.debug("Devices received from MDM: " + jsonArray.toJSONString());
                }
            } catch (IOException e) {
                String errorMessage = "Invalid response from the devices API";
                if (log.isDebugEnabled()) {
                    log.error(errorMessage, e);
                } else {
                    log.error(errorMessage);
                }
            }
        } else {
            log.error("Getting devices from MDM API failed");
        }
    }

    if (jsonArray == null) {
        jsonArray = (JSONArray) new JSONValue().parse("[]");
    }

    List<Device> devices = new ArrayList<Device>();

    Iterator<JSONObject> iterator = jsonArray.iterator();
    while (iterator.hasNext()) {
        JSONObject deviceObj = iterator.next();

        Device device = new Device();
        device.setId(deviceObj.get("deviceIdentifier").toString() + "---" + deviceObj.get("type").toString());
        device.setName(deviceObj.get("name").toString());
        device.setModel(deviceObj.get("name").toString());
        device.setType("mobileDevice");
        device.setImage("/store/extensions/assets/mobileapp/resources/models/none.png");
        device.setPlatform(deviceObj.get("type").toString());
        devices.add(device);

    }

    return devices;
}