Example usage for org.apache.commons.httpclient.methods PostMethod setParameter

List of usage examples for org.apache.commons.httpclient.methods PostMethod setParameter

Introduction

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

Prototype

public void setParameter(String paramString1, String paramString2) 

Source Link

Usage

From source file:com.bluexml.xforms.demo.Util.java

public static Collection<? extends Vector<String>> showAvailableContentWithWorklowId(String alfrescohost,
        String user, String password, String workflowId) throws Exception {
    Set<Vector<String>> result = new HashSet<Vector<String>>();
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();

    PostMethod post = new PostMethod(alfrescohost + "service/xforms/workflow");
    post.setParameter("username", user);
    post.setParameter("method", "getWorkflowPaths");
    post.setParameter("arg0", workflowId);
    HttpClient client = new HttpClient();
    client.executeMethod(post);/*  www  .j a  v  a  2  s.co  m*/

    Document document = builder.parse(new ByteArrayInputStream(
            ("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + post.getResponseBodyAsString()).getBytes()));
    Node root = document.getDocumentElement();
    // in the case of the workflow is ended
    if (findNodes(root.getChildNodes(), "org.alfresco.service.cmr.workflow.WorkflowPath").size() > 0) {
        String pathId = findNode(
                findNode(root.getChildNodes(), "org.alfresco.service.cmr.workflow.WorkflowPath")
                        .getChildNodes(),
                "id").getTextContent();

        post = new PostMethod(alfrescohost + "service/xforms/workflow");
        post.setParameter("username", user);
        post.setParameter("method", "getTasksForWorkflowPath");
        post.setParameter("arg0", pathId);
        client = new HttpClient();
        client.executeMethod(post);

        document = builder.parse(new ByteArrayInputStream(
                ("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + post.getResponseBodyAsString()).getBytes()));
        root = document.getDocumentElement();
        String taskId = findNode(
                findNode(root.getChildNodes(), "org.alfresco.service.cmr.workflow.WorkflowTask")
                        .getChildNodes(),
                "id").getTextContent();

        post = new PostMethod(alfrescohost + "service/xforms/workflow");
        post.setParameter("username", user);
        post.setParameter("method", "getPackageContents");
        post.setParameter("arg0", taskId);
        client = new HttpClient();
        client.executeMethod(post);

        document = builder.parse(new ByteArrayInputStream(
                ("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + post.getResponseBodyAsString()).getBytes()));
        root = document.getDocumentElement();

        for (int i = 0; i < root.getChildNodes().getLength(); i++) {
            Node n = root.getChildNodes().item(i);
            if (n.getNodeType() == Element.ELEMENT_NODE) {
                String protocol = findNode(findNode(n.getChildNodes(), "storeRef").getChildNodes(), "protocol")
                        .getTextContent();
                String workspace = findNode(findNode(n.getChildNodes(), "storeRef").getChildNodes(),
                        "identifier").getTextContent();
                String id = findNode(n.getChildNodes(), "id").getTextContent();

                String url = alfrescohost + "service/api/node/" + protocol + "/" + workspace + "/" + id;
                GetMethod get = new GetMethod(url);
                client = new HttpClient();
                UsernamePasswordCredentials upc = new UsernamePasswordCredentials(user, password);
                client.getState().setCredentials(AuthScope.ANY, upc);
                get.setDoAuthentication(true);
                client.executeMethod(get);
                document = builder.parse(get.getResponseBodyAsStream());
                Node rootContent = document.getDocumentElement();

                Vector<String> v = new Vector<String>();
                String downloadUrl = findNode(rootContent.getChildNodes(), "content").getAttributes()
                        .getNamedItem("src").getNodeValue();
                String title = findNode(rootContent.getChildNodes(), "title").getTextContent();
                String icon = findNode(rootContent.getChildNodes(), "alf:icon").getTextContent();
                v.add(title);
                v.add(downloadUrl);
                v.add(icon);
                result.add(v);
            }
        }
    }
    return result;
}

From source file:edu.du.penrose.systems.util.HttpClientUtils_2.java

static PostMethod setChangehangingFields(PostMethod postMethod, String formContents) {
    final String SESSION_ID = "__sid";
    final String SCREEN_RESOLUTION = "__ScreenResolution";

    String[] sidStuff = formContents.split(SESSION_ID);
    String[] resolutionStuff = formContents.split(SCREEN_RESOLUTION);

    String sidStuff2 = sidStuff[2].substring(1, sidStuff[2].indexOf(">"));
    String sid = sidStuff2.substring(sidStuff2.indexOf("\"") + 1, sidStuff2.lastIndexOf("\""));

    //      String resolution = resolutionStuff[1].substring(0, resolution[1].indexOf(">") );  // value gets set by javascript.

    postMethod.setParameter(SESSION_ID, sid);
    postMethod.setParameter(SCREEN_RESOLUTION, "1280 : 1024"); // TBD see above

    return postMethod;
}

From source file:jsst.core.client.dispatcher.impl.HTTPDispatcher.java

@Override
public HTTPServerResponse dispatch(Method method) throws DispatcherException {
    HttpClient httpClient = new HttpClient();
    PostMethod postMethod = new PostMethod(url);
    postMethod.setParameter(REQUEST_PARAM_CLASS_NAME, method.getDeclaringClass().getCanonicalName());
    postMethod.setParameter(REQUEST_PARAM_METHOD_NAME, method.getName());
    try {/*from w w w  .j av a 2 s.c om*/
        try {
            httpClient.executeMethod(postMethod);
        } catch (ConnectException ex) {
            throw new DispatcherException("Failed to connect to \"" + url + "\". Seems like server is down");
        }
        return new HTTPServerResponse(url, postMethod.getResponseBodyAsString(), postMethod.getStatusCode());
    } catch (IOException e) {
        throw new DispatcherException("Exception caught while sending request to \"" + url + "\"", e);
    } finally {
        postMethod.releaseConnection();
    }
}

From source file:codeOrchestra.lcs.license.ActivationReporter.java

public boolean report() {
    try {//ww  w. ja  va2 s  .c  om
        PostMethod postMethod = new PostMethod(ACTIVATION_URL);
        postMethod.setParameter("sn", serialNumber);
        postMethod.setParameter("fp", getFingerPrint());
        httpClient.executeMethod(postMethod);

        System.out.println("Activation: " + postMethod.getStatusCode());

        return true;
    } catch (Throwable t) {
        // ignore
    }
    return false;
}

From source file:net.duckling.ddl.service.version.impl.VersionService.java

@Override
public Version get(String project, String type) {
    HttpClient dClient = new HttpClient();
    PostMethod method = new PostMethod(getDupdateUrl());
    method.setParameter("type", type);
    method.setParameter("project", project);
    try {/*from w  ww  .  j a  v  a 2  s  .  c o m*/
        dClient.executeMethod(method);
        String response = method.getResponseBodyAsString();
        Map<String, String> map = parseResponse(response);

        Version v = new Version();
        if (map.get("success").equals("true")) {
            v.setVersion(map.get("version"));
            v.setDownloadUrl(map.get("downloadUrl"));
            v.setForcedUpdate(Boolean.valueOf(map.get("forcedUpdate")));
            v.setDescription(map.get("description"));
            v.setCreateTime(map.get("createTime"));
        }
        v.setSuccess(Boolean.valueOf(map.get("success")));
        return v;
    } catch (HttpException e) {
        LOG.error("", e);
    } catch (IOException e) {
        LOG.error("", e);
    } catch (ParseException e) {
        LOG.error("", e);
    }
    return null;
}

From source file:edu.northwestern.bioinformatics.studycalendar.security.plugin.cas.direct.DirectLoginHttpFacade.java

protected PostMethod createLoginPostMethod() {
    PostMethod method = new PostMethod(getLoginUrl());
    method.setParameter("service", getServiceUrl());
    return initMethod(method);
}

From source file:net.duckling.ddl.web.api.APIMobileVersionController.java

private void formatDupdate(HttpServletResponse resp, String type) {
    HttpClient dClient = new HttpClient();
    PostMethod method = new PostMethod(getDupdateUrl());
    method.setParameter("type", type);
    method.setParameter("projectName", getProjectName());
    try {//  w  w w  .  j a v a 2  s. co  m
        dClient.executeMethod(method);
        String response = method.getResponseBodyAsString();
        Map<String, Object> map = dealJsonResult(response);
        JSONObject obj = new JSONObject();
        obj.put("updateMessage", map.get("descreption"));
        obj.put("result", map.get("success"));
        obj.put("version", map.get("version"));
        String url = (String) map.get("downloadUrl");
        if (StringUtils.isEmpty(url)) {
            url = "http://www.escience.cn/apks/ddl-latest.apk";
        }
        obj.put("downloadUrl", url);
        obj.put("isForce", map.get("forcedUpdate"));
        JsonUtil.writeJSONObject(resp, obj);
    } catch (HttpException e) {
        LOG.error("", e);
    } catch (IOException e) {
        LOG.error("", e);
    } catch (ParseException e) {
        LOG.error("", e);
    }

}

From source file:com.cellbots.communication.AppEngineCommChannel.java

@Override
public void listenForMessages(long waitTimeBetweenPolling, boolean returnStream) {
    stopReading = false;/*from w  w  w  .  j a  va  2  s  .c  om*/
    new Thread(new Runnable() {
        @Override
        public void run() {
            Looper.prepare();
            while (!stopReading) {
                try {
                    resetConnection();
                    PostMethod post = new PostMethod(mHttpCmdUrl);
                    post.setParameter("msg", "{}");
                    int result = post.execute(mHttpState, mConnection);
                    String response = post.getResponseBodyAsString();
                    int cmdStart = response.indexOf(startCmdStr);
                    if (cmdStart != -1) {
                        String command = response.substring(cmdStart + startCmdStr.length());
                        command = command.substring(0, command.indexOf("\""));
                        Log.e("command", command);
                        mMessageListener.onMessage(new CommMessage(command, null, "text/text", null, null,
                                mChannelName, CommunicationManager.CHANNEL_GAE));
                    }
                    // Thread.sleep(200);
                } catch (MalformedURLException e) {
                    Log.e(TAG, "Error processing URL: " + e.getMessage());
                } catch (IOException e) {
                    Log.e(TAG, "Error reading command from URL: " + mHttpCmdUrl + " : " + e.getMessage());
                }
            }
        }
    }).start();
}

From source file:cn.vlabs.umt.ui.servlet.OnlineStorageLoginServlet.java

private String getSid(HttpServletRequest request) {
    String uid = null;/*from  www.  jav  a 2  s.  c  o m*/
    ThirdPartyCredential tpc = (ThirdPartyCredential) request.getSession()
            .getAttribute(Attributes.THIRDPARTY_CREDENTIAL);
    if (tpc != null) {
        HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager());
        String loginThirdpartyAppURL = request.getParameter("loginThirdpartyAppURL");
        if (loginThirdpartyAppURL == null) {
            loginThirdpartyAppURL = "http://mail.cnic.cn/coremail/index.jsp";
        }
        PostMethod method = new PostMethod(loginThirdpartyAppURL);
        method.setParameter("uid", tpc.getUsername());
        method.setParameter("password", tpc.getPassword());
        method.setParameter("action:login", "");
        method.setParameter("face", "H");
        try {
            client.executeMethod(method);
        } catch (IOException e) {
            LOGGER.error(e.getMessage(), e);
        } finally {
            if (uid == null) {
                request.setAttribute("tip", "ssoLostPassword");
                request.setAttribute(Attributes.RETURN_URL, request.getParameter(Attributes.RETURN_URL));
            }
        }
        Header locationHeader = (Header) method.getResponseHeader("Location");
        if (locationHeader != null) {
            String location = locationHeader.getValue();
            uid = location.substring(location.lastIndexOf("?") + 5);
        }
        method.releaseConnection();
        client.getHttpConnectionManager().closeIdleConnections(0);
    } else {
        request.setAttribute("tip", "onlyCstnetUserLoginOnlineStorage");
    }
    return uid;
}

From source file:com.ifeng.vdn.ip.repository.service.impl.AliBatchIPAddressChecker.java

@Override
public List<AliIPBean> check(List<String> ips) {

    List<AliIPBean> list = new ArrayList<AliIPBean>();

    AliIPBean ipaddress = null;//from  ww  w .j  a v a2s. c  o m
    String url = "http://ip.taobao.com/service/getIpInfo2.php";

    for (String ip : ips) {

        // Create an instance of HttpClient.
        HttpClient clinet = new HttpClient();

        // Create a method instance.
        PostMethod postMethod = new PostMethod(url);

        // Execute the method.
        try {
            postMethod.setParameter("ip", ip);
            int resultCode = clinet.executeMethod(postMethod);

            if (resultCode == HttpStatus.SC_OK) {
                // Read the response body.
                InputStream responseBody = postMethod.getResponseBodyAsStream();

                ObjectMapper mapper = new ObjectMapper();
                ipaddress = mapper.readValue(responseBody, AliIPBean.class);

                log.info(responseBody.toString());

                list.add(ipaddress);
            } else {
                list.add(new AliIPBean());
                log.error("Method failedd: [{}] , IP: [{}]", postMethod.getStatusCode(), ip);
            }

        } catch (JsonParseException | JsonMappingException | HttpException e) {
            list.add(new AliIPBean());
            log.error(e.getMessage(), e);
        } catch (IOException e) {
            list.add(new AliIPBean());
            log.error(e.getMessage(), e);
        }
    }
    return list;
}