List of usage examples for org.apache.commons.httpclient.methods PostMethod setParameter
public void setParameter(String paramString1, String paramString2)
From source file:com.bluexml.xforms.demo.Util.java
private static List<String> getIdentifiers(String alfrescohost, String user, String definitionName) throws Exception { List<String> result = new ArrayList<String>(); PostMethod post = new PostMethod(alfrescohost + "service/xforms/workflow"); post.setParameter("username", user); post.setParameter("method", "getAllDefinitionsByName"); post.setParameter("arg0", definitionName); HttpClient client = new HttpClient(); client.executeMethod(post);//from w w w.j av a 2 s . c o m DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(post.getResponseBodyAsStream()); Node root = document.getDocumentElement(); for (int i = 0; i < root.getChildNodes().getLength(); i++) { Node n = root.getChildNodes().item(i); if (n.getNodeType() == Element.ELEMENT_NODE) result.add(findNode(n.getChildNodes(), "id").getTextContent()); } return result; }
From source file:com.bluexml.xforms.demo.Util.java
private static String getUserName(String alfrescohost, String user, String protocol, String identifier, String initiator) throws Exception { String firstname = ""; String lastname = ""; PostMethod post = new PostMethod(alfrescohost + "service/xforms/read"); post.setParameter("username", user); post.setParameter("objectId", protocol + "://" + identifier + "/" + initiator); HttpClient client = new HttpClient(); client.executeMethod(post);//from w ww.j a va 2 s.co m DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(post.getResponseBodyAsStream()); Node root = document.getDocumentElement(); NodeList nodes = findNode(root.getChildNodes(), "attributes").getChildNodes(); for (int i = 0; i < nodes.getLength(); ++i) { Node n = nodes.item(i); if (n.getNodeName().equals("attribute")) { Node attr = n.getAttributes().getNamedItem("qualifiedName"); if (attr != null) if (attr.getNodeValue().equals("firstName")) firstname = findNode(n.getChildNodes(), "value").getTextContent(); else if (attr.getNodeValue().equals("lastName")) lastname = findNode(n.getChildNodes(), "value").getTextContent(); } } return firstname + " " + lastname; }
From source file:com.bluexml.xforms.demo.Util.java
private static String getContentId(String alfrescohost, String userName, String taskId) throws Exception { String result = ""; PostMethod post = new PostMethod(alfrescohost + "service/xforms/workflow"); post.setParameter("username", userName); post.setParameter("method", "getPackageContents"); post.setParameter("arg0", taskId); HttpClient client = new HttpClient(); client.executeMethod(post);// w ww.ja v a 2s . c o m DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(post.getResponseBodyAsStream()); Node searchedNode = null; Node root = document.getDocumentElement(); for (int i = 0; i < root.getChildNodes().getLength(); i++) { Node n = root.getChildNodes().item(i); if (n.getNodeType() == Element.ELEMENT_NODE && searchedNode == null) { searchedNode = n; } } if (searchedNode != null) result = findNode(searchedNode.getChildNodes(), "id").getTextContent(); return result; }
From source file:com.bluexml.xforms.demo.Util.java
public static Set<Vector<String>> getDefinitions(String alfrescohost, String user) { Set<Vector<String>> result = new HashSet<Vector<String>>(); try {//from w w w.ja va 2 s . c om PostMethod post = new PostMethod(alfrescohost + "service/xforms/workflow"); post.setParameter("username", user); post.setParameter("method", "getDefinitions"); HttpClient client = new HttpClient(); client.executeMethod(post); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(post.getResponseBodyAsStream()); Node root = document.getDocumentElement(); root = findNode(root.getChildNodes(), "list"); for (int i = 0; i < root.getChildNodes().getLength(); i++) { Node n = root.getChildNodes().item(i); if (n.getNodeType() == Element.ELEMENT_NODE) { Vector<String> v = new Vector<String>(); v.add(findNode(n.getChildNodes(), "id").getTextContent()); v.add(findNode(n.getChildNodes(), "version").getTextContent()); v.add(findNode(n.getChildNodes(), "title").getTextContent()); v.add(findNode(n.getChildNodes(), "description").getTextContent()); v.add(findNode(n.getChildNodes(), "name").getTextContent()); result.add(v); } } } catch (Exception e) { e.printStackTrace(); } return result; }
From source file:com.bluexml.xforms.demo.Util.java
private static Collection<? extends Vector<String>> getInstancesById(String alfrescohost, String user, String id) throws Exception { Set<Vector<String>> result = new HashSet<Vector<String>>(); PostMethod post = new PostMethod(alfrescohost + "service/xforms/workflow"); post.setParameter("username", user); post.setParameter("method", "getActiveWorkflows"); post.setParameter("arg0", id); HttpClient client = new HttpClient(); client.executeMethod(post);//from w w w .j a v a 2 s. com DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(post.getResponseBodyAsStream()); Node root = document.getDocumentElement(); for (int i = 0; i < root.getChildNodes().getLength(); i++) { Node n = root.getChildNodes().item(i); if (n.getNodeType() == Element.ELEMENT_NODE) { Vector<String> v = new Vector<String>(); v.add(findNode(n.getChildNodes(), "id").getTextContent()); v.add(findNode(n.getChildNodes(), "startDate").getTextContent()); String initiator = findNode(findNode(n.getChildNodes(), "initiator").getChildNodes(), "id") .getTextContent(); String protocol = findNode( findNode(findNode(n.getChildNodes(), "initiator").getChildNodes(), "storeRef") .getChildNodes(), "protocol").getTextContent(); String identifier = findNode( findNode(findNode(n.getChildNodes(), "initiator").getChildNodes(), "storeRef") .getChildNodes(), "identifier").getTextContent(); String username = getUserName(alfrescohost, user, protocol, identifier, initiator); v.add(username); v.add(findNode(findNode(n.getChildNodes(), "definition").getChildNodes(), "version") .getTextContent()); result.add(v); } } return result; }
From source file:com.bluexml.xforms.demo.Util.java
public static Collection<? extends Vector<String>> showAvailableContent(String alfrescohost, String user, String password, String taskId) throws Exception { Set<Vector<String>> result = new HashSet<Vector<String>>(); PostMethod post = new PostMethod(alfrescohost + "service/xforms/workflow"); post.setParameter("username", user); post.setParameter("method", "getPackageContents"); post.setParameter("arg0", taskId); HttpClient client = new HttpClient(); client.executeMethod(post);/*w ww . j a va 2 s. co m*/ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(post.getResponseBodyAsStream()); Node 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:com.bluexml.xforms.demo.Util.java
public static Set<Vector<String>> getPooledTasks(String alfrescohost, String user) { Set<Vector<String>> result = new HashSet<Vector<String>>(); try {//from w ww. ja v a2 s . c om DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); // the mapping.xml file is private to the controller. Better use the API. // Document mappingDocument = builder.parse(mapping); PostMethod post = new PostMethod(alfrescohost + "service/xforms/workflow"); post.setParameter("username", user); post.setParameter("method", "getPooledTasks"); post.setParameter("arg0", user); HttpClient client = new HttpClient(); client.executeMethod(post); Document document = builder.parse(new ByteArrayInputStream( ("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + post.getResponseBodyAsString()).getBytes())); Node root = document.getDocumentElement(); root = findNode(root.getChildNodes(), "list"); for (int i = 0; i < root.getChildNodes().getLength(); i++) { Node n = root.getChildNodes().item(i); if (n.getNodeType() == Element.ELEMENT_NODE) { Vector<String> v = new Vector<String>(); String instanceId = findNode( findNode(findNode(n.getChildNodes(), "path").getChildNodes(), "instance") .getChildNodes(), "id").getTextContent(); String taskId = findNode(n.getChildNodes(), "id").getTextContent(); v.add(taskId); v.add(findNode(n.getChildNodes(), "title").getTextContent()); v.add(findNode(n.getChildNodes(), "description").getTextContent()); String name = findNode(n.getChildNodes(), "name").getTextContent(); v.add(getFormName(name)); v.add(getContentId(alfrescohost, user, taskId)); v.add(instanceId); result.add(v); } } } catch (Exception e) { e.printStackTrace(); } return result; }
From source file:com.bluexml.xforms.demo.Util.java
public static Set<Vector<String>> getToDoTasks(String alfrescohost, String user) { Set<Vector<String>> result = new HashSet<Vector<String>>(); try {/* w w w.java 2s. c o m*/ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); // the mapping.xml file is private to the controller. Better use the API. // Document mappingDocument = builder.parse(mapping); PostMethod post = new PostMethod(alfrescohost + "service/xforms/workflow"); post.setParameter("username", user); post.setParameter("method", "getAssignedTasks"); post.setParameter("arg0", user); post.setParameter("arg1", "IN_PROGRESS"); HttpClient client = new HttpClient(); client.executeMethod(post); Document document = builder.parse(new ByteArrayInputStream( ("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + post.getResponseBodyAsString()).getBytes())); Node root = document.getDocumentElement(); root = findNode(root.getChildNodes(), "list"); for (int i = 0; i < root.getChildNodes().getLength(); i++) { Node n = root.getChildNodes().item(i); if (n.getNodeType() == Element.ELEMENT_NODE) { Vector<String> v = new Vector<String>(); String instanceId = findNode( findNode(findNode(n.getChildNodes(), "path").getChildNodes(), "instance") .getChildNodes(), "id").getTextContent(); String taskId = findNode(n.getChildNodes(), "id").getTextContent(); v.add(taskId); v.add(findNode(n.getChildNodes(), "title").getTextContent()); v.add(findNode(n.getChildNodes(), "description").getTextContent()); String name = findNode(n.getChildNodes(), "name").getTextContent(); v.add(getFormName(name)); v.add(getContentId(alfrescohost, user, taskId)); v.add(instanceId); result.add(v); } } } catch (Exception e) { e.printStackTrace(); } return result; }
From source file:edu.du.penrose.systems.util.HttpClientUtils_2.java
static public WebPage academicSearch(URL initialLink) { WebPage wp = new WebPage(); HttpClient client = new HttpClient(); GetMethod getMethod = new GetMethod(initialLink.toString()); getMethod.setFollowRedirects(true);//from w ww . ja v a 2s. c o m try { // System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); // System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); // System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire.header", "debug"); // System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug"); // getMethod.setRequestHeader("User-Agent", "Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101"); // in case they check int statusCode = client.executeMethod(getMethod); String contents = getMethod.getResponseBodyAsString(); String formPage = getMethod.getURI().toString(); // page we were sent to. wp.setStatus(statusCode); wp.setWebPage(contents); // System.out.println();System.out.println();System.out.println();System.out.println();System.out.println(contents); String sid = getSID(contents); String postURL = "http://web.ebscohost.com/ehost/search?vid=1&hid=9&sid=" + sid; PostMethod postMethod = new PostMethod( "http://web.ebscohost.com/ehost/search?vid=1&hid=9&sid=c3220986-66e4-4fd1-ba6a-30504f3694ad%40sessionmgr13"); postMethod.setRequestHeader("User-Agent", "Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101"); // in case they check // postMethod.setFollowRedirects( true ); causes error postMethod.setParameter(SESSION_ID, sid); setResolution(postMethod, contents); setNonchangingFields(postMethod); statusCode = client.executeMethod(postMethod); if (statusCode > 300) { String resultsPage = getMethod.getURI().toString(); // page we were sent to. getMethod = new GetMethod(resultsPage); getMethod.setRequestHeader("User-Agent", "Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101"); // in case they check statusCode = client.executeMethod(getMethod); contents = getMethod.getResponseBodyAsString(); wp.setStatus(statusCode); wp.setWebPage(contents); } contents = postMethod.getResponseBodyAsString(); wp.setStatus(statusCode); wp.setWebPage(contents); System.out.println(); System.out.println(); System.out.println(); System.out.println(); System.out.println(contents); } catch (Exception e) { System.out.println(e); } finally { getMethod.releaseConnection(); } return wp; }
From source file:eu.crowdrec.contest.sender.RequestSender.java
/** * Send a line from a logFile to an HTTP server. * /*from www . j a v a 2 s .c o m*/ * @param logline the line that should by sent * * @param connection the connection to the http server, must not be null * * @return the response or null (if an error has been detected) */ static private String excutePostWithHttpClient(final String logline, final String serverURL) { // split the logLine into several token String[] token = logline.split("\t"); // define the URL parameter String urlParameters = ""; boolean oldMethod = token.length < 4; if (oldMethod) { try { String type = logline.contains("\"event_type\": \"recommendation_request\"") ? "recommendation_request" : "event_notification"; String newLine = logline.substring(0, logline.length() - 1) + ", \"limit\":6, \"type\":\"impression\"}"; urlParameters = String.format("type=%s&body=%s", URLEncoder.encode(type, "UTF-8"), URLEncoder.encode(newLine, "UTF-8")); } catch (UnsupportedEncodingException e1) { logger.warn(e1.toString()); } } else { String type = token[0]; String property = token[3]; String entity = token[4]; // encode the content as URL parameters. try { urlParameters = String.format("type=%s&properties=%s&entities=%s", URLEncoder.encode(type, "UTF-8"), URLEncoder.encode(property, "UTF-8"), URLEncoder.encode(entity, "UTF-8")); } catch (UnsupportedEncodingException e1) { logger.warn(e1.toString()); } } PostMethod postMethod = null; try { StringRequestEntity requestEntity = new StringRequestEntity(urlParameters, "application/x-www-form-urlencoded", "UTF-8"); postMethod = new PostMethod(serverURL); postMethod.setParameter("useCache", "false"); postMethod.setRequestEntity(requestEntity); int statusCode = httpClient.executeMethod(postMethod); String response = statusCode == 200 ? postMethod.getResponseBodyAsString() : "statusCode:" + statusCode; return response.trim(); } catch (IOException e) { logger.warn("receivind response failed, ignored."); } finally { if (postMethod != null) { postMethod.releaseConnection(); } } return null; }