List of usage examples for java.net URL getQuery
public String getQuery()
From source file:org.apache.wookie.controller.WidgetInstancesController.java
/** * Returns the absolute URL of the widget instance including id key, proxy * url and opensocial token//from ww w . j a v a 2 s . c o m * * @param request * the current request * @param instance * the widget instance * @return the absolute URL * @throws IOException */ protected static String getUrl(HttpServletRequest request, IWidgetInstance instance) throws IOException { String url = ""; IStartFile[] startFiles = instance.getWidget().getStartFiles() .toArray(new IStartFile[instance.getWidget().getStartFiles().size()]); IStartFile sf = (IStartFile) LocalizationUtils.getLocalizedElement(startFiles, new String[] { instance.getLang() }); // Try default locale if no appropriate localization found if (sf == null) sf = (IStartFile) LocalizationUtils.getLocalizedElement(startFiles, null); // No start file found, so throw an exception if (sf == null) throw new IOException("No start file located for widget " + instance.getWidget().getGuid()); URL urlWidget = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), sf.getUrl()); if (urlWidget.getQuery() != null) { url += urlWidget + "&idkey=" + instance.getIdKey() //$NON-NLS-1$ + "&proxy=" + urlWidgetProxyServer.toExternalForm() //$NON-NLS-1$ + "&st=" + instance.getOpensocialToken(); //$NON-NLS-1$ } else { url += urlWidget + "?idkey=" + instance.getIdKey() //$NON-NLS-1$ + "&proxy=" + urlWidgetProxyServer.toExternalForm() //$NON-NLS-1$ + "&st=" + instance.getOpensocialToken(); //$NON-NLS-1$ } return url; }
From source file:lucee.commons.net.http.httpclient3.HTTPEngine3Impl.java
/** * FUNKTIONIERT NICHT, HOST WIRD NICHT UEBERNOMMEN * Clones a http method and sets a new url * @param src//from w ww .jav a 2 s . c o m * @param url * @return */ private static HttpMethod clone(HttpMethod src, URL url) { HttpMethod trg = HttpMethodCloner.clone(src); HostConfiguration trgConfig = trg.getHostConfiguration(); trgConfig.setHost(url.getHost(), url.getPort(), url.getProtocol()); trg.setPath(url.getPath()); trg.setQueryString(url.getQuery()); return trg; }
From source file:org.kalypso.ogc.gml.wms.deegree.DeegreeWMSUtilities.java
/** * This function prepares the request parameter. * /* ww w . j ava 2 s . c o m*/ * @param capabilities * The wms capabilities. * @param name * The name of the operation. * @return The request parameter. */ private static HashMap<String, String> prepareRequestParameters(final WMSCapabilities capabilities, final String operationName) throws CoreException { final HashMap<String, String> wmsParameter = new HashMap<>(); /* HACK: in order to keep any existing query parts, add existing query parts from base url. */ final Operation operation = checkOperation(capabilities, operationName); final List<DCP> types = operation.getDCP(); for (final DCP type : types) { if (type instanceof HTTP) { final HTTP httpProtocol = (HTTP) type; final List<URL> getOnlineResources = httpProtocol.getGetOnlineResources(); for (final URL url : getOnlineResources) { if (url != null) { final String query = url.getQuery(); if (query != null && query.length() > 0) { /* The base URL may already contain a query part, we do not want to delete it Quotation from WMS-Spec: */ /* "An OGC Web Service shall be prepared to encounter parameters that are not part of this specification." */ final String[] requestParts = query.split("&"); //$NON-NLS-1$ for (final String requestPart : requestParts) { final String[] queryParts = requestPart.split("="); //$NON-NLS-1$ if (queryParts.length != 2) continue; wmsParameter.put(queryParts[0], queryParts[1]); } } /* The first valid url is enough. */ break; } /* The first http-protocol is enough. */ break; } } } wmsParameter.put("SERVICE", "WMS"); //$NON-NLS-1$ //$NON-NLS-2$ wmsParameter.put("VERSION", capabilities.getVersion()); //$NON-NLS-1$ wmsParameter.put("REQUEST", operationName); //$NON-NLS-1$ wmsParameter.put("EXCEPTIONS", "application/vnd.ogc.se_xml"); //$NON-NLS-1$ //$NON-NLS-2$ return wmsParameter; }
From source file:com.example.aliyundemo.ocr.util.HttpUtil.java
/** * ?Header/*from ww w .j a v a2s . c o m*/ * * @param headers Http * @param appKey APP KEY * @param appSecret APP * @param method Http * @param requestAddress http://host+path+query * @param formParam ?? * @param signHeaderPrefixList ???Header? * @return Header * @throws MalformedURLException */ private static Map<String, String> initialBasicHeader(Map<String, String> headers, String appKey, String appSecret, String method, String requestAddress, Map formParam, List<String> signHeaderPrefixList) throws MalformedURLException { if (headers == null) { headers = new HashMap<String, String>(); } URL url = new URL(requestAddress); StringBuilder stringBuilder = new StringBuilder(); if (StringUtils.isNotBlank(url.getPath())) { stringBuilder.append(url.getPath()); } if (StringUtils.isNotBlank(url.getQuery())) { stringBuilder.append("?"); stringBuilder.append(url.getQuery()); } headers.put(HttpHeader.HTTP_HEADER_USER_AGENT, Constants.USER_AGENT); headers.put(SystemHeader.X_CA_TIMESTAMP, String.valueOf(new Date().getTime())); headers.put(SystemHeader.X_CA_NONCE, UUID.randomUUID().toString()); headers.put(SystemHeader.X_CA_KEY, appKey); headers.put(SystemHeader.X_CA_SIGNATURE, SignUtil.sign(method, stringBuilder.toString(), headers, formParam, appSecret, signHeaderPrefixList)); return headers; }
From source file:Models.Geographic.Repository.RepositoryGoogle.java
/** * Method that geocoding a address from google api * @param country/*from w w w . j a va 2 s . com*/ * @param adm1 * @param adm2 * @param adm3 * @param local_area * @param locality * @param uncertainty * @return */ public static Location georenferencing(String country, String adm1, String adm2, String adm3, String local_area, String locality, double uncertainty) { Location a = null; String key; try { key = FixData.generateKey(new String[] { country, adm1, adm2, adm3, local_area, locality }); if (RepositoryGoogle.db == null) RepositoryGoogle.db = new HashMap(); if (RepositoryGoogle.db.containsKey(key)) return (Location) RepositoryGoogle.db.get(key); String data = (!locality.equals("") ? locality : "") + (!local_area.equals("") ? local_area + "+,+" : "") + (!adm3.equals("") ? adm3 + "+,+" : "") + (!adm2.equals("") ? adm2 + "+,+" : "") + (!adm1.equals("") ? adm1 + "+,+" : "") + (!country.equals("") ? country + "+,+" : ""); URL url = new URL(Configuration.getParameter("geocoding_google_url_send_xml") + "address=" + data.replace(" ", "%20").replace(".", "").replace(";", "")); URL file_url = new URL( url.getProtocol() + "://" + url.getHost() + signRequest(url.getPath(), url.getQuery())); // Get information from URL DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); // Create a proxy to work in CIAT (erase this in another place) //Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy2.ciat.cgiar.org", 8080)); DocumentBuilder db = dbf.newDocumentBuilder(); //Document doc = db.parse(file_url.openConnection(proxy).getInputStream()); Document doc = db.parse(file_url.openConnection().getInputStream()); // Document with data if (doc != null) { NodeList locationList = doc.getElementsByTagName("location"); NodeList locationTypeList = doc.getElementsByTagName("location_type"); NodeList viewPortList = doc.getElementsByTagName("viewport"); Node location = null, lat = null, lng = null; if (locationList.getLength() > 0) { for (int i = 0; i < locationList.getLength(); i++) { location = locationList.item(i); if (location.hasChildNodes()) { lat = location.getChildNodes().item(1); lng = location.getChildNodes().item(3); } } Node locationType = null; if (locationTypeList.getLength() > 0) { for (int i = 0; i < locationTypeList.getLength(); i++) locationType = locationTypeList.item(i); } Node viewPort = null, northeast = null, southwest = null, lat_northeast = null, lng_northeast = null, lat_southwest = null, lng_southwest = null; if (viewPortList.getLength() > 0) { for (int i = 0; i < viewPortList.getLength(); i++) { viewPort = viewPortList.item(i); if (viewPort.hasChildNodes()) { northeast = viewPort.getChildNodes().item(1); southwest = viewPort.getChildNodes().item(3); } /* Extract data from viewport field */ if (northeast.hasChildNodes()) { lat_northeast = northeast.getChildNodes().item(1); lng_northeast = northeast.getChildNodes().item(3); } if (southwest.hasChildNodes()) { lat_southwest = southwest.getChildNodes().item(1); lng_southwest = southwest.getChildNodes().item(3); } } } double[] coordValues = new double[] { Double.parseDouble(lat.getTextContent()), Double.parseDouble(lng.getTextContent()) }; double[] coordValuesNortheast = new double[] { Double.parseDouble(lat_northeast.getTextContent()), Double.parseDouble(lng_northeast.getTextContent()) }; double[] coordValuesSouthwest = new double[] { Double.parseDouble(lat_southwest.getTextContent()), Double.parseDouble(lng_southwest.getTextContent()) }; double distance = FixData.getDistance(coordValuesNortheast, coordValuesSouthwest); // Distance - km between Northeast and Southeast if (distance <= uncertainty) a = new Location(coordValues[0], coordValues[1], distance); else { RepositoryGoogle.db.put(key, a); throw new Exception("Exceede uncertainty. " + "Uncertainty: " + distance + " THRESHOLD: " + Configuration.getParameter("geocoding_threshold")); } } } RepositoryGoogle.db.put(key, a); } catch (NoSuchAlgorithmException | InvalidKeyException | URISyntaxException | IOException | ParserConfigurationException | SAXException ex) { System.out.println(ex); } catch (Exception ex) { System.out.println(ex); } return a; }
From source file:eu.trentorise.smartcampus.network.RemoteConnector.java
private static String normalizeURL(String uriString) throws RemoteException { try {//from ww w . j a v a2s . c o m URL url = new URL(uriString); URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); uriString = uri.toURL().toString(); } catch (Exception e) { throw new RemoteException(e.getMessage()); } return uriString; }
From source file:de.betterform.agent.betty.Betty.java
/** * Parses URL parameters and stores them in the provided map. * * @param url the URL parameter string./*from ww w . j a v a 2s.c om*/ */ public static void parseParameters(URL url, Map map) { if (url != null && url.getQuery() != null && url.getQuery().length() > 0) { String[] list = url.getQuery().split("&"); String[] tupel; for (int index = 0; index < list.length; index++) { tupel = list[index].split("="); map.put(tupel[0], tupel.length > 1 ? tupel[1] : ""); //System.out.println("found parameter: " + tupel[0] + "=" + map.get(tupel[0])); } } }
From source file:com.investoday.code.util.aliyun.api.gateway.util.HttpUtil.java
/** * ?Header/*w ww . j a v a 2s . c o m*/ * * @param headers Http * @param appKey APP KEY * @param appSecret APP * @param method Http * @param requestAddress http://host+path+query * @param formParam ?? * @param signHeaderPrefixList ???Header? * @return Header * @throws MalformedURLException */ private static Map<String, String> initialBasicHeader(Map<String, String> headers, String appKey, String appSecret, String method, String requestAddress, Map formParam, List<String> signHeaderPrefixList) throws MalformedURLException { if (headers == null) { headers = new HashMap<String, String>(); } URL url = new URL(requestAddress); StringBuilder stringBuilder = new StringBuilder(); if (StringUtils.isNotBlank(url.getPath())) { stringBuilder.append(url.getPath()); } if (StringUtils.isNotBlank(url.getQuery())) { stringBuilder.append("?"); stringBuilder.append(url.getQuery()); } headers.put(HttpHeader.HTTP_HEADER_USER_AGENT, Constants.USER_AGENT); // headers.put(SystemHeader.X_CA_TIMESTAMP, String.valueOf(new Date().getTime())); //headers.put(SystemHeader.X_CA_TIMESTAMP, Test11.getGMT()); // headers.put(SystemHeader.X_CA_NONCE, UUID.randomUUID().toString()); headers.put(SystemHeader.X_CA_KEY, appKey); headers.put(SystemHeader.X_CA_SIGNATURE, SignUtil.sign(method, stringBuilder.toString(), headers, formParam, appSecret, signHeaderPrefixList)); return headers; }
From source file:com.iStudy.Study.Renren.Util.java
/** * ?URL??key-value/*from www .j av a 2 s. c o m*/ * * @param url * @return */ public static Bundle parseUrl(String url) { url = url.replace("rrconnect", "http"); url = url.replace("#", "?"); 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:org.codice.alliance.imaging.chip.actionprovider.ImagingChipActionProvider.java
private static Optional<URL> getChippingUrl(Metacard metacard) { // canHandle has already been checked at this point, so no need to verify isPresent final URI derivedResourceUri = getOriginalDerivedResourceUri(metacard).get(); if (canBeChippedLocally(derivedResourceUri)) { final String defaultChippingUrlString = String.format("%s%s?id=%s&source=%s", SystemBaseUrl.EXTERNAL.getBaseUrl(), PATH, metacard.getId(), metacard.getSourceId()); try {/*from w w w. ja v a 2 s.c o m*/ return Optional.of(new URL(defaultChippingUrlString)); } catch (MalformedURLException e) { // This should never happen. } } else { // If the resource.derived-uri attribute value matches the usual Alliance download URL format // ("[protocol]://[host]:[port]/[services name]/catalog/sources/[source id]/[metacard // id]?transform=resource&qualifier=[original or overview]"), assume that there is a // chipping URL that can be constructed from the scheme, host, port, source, and id of // the value. This allows the {@value TITLE} Action to link directly to the remote // system if the derived resource is from another Alliance instance. try { final URL derivedResourceUrl = derivedResourceUri.toURL(); final String host = derivedResourceUrl.getHost(); // {@code null} if the host is undefined final int port = derivedResourceUrl.getPort(); // -1 if the port is not set final String path = derivedResourceUrl.getPath(); // an empty string if one does not exist final String query = derivedResourceUrl.getQuery(); // <CODE>null</CODE> if one does not exist final String expectedQuery = String.format("transform=resource&qualifier=%s", ORIGINAL_QUALIFIER); if (!StringUtils.isEmpty(host) && port != -1 && ALLIANCE_DOWNLOAD_RESOURCE_PATH_PATTERN.matcher(path).matches() && StringUtils.equals(query, expectedQuery)) { final String[] paths = path.split("/"); final String source = paths[4]; final String id = paths[5]; final String chippingPathString = String.format("%s?id=%s&source=%s", PATH, id, source); try { return Optional .of(new URL(derivedResourceUrl.getProtocol(), host, port, chippingPathString)); } catch (MalformedURLException e) { // This should probably never happen because the parts used to construct the URL have // been validated. } } else { // Unable to construct a remote chipping URL because the original resource.derived-uri // does not match the known Alliance format. } } catch (MalformedURLException e) { // Unable to cast derivedResourceUri to a URL, which means that the resource still may be // able to be chipped locally but is not yet supported by the canBeChippedLocally method. } } LOGGER.debug( "Unable to construct a chipping URL for NITF image metacard id={}, source id={}, resource-uri={}. Not displaying the Chip Image Action.", metacard.getId(), metacard.getResourceURI(), metacard.getSourceId()); return Optional.empty(); }