List of usage examples for java.net URL getPort
public int getPort()
From source file:gov.nih.nci.caintegrator.web.action.analysis.GenePatternAnalysisForm.java
/** * Returns the URL where information on the currently selected analysis method may be found. * * @return the method information URL.//from w w w .j a v a 2 s .c o m */ public String getAnalysisMethodInformationUrl() { try { URL serviceUrl = new URL(server.getUrl()); URL infoUrl = new URL(serviceUrl.getProtocol(), serviceUrl.getHost(), serviceUrl.getPort(), "/gp/getTaskDoc.jsp"); return infoUrl.toExternalForm(); } catch (MalformedURLException e) { throw new IllegalStateException("Server URL should already have been validated.", e); } }
From source file:org.geomajas.layer.common.proxy.LayerHttpServiceImpl.java
/** * Get the port out of a full URL.//from w ww.ja v a 2 s . co m * <p> * Note that we only take https & http into account if you are using a non-default port/protocol you will need to * add the port to your baseUrl. * * @param url base url * @return domain name */ private int parsePort(String url) { try { URL u = new URL(url); int defaultport = "https".equalsIgnoreCase(u.getProtocol()) ? URL_DEFAULT_SECURE_PORT : URL_DEFAULT_PORT; return (u.getPort() == -1 ? defaultport : u.getPort()); } catch (MalformedURLException e) { return URL_DEFAULT_SECURE_PORT; } }
From source file:io.apiman.gateway.platforms.servlet.connectors.HttpApiConnection.java
/** * Extracts the port information fromthe given URL. * @param url a URL// www.j a v a2s . co m * @return the port configured in the URL, or empty string if no port specified */ private String determinePort(URL url) { return (url.getPort() == -1) ? "" : ":" + url.getPort(); //$NON-NLS-1$ //$NON-NLS-2$ }
From source file:org.jboss.as.test.integration.management.console.XFrameOptionsHeaderTestCase.java
private CredentialsProvider createCredentialsProvider(URL url) { CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(Authentication.USERNAME, Authentication.PASSWORD);/* w w w . java 2s .co m*/ credentialsProvider.setCredentials(new AuthScope(url.getHost(), url.getPort(), "ManagementRealm"), credentials); return credentialsProvider; }
From source file:org.openqa.grid.internal.utils.SelfRegisteringRemote.java
/** * uses the hub API to get some of its configuration. * @param parameters list of the parameter to be retrieved from the hub * @return//from ww w .j a v a 2s.c om * @throws Exception */ private JSONObject getHubConfiguration(String... parameters) throws Exception { String hubApi = "http://" + nodeConfig.getConfiguration().get(RegistrationRequest.HUB_HOST) + ":" + nodeConfig.getConfiguration().get(RegistrationRequest.HUB_PORT) + "/grid/api/hub"; HttpClient client = httpClientFactory.getHttpClient(); URL api = new URL(hubApi); HttpHost host = new HttpHost(api.getHost(), api.getPort()); String url = api.toExternalForm(); BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("GET", url); JSONObject j = new JSONObject(); JSONArray keys = new JSONArray(); j.put("configuration", keys); r.setEntity(new StringEntity(j.toString())); HttpResponse response = client.execute(host, r); return extractObject(response); }
From source file:com.amazonaws.ipnreturnurlvalidation.SignatureUtilsForOutbound.java
private String getHostHeader(URL url) { int port = url.getPort(); if (port != -1) { if ("HTTPS".equalsIgnoreCase(url.getProtocol()) && port == 443 || "HTTP".equalsIgnoreCase(url.getProtocol()) && port == 80) port = -1;/*from ww w . j a va 2 s . com*/ } return url.getHost().toLowerCase() + (port != -1 ? ":" + port : ""); }
From source file:com._17od.upm.transport.HTTPTransport.java
public byte[] get(String url, String username, String password) throws TransportException { byte[] retVal = null; GetMethod method = new GetMethod(url); //This part is wrapped in a try/finally so that we can ensure //the connection to the HTTP server is always closed cleanly try {//from ww w .j ava2 s. c o m //Set the authentication details if (username != null) { Credentials creds = new UsernamePasswordCredentials(new String(username), new String(password)); URL urlObj = new URL(url); AuthScope authScope = new AuthScope(urlObj.getHost(), urlObj.getPort()); client.getState().setCredentials(authScope, creds); client.getParams().setAuthenticationPreemptive(true); } int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { throw new TransportException("There's been some kind of problem getting the URL [" + url + "].\n\nThe HTTP error message is [" + HttpStatus.getStatusText(statusCode) + "]"); } retVal = method.getResponseBody(); } catch (MalformedURLException e) { throw new TransportException(e); } catch (HttpException e) { throw new TransportException(e); } catch (IOException e) { throw new TransportException(e); } finally { method.releaseConnection(); } return retVal; }
From source file:ch.sbb.releasetrain.utils.http.HttpUtilImpl.java
/** * authenticates the context if user and password are set *///from w w w. j a v a 2s .c om private HttpClientContext initAuthIfNeeded(String url) { HttpClientContext context = HttpClientContext.create(); if (this.user.isEmpty() || this.password.isEmpty()) { log.debug( "http connection without autentication, because no user / password ist known to HttpUtilImpl ..."); return context; } CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(AuthScope.ANY), new UsernamePasswordCredentials(user, password)); URL url4Host; try { url4Host = new URL(url); } catch (MalformedURLException e) { log.error(e.getMessage(), e); return context; } HttpHost targetHost = new HttpHost(url4Host.getHost(), url4Host.getPort(), url4Host.getProtocol()); AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); context.setCredentialsProvider(credsProvider); context.setAuthCache(authCache); return context; }
From source file:io.github.bonigarcia.wdm.WdmHttpClient.java
Proxy createProxy(String proxyUrl) { URL url = determineProxyUrl(proxyUrl); if (url == null) { return null; }/*w w w . j a v a 2s. c o m*/ String proxyHost = url.getHost(); int proxyPort = url.getPort() == -1 ? 80 : url.getPort(); return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)); }
From source file:com.amazonaws.cbui.AmazonFPSCBUIPipeline.java
private String getHostHeader(String urlEndPoint) throws MalformedURLException { URL url = new URL(urlEndPoint); int port = url.getPort(); if (port != -1) { if ("HTTPS".equalsIgnoreCase(url.getProtocol()) && port == 443 || "HTTP".equalsIgnoreCase(url.getProtocol()) && port == 80) port = -1;/*from w w w . j a v a2 s.c om*/ } return url.getHost().toLowerCase() + (port != -1 ? ":" + port : ""); }