List of usage examples for java.net URL getPort
public int getPort()
From source file:org.xwiki.contrib.jira.macro.internal.source.HTTPJIRAFetcher.java
private HttpHost createHttpHost(JIRAServer server) throws MalformedURLException { URL jiraURL = new URL(server.getURL()); return new HttpHost(jiraURL.getHost(), jiraURL.getPort(), jiraURL.getProtocol()); }
From source file:com.contentful.vaultintegration.BaseTest.java
protected String getServerUrl() { URL url = server.getUrl("/"); return "http://" + url.getHost() + ":" + url.getPort(); }
From source file:com.netflix.prana.http.api.HealthCheckHandler.java
private Observable<HttpClientResponse<ByteBuf>> getResponse(String externalHealthCheckURL) { String host = "localhost"; int port = DEFAULT_APPLICATION_PORT; String path = "/healthcheck"; try {// w ww .ja v a2s. co m URL url = new URL(externalHealthCheckURL); host = url.getHost(); port = url.getPort(); path = url.getPath(); } catch (MalformedURLException e) { //continue } Integer timeout = DynamicProperty.getInstance("prana.host.healthcheck.timeout") .getInteger(DEFAULT_CONNECTION_TIMEOUT); HttpClient<ByteBuf, ByteBuf> httpClient = RxNetty.<ByteBuf, ByteBuf>newHttpClientBuilder(host, port) .pipelineConfigurator(PipelineConfigurators.<ByteBuf, ByteBuf>httpClientConfigurator()) .channelOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeout).build(); return httpClient.submit(HttpClientRequest.createGet(path)); }
From source file:org.wso2.carbon.apimgt.gateway.throttling.util.KeyTemplateRetriever.java
/** * This method will retrieve KeyTemplates * * @return String object array which contains Blocking conditions. *//* w w w .j a v a 2 s.c o m*/ private String[] retrieveKeyTemplateData() { try { ThrottleProperties.BlockCondition blockConditionRetrieverConfiguration = ServiceReferenceHolder .getInstance().getThrottleProperties().getBlockCondition(); String url = blockConditionRetrieverConfiguration.getServiceUrl() + "/keyTemplates"; byte[] credentials = Base64.encodeBase64((blockConditionRetrieverConfiguration.getUsername() + ":" + blockConditionRetrieverConfiguration.getPassword()).getBytes(StandardCharsets.UTF_8)); HttpGet method = new HttpGet(url); method.setHeader("Authorization", "Basic " + new String(credentials, StandardCharsets.UTF_8)); URL keyMgtURL = new URL(url); int keyMgtPort = keyMgtURL.getPort(); String keyMgtProtocol = keyMgtURL.getProtocol(); HttpClient httpClient = APIUtil.getHttpClient(keyMgtPort, keyMgtProtocol); HttpResponse httpResponse = null; int retryCount = 0; boolean retry; do { try { httpResponse = httpClient.execute(method); retry = false; } catch (IOException ex) { retryCount++; if (retryCount < keyTemplateRetrievalRetries) { retry = true; log.warn("Failed retrieving throttling data from remote endpoint: " + ex.getMessage() + ". Retrying after " + keyTemplateRetrievalTimeoutInSeconds + " seconds..."); Thread.sleep(keyTemplateRetrievalTimeoutInSeconds * 1000); } else { throw ex; } } } while (retry); String responseString = EntityUtils.toString(httpResponse.getEntity(), "UTF-8"); if (responseString != null && !responseString.isEmpty()) { JSONArray jsonArray = (JSONArray) new JSONParser().parse(responseString); return (String[]) jsonArray.toArray(new String[jsonArray.size()]); } } catch (IOException | InterruptedException | ParseException e) { log.error("Exception when retrieving throttling data from remote endpoint ", e); } return null; }
From source file:org.miloss.fgsms.presentation.StatusHelper.java
/** * determines if an fgsms service is currently accessible. not for use * with other services.//from www.ja v a2 s . com * * @param endpoint * @return */ public String sendGetRequest(String endpoint) { // String result = null; if (endpoint.startsWith("http")) { // Send a GET request to the servlet try { URL url = new URL(endpoint); int port = url.getPort(); if (port <= 0) { if (endpoint.startsWith("https:")) { port = 443; } else { port = 80; } } HttpClientBuilder create = HttpClients.custom(); if (mode == org.miloss.fgsms.common.Constants.AuthMode.UsernamePassword) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(url.getHost(), port), new UsernamePasswordCredentials(username, Utility.DE(password))); create.setDefaultCredentialsProvider(credsProvider); ; } CloseableHttpClient c = create.build(); CloseableHttpResponse response = c.execute(new HttpHost(url.getHost(), port), new HttpGet(endpoint)); c.close(); int status = response.getStatusLine().getStatusCode(); if (status == 200) { return "OK"; } return String.valueOf(status); } catch (Exception ex) { Logger.getLogger(Helper.class).log(Level.WARN, "error fetching http doc from " + endpoint + ex.getLocalizedMessage()); return "offline"; } } else { return "undeterminable"; } }
From source file:com.cisco.cta.taxii.adapter.httpclient.CredentialsProviderFactory.java
private void addProxyCredentials(CredentialsProvider credsProvider) { if (proxySettings.getUrl() == null) { return;/*from w ww.ja va 2s . c o m*/ } if (proxySettings.getAuthenticationType() == null) { throw new IllegalStateException("Both proxy url and proxy authentication type have to be specified."); } ProxyAuthenticationType authType = proxySettings.getAuthenticationType(); URL proxyUrl = proxySettings.getUrl(); HttpHost proxyHost = new HttpHost(proxyUrl.getHost(), proxyUrl.getPort(), proxyUrl.getProtocol()); Credentials credentials; switch (authType) { case NONE: break; case BASIC: credentials = new UsernamePasswordCredentials(proxySettings.getUsername(), proxySettings.getPassword()); credsProvider.setCredentials(new AuthScope(proxyHost.getHostName(), proxyHost.getPort()), credentials); break; case NTLM: credentials = new NTCredentials(proxySettings.getUsername(), proxySettings.getPassword(), proxySettings.getWorkstation(), proxySettings.getDomain()); credsProvider.setCredentials(new AuthScope(proxyHost.getHostName(), proxyHost.getPort()), credentials); break; default: throw new IllegalStateException("Unsupported authentication type: " + authType); } }
From source file:com.woonoz.proxy.servlet.UrlRewriterImpl.java
private int getPortOrDefault(URL url) { final int port = url.getPort(); if (port == -1) { return url.getDefaultPort(); } else {// ww w.ja v a2 s . co m return port; } }
From source file:org.wso2.carbon.apimgt.gateway.throttling.util.BlockingConditionRetriever.java
/** * This method will retrieve blocking conditions by calling a WebService. * * @return String object array which contains throttled keys. *//*from w w w. j ava2 s . c o m*/ private BlockConditionsDTO retrieveBlockConditionsData() { try { ThrottleProperties.BlockCondition blockConditionRetrieverConfiguration = ServiceReferenceHolder .getInstance().getThrottleProperties().getBlockCondition(); String url = blockConditionRetrieverConfiguration.getServiceUrl() + "/block"; byte[] credentials = Base64.encodeBase64((blockConditionRetrieverConfiguration.getUsername() + ":" + blockConditionRetrieverConfiguration.getPassword()).getBytes(StandardCharsets.UTF_8)); HttpGet method = new HttpGet(url); method.setHeader("Authorization", "Basic " + new String(credentials, StandardCharsets.UTF_8)); URL keyMgtURL = new URL(url); int keyMgtPort = keyMgtURL.getPort(); String keyMgtProtocol = keyMgtURL.getProtocol(); HttpClient httpClient = APIUtil.getHttpClient(keyMgtPort, keyMgtProtocol); HttpResponse httpResponse = null; int retryCount = 0; boolean retry; do { try { httpResponse = httpClient.execute(method); retry = false; } catch (IOException ex) { retryCount++; if (retryCount < blockConditionsDataRetrievalRetries) { retry = true; log.warn("Failed retrieving Blocking Conditions from remote endpoint: " + ex.getMessage() + ". Retrying after " + blockConditionsDataRetrievalTimeoutInSeconds + " seconds..."); Thread.sleep(blockConditionsDataRetrievalTimeoutInSeconds * 1000); } else { throw ex; } } } while (retry); String responseString = EntityUtils.toString(httpResponse.getEntity(), "UTF-8"); if (responseString != null && !responseString.isEmpty()) { return new Gson().fromJson(responseString, BlockConditionsDTO.class); } } catch (IOException | InterruptedException e) { log.error("Exception when retrieving Blocking Conditions from remote endpoint ", e); } return null; }
From source file:com.esri.gpt.control.webharvest.validator.WAFValidator.java
@Override public boolean checkConnection(IMessageCollector mb) { if (url.toLowerCase().startsWith("ftp://")) { FTPClient client = null;/*from ww w.ja v a 2 s.c o m*/ try { URL u = new URL(url); String host = u.getHost(); int port = u.getPort() >= 0 ? u.getPort() : 21; client = new FTPClient(); client.connect(host, port); CredentialProvider cp = getCredentialProvider(); if (cp == null) { client.login("anonymous", "anonymous"); } else { client.login(cp.getUsername(), cp.getPassword()); } return true; } catch (MalformedURLException ex) { mb.addErrorMessage("catalog.harvest.manage.test.err.HarvestInvalidUrl"); return false; } catch (IOException ex) { mb.addErrorMessage("catalog.harvest.manage.test.err.HarvestConnectionException"); return false; } finally { if (client != null) { try { client.disconnect(); } catch (IOException ex) { } } } } else { return super.checkConnection(mb); } }
From source file:org.openbaton.nfvo.vnfm_reg.impl.register.RestRegister.java
@Scheduled(initialDelay = 15000, fixedDelay = 20000) public void checkHeartBeat() throws MalformedURLException { for (VnfmManagerEndpoint endpoint : vnfmEndpointRepository.findAll()) { if (endpoint.getEndpointType().ordinal() == EndpointType.REST.ordinal()) { if (endpoint.isEnabled()) { try { URL url = new URL(endpoint.getEndpoint()); if (!pingHost(url.getHost(), url.getPort(), 2)) { if (endpoint.isActive()) { log.info("Set endpoint " + endpoint.getType() + " to unactive"); endpoint.setActive(false); vnfmEndpointRepository.save(endpoint); }//from w w w . java 2 s. c o m } else { if (!endpoint.isActive()) { log.info("Set endpoint " + endpoint.getType() + " to active"); endpoint.setActive(true); vnfmEndpointRepository.save(endpoint); } } } catch (MalformedURLException ignored) { if (endpoint.isActive()) { log.warn("Not able to check endpoint: " + endpoint.getEndpoint()); endpoint.setActive(false); vnfmEndpointRepository.save(endpoint); } } } } } }