List of usage examples for org.apache.commons.httpclient NameValuePair NameValuePair
public NameValuePair(String name, String value)
From source file:com.ebay.jetstream.application.dataflows.VisualDataFlow.java
private URL getYumlPic(String yumlData) { try {/*from www .j a va 2 s. co m*/ if (!graphYuml.containsKey(yumlData)) { HttpClient httpclient = new HttpClient(); PostMethod post = new PostMethod(yumlActivityUrl); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); post.addParameter(new NameValuePair("dsl_text", yumlData)); httpclient.executeMethod(post); URL url = new URL(yumlUrl + post.getResponseBodyAsString()); graphYuml.put(yumlData, url); return url; } else { return graphYuml.get(yumlData); } } catch (Exception e) { logger.error(" Exception while rendering pipeline ", e); return null; } }
From source file:com.github.jobs.api.GithubJobsApi.java
public static Job getJob(String id, boolean markdown) { String baseUrl = String.format(ApiConstants.JOB_URL, id); ArrayList<NameValuePair> pairs = new ArrayList<NameValuePair>(); if (markdown) { pairs.add(new NameValuePair(ApiConstants.MARKDOWN, String.valueOf(markdown))); }/* w ww .j a v a2 s. com*/ try { String url = createUrl(baseUrl, pairs); String response = HttpHandler.getInstance().getRequest(url); // convert json to object Gson gson = new Gson(); return gson.fromJson(response, Job.class); } catch (URIException e) { e.printStackTrace(); } return null; }
From source file:com.zimbra.cs.util.yauth.RawAuth.java
public static String getToken(String appId, String user, String pass) throws AuthenticationException, IOException { debug("Sending getToken request: appId = %s, user = %s", appId, user); Response res = doGet(GET_AUTH_TOKEN, new NameValuePair(APPID, appId), new NameValuePair(LOGIN, user), new NameValuePair(PASSWD, pass)); String token = res.getRequiredField(AUTH_TOKEN); debug("Got getToken response: token = %s", token); return token; }
From source file:com.sun.syndication.feed.weather.WeatherGateway.java
public WeatherGateway(WeatherConfigurationI config) { licenseKey = config.getLicenseKey(); partnerID = config.getPartnerID();/*from w ww. j a v a2 s .co m*/ weatherServer = config.getWeatherServer(); defaultMetricSystem = config.isMetric(); userid = new NameValuePair(PARTNER_ID, partnerID); password = new NameValuePair(LICENSE_KEY, licenseKey); prod = new NameValuePair(PRODUCT_CODE, XOAP_CODE); }
From source file:com.mrfeinberg.translation.plugin.altavista.AltavistaTranslationService.java
@Override protected HttpMethod getHttpMethod(final String phrase, final LanguagePair lp) { final PostMethod post = new PostMethod("http://babelfish.yahoo.com/translate_txt"); post.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8"); post.addRequestHeader("Accept-Charset", "ISO-8859-1,utf-8"); final NameValuePair[] params = new NameValuePair[] { new NameValuePair("doit", "done"), new NameValuePair("ei", "UTF-8"), new NameValuePair("intl", "1"), new NameValuePair("trtext", phrase), new NameValuePair("lp", LANGUAGES.get(lp.a()) + "_" + LANGUAGES.get(lp.b())), }; post.setRequestBody(params);/*from w w w. ja v a2s .com*/ return post; }
From source file:io.seldon.client.test.js.BaseJavascriptTest.java
public void createItem() throws IOException { String newItem = "/js/item/new"; NameValuePair[] parameterArray = { new NameValuePair("id", testState.getItemPrefix() + randomString()), new NameValuePair("type", "1"), // ...title, category, tags... new NameValuePair("consumer_key", testState.getConsumerKey()), new NameValuePair("jsonpCallback", testState.getJsonpCallback()) }; ItemBean itemBean = retrievePayload(newItem, parameterArray, ItemBean.class); System.out.println("Response: " + itemBean); }
From source file:net.datapipe.CloudStack.CloudStackAPI.java
public Document updateAutoScaleVMGroup(String autoScaleVMGroupId, HashMap<String, String> optional) throws Exception { LinkedList<NameValuePair> arguments = newQueryValues("updateAutoScaleVmGroup", optional); arguments.add(new NameValuePair("id", autoScaleVMGroupId)); return Request(arguments); }
From source file:net.mojodna.searchable.solr.SolrSearcher.java
public ResultSet search(final String query, final Integer start, final Integer count) throws IndexException { try {/*from ww w.j av a 2 s . c o m*/ final GetMethod get = new GetMethod(solrPath); final List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new NameValuePair("q", query)); if (null != start) { params.add(new NameValuePair("start", start.toString())); } if (null != count) { params.add(new NameValuePair("rows", count.toString())); } params.add(new NameValuePair("version", "2.1")); params.add(new NameValuePair("indent", "on")); get.setQueryString(params.toArray(new NameValuePair[] {})); final int responseCode = getHttpClient().executeMethod(get); final SAXBuilder builder = new SAXBuilder(); final Document response = builder.build(get.getResponseBodyAsStream()); final Element resultNode = response.getRootElement().getChild("result"); final ResultSetImpl resultSet = new ResultSetImpl( new Integer(resultNode.getAttributeValue("numFound"))); resultSet.setOffset(new Integer(resultNode.getAttributeValue("start"))); List<Element> docs = resultNode.getChildren("doc"); for (int i = 0; i < docs.size(); i++) { final Element doc = docs.get(i); Result result = null; // load the class name String className = null; String id = null; String idType = null; for (final Iterator it = doc.getChildren("str").iterator(); it.hasNext();) { final Element str = (Element) it.next(); final String name = str.getAttributeValue("name"); if (IndexSupport.TYPE_FIELD_NAME.equals(name)) { className = str.getTextTrim(); } else if (IndexSupport.ID_FIELD_NAME.equals(name)) { id = str.getTextTrim(); } else if (IndexSupport.ID_TYPE_FIELD_NAME.equals(name)) { idType = str.getTextTrim(); } } try { // attempt to instantiate an instance of the specified class try { if (null != className) { final Object o = Class.forName(className).newInstance(); if (o instanceof Result) { log.debug("Created new instance of: " + className); result = (Result) o; } } } catch (final ClassNotFoundException e) { // class was invalid, or something } // fall back to a GenericResult as a container if (null == result) result = new GenericResult(); if (result instanceof Searchable) { // special handling for searchables final String idField = SearchableBeanUtils .getIdPropertyName(((Searchable) result).getClass()); // attempt to load the id and set the id property on the Searchable appropriately if (null != id) { log.debug("Setting id to '" + id + "' of type " + idType); try { final Object idValue = ConvertUtils.convert(id, Class.forName(idType)); PropertyUtils.setSimpleProperty(result, idField, idValue); } catch (final ClassNotFoundException e) { log.warn("Id type was not a class that could be found: " + idType); } } else { log.warn("Id value was null."); } } else { final GenericResult gr = new GenericResult(); gr.setId(id); gr.setType(className); result = gr; } } catch (final Exception e) { throw new SearchException("Could not reconstitute resultant object.", e); } result.setRanking(i); resultSet.add(result); } return resultSet; } catch (final JDOMException e) { throw new IndexingException(e); } catch (final IOException e) { throw new IndexingException(e); } }
From source file:edu.scripps.fl.pubchem.EUtilsFactory.java
public Callable<InputStream> getInputStream(final String url, final Object... params) throws IOException { return new Callable<InputStream>() { public InputStream call() throws Exception { StringBuffer sb = new StringBuffer(); sb.append(url).append("?"); PostMethod post = new PostMethod(url); List<NameValuePair> data = new ArrayList<NameValuePair>(); data.add(new NameValuePair("tool", EUtilsFactory.this.tool)); data.add(new NameValuePair("email", EUtilsFactory.this.email)); for (int ii = 0; ii < params.length; ii += 2) { String name = params[ii].toString(); String value = ""; if ((ii + 1) < params.length) value = params[ii + 1].toString(); data.add(new NameValuePair(name, value)); sb.append(name).append("=").append(value).append("&"); }//from ww w . j a v a2s . co m post.setRequestBody(data.toArray(new NameValuePair[0])); HttpClient httpclient = new HttpClient(); int result = httpclient.executeMethod(post); // log.debug("Fetching from: " + url + StringUtils.join(params, " ")); log.debug("Fetching from: " + sb); InputStream in = post.getResponseBodyAsStream(); return in; } }; }
From source file:com.navercorp.pinpoint.plugin.httpclient3.HttpClientIT.java
@Test public void test() throws Exception { HttpClient client = new HttpClient(); client.getParams().setConnectionManagerTimeout(CONNECTION_TIMEOUT); client.getParams().setSoTimeout(SO_TIMEOUT); GetMethod method = new GetMethod(webServer.getCallHttpUrl()); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); method.setQueryString(new NameValuePair[] { new NameValuePair("key2", "value2") }); try {/* w w w . jav a 2 s . c o m*/ // Execute the method. client.executeMethod(method); } catch (Exception ignored) { } finally { method.releaseConnection(); } PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); verifier.printCache(); }