List of usage examples for java.net URL getQuery
public String getQuery()
From source file:com.crazytest.config.TestCase.java
protected void postWithCredential(String endpoint, String params) throws UnsupportedEncodingException, URISyntaxException, MalformedURLException { String endpointString = hostUrl + endpoint + "?auth-key=" + this.authToken + "&token=" + this.authToken + "&userID=" + this.userID + params; URL url = new URL(endpointString); URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); HttpPost postRequest = new HttpPost(uri); postRequest.setHeader("Content-Type", "application/x-www-form-urlencoded"); postRequest.setHeader("User-Agent", "Safari"); this.postRequest = postRequest; LOGGER.info("request: {}", postRequest.getRequestLine()); LOGGER.info("request: {}", postRequest.getParams().getParameter("licenseeID")); }
From source file:com.crazytest.config.TestCase.java
protected void putWithCredential(String endpoint, List<NameValuePair> params) throws MalformedURLException, URISyntaxException, UnsupportedEncodingException { String endpointString = hostUrl + endpoint + "?auth-key=" + this.authToken + "&token=" + this.authToken + "&userID=" + this.userID; URL url = new URL(endpointString); URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); HttpPut putRequest = new HttpPut(uri); putRequest.setEntity(new UrlEncodedFormEntity(params)); putRequest.setHeader("Content-Type", "application/x-www-form-urlencoded"); putRequest.setHeader("User-Agent", "Safari"); this.putRequest = putRequest; LOGGER.info("request: {}", putRequest.getRequestLine()); }
From source file:com.crazytest.config.TestCase.java
protected void postWithCredential(String endpoint, List<NameValuePair> params) throws UnsupportedEncodingException, URISyntaxException, MalformedURLException { String endpointString = hostUrl + endpoint + "?auth-key=" + this.authToken + "&token=" + this.authToken + "&userID=" + this.userID; URL url = new URL(endpointString); URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); HttpPost postRequest = new HttpPost(uri); postRequest.setEntity(new UrlEncodedFormEntity(params)); postRequest.setHeader("Content-Type", "application/x-www-form-urlencoded"); postRequest.setHeader("User-Agent", "Safari"); this.postRequest = postRequest; LOGGER.info("request:{}", postRequest.getRequestLine()); LOGGER.info("request:{}", postRequest.getParams().getParameter("licenseeID")); }
From source file:com.crazytest.config.TestCase.java
protected void postWithCredential(String endpoint, StringEntity params) throws UnsupportedEncodingException, URISyntaxException, MalformedURLException { String endpointString = hostUrl + endpoint + "?auth-key=" + this.authToken + "&token=" + this.authToken + "&userID=" + this.userID; URL url = new URL(endpointString); URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); HttpPost postRequest = new HttpPost(uri); postRequest.setEntity(params);//from w ww . ja v a2 s . c o m LOGGER.info("post request entity={}", postRequest); postRequest.setHeader("Content-Type", "application/json"); postRequest.setHeader("User-Agent", "Safari"); this.postRequest = postRequest; LOGGER.info("request:{}", postRequest.getRequestLine()); LOGGER.info("request:{}", postRequest.getParams().getParameter("licenseeID")); }
From source file:com.yunmall.ymsdk.net.http.AsyncHttpClient.java
/** * Will encode url, if not disabled, and adds params on the end of it * * @param url String with URL, should be valid URL without params * @param params RequestParams to be appended on the end of URL * @param shouldEncodeUrl whether url should be encoded (replaces spaces with %20) * @return encoded url if requested with params appended if any available *//*from w w w .j a v a 2 s . c om*/ public static String getUrlWithQueryString(boolean shouldEncodeUrl, String url, RequestParams params) { if (url == null) { return null; } if (shouldEncodeUrl) { try { String decodedURL = URLDecoder.decode(url, "UTF-8"); URL _url = new URL(decodedURL); URI _uri = new URI(_url.getProtocol(), _url.getUserInfo(), _url.getHost(), _url.getPort(), _url.getPath(), _url.getQuery(), _url.getRef()); url = _uri.toASCIIString(); } catch (Exception ex) { // Should not really happen, added just for sake of validity YmLog.e(LOG_TAG, "getUrlWithQueryString encoding URL", ex); } } if (params != null) { // Construct the query string and trim it, in case it // includes any excessive white spaces. String paramString = params.getParamString().trim(); // Only add the query string if it isn't empty and it // isn't equal to '?'. if (!paramString.equals("") && !paramString.equals("?")) { url += url.contains("?") ? "&" : "?"; url += paramString; } } url = url.replaceAll(" ", "%20"); return url; }
From source file:jproxy.HttpRequestHdr.java
public String getUrlWithoutQuery(URL _url) { String fullUrl = _url.toString(); String urlWithoutQuery = fullUrl; String query = _url.getQuery(); if (query != null) { // Get rid of the query and the ? urlWithoutQuery = urlWithoutQuery.substring(0, urlWithoutQuery.length() - query.length() - 1); }/*w ww . j a va 2 s.c om*/ return urlWithoutQuery; }
From source file:org.easysoa.registry.dbb.rest.ServiceFinderRest.java
/** * JSONP for bookmarklet//from www. ja v a2 s. c om * NB. requires application/javascript mimetype to work on bookmarklet's * jquery $.ajax() side in jsonp, but doesn't work if set here, has to be put at the tope * @param uriInfo * @return * @throws Exception */ @GET @Path("/find/{url:.*}") public Object findServices(@Context UriInfo uriInfo) throws Exception { URL url = null; String callback = null; try { // Retrieve URL String restServiceURL = uriInfo.getBaseUri().toString() + "easysoa/servicefinder/find/"; url = new URL(uriInfo.getRequestUri().toString().substring(restServiceURL.length())); if (url.getQuery() != null && url.getQuery().contains("callback=")) { List<NameValuePair> queryTokens = URLEncodedUtils.parse(url.toURI(), "UTF-8"); for (NameValuePair token : queryTokens) { if (token.getName().equals("callback")) { callback = token.getValue(); // now let's remove this callback from original jsonp URL } } } } catch (MalformedURLException e) { logger.debug(e); return "{ errors: '" + formatError(e) + "' }"; } // Find WSDLs String foundServicesJson = findServices(new BrowsingContext(url)); String res; if (callback != null) { res = callback + '(' + foundServicesJson + ");"; // ')' // TODO OK } else { res = foundServicesJson; } return res; }
From source file:org.apache.hadoop.hive.ql.udf.generic.GenericUDTFParseUrlTuple.java
private String evaluate(URL url, int index) { if (url == null || index < 0 || index >= partnames.length) { return null; }/*from w ww .j av a2 s . co m*/ switch (partnames[index]) { case HOST: return url.getHost(); case PATH: return url.getPath(); case QUERY: return url.getQuery(); case REF: return url.getRef(); case PROTOCOL: return url.getProtocol(); case FILE: return url.getFile(); case AUTHORITY: return url.getAuthority(); case USERINFO: return url.getUserInfo(); case QUERY_WITH_KEY: return evaluateQuery(url.getQuery(), paths[index]); case NULLNAME: default: return null; } }
From source file:com.eucalyptus.http.MappingHttpRequest.java
public MappingHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri) { super(httpVersion); this.method = method; this.uri = uri; try {//w w w .j a v a 2 s .co m URL url = new URL("http://eucalyptus" + uri); this.servicePath = url.getPath(); this.parameters = Maps.newHashMap(); this.rawParameters = Maps.newHashMap(); this.nonQueryParameterKeys = Sets.newHashSet(); this.query = this.query == url.getQuery() ? this.query : url.getQuery();// new URLCodec().decode(url.toURI( ).getQuery( ) ).replaceAll( " ", "+" ); this.formFields = Maps.newHashMap(); this.populateParameters(); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
From source file:com.adito.reverseproxy.ReverseProxyMethodHandler.java
/** * Encodes a URL /*from w w w .j a v a 2 s. com*/ * @param location * @return */ public static final String encodeURL(String location) { try { URL url = new URL(location); StringBuffer buf = new StringBuffer(); buf.append(url.getProtocol()); buf.append("://"); if (!Util.isNullOrTrimmedBlank(url.getUserInfo())) { buf.append(DAVUtilities.encodeURIUserInfo(url.getUserInfo())); buf.append("@"); } buf.append(url.getHost()); if (url.getPort() != -1) { buf.append(":"); buf.append(url.getPort()); } if (!Util.isNullOrTrimmedBlank(url.getPath())) { buf.append(URLUTF8Encoder.encode(url.getPath(), false)); } if (!Util.isNullOrTrimmedBlank(url.getQuery())) { buf.append("?"); buf.append(encodeQuery(url.getQuery())); } return buf.toString(); } catch (MalformedURLException e) { int idx = location.indexOf('?'); if (idx > -1 && idx < location.length() - 1) { return URLUTF8Encoder.encode(location.substring(0, idx), false) + "?" + encodeQuery(location.substring(idx + 1)); } else return URLUTF8Encoder.encode(location, false); } }