List of usage examples for java.net URL getQuery
public String getQuery()
From source file:org.ksb.util.geo.G3UrlSigner.java
/** * Test URL signing interactively//from w w w. ja va 2s . c o m * * @param args * @throws IOException * @throws InvalidKeyException * @throws NoSuchAlgorithmException * @throws URISyntaxException */ public static void main(String[] args) throws IOException, InvalidKeyException, NoSuchAlgorithmException, URISyntaxException { // Convert the string to a URL so we can parse it URL url = new URL(urlString); G3UrlSigner signer = new G3UrlSigner(keyString); String request = signer.signRequest(url.getPath(), url.getQuery()); System.out.println("Signed URL :" + url.getProtocol() + "://" + url.getHost() + request); }
From source file:Main.java
public static void main(String[] args) { try {/*from w w w. j a v a2 s. co m*/ URL url = new URL("http://www.java2s.com/query?abc=def"); System.out.println("URL is " + url.toString()); System.out.println("authority is " + url.getAuthority()); System.out.println("default port is " + url.getDefaultPort()); System.out.println("query is " + url.getQuery()); } catch (IOException e) { e.printStackTrace(); } }
From source file:MainClass.java
public static void main(String[] args) { try {// ww w .j a va 2s . co m URL url = new URL("http://www.java2s.com"); System.out.println("URL is " + url.toString()); System.out.println("authority is " + url.getAuthority()); System.out.println("path is " + url.getPath()); System.out.println("default port is " + url.getDefaultPort()); System.out.println("query is " + url.getQuery()); System.out.println("ref is " + url.getRef()); } catch (IOException e) { e.printStackTrace(); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { URL url = new URL("http://www.yahoo.com:80/en/index.html?name=joe#first"); System.out.println("protocol:" + url.getProtocol()); System.out.println("prot:" + url.getPort()); System.out.println("host:" + url.getHost()); System.out.println("path:" + url.getPath()); System.out.println("file:" + url.getFile()); System.out.println("query:" + url.getQuery()); System.out.println("ref:" + url.getRef()); }
From source file:Main.java
public static void main(String[] args) throws Exception { URL url = new URL(args[0]); System.out.println("URL is " + url.toString()); System.out.println("protocol is " + url.getProtocol()); System.out.println("authority is " + url.getAuthority()); System.out.println("file name is " + url.getFile()); System.out.println("host is " + url.getHost()); System.out.println("path is " + url.getPath()); System.out.println("port is " + url.getPort()); System.out.println("default port is " + url.getDefaultPort()); System.out.println("query is " + url.getQuery()); System.out.println("ref is " + url.getRef()); }
From source file:com.xx_dev.speed_test.SpeedTestClient.java
public static void main(String[] args) { EventLoopGroup group = new NioEventLoopGroup(); try {/*from w w w .j a v a2 s .co m*/ URL url = new URL(args[0]); boolean isSSL = false; String host = url.getHost(); int port = 80; if (StringUtils.equals(url.getProtocol(), "https")) { port = 443; isSSL = true; } if (url.getPort() > 0) { port = url.getPort(); } String path = url.getPath(); if (StringUtils.isNotBlank(url.getQuery())) { path += "?" + url.getQuery(); } PrintWriter resultPrintWriter = null; if (StringUtils.isNotBlank(args[1])) { String resultFile = args[1]; resultPrintWriter = new PrintWriter( new OutputStreamWriter(new FileOutputStream(resultFile, false), "UTF-8")); } Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class) .handler(new SpeedTestHttpClientChannelInitializer(isSSL, resultPrintWriter)); // Make the connection attempt. Channel ch = b.connect(host, port).sync().channel(); // Prepare the HTTP request. HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, path); request.headers().set(HttpHeaders.Names.HOST, host); request.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE); //request.headers().set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP); // Send the HTTP request. ch.writeAndFlush(request); // Wait for the server to close the connection. ch.closeFuture().sync(); if (resultPrintWriter != null) { resultPrintWriter.close(); } } catch (InterruptedException e) { logger.error(e.getMessage(), e); } catch (FileNotFoundException e) { logger.error(e.getMessage(), e); } catch (UnsupportedEncodingException e) { logger.error(e.getMessage(), e); } catch (MalformedURLException e) { logger.error(e.getMessage(), e); } finally { group.shutdownGracefully(); } }
From source file:Main.java
/** * Parse a URL query and fragment parameters into a key-value bundle. */// www. ja v a 2s . co m public static Bundle parseUrl(String url) { // hack to prevent MalformedURLException url = url.replace("weiboconnect", "http"); try { URL u = new URL(url); Bundle b = decodeUrl(u.getQuery()); b.putAll(decodeUrl(u.getRef())); return b; } catch (MalformedURLException e) { return new Bundle(); } }
From source file:Main.java
public static Bundle parseUrl(String url) { url = url.replace("rrconnect", "http"); try {//from w w w . j ava 2 s .co m URL u = new URL(url); Bundle b = decodeUrl(u.getQuery()); b.putAll(decodeUrl(u.getRef())); return b; } catch (MalformedURLException e) { return new Bundle(); } }
From source file:Main.java
public static Bundle parseUrl(String url) { Bundle ret;/* w w w .j av a 2 s . com*/ url = url.replace("bdconnect", "http"); try { URL urlParam = new URL(url); ret = decodeUrl(urlParam.getQuery()); ret.putAll(decodeUrl(urlParam.getRef())); return ret; } catch (MalformedURLException e) { return new Bundle(); } }
From source file:Main.java
public static Bundle urlToBundle(String url) { int index = url.indexOf("://"); if (index >= 0) { url = "http://" + url.substring(index + 1); } else {/* w w w . j ava2s. com*/ url = "http://" + url; } try { URL e = new URL(url); Bundle b = decodeUrl(e.getQuery()); b.putAll(decodeUrl(e.getRef())); return b; } catch (Throwable var4) { return new Bundle(); } }