List of usage examples for java.net URL getPort
public int getPort()
From source file:fedora.client.FedoraClient.java
/** * Get the appropriate API-A/M stub, given a SOAPEndpoint. *//* www .j a v a 2 s . c o m*/ private Object getSOAPStub(SOAPEndpoint endpoint) throws ServiceException, IOException { URL url = endpoint.getURL(); String protocol = url.getProtocol(); String host = url.getHost(); int port = url.getPort(); //String path = url.getPath(); if (port == -1) { port = url.getDefaultPort(); } if (endpoint == m_accessEndpoint) { APIAStubFactory.SOCKET_TIMEOUT_SECONDS = SOCKET_TIMEOUT_SECONDS; return APIAStubFactory.getStubAltPath(protocol, host, port, url.getPath(), m_user, m_pass); } else if (endpoint == m_managementEndpoint) { APIMStubFactory.SOCKET_TIMEOUT_SECONDS = SOCKET_TIMEOUT_SECONDS; return APIMStubFactory.getStubAltPath(protocol, host, port, url.getPath(), m_user, m_pass); } else { throw new IllegalArgumentException("Unrecognized endpoint: " + endpoint.getName()); } }
From source file:com.tremolosecurity.provisioning.sharepoint.SharePointGroups.java
@Override public void init(Map<String, Attribute> cfg, ConfigManager cfgMgr, String name) throws ProvisioningException { this.name = name; this.cfg = cfgMgr; Attribute attr = cfg.get("webServicesURL"); if (attr == null) { throw new ProvisioningException("No web services url"); }// w w w .j ava 2 s . c o m this.webServicesURL = attr.getValues().get(0); logger.info("Web Services URL : '" + this.webServicesURL + "'"); try { this.defaultServiceURL = new URL(this.webServicesURL); } catch (MalformedURLException e1) { throw new ProvisioningException("Can not parse web services url", e1); } attr = cfg.get("authMode"); if (attr != null) { if (attr.getValues().get(0).equalsIgnoreCase("ntlm")) { authType = AuthType.NTLM; } else { authType = AuthType.UnisonLastMile; } } else { authType = AuthType.UnisonLastMile; } if (authType == AuthType.UnisonLastMile) { configureLastMile(cfg); } else if (authType == AuthType.NTLM) { configureNTLM(cfg); } if (cfgMgr.getConfigXmlPath().startsWith("WEB-INF")) { String wsdlPath = cfgMgr.getContext().getRealPath("WEB-INF/wsdl/usergroup.asmx?wsdl"); this.wsdl = new File(wsdlPath); if (!wsdl.exists()) { throw new ProvisioningException("WSDL does not exist : '" + wsdlPath + "'"); } } else { String wsdlPath = cfgMgr.getConfigXmlPath(); wsdlPath = wsdlPath.substring(0, wsdlPath.lastIndexOf('/')) + "/wsdl/usergroup.asmx.wsdl"; this.wsdl = new File(wsdlPath); if (!wsdl.exists()) { throw new ProvisioningException("WSDL does not exist : '" + wsdlPath + "'"); } } try { URL touchurl = new URL(this.webServicesURL); StringBuffer nurl = new StringBuffer(); nurl.append(touchurl.getProtocol()).append("://").append(touchurl.getHost()); if ((touchurl.getPort() != -1) && ((touchurl.getProtocol().equalsIgnoreCase("https") && touchurl.getPort() != 443) || (touchurl.getProtocol().equalsIgnoreCase("http") && touchurl.getPort() != 80))) { nurl.append(':').append(touchurl.getPort()); } nurl.append("/Pages/Default.aspx"); this.touchURL = nurl.toString(); } catch (MalformedURLException e) { throw new ProvisioningException("Could not parse wsdl url", e); } if (cfg.get("multiSite") != null) { if (cfg.get("multiSite").getValues().get(0).equalsIgnoreCase("true")) { this.multiSite = true; } else { this.multiSite = false; } } else { this.multiSite = false; } if (this.multiSite) { this.uris = new HashMap<String, URL>(); if (cfg.get("siteURI") == null) { throw new ProvisioningException("siteURI not set"); } for (String uri : cfg.get("siteURI").getValues()) { URL touchurl = null; try { touchurl = new URL(this.webServicesURL); } catch (MalformedURLException e) { throw new ProvisioningException("Could not parse URL", e); } StringBuffer nurl = new StringBuffer(); nurl.append(touchurl.getProtocol()).append("://").append(touchurl.getHost()); if ((touchurl.getPort() != -1) && ((touchurl.getProtocol().equalsIgnoreCase("https") && touchurl.getPort() != 443) || (touchurl.getProtocol().equalsIgnoreCase("http") && touchurl.getPort() != 80))) { nurl.append(':').append(touchurl.getPort()); } String wsuri = ""; if (uri.endsWith("/")) { wsuri = uri.substring(0, uri.lastIndexOf('/')); } else { wsuri = uri; } nurl.append(wsuri).append("/_vti_bin/usergroup.asmx"); logger.info("Adding site map for '" + uri + "' to '" + nurl + "'"); try { this.uris.put(uri, new URL(nurl.toString())); } catch (MalformedURLException e) { throw new ProvisioningException("Could not parse web services url", e); } } } }
From source file:org.jasig.cas.client.authentication.AuthenticationFilterTests.java
@Test public void testIgnorePatternsWithExactMatching() throws Exception { final AuthenticationFilter f = new AuthenticationFilter(); final MockServletContext context = new MockServletContext(); context.addInitParameter("casServerLoginUrl", CAS_LOGIN_URL); final URL url = new URL(CAS_SERVICE_URL + "?param=valueToIgnore"); context.addInitParameter("ignorePattern", url.toExternalForm()); context.addInitParameter("ignoreUrlPatternType", "EXACT"); context.addInitParameter("service", CAS_SERVICE_URL); f.init(new MockFilterConfig(context)); final MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme(url.getProtocol()); request.setServerName(url.getHost()); request.setServerPort(url.getPort()); request.setQueryString(url.getQuery()); request.setRequestURI(url.getPath()); final MockHttpSession session = new MockHttpSession(); request.setSession(session);//from w w w . jav a 2 s . c o m final MockHttpServletResponse response = new MockHttpServletResponse(); final FilterChain filterChain = new FilterChain() { public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { } }; f.doFilter(request, response, filterChain); assertNull(response.getRedirectedUrl()); }
From source file:com.vaadin.tests.testbenchapi.AbstractTB3Test.java
protected String getRemoteControlName() { try {/*from ww w . j ava 2s. c o m*/ RemoteWebDriver d = getRemoteDriver(); if (d == null) { return null; } HttpCommandExecutor ce = (HttpCommandExecutor) d.getCommandExecutor(); String hostName = ce.getAddressOfRemoteServer().getHost(); int port = ce.getAddressOfRemoteServer().getPort(); HttpHost host = new HttpHost(hostName, port); DefaultHttpClient client = new DefaultHttpClient(); URL sessionURL = new URL( "http://" + hostName + ":" + port + "/grid/api/testsession?session=" + d.getSessionId()); BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST", sessionURL.toExternalForm()); HttpResponse response = client.execute(host, r); JsonObject object = extractObject(response); URL myURL = new URL(object.get("proxyId").getAsString()); if ((myURL.getHost() != null) && (myURL.getPort() != -1)) { return myURL.getHost(); } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:org.apache.servicemix.http.jetty.JettyContextManager.java
protected String getKey(URL url) { String host = url.getHost();/*www . j av a 2 s. c om*/ try { InetAddress addr = InetAddress.getByName(host); if (addr.isAnyLocalAddress()) { host = InetAddress.getLocalHost().getHostName(); } } catch (UnknownHostException e) { //unable to lookup host name, using IP address instead } return url.getProtocol() + "://" + host + ":" + url.getPort(); }
From source file:com.servoy.extensions.plugins.http.HttpProvider.java
/** * @param url//from ww w .jav a2 s. c o m * @param httpClientName * @param username * @param password * @return */ private String getPageData(String url, String httpClientName, String username, String password) { try { DefaultHttpClient client = getOrCreateHTTPclient(httpClientName, url); HttpGet get = new HttpGet(url); HttpResponse res = client.execute(get); // you can get the status from here... (return code) BasicCredentialsProvider bcp = new BasicCredentialsProvider(); if (username != null) { URL _url = createURLFromString(url); bcp.setCredentials(new AuthScope(_url.getHost(), _url.getPort()), new UsernamePasswordCredentials(username, password)); client.setCredentialsProvider(bcp); } lastPageEncoding = EntityUtils.getContentCharSet(res.getEntity()); return EntityUtils.toString(res.getEntity()); } catch (Exception e) { Debug.error(e); return "";//$NON-NLS-1$ } }
From source file:de.undercouch.gradle.tasks.download.DownloadAction.java
private void executeHttpProtocol(URL src, HttpClientFactory clientFactory, long timestamp, File destFile) throws IOException { //create HTTP host from URL HttpHost httpHost = new HttpHost(src.getHost(), src.getPort(), src.getProtocol()); //create HTTP client CloseableHttpClient client = clientFactory.createHttpClient(httpHost, acceptAnyCertificate); //open URL connection CloseableHttpResponse response = openConnection(httpHost, src.getFile(), timestamp, client); //check if file on server was modified long lastModified = parseLastModified(response); int code = response.getStatusLine().getStatusCode(); if (code == HttpStatus.SC_NOT_MODIFIED || (lastModified != 0 && timestamp >= lastModified)) { if (!quiet) { project.getLogger().info("Not modified. Skipping '" + src + "'"); }/*from ww w .j a va 2 s . c om*/ ++upToDate; return; } //perform the download try { performDownload(response, destFile); } finally { response.close(); } }
From source file:com.couchbase.cbadmin.client.CouchbaseAdmin.java
@Override public void addNewNode(URL newNode, String nnUser, String nnPass) throws RestApiException { int ePort = newNode.getPort(); if (ePort == -1) { ePort = entryPoint.getPort();//w w w. j av a2 s . co m } InetAddress inaddr = getIp4Lookup(newNode.getHost()); if (newNode.getHost().equals(entryPoint.getHost()) && ePort == entryPoint.getPort()) { throw new IllegalArgumentException("Can't join node to self"); } Map<String, String> params = new HashMap<String, String>(); params.put("user", nnUser); params.put("password", nnPass); params.put("hostname", inaddr.getHostAddress() + ":" + ePort); HttpPost post = new HttpPost(); post.setEntity(makeFormEntity(params)); try { getResponseJson(post, P_ADDNODE, 200); } catch (IOException ex) { throw new RestApiException(ex); } }
From source file:org.jasig.portal.security.provider.saml.SAMLDelegatedAuthenticationService.java
/** * Sets up the SSL parameters of a connection to the IdP, including the * client certificate and server certificate trust. The program that set up * the SAMLSession object is responsible for providing these optional SSL * parameters.//from w w w. j a va 2s .co m * * @param client * @param samlSession * @param authnState * @throws MalformedURLException */ private void setupIdPClientConnection(HttpClient client, SAMLSession samlSession, DelegatedSAMLAuthenticationState authnState) throws MalformedURLException { URL url = new URL(authnState.getIdpEndpoint()); String protocol = url.getProtocol(); int port = url.getPort(); // Unless we are using SSL/TLS, there is no need to do the socket factory if (protocol.equalsIgnoreCase("https")) { SSLSocketFactory socketFactory = samlSession.getIdPSocketFactory(); if (port == -1) port = 443; Scheme sch = new Scheme(protocol, socketFactory, port); client.getConnectionManager().getSchemeRegistry().unregister(protocol); client.getConnectionManager().getSchemeRegistry().register(sch); } }