List of usage examples for java.net URL getPort
public int getPort()
From source file:org.wso2.carbon.appmgt.gateway.utils.GatewayUtils.java
public static String getAppRootURL(MessageContext messageContext) { org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) messageContext) .getAxis2MessageContext(); try {/*from www . j a v a 2 s. c om*/ // SERVICE_PREFIX gives the URL of the root. e.g. https://192.168.0.1:8243 // WARNING : Service prefix always gives the IP address even if the request is made with a host name. // So we should only get the protocol from the service prefix. String servicePrefix = axis2MessageContext.getProperty("SERVICE_PREFIX").toString(); URL serverRootURL = new URL(servicePrefix); String protocol = serverRootURL.getProtocol(); // Get the published gateway URL for the protocol Environment defaultGatewayEnv = ServiceReferenceHolder.getInstance().getAPIManagerConfiguration() .getApiGatewayEnvironments().get(0); String commaSeparatedGatewayEndpoints = defaultGatewayEnv.getApiGatewayEndpoint(); String[] gatewayEndpoints = commaSeparatedGatewayEndpoints.split(","); URL gatewayEndpointURL = null; for (String gatewayEndpoint : gatewayEndpoints) { URL parsedEndpointURL = new URL(gatewayEndpoint); if (parsedEndpointURL.getProtocol().equals(protocol)) { gatewayEndpointURL = parsedEndpointURL; break; } } String webAppContext = (String) messageContext.getProperty(RESTConstants.REST_API_CONTEXT); String webAppVersion = (String) messageContext.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION); URL appRootURL = new URL(gatewayEndpointURL.getProtocol(), gatewayEndpointURL.getHost(), gatewayEndpointURL.getPort(), webAppContext + "/" + webAppVersion + "/"); return appRootURL.toString(); } catch (MalformedURLException e) { log.error("Error occurred while constructing the app root URL.", e); return null; } }
From source file:org.apache.juddi.v3.client.mapping.wadl.WADL2UDDI.java
/** * Parses a web accessible WADL file//from ww w. j ava2s.com * @param weburl * @param username * @param password * @param ignoreSSLErrors if true, SSL errors are ignored * @return a non-null "Application" object, represeting a WADL's application root XML * Sample code:<br> * <pre> * Application app = WADL2UDDI.parseWadl(new URL("http://server/wsdl.wsdl"), "username", "password", * clerkManager.getClientConfig().isX_To_Wsdl_Ignore_SSL_Errors() ); * </pre> */ public static Application parseWadl(URL weburl, String username, String password, boolean ignoreSSLErrors) { DefaultHttpClient httpclient = null; Application unmarshal = null; try { String url = weburl.toString(); if (!url.toLowerCase().startsWith("http")) { return parseWadl(weburl); } boolean usessl = false; int port = 80; if (url.toLowerCase().startsWith("https://")) { port = 443; usessl = true; } if (weburl.getPort() > 0) { port = weburl.getPort(); } if (ignoreSSLErrors && usessl) { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("https", port, new MockSSLSocketFactory())); ClientConnectionManager cm = new BasicClientConnectionManager(schemeRegistry); httpclient = new DefaultHttpClient(cm); } else { httpclient = new DefaultHttpClient(); } if (username != null && username.length() > 0 && password != null && password.length() > 0) { httpclient.getCredentialsProvider().setCredentials(new AuthScope(weburl.getHost(), port), new UsernamePasswordCredentials(username, password)); } HttpGet httpGet = new HttpGet(url); try { HttpResponse response1 = httpclient.execute(httpGet); //System.out.println(response1.getStatusLine()); // HttpEntity entity1 = response1.getEntity(); // do something useful with the response body // and ensure it is fully consumed ResponseHandler<String> responseHandler = new BasicResponseHandler(); String handleResponse = responseHandler.handleResponse(response1); StringReader sr = new StringReader(handleResponse); unmarshal = JAXB.unmarshal(sr, Application.class); } finally { httpGet.releaseConnection(); } } catch (Exception e) { log.error(e.getMessage(), e); } finally { if (httpclient != null) { httpclient.getConnectionManager().shutdown(); } } return unmarshal; }
From source file:fm.last.peyote.cacti.JmxInputProcessor.java
private String convertToCactiUrl(String urlString) throws MalformedURLException { URL url = new URL(urlString); return url.getProtocol() + "://<host>:" + url.getPort() + url.getPath(); }
From source file:com.adito.core.RequestParameterMap.java
private static URL parseProxiedURL(String location, MultiMap map) { try {//from w ww.j a v a 2 s . com URL proxiedURL = new URL(location); URL proxiedURLBase = proxiedURL; // Extract parameters from the proxied URL String query = proxiedURL.getQuery(); if (query != null) { proxiedURLBase = new URL(proxiedURL.getProtocol(), proxiedURL.getHost(), proxiedURL.getPort() < 1 ? -1 : proxiedURL.getPort(), proxiedURL.getPath()); parseQuery(map, query); } return proxiedURLBase; } catch (MalformedURLException murle) { log.error("Invalid proxied URL '" + location + "'"); } return null; }
From source file:com.cisco.cta.taxii.adapter.httpclient.HttpClientFactory.java
public HttpClient create() { HttpClientBuilder clientBuilder = HttpClientBuilder.create(); if (proxySettings.getUrl() != null) { URL proxyUrl = proxySettings.getUrl(); HttpHost proxyHost = new HttpHost(proxyUrl.getHost(), proxyUrl.getPort(), proxyUrl.getProtocol()); clientBuilder.setProxy(proxyHost); }//w ww .j av a2 s.c o m return clientBuilder.build(); }
From source file:com.ibm.mf.geofence.demo.SlackHTTPService.java
@Override protected Uri getBaseQueryURI() throws Exception { URL url = new URL(getServerURL()); int port = url.getPort(); String portStr = (port < 0) ? "" : ":" + port; Uri.Builder builder = new Uri.Builder().scheme(url.getProtocol()).encodedAuthority(url.getHost() + portStr); return builder.build(); }
From source file:org.commonjava.indy.client.core.auth.BasicAuthenticator.java
public HttpClientContext decoratePrototypeContext(final URL url, final HttpClientContext ctx) { final AuthScope as = new AuthScope(url.getHost(), url.getPort() < 0 ? url.getDefaultPort() : url.getPort()); return decoratePrototypeContext(as, null, null, ctx); }
From source file:com.mirth.connect.connectors.http.HttpConnectorServlet.java
@Override public ConnectionTestResponse testConnection(String channelId, String channelName, HttpDispatcherProperties properties) { try {/*from w w w . j a va 2 s. co m*/ URL url = new URL(replacer.replaceValues(properties.getHost(), channelId, channelName)); int port = url.getPort(); // If no port was provided, default to port 80 or 443. return ConnectorUtil.testConnection(url.getHost(), (port == -1) ? (StringUtils.equalsIgnoreCase(url.getProtocol(), "https") ? 443 : 80) : port, TIMEOUT); } catch (Exception e) { throw new MirthApiException(e); } }
From source file:com.cisco.cta.taxii.adapter.httpclient.BasicAuthHttpRequestFactory.java
public BasicAuthHttpRequestFactory(HttpClient httpClient, TaxiiServiceSettings settings, ProxySettings proxySettings, CredentialsProvider credsProvider) { super(httpClient); this.credsProvider = credsProvider; URL url = settings.getPollEndpoint(); HttpHost targetHost = new HttpHost(url.getHost(), url.getPort(), url.getProtocol()); // Create auth cache with BASIC scheme authCache = new BasicAuthCache(); authCache.put(targetHost, new BasicScheme()); }
From source file:com.couchbase.lite.performance.Test6_PushReplication.java
private boolean isSyncGateway(URL remote) { return (remote.getPort() == 4984 || remote.getPort() == 4984); }