List of usage examples for org.apache.commons.httpclient HttpMethodBase getQueryString
@Override
public String getQueryString()
From source file:com.eucalyptus.blockstorage.HttpTransfer.java
/** * Constructs and returns the canonicalQuery string per EucaRSA-V2 specs. * @param httpBaseRequest//from w ww .j a v a 2 s . c o m * @return */ private static String calcCanonicalQuery(HttpMethodBase httpBaseRequest) { StringBuilder canonicalQuery = new StringBuilder(); //Sort query elements, assume all values are already URL encoded String tmpQuery = httpBaseRequest.getQueryString(); HashMap<String, String> parameters = new HashMap<String, String>(); if (!Strings.isNullOrEmpty(tmpQuery)) { String[] rawQueryParams = tmpQuery.split("&"); String[] queryParamNames = new String[rawQueryParams.length]; String[] tmpKV = null; int i = 0; for (String paramKV : rawQueryParams) { tmpKV = paramKV.split("="); queryParamNames[i++] = tmpKV[0]; if (tmpKV.length == 2) { parameters.put(tmpKV[0], tmpKV[1]); } else { parameters.put(tmpKV[0], ""); } } Arrays.sort(queryParamNames); for (String paramName : queryParamNames) { canonicalQuery.append(paramName).append('='); if (parameters.get(paramName) != null) { canonicalQuery.append(parameters.get(paramName)); } else { //Single key, no value canonicalQuery.append(""); } canonicalQuery.append('&'); } if (canonicalQuery.length() > 0) { canonicalQuery.deleteCharAt(canonicalQuery.length() - 1); //Delete the trailing '&' } } return canonicalQuery.toString(); }
From source file:com.cyberway.issue.crawler.datamodel.credential.HtmlFormCredential.java
public boolean populate(CrawlURI curi, HttpClient http, HttpMethod method, String payload) { // http is not used. // payload is not used. boolean result = false; Map formItems = null;// w ww. ja v a2s .c o m try { formItems = getFormItems(curi); } catch (AttributeNotFoundException e1) { logger.severe("Failed get of form items for " + curi); } if (formItems == null || formItems.size() <= 0) { try { logger.severe("No form items for " + method.getURI()); } catch (URIException e) { logger.severe("No form items and exception getting uri: " + e.getMessage()); } return result; } NameValuePair[] data = new NameValuePair[formItems.size()]; int index = 0; String key = null; for (Iterator i = formItems.keySet().iterator(); i.hasNext();) { key = (String) i.next(); data[index++] = new NameValuePair(key, (String) formItems.get(key)); } if (method instanceof PostMethod) { ((PostMethod) method).setRequestBody(data); result = true; } else if (method instanceof GetMethod) { // Append these values to the query string. // Get current query string, then add data, then get it again // only this time its our data only... then append. HttpMethodBase hmb = (HttpMethodBase) method; String currentQuery = hmb.getQueryString(); hmb.setQueryString(data); String newQuery = hmb.getQueryString(); hmb.setQueryString(((StringUtils.isNotEmpty(currentQuery)) ? currentQuery + "&" : "") + newQuery); result = true; } else { logger.severe("Unknown method type: " + method); } return result; }
From source file:com.sun.syndication.propono.atom.client.OAuthStrategy.java
public void addAuthentication(HttpClient httpClient, HttpMethodBase method) throws ProponoException { if (state != State.ACCESS_TOKEN) { throw new ProponoException("ERROR: authentication strategy failed init"); }/*from www . j a v a2 s. co m*/ // add OAuth name/values to request query string // wish we didn't have to parse them apart first, ugh List originalqlist = null; if (method.getQueryString() != null) { String qstring = method.getQueryString().trim(); qstring = qstring.startsWith("?") ? qstring.substring(1) : qstring; originalqlist = new ParameterParser().parse(qstring, '&'); } else { originalqlist = new ArrayList(); } // put query string into hashmap form to please OAuth.net classes Map params = new HashMap(); for (Iterator it = originalqlist.iterator(); it.hasNext();) { NameValuePair pair = (NameValuePair) it.next(); params.put(pair.getName(), pair.getValue()); } // add OAuth params to query string params.put("xoauth_requestor_id", username); params.put("oauth_consumer_key", consumerKey); params.put("oauth_signature_method", keyType); params.put("oauth_timestamp", Long.toString(timestamp)); params.put("oauth_nonce", nonce); params.put("oauth_token", accessToken); params.put("oauth_token_secret", tokenSecret); // sign complete URI String finalUri = null; OAuthServiceProvider provider = new OAuthServiceProvider(reqUrl, authzUrl, accessUrl); OAuthConsumer consumer = new OAuthConsumer(null, consumerKey, consumerSecret, provider); OAuthAccessor accessor = new OAuthAccessor(consumer); accessor.tokenSecret = tokenSecret; OAuthMessage message; try { message = new OAuthMessage(method.getName(), method.getURI().toString(), params.entrySet()); message.sign(accessor); finalUri = OAuth.addParameters(message.URL, message.getParameters()); } catch (Exception ex) { throw new ProponoException("ERROR: OAuth signing request", ex); } // pull query string off and put it back onto method method.setQueryString(finalUri.substring(finalUri.lastIndexOf("?"))); }
From source file:jeeves.utils.XmlRequest.java
private String getSentData(HttpMethodBase httpMethod) { StringBuilder sentData = new StringBuilder(httpMethod.getName()).append(" ").append(httpMethod.getPath()); if (httpMethod.getQueryString() != null) { sentData.append("?" + httpMethod.getQueryString()); }/*from w w w . j a v a2s .com*/ sentData.append("\r\n"); for (Header h : httpMethod.getRequestHeaders()) { sentData.append(h); } sentData.append("\r\n"); if (httpMethod instanceof PostMethod) { sentData.append(postData); } return sentData.toString(); }
From source file:com.rometools.propono.atom.client.OAuthStrategy.java
@Override public void addAuthentication(final HttpClient httpClient, final HttpMethodBase method) throws ProponoException { if (state != State.ACCESS_TOKEN) { throw new ProponoException("ERROR: authentication strategy failed init"); }/*w w w .j a va 2 s .co m*/ // add OAuth name/values to request query string // wish we didn't have to parse them apart first, ugh List<NameValuePair> originalqlist = null; if (method.getQueryString() != null) { String qstring = method.getQueryString().trim(); qstring = qstring.startsWith("?") ? qstring.substring(1) : qstring; @SuppressWarnings("unchecked") final List<NameValuePair> parameters = new ParameterParser().parse(qstring, '&'); originalqlist = parameters; } else { originalqlist = new ArrayList<NameValuePair>(); } // put query string into hashmap form to please OAuth.net classes final Map<String, String> params = new HashMap<String, String>(); for (final Object element : originalqlist) { final NameValuePair pair = (NameValuePair) element; params.put(pair.getName(), pair.getValue()); } // add OAuth params to query string params.put("xoauth_requestor_id", username); params.put("oauth_consumer_key", consumerKey); params.put("oauth_signature_method", keyType); params.put("oauth_timestamp", Long.toString(timestamp)); params.put("oauth_nonce", nonce); params.put("oauth_token", accessToken); params.put("oauth_token_secret", tokenSecret); // sign complete URI String finalUri = null; final OAuthServiceProvider provider = new OAuthServiceProvider(reqUrl, authzUrl, accessUrl); final OAuthConsumer consumer = new OAuthConsumer(null, consumerKey, consumerSecret, provider); final OAuthAccessor accessor = new OAuthAccessor(consumer); accessor.tokenSecret = tokenSecret; OAuthMessage message; try { message = new OAuthMessage(method.getName(), method.getURI().toString(), params.entrySet()); message.sign(accessor); finalUri = OAuth.addParameters(message.URL, message.getParameters()); } catch (final Exception ex) { throw new ProponoException("ERROR: OAuth signing request", ex); } // pull query string off and put it back onto method method.setQueryString(finalUri.substring(finalUri.lastIndexOf("?"))); }
From source file:com.assemblade.client.AbstractClient.java
private void generateSignature(HttpMethodBase method) throws URIException { if (authentication != null) { String verb = method.getName(); String url = OAuthEncoder.encode(method.getURI().toString()); List<NameValuePair> queryStrings = new ArrayList<NameValuePair>(); queryStrings.add(new NameValuePair(OAuthConstants.CONSUMER_KEY, authentication.getToken())); queryStrings.add(new NameValuePair(OAuthConstants.NONCE, timestampService.getNonce())); queryStrings.add(new NameValuePair(OAuthConstants.SIGN_METHOD, signatureService.getSignatureMethod())); queryStrings.add(new NameValuePair(OAuthConstants.TIMESTAMP, timestampService.getTimestampInSeconds())); queryStrings.add(new NameValuePair(OAuthConstants.VERSION, "1.0")); method.setQueryString(queryStrings.toArray(new NameValuePair[] {})); String queryString = OAuthEncoder.encode(method.getQueryString()); String baseString = verb + "&" + url + "&" + queryString; String signature = signatureService.getSignature(baseString, authentication.getSecret(), ""); queryStrings.add(new NameValuePair(OAuthConstants.SIGNATURE, signature)); method.setQueryString(queryStrings.toArray(new NameValuePair[] {})); }//from www . ja v a2 s .co m }
From source file:org.fao.geonet.csw.common.requests.CatalogRequest.java
private HttpMethodBase setupHttpMethod() throws UnsupportedEncodingException { HttpMethodBase httpMethod; if (method == Method.GET) { alGetParams = new ArrayList<NameValuePair>(); if (alSetupGetParams.size() != 0) { alGetParams.addAll(alSetupGetParams); }//w ww. j av a 2 s . c om setupGetParams(); httpMethod = new GetMethod(); httpMethod.setPath(path); httpMethod.setQueryString(alGetParams.toArray(new NameValuePair[1])); System.out.println("GET params:" + httpMethod.getQueryString()); if (useSOAP) httpMethod.addRequestHeader("Accept", "application/soap+xml"); } else { Element params = getPostParams(); PostMethod post = new PostMethod(); if (!useSOAP) { postData = Xml.getString(new Document(params)); post.setRequestEntity(new StringRequestEntity(postData, "application/xml", "UTF8")); } else { postData = Xml.getString(new Document(soapEmbed(params))); post.setRequestEntity(new StringRequestEntity(postData, "application/soap+xml", "UTF8")); } System.out.println("POST params:" + Xml.getString(params)); httpMethod = post; httpMethod.setPath(path); } // httpMethod.setFollowRedirects(true); if (useAuthent) { Credentials cred = new UsernamePasswordCredentials(username, password); AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM); client.getState().setCredentials(scope, cred); httpMethod.setDoAuthentication(true); } return httpMethod; }
From source file:org.fao.geonet.csw.common.requests.CatalogRequest.java
private void setupSentData(HttpMethodBase httpMethod) { sentData = httpMethod.getName() + " " + httpMethod.getPath(); if (httpMethod.getQueryString() != null) sentData += "?" + httpMethod.getQueryString(); sentData += "\r\n"; for (Header h : httpMethod.getRequestHeaders()) sentData += h;/*from w w w . j a v a 2 s .c o m*/ sentData += "\r\n"; if (httpMethod instanceof PostMethod) sentData += postData; }
From source file:org.fao.oaipmh.requests.Transport.java
private void setupSentData(HttpMethodBase httpMethod) { sentData = httpMethod.getName() + " " + httpMethod.getPath(); if (httpMethod.getQueryString() != null) sentData += "?" + httpMethod.getQueryString(); sentData += "\r\n"; for (Header h : httpMethod.getRequestHeaders()) sentData += h;//from w w w .j av a2 s .c o m sentData += "\r\n"; }