List of usage examples for java.net URL getHost
public String getHost()
From source file:com.ikanow.infinit.e.harvest.extraction.document.file.InfiniteFile.java
public URI getURI() throws MalformedURLException, URISyntaxException { // (note this doesn't work nicely with spaces) if (null != _smbFile) { URL url = _smbFile.getURL(); return new URI(url.getProtocol(), url.getHost(), url.getPath(), url.getQuery(), null); // (this odd construct is needed to handle spaces in paths) } else {/*from www.j av a 2 s . c o m*/ return _localFile.toURI(); // (confirmed spaces in paths works here) } }
From source file:net.sourceforge.jwbf.bots.HttpBot.java
/** * /*from w ww. j av a 2s . c om*/ * @param client * if you whant to add some specials * @param u * like http://www.yourOwnWiki.org/w/index.php * */ protected final void setConnection(final HttpClient client, final URL u) { this.client = client; client.getParams().setParameter("http.useragent", "JWBF " + JWBF.getVersion()); client.getHostConfiguration().setHost(u.getHost(), u.getPort(), u.getProtocol()); cc = new HttpActionClient(client, u.getPath()); }
From source file:com.hp.mercury.ci.jenkins.plugins.OOBuildStep.java
private static void initializeHttpClient(DescriptorImpl descriptor) { final int maxConnectionsPerRoute = 100; final int maxConnectionsTotal = 100; ThreadSafeClientConnManager threadSafeClientConnManager = new ThreadSafeClientConnManager(); threadSafeClientConnManager.setDefaultMaxPerRoute(maxConnectionsPerRoute); threadSafeClientConnManager.setMaxTotal(maxConnectionsTotal); httpClient = new DefaultHttpClient(threadSafeClientConnManager); if (descriptor.isIgnoreSsl()) { threadSafeClientConnManager.getSchemeRegistry() .register(new Scheme("https", 443, new FakeSocketFactory())); } else if (descriptor.getKeystorePath() != null) { try {//from www . ja v a 2 s . c om SSLSocketFactory sslSocketFactory = sslSocketFactoryFromCertificateFile( descriptor.getKeystorePath(), decrypt(descriptor.getKeystorePassword()).toCharArray()); sslSocketFactory.setHostnameVerifier(new BrowserCompatHostnameVerifier()); // For less strict rules in dev mode you can try //sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier()); threadSafeClientConnManager.getSchemeRegistry() .register(new Scheme("https", 443, sslSocketFactory)); } catch (NoSuchAlgorithmException e) { LOG.error("Could not register https scheme: ", e); } catch (KeyManagementException e) { LOG.error("Could not register https scheme: ", e); } catch (KeyStoreException e) { LOG.error("Could not register https scheme: ", e); } catch (UnrecoverableKeyException e) { LOG.error("Could not register https scheme: ", e); } catch (IOException e) { LOG.error("Could not load keystore file: ", e); } catch (CertificateException e) { LOG.error("Could not load keystore file: ", e); } } final HttpParams params = httpClient.getParams(); final int timeoutInSeconds = descriptor.getTimeout() * 1000; HttpConnectionParams.setConnectionTimeout(params, timeoutInSeconds); HttpConnectionParams.setSoTimeout(params, timeoutInSeconds); HttpProtocolParams.setUseExpectContinue(httpClient.getParams(), false); for (OOServer s : descriptor.getOoServers(true).values()) { URL url = null; try { url = new URL(s.getUrl()); } catch (MalformedURLException mue) { //can't happen, we pre-validate the URLS during configuration and set active to false if bad. } //check why it doesn't use the credentials provider httpClient.getCredentialsProvider().setCredentials( new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM, "basic"), new UsernamePasswordCredentials(s.getUsername(), decrypt(s.getPassword()))); } }
From source file:cn.openwatch.internal.http.loopj.AsyncHttpClient.java
/** * Will encode url, if not disabled, and adds params on the end of it * * @param url String with URL, should be valid URL without params * @param params RequestParams to be appended on the end of URL * @param shouldEncodeUrl whether url should be encoded (replaces spaces with %20) * @return encoded url if requested with params appended if any available *///from w w w. ja v a2s . com public static String getUrlWithQueryString(boolean shouldEncodeUrl, String url, RequestParams params) { if (url == null) return null; if (shouldEncodeUrl) { try { String decodedURL = URLDecoder.decode(url, "UTF-8"); URL _url = new URL(decodedURL); URI _uri = new URI(_url.getProtocol(), _url.getUserInfo(), _url.getHost(), _url.getPort(), _url.getPath(), _url.getQuery(), _url.getRef()); url = _uri.toASCIIString(); } catch (Exception ex) { // Should not really happen, added just for sake of validity } } if (params != null) { // Construct the query string and trim it, in case it // includes any excessive white spaces. String paramString = params.getParamString().trim(); // Only add the query string if it isn't empty and it // isn't equal to '?'. if (!paramString.equals("") && !paramString.equals("?")) { url += url.contains("?") ? "&" : "?"; url += paramString; } } return url; }
From source file:cz.zcu.kiv.eegdatabase.logic.util.BasicAuthHttpClient.java
public BasicAuthHttpClient(URL url, String username, String password, ThreadSafeClientConnManager connManager) { super(connManager); this.url = url; BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(url.getHost(), AuthScope.ANY_PORT), new UsernamePasswordCredentials(username, password)); setCredentialsProvider(credsProvider); }
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)); }/* w w w . j a v a2s . c om*/ }
From source file:dk.netarkivet.common.distribute.HTTPRemoteFileRegistry.java
/** * Get the url for cleaning up after a remote file registered under some * URL./*from w w w .j av a2 s . c o 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:com.microsoft.aad.adal.Discovery.java
/** * service side does not validate tenant, so it is sending common keyword as * tenant.//w w w. j a va 2 s . c o m * * @param authorizationEndpointUrl * @return https://hostname/common */ private String getAuthorizationCommonEndpoint(final URL authorizationEndpointUrl) { return new Uri.Builder().scheme("https").authority(authorizationEndpointUrl.getHost()) .appendPath(AUTHORIZATION_COMMON_ENDPOINT).build().toString(); }
From source file:com.google.zxing.client.android.result.ClickVURIResultHandler.java
public void registerClickV(String uri) { String host = "http://lit-taiga-5566.herokuapp.com/"; String query = null, path = null; String telId = getTelNumber() == null ? getMacAddress() : getTelNumber(); try {/*from w w w. j a v a 2s. c o m*/ URL url = new URL(uri.replaceAll("clickv://", host)); query = url.getQuery(); path = url.getProtocol() + "://" + url.getHost() + "/" + url.getPath(); } catch (MalformedURLException e) { e.printStackTrace(); } Toast.makeText(getActivity(), "??? :: " + query, Toast.LENGTH_SHORT).show(); try { new ServerConnenctionTask().execute(path, query, telId); Toast.makeText(getActivity(), "" + uri, Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(getActivity(), "?." + uri, Toast.LENGTH_SHORT).show(); } }