List of usage examples for java.net URL getPort
public int getPort()
From source file:com.apigee.sdk.apm.http.impl.client.cache.URIExtractor.java
public String canonicalizeUri(String uri) { try {// w w w .j a v a2 s . c om URL u = new URL(uri); String protocol = u.getProtocol().toLowerCase(); String hostname = u.getHost().toLowerCase(); int port = canonicalizePort(u.getPort(), protocol); String path = canonicalizePath(u.getPath()); if ("".equals(path)) path = "/"; String query = u.getQuery(); String file = (query != null) ? (path + "?" + query) : path; URL out = new URL(protocol, hostname, port, file); return out.toString(); } catch (MalformedURLException e) { return uri; } }
From source file:com.connectsdk.core.upnp.Device.java
public Device(String url, String searchTarget) throws IOException { URL urlObject = new URL(url); if (urlObject.getPort() == -1) { baseURL = String.format("%s://%s", urlObject.getProtocol(), urlObject.getHost()); } else {/*from w w w. ja v a 2s .c om*/ baseURL = String.format("%s://%s:%d", urlObject.getProtocol(), urlObject.getHost(), urlObject.getPort()); } ipAddress = urlObject.getHost(); port = urlObject.getPort(); this.searchTarget = searchTarget; UUID = null; if (searchTarget.equalsIgnoreCase("urn:dial-multiscreen-org:service:dial:1")) applicationURL = getApplicationURL(url); }
From source file:io.apiman.gateway.vertx.connector.HttpConnector.java
/** * Construct an {@link HttpConnector} instance. The {@link #resultHandler} must remain exclusive to a * given instance./* w w w . j av a 2s . c o m*/ * * @param vertx a vertx * @param service a service * @param request a request with fields filled * @param resultHandler a handler, called when reading is permitted */ public HttpConnector(Vertx vertx, Container container, Service service, ServiceRequest request, IAsyncResultHandler<IServiceConnectionResponse> resultHandler) { this.vertx = vertx; this.logger = container.logger(); this.serviceRequest = request; this.resultHandler = resultHandler; this.exceptionHandler = new ExceptionHandler(); URL serviceEndpoint = parseServiceEndpoint(service); serviceHost = serviceEndpoint.getHost(); servicePort = serviceEndpoint.getPort(); servicePath = StringUtils.removeEnd(serviceEndpoint.getPath(), "/"); //$NON-NLS-1$ doConnection(); }
From source file:com.tremolosecurity.provisioning.core.providers.TremoloTarget.java
@Override public void init(Map<String, Attribute> cfg, ConfigManager cfgMgr, String name) throws ProvisioningException { this.name = name; this.cfgMgr = cfgMgr; if (cfg.get("createUsersWF") == null) { throw new ProvisioningException("Create user workflow not specified"); }/* www. j av a2 s. com*/ this.createUserWF = cfg.get("createUsersWF").getValues().get(0); if (cfg.get("deleteUserWF") == null) { throw new ProvisioningException("Delete user workflow not specified"); } this.deleteUserWF = cfg.get("deleteUserWF").getValues().get(0); if (cfg.get("setUserPasswordWF") == null) { throw new ProvisioningException("Set user password workflow not specified"); } this.setUserPasswordWF = cfg.get("setUserPasswordWF").getValues().get(0); if (cfg.get("syncUserWF") == null) { throw new ProvisioningException("Synchronize user workflow not specified"); } this.syncUserWF = cfg.get("syncUserWF").getValues().get(0); if (cfg.get("uidAttrName") == null) { throw new ProvisioningException("User identifier attribute name not found"); } this.uidAttrName = cfg.get("uidAttrName").getValues().get(0); if (cfg.get("wfUrlBase") == null) { throw new ProvisioningException("WorkflowImpl URL base not specified"); } this.wfUrlBase = cfg.get("wfUrlBase").getValues().get(0); try { URL url = new URL(this.wfUrlBase); if (url.getPort() > 0) { this.port = url.getPort(); } else { this.port = 443; } } catch (MalformedURLException e) { throw new ProvisioningException("Could not configure target", e); } phcm = new PoolingHttpClientConnectionManager(cfgMgr.getHttpClientSocketRegistry()); httpclient = HttpClients.custom().setConnectionManager(phcm).build(); }
From source file:org.deegree.protocol.ows.http.OwsHttpClientImpl.java
private void setCredentials(URL url, DefaultHttpClient client) { if (user != null) { client.getCredentialsProvider().setCredentials(new AuthScope(url.getHost(), url.getPort()), new UsernamePasswordCredentials(user, pass)); }/*from w ww. j a va2 s .co m*/ }
From source file:dk.netarkivet.common.distribute.HTTPRemoteFileRegistry.java
/** * Get the url for cleaning up after a remote file registered under some * URL.//from www. j a va2s . co m * @param url some URL * * @return the cleanup url. * @throws MalformedURLException If unable to construct the cleanup url */ URL getCleanupUrl(URL url) throws MalformedURLException { return new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getPath() + UNREGISTER_URL_POSTFIX); }
From source file:edu.ucsb.eucalyptus.admin.server.extensions.store.ImageStoreServiceImpl.java
private NameValuePair[] getFinalParameters(Method method, String uri, Parameter[] params, UserInfoWeb user) throws MalformedURLException { if (params == null) { // Simplify the logic below. params = new Parameter[0]; }/*from w w w . ja v a 2 s. c o m*/ URL url = new URL(uri); SignatureGenerator signatureGenerator = new SignatureGenerator(method.toString(), url.getHost(), url.getPort(), url.getPath()); Parameter[] finalParams = new Parameter[params.length + 7]; System.arraycopy(params, 0, finalParams, 0, params.length); int i = params.length; finalParams[i++] = new Parameter("SignatureMethod", SIGNATURE_METHOD); finalParams[i++] = new Parameter("SignatureVersion", SIGNATURE_VERSION); finalParams[i++] = new Parameter("Version", API_VERSION); finalParams[i++] = new Parameter("ClientId", user.getQueryId()); finalParams[i++] = new Parameter("Expires", new Long((System.currentTimeMillis() / 1000) + EXPIRES_DELAY_SECONDS).toString()); finalParams[i++] = new Parameter("Nonce", new Long(System.nanoTime()).toString()); for (Parameter param : finalParams) { if (param != null) { signatureGenerator.addParameter(param.getName(), param.getValue()); } } String signature = signatureGenerator.getSignature(user.getSecretKey()); finalParams[i++] = new Parameter("Signature", signature); return getNameValuePairs(finalParams); }
From source file:crawler.RobotstxtServer.java
private HostDirectives fetchDirectives(URL url) { WebURL robotsTxtUrl = new WebURL(); String host = getHost(url);/*w w w . ja v a 2s . c o m*/ String port = ((url.getPort() == url.getDefaultPort()) || (url.getPort() == -1)) ? "" : (":" + url.getPort()); String proto = url.getProtocol(); robotsTxtUrl.setURL(proto + "://" + host + port + "/robots.txt"); HostDirectives directives = null; PageFetchResult fetchResult = null; try { for (int redir = 0; redir < 3; ++redir) { fetchResult = pageFetcher.fetchPage(robotsTxtUrl); int status = fetchResult.getStatusCode(); // Follow redirects up to 3 levels if ((status == HttpStatus.SC_MULTIPLE_CHOICES || status == HttpStatus.SC_MOVED_PERMANENTLY || status == HttpStatus.SC_MOVED_TEMPORARILY || status == HttpStatus.SC_SEE_OTHER || status == HttpStatus.SC_TEMPORARY_REDIRECT || status == 308) && // SC_PERMANENT_REDIRECT RFC7538 fetchResult.getMovedToUrl() != null) { robotsTxtUrl.setURL(fetchResult.getMovedToUrl()); fetchResult.discardContentIfNotConsumed(); } else { // Done on all other occasions break; } } if (fetchResult.getStatusCode() == HttpStatus.SC_OK) { Page page = new Page(robotsTxtUrl); // Most recent answer on robots.txt max size is // https://goo.gl/OqpKbP fetchResult.fetchContent(page, 10_000 * 1024); if (Util.hasPlainTextContent(page.getContentType())) { String content; if (page.getContentCharset() == null) { content = new String(page.getContentData()); } else { content = new String(page.getContentData(), page.getContentCharset()); } directives = RobotstxtParser.parse(content, config); } else if (page.getContentType().contains("html")) { // TODO This one should be upgraded to remove all // html tags String content = new String(page.getContentData()); directives = RobotstxtParser.parse(content, config); } else { logger.warn("Can't read this robots.txt: {} as it is not written in plain text, " + "contentType: {}", robotsTxtUrl.getURL(), page.getContentType()); } } else { logger.debug("Can't read this robots.txt: {} as it's status code is {}", robotsTxtUrl.getURL(), fetchResult.getStatusCode()); } } catch (SocketException | UnknownHostException | SocketTimeoutException | NoHttpResponseException se) { // No logging here, as it just means that robots.txt doesn't exist on this server // which is perfectly ok logger.trace("robots.txt probably does not exist.", se); } catch (PageBiggerThanMaxSizeException pbtms) { logger.error("Error occurred while fetching (robots) url: {}, {}", robotsTxtUrl.getURL(), pbtms.getMessage()); } catch (Exception e) { logger.error("Error occurred while fetching (robots) url: " + robotsTxtUrl.getURL(), e); } finally { if (fetchResult != null) { fetchResult.discardContentIfNotConsumed(); } } if (directives == null) { // We still need to have this object to keep track of the time we fetched it directives = new HostDirectives(config); } synchronized (host2directivesCache) { if (host2directivesCache.size() == config.getCacheSize()) { String minHost = null; long minAccessTime = Long.MAX_VALUE; for (Map.Entry<String, HostDirectives> entry : host2directivesCache.entrySet()) { long entryAccessTime = entry.getValue().getLastAccessTime(); if (entryAccessTime < minAccessTime) { minAccessTime = entryAccessTime; minHost = entry.getKey(); } } host2directivesCache.remove(minHost); } host2directivesCache.put(host, directives); } return directives; }
From source file:com.googlesource.gerrit.plugins.github.oauth.OAuthGitFilter.java
private int getPort(URL originalUrl) { String protocol = originalUrl.getProtocol().toLowerCase(); int port = originalUrl.getPort(); if (port == -1) { return protocol.equals("https") ? 443 : 80; } else {//from w w w . j a va 2s. com return port; } }