List of usage examples for java.net URI getPort
public int getPort()
From source file:annis.libgui.Helper.java
public static String generateCitation(String aql, Set<String> corpora, int contextLeft, int contextRight, String segmentation, int start, int limit) { try {/*from w w w . j a va 2 s . c om*/ URI appURI = UI.getCurrent().getPage().getLocation(); return new URI(appURI.getScheme(), null, appURI.getHost(), appURI.getPort(), getContext(), null, StringUtils.join( citationFragment(aql, corpora, contextLeft, contextRight, segmentation, start, limit), "&")).toASCIIString(); } catch (URISyntaxException ex) { log.error(null, ex); } return "ERROR"; }
From source file:URISupport.java
/** * Creates a URI with the given query/*from w w w . j a va2 s.co m*/ */ public static URI createURIWithQuery(URI uri, String query) throws URISyntaxException { return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), query, uri.getFragment()); }
From source file:com.sun.jersey.client.apache4.ApacheHttpClient4.java
/** * Create a default Apache HTTP client handler. * * @param cc ClientConfig instance. Might be null. * * @return a default Apache HTTP client handler. */// w ww. jav a2s .c om private static ApacheHttpClient4Handler createDefaultClientHandler(final ClientConfig cc) { Object connectionManager = null; Object httpParams = null; if (cc != null) { connectionManager = cc.getProperties().get(ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER); if (connectionManager != null) { if (!(connectionManager instanceof ClientConnectionManager)) { Logger.getLogger(ApacheHttpClient4.class.getName()).log(Level.WARNING, "Ignoring value of property " + ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER + " (" + connectionManager.getClass().getName() + ") - not instance of org.apache.http.conn.ClientConnectionManager."); connectionManager = null; } } httpParams = cc.getProperties().get(ApacheHttpClient4Config.PROPERTY_HTTP_PARAMS); if (httpParams != null) { if (!(httpParams instanceof HttpParams)) { Logger.getLogger(ApacheHttpClient4.class.getName()).log(Level.WARNING, "Ignoring value of property " + ApacheHttpClient4Config.PROPERTY_HTTP_PARAMS + " (" + httpParams.getClass().getName() + ") - not instance of org.apache.http.params.HttpParams."); httpParams = null; } } } final DefaultHttpClient client = new DefaultHttpClient((ClientConnectionManager) connectionManager, (HttpParams) httpParams); CookieStore cookieStore = null; boolean preemptiveBasicAuth = false; if (cc != null) { for (Map.Entry<String, Object> entry : cc.getProperties().entrySet()) client.getParams().setParameter(entry.getKey(), entry.getValue()); if (cc.getPropertyAsFeature(ApacheHttpClient4Config.PROPERTY_DISABLE_COOKIES)) client.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES); Object credentialsProvider = cc.getProperty(ApacheHttpClient4Config.PROPERTY_CREDENTIALS_PROVIDER); if (credentialsProvider != null && (credentialsProvider instanceof CredentialsProvider)) { client.setCredentialsProvider((CredentialsProvider) credentialsProvider); } final Object proxyUri = cc.getProperties().get(ApacheHttpClient4Config.PROPERTY_PROXY_URI); if (proxyUri != null) { final URI u = getProxyUri(proxyUri); final HttpHost proxy = new HttpHost(u.getHost(), u.getPort(), u.getScheme()); if (cc.getProperties().containsKey(ApacheHttpClient4Config.PROPERTY_PROXY_USERNAME) && cc.getProperties().containsKey(ApacheHttpClient4Config.PROPERTY_PROXY_PASSWORD)) { client.getCredentialsProvider().setCredentials(new AuthScope(u.getHost(), u.getPort()), new UsernamePasswordCredentials( cc.getProperty(ApacheHttpClient4Config.PROPERTY_PROXY_USERNAME).toString(), cc.getProperty(ApacheHttpClient4Config.PROPERTY_PROXY_PASSWORD).toString())); } client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } preemptiveBasicAuth = cc .getPropertyAsFeature(ApacheHttpClient4Config.PROPERTY_PREEMPTIVE_BASIC_AUTHENTICATION); } if (client.getParams().getParameter(ClientPNames.COOKIE_POLICY) == null || !client.getParams() .getParameter(ClientPNames.COOKIE_POLICY).equals(CookiePolicy.IGNORE_COOKIES)) { cookieStore = new BasicCookieStore(); client.setCookieStore(cookieStore); } return new ApacheHttpClient4Handler(client, cookieStore, preemptiveBasicAuth); }
From source file:URISupport.java
public static URI changeScheme(URI bindAddr, String scheme) throws URISyntaxException { return new URI(scheme, bindAddr.getUserInfo(), bindAddr.getHost(), bindAddr.getPort(), bindAddr.getPath(), bindAddr.getQuery(), bindAddr.getFragment()); }
From source file:com.spectralogic.ds3client.NetworkClientImpl.java
private static HttpHost buildHost(final ConnectionDetails connectionDetails) throws MalformedURLException { final URI proxyUri = connectionDetails.getProxy(); if (proxyUri != null) { return new HttpHost(proxyUri.getHost(), proxyUri.getPort(), proxyUri.getScheme()); } else {//from ww w . java2s . c o m final URL url = NetUtils.buildUrl(connectionDetails, "/"); return new HttpHost(url.getHost(), NetUtils.getPort(url), url.getProtocol()); } }
From source file:org.apache.gobblin.utils.HttpUtils.java
/** * Convert D2 URL template into a string used for throttling limiter * * Valid:/*from w w w . jav a2 s. com*/ * d2://host/${resource-id} * * Invalid: * d2://host${resource-id}, because we cannot differentiate the host */ public static String createR2ClientLimiterKey(Config config) { String urlTemplate = config.getString(HttpConstants.URL_TEMPLATE); try { String escaped = URIUtil.encodeQuery(urlTemplate); URI uri = new URI(escaped); if (uri.getHost() == null) throw new RuntimeException("Cannot get host part from uri" + urlTemplate); String key = uri.getScheme() + "/" + uri.getHost(); if (uri.getPort() > 0) { key = key + "/" + uri.getPort(); } log.info("Get limiter key [" + key + "]"); return key; } catch (Exception e) { throw new RuntimeException("Cannot create R2 limiter key", e); } }
From source file:com.google.caja.precajole.StaticPrecajoleMap.java
public static String normalizeUri(String uri) { try {/*from ww w.j a va 2 s . c o m*/ URI u = new URI(uri).normalize(); if (u.getHost() != null) { u = new URI(lowercase(u.getScheme()), u.getUserInfo(), lowercase(u.getHost()), u.getPort(), u.getPath(), u.getQuery(), u.getFragment()); } else if (u.getScheme() != null) { u = new URI(lowercase(u.getScheme()), u.getSchemeSpecificPart(), u.getFragment()); } return u.toString(); } catch (URISyntaxException e) { return uri; } }
From source file:co.cask.cdap.etl.tool.UpgradeTool.java
private static ClientConfig getClientConfig(CommandLine commandLine) throws IOException { String uriStr = commandLine.hasOption("u") ? commandLine.getOptionValue("u") : "localhost:10000"; if (!uriStr.contains("://")) { uriStr = "http://" + uriStr; }// ww w .j av a 2 s . c om URI uri = URI.create(uriStr); String hostname = uri.getHost(); int port = uri.getPort(); boolean sslEnabled = "https".equals(uri.getScheme()); ConnectionConfig connectionConfig = ConnectionConfig.builder().setHostname(hostname).setPort(port) .setSSLEnabled(sslEnabled).build(); int readTimeout = commandLine.hasOption("t") ? Integer.parseInt(commandLine.getOptionValue("t")) : DEFAULT_READ_TIMEOUT_MILLIS; ClientConfig.Builder clientConfigBuilder = ClientConfig.builder().setDefaultReadTimeout(readTimeout) .setConnectionConfig(connectionConfig); if (commandLine.hasOption("a")) { String tokenFilePath = commandLine.getOptionValue("a"); File tokenFile = new File(tokenFilePath); if (!tokenFile.exists()) { throw new IllegalArgumentException("Access token file " + tokenFilePath + " does not exist."); } if (!tokenFile.isFile()) { throw new IllegalArgumentException("Access token file " + tokenFilePath + " is not a file."); } String tokenValue = new String(Files.readAllBytes(tokenFile.toPath()), StandardCharsets.UTF_8).trim(); AccessToken accessToken = new AccessToken(tokenValue, 82000L, "Bearer"); clientConfigBuilder.setAccessToken(accessToken); } return clientConfigBuilder.build(); }
From source file:net.oauth.signature.OAuthSignatureMethod.java
protected static String normalizeUrl(String url) throws URISyntaxException { URI uri = new URI(url); String scheme = uri.getScheme().toLowerCase(); String authority = uri.getAuthority().toLowerCase(); boolean dropPort = (scheme.equals("http") && uri.getPort() == 80) || (scheme.equals("https") && uri.getPort() == 443); if (dropPort) { // find the last : in the authority int index = authority.lastIndexOf(":"); if (index >= 0) { authority = authority.substring(0, index); }//from w w w . ja v a2 s. c o m } String path = uri.getRawPath(); if (path == null || path.length() <= 0) { path = "/"; // conforms to RFC 2616 section 3.2.2 } // we know that there is no query and no fragment here. return scheme + "://" + authority + path; }
From source file:password.pwm.http.servlet.oauth.OAuthMachine.java
public static String figureOauthSelfEndPointUrl(final PwmRequest pwmRequest) { final String debugSource; final String redirect_uri; {// w w w.j a v a2 s . c o m final String returnUrlOverride = pwmRequest.getConfig() .readAppProperty(AppProperty.OAUTH_RETURN_URL_OVERRIDE); final String siteURL = pwmRequest.getConfig().readSettingAsString(PwmSetting.PWM_SITE_URL); if (returnUrlOverride != null && !returnUrlOverride.trim().isEmpty()) { debugSource = "AppProperty(\"" + AppProperty.OAUTH_RETURN_URL_OVERRIDE.getKey() + "\")"; redirect_uri = returnUrlOverride + PwmServletDefinition.OAuthConsumer.servletUrl(); } else if (siteURL != null && !siteURL.trim().isEmpty()) { debugSource = "SiteURL Setting"; redirect_uri = siteURL + PwmServletDefinition.OAuthConsumer.servletUrl(); } else { debugSource = "Input Request URL"; final String inputURI = pwmRequest.getHttpServletRequest().getRequestURL().toString(); try { final URI requestUri = new URI(inputURI); final int port = requestUri.getPort(); redirect_uri = requestUri.getScheme() + "://" + requestUri.getHost() + (port > 0 && port != 80 && port != 443 ? ":" + requestUri.getPort() : "") + pwmRequest.getContextPath() + PwmServletDefinition.OAuthConsumer.servletUrl(); } catch (URISyntaxException e) { throw new IllegalStateException( "unable to parse inbound request uri while generating oauth redirect: " + e.getMessage()); } } } LOGGER.trace("calculated oauth self end point URI as '" + redirect_uri + "' using method " + debugSource); return redirect_uri; }