List of usage examples for java.net URI getRawQuery
public String getRawQuery()
From source file:com.box.restclientv2.httpclientsupport.HttpClientURIBuilder.java
private void digestURI(final URI uri) throws URISyntaxException { this.scheme = uri.getScheme(); this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart(); this.encodedAuthority = uri.getRawAuthority(); this.host = uri.getHost(); this.port = uri.getPort(); this.encodedUserInfo = uri.getRawUserInfo(); this.userInfo = uri.getUserInfo(); this.encodedPath = uri.getRawPath(); this.path = uri.getPath(); this.encodedQuery = uri.getRawQuery(); this.queryParams = parseQuery(uri.getRawQuery(), HttpClientConsts.UTF_8); this.encodedFragment = uri.getRawFragment(); this.fragment = uri.getFragment(); }
From source file:org.cbioportal.security.spring.PortalSavedRequestAwareAuthenticationSuccessHandler.java
private String getRelativeURI(HttpServletRequest request, String targetURI) { String relativeURI = null;//w ww .j a v a 2 s . com try { URI originalURI = new URI(targetURI); logger.debug("getRelativeURI(): request.getServletContext() = '" + request.getServletContext() + "'"); logger.debug("getRelativeURI(): testing '" + new URI(request.getContextPath()) + "'"); // URI(String scheme, String authority, String path, String query, String fragment) // use relativize so we do not include context path e.g. /cbioportal/ // use resolve to make sure we have a "/" at the front relativeURI = new URI("/") .resolve(new URI(request.getContextPath()).relativize(new URI(null, null, originalURI.getRawPath(), originalURI.getRawQuery(), originalURI.getRawFragment()))) .toString(); logger.debug("getRelativeURI(): changing '" + targetURI + "' to '" + relativeURI + "'"); } catch (URISyntaxException e) { return null; } return relativeURI; }
From source file:org.mcxiaoke.commons.http.util.URIBuilderEx.java
private void digestURI(final URI uri) { this.scheme = uri.getScheme(); this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart(); this.encodedAuthority = uri.getRawAuthority(); this.host = uri.getHost(); this.port = uri.getPort(); this.encodedUserInfo = uri.getRawUserInfo(); this.userInfo = uri.getUserInfo(); this.encodedPath = uri.getRawPath(); this.path = uri.getPath(); this.encodedQuery = uri.getRawQuery(); this.queryParams = parseQuery(uri.getRawQuery(), URIUtilsEx.UTF_8); this.encodedFragment = uri.getRawFragment(); this.fragment = uri.getFragment(); }
From source file:org.languagetool.server.LanguageToolHttpHandler.java
private Map<String, String> getRequestQuery(HttpExchange httpExchange, URI requestedUri) throws IOException { Map<String, String> params = new HashMap<>(); if ("post".equalsIgnoreCase(httpExchange.getRequestMethod())) { try (InputStreamReader isr = new InputStreamReader(httpExchange.getRequestBody(), ENCODING)) { params.putAll(parseQuery(readerToString(isr, config.getMaxTextHardLength()), httpExchange)); params.putAll(parseQuery(requestedUri.getRawQuery(), httpExchange)); // POST requests can have query parameters, too return params; }/* w w w .j a v a2 s. c o m*/ } else { return parseQuery(requestedUri.getRawQuery(), httpExchange); } }
From source file:nl.basjes.parse.httpdlog.dissectors.HttpUriDissector.java
@Override public void dissect(final Parsable<?> parsable, final String inputname) throws DissectionFailure { final ParsedField field = parsable.getParsableField(INPUT_TYPE, inputname); String uriString = field.getValue().getString(); if (uriString == null || uriString.isEmpty()) { return; // Nothing to do here }/*from w w w.ja v a 2 s. c o m*/ // First we cleanup the URI so we fail less often over 'garbage' URIs. // See: http://stackoverflow.com/questions/11038967/brackets-in-a-request-url-are-legal-but-not-in-a-uri-java try { uriString = URIUtil.encode(uriString, badUriChars, "UTF-8"); } catch (URIException e) { throw new DissectionFailure( "Failed to parse URI >>" + field.getValue().getString() + "<< because of : " + e.getMessage()); } // Before we hand it to the standard parser we hack it around a bit so we can parse // nasty edge cases that are illegal yet do occur in real clickstreams. // Also we force the query string to start with ?& so the returned query string starts with & // Which leads to more consistent output after parsing. int firstQuestionMark = uriString.indexOf('?'); int firstAmpersand = uriString.indexOf('&'); // Now we can have one of 3 situations: // 1) No query string // 2) Query string starts with a '?' // (and optionally followed by one or more '&' or '?' ) // 3) Query string starts with a '&'. This is invalid but does occur! // We may have ?x=x&y=y?z=z so we normalize it always // to: ?&x=x&y=y&z=z if (firstAmpersand != -1 || firstQuestionMark != -1) { uriString = uriString.replaceAll("\\?", "&"); uriString = uriString.replaceFirst("&", "?&"); } // We find that people muck up the URL by putting % signs in the URLs that are NOT escape sequences // So any % that is not followed by a two 'hex' letters is fixed uriString = BAD_EXCAPE_PATTERN.matcher(uriString).replaceAll("%25$1"); uriString = BAD_EXCAPE_PATTERN.matcher(uriString).replaceAll("%25$1"); boolean isUrl = true; URI uri; try { if (uriString.charAt(0) == '/') { uri = URI.create("dummy-protocol://dummy.host.name" + uriString); isUrl = false; // I.e. we do not return the values we just faked. } else { uri = URI.create(uriString); } } catch (IllegalArgumentException e) { throw new DissectionFailure( "Failed to parse URI >>" + field.getValue().getString() + "<< because of : " + e.getMessage()); } if (wantQuery || wantPath || wantRef) { if (wantQuery) { String query = uri.getRawQuery(); if (query == null) { query = ""; } parsable.addDissection(inputname, "HTTP.QUERYSTRING", "query", query); } if (wantPath) { parsable.addDissection(inputname, "HTTP.PATH", "path", uri.getPath()); } if (wantRef) { parsable.addDissection(inputname, "HTTP.REF", "ref", uri.getFragment()); } } if (isUrl) { if (wantProtocol) { parsable.addDissection(inputname, "HTTP.PROTOCOL", "protocol", uri.getScheme()); } if (wantUserinfo) { parsable.addDissection(inputname, "HTTP.USERINFO", "userinfo", uri.getUserInfo()); } if (wantHost) { parsable.addDissection(inputname, "HTTP.HOST", "host", uri.getHost()); } if (wantPort) { if (uri.getPort() != -1) { parsable.addDissection(inputname, "HTTP.PORT", "port", uri.getPort()); } } } }
From source file:com.mcxiaoke.next.http.util.URIBuilder.java
private void digestURI(final URI uri) { this.scheme = uri.getScheme(); this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart(); this.encodedAuthority = uri.getRawAuthority(); this.host = uri.getHost(); this.port = uri.getPort(); this.encodedUserInfo = uri.getRawUserInfo(); this.userInfo = uri.getUserInfo(); this.encodedPath = uri.getRawPath(); this.path = uri.getPath(); this.encodedQuery = uri.getRawQuery(); this.queryParams = parseQuery(uri.getRawQuery(), Charsets.UTF_8); this.encodedFragment = uri.getRawFragment(); this.fragment = uri.getFragment(); }
From source file:com.fatwire.dta.sscrawler.App.java
protected void doWork(final CommandLine cmd) throws Exception { final Crawler crawler = new Crawler(); URI startUri = null; startUri = URI.create(cmd.getArgs()[1]); if (cmd.hasOption('m')) { crawler.setMaxPages(Integer.parseInt(cmd.getOptionValue('m'))); }//from w w w . j a v a 2s. c o m final int threads = Integer.parseInt(cmd.getOptionValue('t', "5")); if (startUri == null) { throw new IllegalArgumentException("startUri is not set"); } final int t = startUri.toASCIIString().indexOf("/ContentServer"); if (t == -1) { throw new IllegalArgumentException("/ContentServer is not found on the startUri."); } crawler.setStartUri(new URI(null, null, null, -1, startUri.getRawPath(), startUri.getRawQuery(), startUri.getFragment())); final HostConfig hc = createHostConfig(URI.create(startUri.toASCIIString().substring(0, t))); final String proxyUsername = cmd.getOptionValue("pu"); final String proxyPassword = cmd.getOptionValue("pw"); final String proxyHost = cmd.getOptionValue("ph"); final int proxyPort = Integer.parseInt(cmd.getOptionValue("", "8080")); if (StringUtils.isNotBlank(proxyUsername) && StringUtils.isNotBlank(proxyUsername)) { hc.setProxyCredentials(new UsernamePasswordCredentials(proxyUsername, proxyPassword)); } if (StringUtils.isNotBlank(proxyHost)) { hc.setProxyHost(new ProxyHost(proxyHost, proxyPort)); } else if (StringUtils.isNotBlank(System.getProperty("http.proxyhost")) && StringUtils.isNotBlank(System.getProperty("http.proxyport"))) { hc.setProxyHost(new ProxyHost(System.getProperty("http.proxyhost"), Integer.parseInt(System.getProperty("http.proxyport")))); } crawler.setHostConfig(hc); SSUriHelper helper = null; if (cmd.hasOption('f')) { final UriHelperFactory f = (UriHelperFactory) Class.forName(cmd.getOptionValue('f')).newInstance(); helper = f.create(crawler.getStartUri().getPath()); } else { helper = new SSUriHelper(crawler.getStartUri().getPath()); } final ThreadPoolExecutor readerPool = new RenderingThreadPool(threads); final MBeanServer platform = java.lang.management.ManagementFactory.getPlatformMBeanServer(); try { platform.registerMBean(readerPool, new ObjectName("com.fatwire.crawler:name=readerpool")); } catch (final Throwable x) { LogFactory.getLog(App.class).error(x.getMessage(), x); } crawler.setExecutor(readerPool); File path = null; if (cmd.hasOption('d')) { path = new File(cmd.getOptionValue("d")); } else { path = getOutputDir(); } if (path != null) { final SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HHmm"); path = new File(path, df.format(new Date())); path.mkdirs(); } crawler.setReporters(createReporters(path, helper)); crawler.setUriHelper(helper); try { crawler.work(); } finally { readerPool.shutdown(); try { platform.unregisterMBean(new ObjectName("com.fatwire.crawler:name=readerpool")); } catch (final Throwable x) { LogFactory.getLog(App.class).error(x.getMessage(), x); } } }
From source file:com.subgraph.vega.internal.http.proxy.VegaHttpRequestParser.java
@Override public HttpMessage parse() throws IOException, HttpException { RequestLine requestLine;// ww w . j ava2s .co m try { requestLine = parseRequestLine(sessionBuffer); } catch (ParseException px) { throw new ProtocolException(px.getMessage(), px); } List<CharArrayBuffer> headerLines = new ArrayList<CharArrayBuffer>(); Header[] headers = AbstractMessageParser.parseHeaders(sessionBuffer, maxHeaderCount, maxLineLen, lineParser, headerLines); if (conn.isSslConnection()) { URI uri; try { uri = new URI(requestLine.getUri()); } catch (URISyntaxException e) { throw new ProtocolException("Invalid URI: " + requestLine.getUri(), e); } if (uri.getScheme() == null) { final Header hostHeader = getFirstHeader(headers, HTTP.TARGET_HOST); final StringBuilder buf = new StringBuilder(); if (hostHeader != null) { // REVISIT: does using the Host header value instead of the SSL host risk opening another connection? buf.append("https://"); buf.append(hostHeader.getValue()); } else { buf.append(conn.getSslHost().toURI()); } buf.append(uri.getRawPath()); if (uri.getRawQuery() != null) { buf.append("?"); buf.append(uri.getRawQuery()); } requestLine = new BasicRequestLine(requestLine.getMethod(), buf.toString(), requestLine.getProtocolVersion()); } } HttpMessage message = requestFactory.newHttpRequest(requestLine); message.setHeaders(headers); return message; }
From source file:HttpDownloadManager.java
public Download download(URI uri, Listener l) throws IOException { if (released) throw new IllegalStateException("Can't download() after release()"); // Get info from the URI String scheme = uri.getScheme(); if (scheme == null || !scheme.equals("http")) throw new IllegalArgumentException("Must use 'http:' protocol"); String hostname = uri.getHost(); int port = uri.getPort(); if (port == -1) port = 80; // Use default port if none specified String path = uri.getRawPath(); if (path == null || path.length() == 0) path = "/"; String query = uri.getRawQuery(); if (query != null) path += "?" + query; // Create a Download object with the pieces of the URL Download download = new DownloadImpl(hostname, port, path, l); // Add it to the list of pending downloads. This is a synchronized list pendingDownloads.add(download);//from w w w . j a v a 2 s .c o m // And ask the thread to stop blocking in the select() call so that // it will notice and process this new pending Download object. selector.wakeup(); // Return the Download so that the caller can monitor it if desired. return download; }
From source file:org.asamk.signal.Manager.java
public void addDeviceLink(URI linkUri) throws IOException, InvalidKeyException { Map<String, String> query = getQueryMap(linkUri.getRawQuery()); String deviceIdentifier = query.get("uuid"); String publicKeyEncoded = query.get("pub_key"); if (TextUtils.isEmpty(deviceIdentifier) || TextUtils.isEmpty(publicKeyEncoded)) { throw new RuntimeException("Invalid device link uri"); }// w w w . j a v a2 s .c o m ECPublicKey deviceKey = Curve.decodePoint(Base64.decode(publicKeyEncoded), 0); addDevice(deviceIdentifier, deviceKey); }