List of usage examples for java.net URL getPort
public int getPort()
From source file:lucee.commons.net.http.httpclient.HTTPResponse4Impl.java
public URL getTargetURL() { URL start = getURL(); HttpUriRequest req = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); URI uri = req.getURI();//from w ww. j a v a 2 s. c o m String path = uri.getPath(); String query = uri.getQuery(); if (!StringUtil.isEmpty(query)) path += "?" + query; URL _url = start; try { _url = new URL(start.getProtocol(), start.getHost(), start.getPort(), path); } catch (MalformedURLException e) { } return _url; }
From source file:com.k42b3.neodym.oauth.Oauth.java
private String getNormalizedUrl(String rawUrl) throws Exception { rawUrl = rawUrl.toLowerCase();//w w w . j a va2s . c o m URL url = new URL(rawUrl); int port = url.getPort(); if (port == -1 || port == 80 || port == 443) { return url.getProtocol() + "://" + url.getHost() + url.getPath(); } else { return url.getProtocol() + "://" + url.getHost() + ":" + port + url.getPath(); } }
From source file:com.esri.gpt.catalog.arcgis.metadata.AGSInterrogator.java
/** * Makes a guess at the reverse proxy endpoint assoctated with an internal SOAP endpoint. * <br/>Sometimes the ArcGIS server REST API references internal SOAP endpoints that are * inaccessible outside the local area network. * <br/>this method simple replaces the host:port for a SOAP endpoint with the host:port * of the pre-determined REST endpoint/* w w w . j a va2 s . c o m*/ * @param soapEndpoint the SOAP endpoint that failed * @return the modified endpoint */ private String guessReverseProxyUrl(String soapEndpoint) { try { URL urlRest = new URL(this.target.getRestUrl()); URL urlSoap = new URL(soapEndpoint); String reversed = urlRest.getProtocol() + "://" + urlRest.getHost(); if ((urlRest.getPort() != -1) && (urlRest.getPort() != 80)) { reversed += ":" + urlRest.getPort(); } if ((urlSoap.getPath() != null) && (urlSoap.getPath().length() > 0)) { reversed += urlSoap.getPath(); return reversed; } } catch (MalformedURLException e) { String msg = "Unable to guess ArcGIS services catalog soap url (try reverse proxy):"; msg += "\n restUrl=" + StringEscapeUtils.escapeHtml4(Val.stripControls(this.target.getRestUrl())) + "\n soapUrl=" + StringEscapeUtils.escapeHtml4(Val.stripControls(soapEndpoint)); LOGGER.finer(msg + "\n" + e.toString()); } return null; }
From source file:org.openremote.android.console.net.ORConnection.java
/** * Establish the HttpBasicAuthentication httpconnection depend on param <b>isNeedHttpBasicAuth</b> * and param <b>isUseSSLfor</b> with url caller, and then the caller can deal with the * httprequest result within ORConnectionDelegate instance. * * @param context global Android application context * @param httpMethod enum POST or GET * @param useHTTPAuth indicates whether the HTTP 'Authentication' header should be added * to the HTTP request * @param url the URL to connect to * @param delegateParam callback delegate to deal with return values, data and exceptions *//* w w w.j av a 2 s.com*/ public ORConnection(final Context context, ORHttpMethod httpMethod, boolean useHTTPAuth, String url, ORConnectionDelegate delegateParam) { initHandler(context); delegate = delegateParam; this.context = context; HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 4 * 1000); HttpConnectionParams.setSoTimeout(params, 5 * 1000); httpClient = new DefaultHttpClient(params); try { URL targetUrl = new URL(url); targetUrl.toURI(); if ("https".equals(targetUrl.getProtocol())) { Scheme sch = new Scheme(targetUrl.getProtocol(), new SelfCertificateSSLSocketFactory(context), targetUrl.getPort()); httpClient.getConnectionManager().getSchemeRegistry().register(sch); } } catch (MalformedURLException e) { Log.e(LOG_CATEGORY, "Create URL fail:" + url); return; } catch (URISyntaxException e) { Log.e(LOG_CATEGORY, "Could not convert " + url + " to a compliant URI"); return; } if (ORHttpMethod.POST.equals(httpMethod)) { httpRequest = new HttpPost(url); } else if (ORHttpMethod.GET.equals(httpMethod)) { httpRequest = new HttpGet(url); } if (httpRequest == null) { Log.e(LOG_CATEGORY, "Create HttpRequest fail:" + url); return; } if (useHTTPAuth) { SecurityUtil.addCredentialToHttpRequest(context, httpRequest); } execute(); }
From source file:com.vmware.vfabric.hyperic.plugin.vfws.PWSServerDetector.java
private URL getBmxQueryUrl(URL url, String path) { try {/*w w w. j av a2 s .c om*/ URL newUrl = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getPath() + path); return newUrl; } catch (MalformedURLException e) { // return old url? return url; } }
From source file:io.selendroid.standalone.server.grid.SelfRegisteringRemote.java
/** * Extracts the configuration.//from ww w. j av a 2 s. c om * * @return The configuration * @throws JSONException On JSON errors. */ private JSONObject getConfiguration() throws JSONException { JSONObject configuration = new JSONObject(); configuration.put("port", config.getPort()); configuration.put("register", true); if (config.getProxy() != null) { configuration.put("proxy", config.getProxy()); } else { configuration.put("proxy", "org.openqa.grid.selenium.proxy.DefaultRemoteProxy"); } configuration.put("role", "node"); configuration.put("registerCycle", 5000); configuration.put("maxSession", config.getMaxSession()); // adding hub details URL registrationUrl; try { registrationUrl = new URL(config.getRegistrationUrl()); } catch (MalformedURLException e) { log.log(Level.SEVERE, "Grid hub url cannot be parsed", e); throw new SelendroidException("Grid hub url cannot be parsed: " + e.getMessage()); } configuration.put("hubHost", registrationUrl.getHost()); configuration.put("hubPort", registrationUrl.getPort()); // adding driver details configuration.put("seleniumProtocol", "WebDriver"); configuration.put("host", config.getServerHost()); configuration.put("remoteHost", "http://" + config.getServerHost() + ":" + config.getPort()); return configuration; }
From source file:org.wso2.carbon.device.mgt.etc.ApisAppClient.java
public void setBase64EncodedConsumerKeyAndSecret(List<DeviceTypeConfig> iotDeviceTypeConfigList) { if (!isEnabled) return;// w w w .j a va2 s. c om URL loginURL = null; try { loginURL = new URL(loginEndpoint); } catch (MalformedURLException e) { String errMsg = "Malformed URL " + loginEndpoint; log.error(errMsg); return; } HttpClient httpClient = null; try { httpClient = IoTUtil.getHttpClient(loginURL.getPort(), loginURL.getProtocol()); } catch (Exception e) { log.error("Error on getting a http client for port :" + loginURL.getPort() + " protocol :" + loginURL.getProtocol()); return; } HttpPost postMethod = new HttpPost(loginEndpoint); JSONObject apiJsonResponse; try { HttpResponse httpResponse = httpClient.execute(postMethod); String response = IoTUtil.getResponseString(httpResponse); if (log.isDebugEnabled()) { log.debug(response); } JSONObject jsonObject = new JSONObject(response); boolean apiError = jsonObject.getBoolean("error"); if (!apiError) { String cookie = httpResponse.getHeaders("Set-Cookie")[0].getValue().split(";")[0]; HttpGet getMethod = new HttpGet(subscriptionListEndpoint); getMethod.setHeader("cookie", cookie); httpResponse = httpClient.execute(getMethod); response = IoTUtil.getResponseString(httpResponse); if (log.isDebugEnabled()) { log.debug(response); } apiJsonResponse = new JSONObject(response); apiError = apiJsonResponse.getBoolean("error"); if (apiError) { log.error("invalid subscription endpoint " + subscriptionListEndpoint); return; } } else { log.error("invalid access for login endpoint " + loginEndpoint); return; } } catch (IOException | JSONException | DeviceMgtCommonsException e) { log.warn("Trying to connect to the Api manager"); return; } try { JSONArray jsonSubscriptions = apiJsonResponse.getJSONObject("subscriptions") .getJSONArray("applications"); HashMap<String, String> subscriptionMap = new HashMap<>(); for (int n = 0; n < jsonSubscriptions.length(); n++) { JSONObject object = jsonSubscriptions.getJSONObject(n); String appName = object.getString("name"); String prodConsumerKey = object.getString("prodConsumerKey"); String prodConsumerSecret = object.getString("prodConsumerSecret"); subscriptionMap.put(appName, new String(Base64.encodeBase64((prodConsumerKey + ":" + prodConsumerSecret).getBytes()))); } for (DeviceTypeConfig iotDeviceTypeConfig : iotDeviceTypeConfigList) { String deviceType = iotDeviceTypeConfig.getType(); String deviceTypeApiApplicationName = iotDeviceTypeConfig.getApiApplicationName(); String base64EncodedString = subscriptionMap.get(deviceTypeApiApplicationName); if (base64EncodedString != null && base64EncodedString.length() != 0) { deviceTypeToApiAppMap.put(deviceType, base64EncodedString); } } } catch (JSONException e) { log.error("Json exception: " + e.getMessage(), e); } }
From source file:jeeves.utils.XmlRequest.java
public void setUrl(URL url) { host = url.getHost();/*from w w w.j a va 2 s . c om*/ port = (url.getPort() == -1) ? url.getDefaultPort() : url.getPort(); protocol = url.getProtocol(); address = url.getPath(); query = url.getQuery(); }
From source file:org.openqa.selenium.remote.internal.ApacheHttpClient.java
public ApacheHttpClient(HttpClient client, URL url) { this.client = checkNotNull(client, "null HttpClient"); this.url = checkNotNull(url, "null URL"); // Some machines claim "localhost.localdomain" is the same as "localhost". // This assumption is not always true. String host = url.getHost().replace(".localdomain", ""); this.targetHost = new HttpHost(host, url.getPort(), url.getProtocol()); }
From source file:es.pode.soporte.seguridad.openId.ui.openid.OpenIDAuthenticationProcessingFilter.java
protected String lookupRealm(String returnToUrl) { if (log.isDebugEnabled()) log.debug("[OpenIDAuthenticationProcessingFilter] lookupRealm"); String mapping = (String) realmMapping.get(returnToUrl); if (mapping == null) { try {/*from w w w . ja v a 2s . co m*/ URL url = new URL(returnToUrl); int port = (url.getPort() == -1) ? 80 : url.getPort(); StringBuffer realmBuffer = new StringBuffer(returnToUrl.length()).append(url.getProtocol()) .append("://").append(url.getHost()).append(":").append(port).append("/"); mapping = realmBuffer.toString(); } catch (MalformedURLException e) { log.warn("returnToUrl was not a valid URL: [" + returnToUrl + "]", e); } } log.debug("[devuelvo] " + returnToUrl); return returnToUrl; // return mapping; }