List of usage examples for java.net URI getQuery
public String getQuery()
From source file:com.eucalyptus.blockstorage.HttpTransfer.java
/** * Constructs the requested method, optionally signing the request via EucaRSA-V2 signing method if signRequest=true * Signing the request can be done later as well by explicitly calling signEucaInternal() and passing it the output of this method. * That case is useful for constructing the request and then adding headers explicitly before signing takes place. * @param verb - The HTTP verb GET|PUT|POST|DELETE|UPDATE * @param addr - THe destination address for the request * @param eucaOperation - The EucaOperation, if any (e.g. StoreSnapshot, GetWalrusSnapshot, or other values from ObjectStorageProperties.StorageOperations) * @param eucaHeader - The Euca Header value, if any. This is not typically used. * @param signRequest - Determines if the request is signed at construction time or must be done explicitly later (boolean) * @return// w w w. j a v a 2s . co m */ public HttpMethodBase constructHttpMethod(String verb, String addr, String eucaOperation, String eucaHeader, boolean signRequest) { String date = DateUtil.formatDate(new Date(), ISO_8601_FORMAT); //String date = new Date().toString(); String httpVerb = verb; String addrPath = null; java.net.URI addrUri = null; try { addrUri = new URL(addr).toURI(); addrPath = addrUri.getPath().toString(); String query = addrUri.getQuery(); if (query != null) { addrPath += "?" + query; } } catch (Exception ex) { LOG.error(ex, ex); return null; } HttpMethodBase method = null; if (httpVerb.equals("PUT")) { method = new PutMethodWithProgress(addr); } else if (httpVerb.equals("DELETE")) { method = new DeleteMethod(addr); } else { method = new GetMethod(addr); } method.setRequestHeader("Date", date); //method.setRequestHeader("Expect", "100-continue"); method.setRequestHeader(EUCALYPTUS_OPERATION, eucaOperation); if (eucaHeader != null) { method.setRequestHeader(EUCALYPTUS_HEADER, eucaHeader); } if (signRequest) { signEucaInternal(method); } return method; }
From source file:fakingXmocking.CurrencyConversionHttpClientFake.java
@Mock public HttpResponse execute(HttpUriRequest req) { URI uri = req.getURI(); final String response; if ("www.jhall.demon.co.uk".equals(uri.getHost())) { response = "<h3>Currency Data</h3>\r\n" + "<table><tr>\r\n" + " <td valign=top>USD</td>\r\n" + " <td valign=top>EUR</td>\r\n" + " <td valign=top>BRL</td>\r\n" + " <td valign=top>CNY</td>\r\n" + "</tr></table>"; } else {//from w w w .j av a2 s . c om String[] params = uri.getQuery().split("&"); response = formatResultContainingCurrencyConversion(params); } return new BasicHttpResponse(req.getProtocolVersion(), 200, "OK") { @Override public HttpEntity getEntity() { return createHttpResponse(response); } }; }
From source file:eu.esdihumboldt.hale.common.core.io.PathUpdate.java
/** * Create an alternative path for the given location if it matches changes * from old to new location. If either old or new location is null, or the * given URI wasn't changed in the same way, this method has no effect. * /* w w w . j a va 2 s . c o m*/ * @param oldSource path where the file was saved to * @return the new URI */ public URI changePath(URI oldSource) { if (oldRaw == null || oldRaw.isEmpty()) { return oldSource; } else { if (oldSource.toString().startsWith(oldRaw)) { return URI.create(oldSource.toString().replace(oldRaw, newRaw)); } else { // try to fix cases where oldRaw matches '<scheme>:///<rest>' // but oldSource matches '<scheme>:/<rest>' or vice versa try { URI oldRawUri = new URI(oldRaw); // URI.normalize() will not remove the additional slashes URI normalizedOldRaw = new URI(oldRawUri.getScheme(), oldRawUri.getHost(), oldRawUri.getPath(), oldRawUri.getQuery(), oldRawUri.getFragment()); URI normalizedOldSource = new URI(oldSource.getScheme(), oldSource.getHost(), oldSource.getPath(), oldSource.getQuery(), oldSource.getFragment()); return URI.create(normalizedOldSource.toString().replace(normalizedOldRaw.toString(), newRaw)); } catch (URISyntaxException e) { // tough luck return oldSource; } } } }
From source file:org.eclipse.orion.server.git.objects.Status.java
private URI statusToFileLocation(URI u) throws URISyntaxException { String uriPath = u.getPath(); String prefix = uriPath.substring(0, uriPath.indexOf(GitServlet.GIT_URI)); uriPath = uriPath.substring(prefix.length() + (GitServlet.GIT_URI + '/' + Status.RESOURCE).length()); return new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), uriPath, u.getQuery(), u.getFragment());//from ww w . ja v a 2 s. c om }
From source file:org.apache.synapse.commons.evaluators.source.URLTextRetriever.java
public String getSourceText(EvaluatorContext context) throws EvaluatorException { if (fragment == null) { return context.getUrl(); }//from w w w. j av a 2 s.c om try { URI uri = new URI(context.getUrl()); switch (fragment) { case protocol: return uri.getScheme(); case user: return uri.getUserInfo(); case host: return uri.getHost(); case port: return String.valueOf(uri.getPort()); case path: return uri.getPath(); case query: return uri.getQuery(); case ref: return uri.getFragment(); default: return context.getUrl(); } } catch (URISyntaxException e) { String message = "Error parsing URL: " + context.getUrl(); log.error(message); throw new EvaluatorException(message); } }
From source file:com.chigix.bio.proxy.buffer.FixedBufferTest.java
License:asdf
@Test public void testURI() { try {// w w w. j a v a 2 s. c o m URI uri = new URI( "http://www.baidu.com/awefawgwage/awefwfa/wefafwef/awdfa?safwefawf=awefaf&afwef=fafwef"); System.out.println(uri.getScheme()); System.out.println(uri.getHost()); System.out.println(uri.getPort()); System.out.println(uri.getQuery()); System.out.println(uri.getPath()); } catch (URISyntaxException ex) { Logger.getLogger(FixedBufferTest.class.getName()).log(Level.SEVERE, null, ex); } String illegalQuery = "http://sclick.baidu.com/w.gif?q=a&fm=se&T=1423492890&y=55DFFF7F&rsv_cache=0&rsv_pre=0&rsv_reh=109_130_149_109_85_195_85_85_85_85|540&rsv_scr=1899_1720_0_0_1080_1920&rsv_sid=10383_1469_12498_10902_11101_11399_11277_11241_11401_12550_11243_11403_12470&cid=0&qid=fd67eec000006821&t=1423492880700&rsv_iorr=1&rsv_tn=baidu&path=http%3A%2F%2Fwww.baidu.com%2Fs%3Fie%3Dutf-8%26f%3D8%26rsv_bp%3D1%26rsv_idx%3D1%26ch%3D%26tn%3Dbaidu%26bar%3D%26wd%3Da%26rn%3D%26rsv_pq%3Dda7dc5fb00004904%26rsv_t%3D55188AMIFp8JX4Jb3hJkfCZHYxQdZOBK%252FhV0kLFfAPijGGrceXBoFpnHzmI%26rsv_enter%3D1%26inputT%3D111"; URI uri; while (true) { try { uri = new URI(illegalQuery); } catch (URISyntaxException ex) { System.out.println(illegalQuery); System.out.println(illegalQuery.charAt(ex.getIndex())); System.out.println(illegalQuery.substring(0, ex.getIndex())); System.out.println(illegalQuery.substring(ex.getIndex() + 1)); try { illegalQuery = illegalQuery.substring(0, ex.getIndex()) + URLEncoder.encode(String.valueOf(illegalQuery.charAt(ex.getIndex())), "utf-8") + illegalQuery.substring(ex.getIndex() + 1); } catch (UnsupportedEncodingException ex1) { } System.out.println(illegalQuery); continue; } break; } System.out.println("SCHEME: " + uri.getScheme()); System.out.println("HOST: " + uri.getHost()); System.out.println("path: " + uri.getRawPath()); System.out.println("query: " + uri.getRawQuery()); System.out.println("PORT: " + uri.getPort()); }
From source file:com.jaeksoft.searchlib.crawler.rest.RestCrawlThread.java
private final void callbackPerDoc(HttpDownloader downloader, URI uri, String queryPrefix, String key) throws ClientProtocolException, IllegalStateException, IOException, URISyntaxException, SearchLibException {// ww w. j a v a2s . c om StringBuilder queryString = new StringBuilder(); String query = uri.getQuery(); if (query != null) queryString.append(query); if (!StringUtils.isEmpty(queryPrefix)) { if (queryString.length() != 0) queryString.append('&'); queryString.append(queryPrefix); if (!StringUtils.isEmpty(key)) { queryString.append('='); queryString.append(key); } } callback(downloader, uri, queryString.toString()); }
From source file:com.esri.geoportal.commons.http.BotsHttpClient.java
private URI updateURI(URI uri, PHP php) throws URISyntaxException { return new URI(php.protocol != null ? php.protocol : uri.getScheme(), uri.getUserInfo(), php.host != null ? php.host : uri.getHost(), php.host != null ? php.port != null ? php.port : -1 : uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment());/*from w ww . j av a 2 s . com*/ }
From source file:com.jaeksoft.searchlib.crawler.rest.RestCrawlThread.java
private final void callbackAllDocs(HttpDownloader downloader, URI uri, String queryPrefix, List<String> pkList) throws ClientProtocolException, IllegalStateException, IOException, URISyntaxException, SearchLibException {//from www. j av a 2 s.co m StringBuilder queryString = new StringBuilder(); String query = uri.getQuery(); if (query != null) queryString.append(query); if (!StringUtils.isEmpty(queryPrefix) && pkList != null) { for (String key : pkList) { if (queryString.length() != 0) queryString.append('&'); queryString.append(queryPrefix); queryString.append('='); queryString.append(key); } } callback(downloader, uri, queryString.toString()); }
From source file:com.jrodeo.remote.TestHttpCore.java
Stats execute(final URI target, final byte[] content, int n, int c) throws Exception { this.pool.setMaxTotal(2000); this.pool.setDefaultMaxPerRoute(c); HttpHost targetHost = new HttpHost(target.getHost(), target.getPort()); StringBuilder buffer = new StringBuilder(); buffer.append(target.getPath());//from w ww . j ava 2 s .c o m if (target.getQuery() != null) { buffer.append("?"); buffer.append(target.getQuery()); } String requestUri = buffer.toString(); Stats stats = new Stats(n, c); WorkerThread[] workers = new WorkerThread[c]; for (int i = 0; i < workers.length; i++) { workers[i] = new WorkerThread(stats, targetHost, requestUri, content); } for (int i = 0; i < workers.length; i++) { workers[i].start(); } for (int i = 0; i < workers.length; i++) { workers[i].join(); } return stats; }