List of usage examples for java.net URL getPort
public int getPort()
From source file:org.silvertunnel.netlib.adapter.httpclient.HttpClientUtil.java
private static InputStream action_NOT_NEEDED(URL url) throws IOException { HttpHost target = new HttpHost(url.getHost(), url.getPort(), url.getProtocol()); DefaultHttpClient httpclient = new DefaultHttpClient(connMgr, params); HttpGet req = new HttpGet(url.getPath()); log.info("executing request to " + target); HttpResponse rsp = httpclient.execute(target, req); HttpEntity entity = rsp.getEntity(); /*/*w w w. java 2 s .c o m*/ if (entity != null) { log.info(EntityUtils.toString(entity)); } */ return entity.getContent(); // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources //TODO: httpclient.getConnectionManager().shutdown(); }
From source file:fr.dutra.confluence2wordpress.util.UrlUtils.java
/** * Sanitizes the given URL by escaping the path and query parameters, if necessary. * @see "http://stackoverflow.com/questions/724043/http-url-address-encoding-in-java" * @param url//from w w w . j ava2 s . c o m * @return * @throws URISyntaxException * @throws MalformedURLException */ public static String sanitize(String url) throws URISyntaxException, MalformedURLException { URL temp = new URL(url); URI uri = new URI(temp.getProtocol(), temp.getUserInfo(), temp.getHost(), temp.getPort(), temp.getPath(), temp.getQuery(), temp.getRef()); return uri.toASCIIString(); }
From source file:de.fhg.iais.asc.ASC.java
private static void setGlobalProxy(List<AscConfiguration> configs) { for (AscConfiguration config : configs) { String proxyUrl = config.get(AscConfiguration.PROXY, ""); try {/*from www .ja va 2s . c o m*/ if (!Strings.isNullOrEmpty(proxyUrl)) { URL url = new URL(proxyUrl); String host = url.getHost(); String port = String.valueOf(url.getPort()); System.setProperty("http.proxyHost", host); System.setProperty("http.proxyPort", port); System.setProperty("https.proxyHost", host); System.setProperty("https.proxyPort", port); } } catch (Exception e) { System.setProperty("http.proxyHost", null); System.setProperty("http.proxyPort", null); System.setProperty("https.proxyHost", null); System.setProperty("https.proxyPort", null); continue; } } }
From source file:SageCollegeProject.guideBox.java
public static String GetEncWebCall(String webcall) { try {//from ww w.j a va 2 s . co m URL url = new URL(webcall); URI test = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); return test.toASCIIString(); } catch (URISyntaxException | MalformedURLException ex) { Logger.getLogger(guideBox.class.getName()).log(Level.SEVERE, null, ex); } return ""; }
From source file:Utils.java
public static String addDefaultPortIfMissing(String urlString, String defaultPort) { URL url = null; try {/* w ww . j a v a 2 s . c o m*/ url = new URL(urlString); } catch (MalformedURLException e) { return urlString; } if (url.getPort() != -1) { return urlString; } String regex = "http://([^/]+)"; String found = getFirstFound(urlString, regex); String replacer = "http://" + found + ":" + defaultPort; if (!isEmpty(found)) { urlString = urlString.replaceFirst(regex, replacer); } return urlString; }
From source file:com.npower.dl.DownloadFactory.java
/** * Extract Server URL: /* w ww.j av a 2s .c o m*/ * http(s)://server:port * * @param requestURL * @return * @throws MalformedURLException */ public static String getServerURL(String requestURL) throws MalformedURLException { URL url = new URL(requestURL); String protocol = url.getProtocol(); String server = url.getHost(); int port = url.getPort(); if (port <= 0) { if (protocol.equalsIgnoreCase("https")) { port = 443; } else { port = 80; } } String serverURL = protocol + "://" + server + ":" + port; return serverURL; }
From source file:com.eviware.soapui.impl.wsdl.support.http.ProxyUtils.java
public static HostConfiguration initProxySettings(Settings settings, HttpState httpState, HostConfiguration hostConfiguration, String urlString, PropertyExpansionContext context) { boolean enabled = proxyEnabled; // check system properties first String proxyHost = System.getProperty("http.proxyHost"); String proxyPort = System.getProperty("http.proxyPort"); if (proxyHost == null && enabled) proxyHost = PropertyExpander.expandProperties(context, settings.getString(ProxySettings.HOST, "")); if (proxyPort == null && proxyHost != null && enabled) proxyPort = PropertyExpander.expandProperties(context, settings.getString(ProxySettings.PORT, "")); if (!StringUtils.isNullOrEmpty(proxyHost) && !StringUtils.isNullOrEmpty(proxyPort)) { // check excludes String[] excludes = PropertyExpander .expandProperties(context, settings.getString(ProxySettings.EXCLUDES, "")).split(","); try {//w w w . j a v a2 s . c o m URL url = new URL(urlString); if (!excludes(excludes, url.getHost(), url.getPort())) { hostConfiguration.setProxy(proxyHost, Integer.parseInt(proxyPort)); String proxyUsername = PropertyExpander.expandProperties(context, settings.getString(ProxySettings.USERNAME, null)); String proxyPassword = PropertyExpander.expandProperties(context, settings.getString(ProxySettings.PASSWORD, null)); if (proxyUsername != null && proxyPassword != null) { Credentials proxyCreds = new UsernamePasswordCredentials(proxyUsername, proxyPassword == null ? "" : proxyPassword); // check for nt-username int ix = proxyUsername.indexOf('\\'); if (ix > 0) { String domain = proxyUsername.substring(0, ix); if (proxyUsername.length() > ix + 1) { String user = proxyUsername.substring(ix + 1); proxyCreds = new NTCredentials(user, proxyPassword, proxyHost, domain); } } httpState.setProxyCredentials(AuthScope.ANY, proxyCreds); } } } catch (MalformedURLException e) { SoapUI.logError(e); } } return hostConfiguration; }
From source file:de.fhg.iais.asc.xslt.binaries.download.Downloader.java
private static URI createURI(URL url) throws URISyntaxException { return new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); }
From source file:org.n52.web.common.RequestUtils.java
/** * Get the request {@link URL} without the query parameter * * @return Request {@link URL} without query parameter * @throws IOException//from w w w .jav a 2 s . com * @throws URISyntaxException */ public static String resolveQueryLessRequestUrl() throws IOException, URISyntaxException { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()) .getRequest(); URL url = new URL(request.getRequestURL().toString()); String scheme = url.getProtocol(); String userInfo = url.getUserInfo(); String host = url.getHost(); int port = url.getPort(); String path = request.getRequestURI(); if (path != null && path.endsWith("/")) { path = path.substring(0, path.length() - 1); } URI uri = new URI(scheme, userInfo, host, port, path, null, null); return uri.toString(); }
From source file:jettyClient.simpleClient.Parameters.java
/** * Attempts to create an URL from the given parameter. * //from w ww . java 2 s . c o m * @param string * A string value that will be turned into an URL. * @return An URL with the value of the given string. */ public static URL getURL(String string) { URL url = null; try { url = new URL(string); if (url.getPort() == -1) { System.out.println("Error: Missing port number in URL."); logger.info("Error: Missing port number in URL." + string); throw new MalformedURLException(); } } catch (MalformedURLException e) { url = null; logger.info("Malformed endpoint URL: " + string); } return url; }