List of usage examples for java.net URL getPort
public int getPort()
From source file:ua.pp.msk.cliqr.GetProcessorImpl.java
private void init(URL targetURL, String user, String password) throws ClientSslException { this.targetUrl = targetURL; logger.debug("Initializing " + this.getClass().getName() + " with target URL " + targetURL.toString()); HttpHost htHost = new HttpHost(targetUrl.getHost(), targetUrl.getPort(), targetUrl.getProtocol()); AuthCache aCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); aCache.put(htHost, basicAuth);/*from w w w .j a v a2 s . c o m*/ UsernamePasswordCredentials creds = new UsernamePasswordCredentials(user, password); BasicCredentialsProvider cProvider = new BasicCredentialsProvider(); cProvider.setCredentials(new AuthScope(htHost), creds); logger.debug("Credential provider: " + cProvider.toString()); context = new BasicHttpContext(); ClientContextConfigurer cliCon = new ClientContextConfigurer(context); cliCon.setCredentialsProvider(cProvider); context.setAttribute(ClientContext.AUTH_CACHE, aCache); SSLSocketFactory sslConnectionSocketFactory = null; try { sslConnectionSocketFactory = new SSLSocketFactory(new TrustSelfSignedStrategy(), new CliQrHostnameVerifier()); } catch (KeyManagementException ex) { logger.error("Cannot manage secure keys", ex); throw new ClientSslException("Cannot manage secure keys", ex); } catch (KeyStoreException ex) { logger.error("Cannot build SSL context due to KeyStore error", ex); throw new ClientSslException("Cannot build SSL context due to KeyStore error", ex); } catch (NoSuchAlgorithmException ex) { logger.error("Unsupported security algorithm", ex); throw new ClientSslException("Unsupported security algorithm", ex); } catch (UnrecoverableKeyException ex) { logger.error("Unrecoverable key", ex); throw new ClientSslException("Unrecoverrable key", ex); } DefaultHttpClient defClient = new DefaultHttpClient(); defClient.setRedirectStrategy(new CliQrRedirectStrategy()); defClient.setCredentialsProvider(cProvider); Scheme https = new Scheme("https", 443, sslConnectionSocketFactory); defClient.getConnectionManager().getSchemeRegistry().register(https); defClient.setTargetAuthenticationStrategy(new TargetAuthenticationStrategy()); client = defClient; }
From source file:org.alfresco.maven.plugin.AbstractRefreshWebappMojo.java
/** * Utility method to ping/call the Alfresco Tomcat server and see if it is up (running) * * @return true if the Alfresco Tomcat server was reachable and up *///from ww w . j a v a 2 s .com private boolean ping() { try { URL alfrescoTomcatUrl = buildFinalUrl(""); TelnetClient telnetClient = new TelnetClient(); telnetClient.setDefaultTimeout(500); telnetClient.connect(alfrescoTomcatUrl.getHost(), alfrescoTomcatUrl.getPort()); return true; } catch (Exception ex) { return false; } }
From source file:it.geosolutions.geofence.gui.server.service.impl.InstancesManagerServiceImpl.java
private void setAuth(HttpClient client, String url, String username, String pw) throws MalformedURLException { URL u = new URL(url); if (username != null && pw != null) { Credentials defaultcreds = new UsernamePasswordCredentials(username, pw); client.getState().setCredentials(new AuthScope(u.getHost(), u.getPort()), defaultcreds); client.getParams().setAuthenticationPreemptive(true); // GS2 by default always requires authentication } else {//from w ww . j av a 2s .c om if (logger.isDebugEnabled()) { logger.debug("Not setting credentials to access to " + url); } } }
From source file:com.tingtingapps.securesms.mms.LegacyMmsConnection.java
protected CloseableHttpClient constructHttpClient() throws IOException { RequestConfig config = RequestConfig.custom().setConnectTimeout(20 * 1000) .setConnectionRequestTimeout(20 * 1000).setSocketTimeout(20 * 1000).setMaxRedirects(20).build(); URL mmsc = new URL(apn.getMmsc()); CredentialsProvider credsProvider = new BasicCredentialsProvider(); if (apn.hasAuthentication()) { credsProvider.setCredentials(/*from www. ja v a2s . c o m*/ new AuthScope(mmsc.getHost(), mmsc.getPort() > -1 ? mmsc.getPort() : mmsc.getDefaultPort()), new UsernamePasswordCredentials(apn.getUsername(), apn.getPassword())); } return HttpClients.custom().setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4()) .setRedirectStrategy(new LaxRedirectStrategy()) .setUserAgent(TextSecurePreferences.getMmsUserAgent(context, USER_AGENT)) .setConnectionManager(new BasicHttpClientConnectionManager()).setDefaultRequestConfig(config) .setDefaultCredentialsProvider(credsProvider).build(); }
From source file:ua.pp.msk.gradle.http.Client.java
private void init(URL targetURL, String user, String password) throws ClientSslException { this.targetUrl = targetURL; logger.debug("Initializing " + this.getClass().getName() + " with target URL " + targetURL.toString()); HttpHost htHost = new HttpHost(targetUrl.getHost(), targetUrl.getPort(), targetUrl.getProtocol()); AuthCache aCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); aCache.put(htHost, basicAuth);//from w ww . j a v a2s . co m UsernamePasswordCredentials creds = new UsernamePasswordCredentials(user, password); BasicCredentialsProvider cProvider = new BasicCredentialsProvider(); cProvider.setCredentials(new AuthScope(htHost), creds); logger.debug("Credential provider: " + cProvider.toString()); context = new BasicHttpContext(); ClientContextConfigurer cliCon = new ClientContextConfigurer(context); cliCon.setCredentialsProvider(cProvider); context.setAttribute(ClientContext.AUTH_CACHE, aCache); SSLSocketFactory sslConnectionSocketFactory = null; try { sslConnectionSocketFactory = new SSLSocketFactory(new TrustSelfSignedStrategy(), new NexusHostnameVerifier()); } catch (KeyManagementException ex) { logger.error("Cannot manage secure keys", ex); throw new ClientSslException("Cannot manage secure keys", ex); } catch (KeyStoreException ex) { logger.error("Cannot build SSL context due to KeyStore error", ex); throw new ClientSslException("Cannot build SSL context due to KeyStore error", ex); } catch (NoSuchAlgorithmException ex) { logger.error("Unsupported security algorithm", ex); throw new ClientSslException("Unsupported security algorithm", ex); } catch (UnrecoverableKeyException ex) { logger.error("Unrecoverable key", ex); throw new ClientSslException("Unrecoverrable key", ex); } DefaultHttpClient defClient = new DefaultHttpClient(); defClient.setRedirectStrategy(new NexusRedirectStrategy()); defClient.setCredentialsProvider(cProvider); Scheme https = new Scheme("https", 443, sslConnectionSocketFactory); defClient.getConnectionManager().getSchemeRegistry().register(https); defClient.setTargetAuthenticationStrategy(new TargetAuthenticationStrategy()); client = defClient; }
From source file:org.openremote.android.console.model.PollingHelper.java
/** * Request current status and start polling. *//* w w w. j a va 2s . com*/ public void requestCurrentStatusAndStartPolling(Context context) { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 50 * 1000); //make polling socket timout bigger than Controller (50s) HttpConnectionParams.setSoTimeout(params, 55 * 1000); client = new DefaultHttpClient(params); if (isPolling) { return; } try { URL uri = new URL(serverUrl); uri.toURI(); if ("https".equals(uri.getProtocol())) { Scheme sch = new Scheme(uri.getProtocol(), new SelfCertificateSSLSocketFactory(context), uri.getPort()); client.getConnectionManager().getSchemeRegistry().register(sch); } } catch (MalformedURLException e) { Log.e(LOG_CATEGORY, "Create URL fail:" + serverUrl); return; } catch (URISyntaxException e) { Log.e(LOG_CATEGORY, "Could not convert " + serverUrl + " to a compliant URI"); return; } isPolling = true; handleRequest(serverUrl + "/rest/status/" + pollingStatusIds); while (isPolling) { doPolling(); } }
From source file:io.github.gsteckman.rpi_rest.SubscriptionManager.java
/** * Sends the provided message to the host and port specified in the URL object. * // w w w .j a v a 2 s.co m * @param url * Provides the host and port to which the message is sent via TCP. * @param message * The message to send, including all headers and message body. * @throws IOException * If an exception occured writing to the socket. */ private void sendNotify(final URL url, final String message) throws IOException { Socket sock = new Socket(url.getHost(), url.getPort()); OutputStreamWriter out = new OutputStreamWriter(sock.getOutputStream()); out.write(message); out.close(); sock.close(); }
From source file:Main.java
/** * Checks, whether the URL points to the same service. A service is equal * if the protocol, host and port are equal. * * @param url a url/*from w w w . j av a2 s .c o m*/ * @param baseUrl an other url, that should be compared. * @return true, if the urls point to the same host and port and use the * same protocol, false otherwise. */ private boolean isSameService(final URL url, final URL baseUrl) { if (!url.getProtocol().equals(baseUrl.getProtocol())) { return false; } if (!url.getHost().equals(baseUrl.getHost())) { return false; } if (url.getPort() != baseUrl.getPort()) { return false; } return true; }
From source file:com.betfair.cougar.client.AbstractHttpExecutable.java
protected int extractPortFromAddress() throws IOException { String remoteAddress = remoteAddressRef.get(); if (remoteAddress == null || remoteAddress.equals("NOT ASSIGNED")) { throw new IllegalArgumentException("Remote address not set!"); }/* w w w . j a v a 2s . c o m*/ URL url = new URL(remoteAddress); return url.getPort(); }