List of usage examples for java.net URL getPort
public int getPort()
From source file:com.predic8.membrane.core.interceptor.balancer.NodeOnlineChecker.java
public Node getNodeFromExchange(Exchange exc, int destination) { URL destUrl = getUrlObjectFromDestination(exc, destination); return new Node(destUrl.getProtocol() + "://" + destUrl.getHost(), destUrl.getPort()); }
From source file:biz.neustar.nexus.plugins.gitlab.GitlabAuthenticatingRealmIT.java
License:asdf
@Test public void testPlugin() throws Exception { assertTrue(nexus().isRunning());/*from w ww .ja v a 2 s.c o m*/ URL nexusUrl = nexus().getUrl(); URI uri = new URIBuilder().setHost(nexusUrl.getHost()).setPath(nexusUrl.getPath()) .setPort(nexusUrl.getPort()).setParameters(URLEncodedUtils.parse(nexusUrl.getQuery(), UTF_8)) .setScheme(nexusUrl.getProtocol()).setUserInfo("jdamick", "asdfasdfasdf").build() .resolve("content/groups/public/"); HttpClient httpclient = HttpClientBuilder.create().build(); {// request 1 HttpGet req1 = new HttpGet(uri); HttpResponse resp1 = httpclient.execute(req1); assertEquals(200, resp1.getStatusLine().getStatusCode()); RecordedRequest request = server.takeRequest(); // 1 request recorded assertEquals("/api/v3/session", request.getPath()); req1.releaseConnection(); } // failure checks { // request 2 HttpGet req2 = new HttpGet(uri); HttpResponse resp2 = httpclient.execute(req2); assertEquals(401, resp2.getStatusLine().getStatusCode()); req2.releaseConnection(); } { // request 3 HttpGet req3 = new HttpGet(uri); HttpResponse resp3 = httpclient.execute(req3); assertEquals(401, resp3.getStatusLine().getStatusCode()); req3.releaseConnection(); } }
From source file:org.dataconservancy.access.connector.MultiThreadedConnectorTest.java
@Override protected DcsConnectorConfig getConnectorConfig() { final DcsConnectorConfig config = new DcsConnectorConfig(); try {/*from w ww . j a v a 2 s . c o m*/ URL u = new URL( String.format(accessServiceUrl, testServer.getServiceHostName(), testServer.getServicePort())); config.setScheme(u.getProtocol()); config.setHost(u.getHost()); config.setPort(u.getPort()); config.setContextPath(u.getPath()); } catch (MalformedURLException e) { fail("Malformed DCS access http url: " + e.getMessage()); } config.setMaxOpenConn(2); return config; }
From source file:com.jaspersoft.studio.server.protocol.restv2.RestV2Connection.java
@Override public boolean connect(IProgressMonitor monitor, ServerProfile sp) throws Exception { this.sp = sp; URL url = sp.getURL(); HttpHost host = new HttpHost(url.getHost(), url.getPort(), url.getProtocol()); exec = Executor.newInstance().auth(host, sp.getUser(), Pass.getPass(sp.getPass())); exec.authPreemptive(host);/*from w w w .j a v a 2s .c om*/ net.sf.jasperreports.eclipse.util.HttpUtils.setupProxy(exec, url.toURI()); getServerInfo(monitor); return true; }
From source file:com.lazerycode.ebselen.customhandlers.FileDownloader.java
public String downloader(WebElement element, String attribute) throws Exception { //Assuming that getAttribute does some magic to return a fully qualified URL String downloadLocation = element.getAttribute(attribute); if (downloadLocation.trim().equals("")) { throw new Exception("The element you have specified does not link to anything!"); }/* w w w .j av a 2 s . co m*/ URL downloadURL = new URL(downloadLocation); HttpClient client = new HttpClient(); client.getParams().setCookiePolicy(CookiePolicy.RFC_2965); client.setHostConfiguration(mimicHostConfiguration(downloadURL.getHost(), downloadURL.getPort())); client.setState(mimicCookieState(driver.manage().getCookies())); HttpMethod getRequest = new GetMethod(downloadURL.getPath()); FileHandler downloadedFile = new FileHandler( downloadPath + downloadURL.getFile().replaceFirst("/|\\\\", ""), true); try { int status = client.executeMethod(getRequest); LOGGER.info("HTTP Status {} when getting '{}'", status, downloadURL.toExternalForm()); BufferedInputStream in = new BufferedInputStream(getRequest.getResponseBodyAsStream()); int offset = 0; int len = 4096; int bytes = 0; byte[] block = new byte[len]; while ((bytes = in.read(block, offset, len)) > -1) { downloadedFile.getWritableFileOutputStream().write(block, 0, bytes); } downloadedFile.close(); in.close(); LOGGER.info("File downloaded to '{}'", downloadedFile.getAbsoluteFile()); } catch (Exception Ex) { LOGGER.error("Download failed: {}", Ex); throw new Exception("Download failed!"); } finally { getRequest.releaseConnection(); } return downloadedFile.getAbsoluteFile(); }
From source file:com.redhat.rhn.frontend.servlets.RhnHttpServletRequest.java
/** * {@inheritDoc}//from www. j a va2s .c om */ public StringBuffer getRequestURL() { try { URL u = new URL(super.getRequestURL().toString()); StringBuffer sb = new StringBuffer( new URL(getProtocol(), getServerName(), u.getPort(), u.getFile()).toExternalForm()); return sb; } catch (MalformedURLException e) { throw new IllegalArgumentException("Bad argument when creating URL"); } }
From source file:com.testmax.util.FileDownLoader.java
public String downloader(WebElement element, String attribute) throws Exception { //Assuming that getAttribute does some magic to return a fully qualified URL String downloadLocation = element.getAttribute(attribute); if (downloadLocation.trim().equals("")) { throw new Exception("The element you have specified does not link to anything!"); }/*from w w w .j a va 2s . co m*/ URL downloadURL = new URL(downloadLocation); HttpClient client = new HttpClient(); client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); client.setHostConfiguration(mimicHostConfiguration(downloadURL.getHost(), downloadURL.getPort())); client.setState(mimicCookieState(driver.manage().getCookies())); HttpMethod getRequest = new GetMethod(downloadURL.getPath()); String file_path = downloadPath + downloadURL.getFile().replaceFirst("/|\\\\", ""); FileWriter downloadedFile = new FileWriter(file_path, true); try { int status = client.executeMethod(getRequest); WmLog.getCoreLogger().info("HTTP Status {} when getting '{}'" + status + downloadURL.toExternalForm()); BufferedInputStream in = new BufferedInputStream(getRequest.getResponseBodyAsStream()); int offset = 0; int len = 4096; int bytes = 0; byte[] block = new byte[len]; while ((bytes = in.read(block, offset, len)) > -1) { downloadedFile.write(bytes); } downloadedFile.close(); in.close(); WmLog.getCoreLogger().info("File downloaded to '{}'" + file_path); } catch (Exception Ex) { WmLog.getCoreLogger().error("Download failed: {}", Ex); throw new Exception("Download failed!"); } finally { getRequest.releaseConnection(); } return file_path; }
From source file:org.apache.hadoop.hbase.http.TestSpnegoHttpServer.java
@Test public void testAllowedClient() throws Exception { // Create the subject for the client final Subject clientSubject = JaasKrbUtil.loginUsingKeytab(CLIENT_PRINCIPAL, clientKeytab); final Set<Principal> clientPrincipals = clientSubject.getPrincipals(); // Make sure the subject has a principal assertFalse(clientPrincipals.isEmpty()); // Get a TGT for the subject (might have many, different encryption types). The first should // be the default encryption type. Set<KerberosTicket> privateCredentials = clientSubject.getPrivateCredentials(KerberosTicket.class); assertFalse(privateCredentials.isEmpty()); KerberosTicket tgt = privateCredentials.iterator().next(); assertNotNull(tgt);/*from w w w .j a v a2s . c o m*/ // The name of the principal final String principalName = clientPrincipals.iterator().next().getName(); // Run this code, logged in as the subject (the client) HttpResponse resp = Subject.doAs(clientSubject, new PrivilegedExceptionAction<HttpResponse>() { @Override public HttpResponse run() throws Exception { // Logs in with Kerberos via GSS GSSManager gssManager = GSSManager.getInstance(); // jGSS Kerberos login constant Oid oid = new Oid("1.2.840.113554.1.2.2"); GSSName gssClient = gssManager.createName(principalName, GSSName.NT_USER_NAME); GSSCredential credential = gssManager.createCredential(gssClient, GSSCredential.DEFAULT_LIFETIME, oid, GSSCredential.INITIATE_ONLY); HttpClientContext context = HttpClientContext.create(); Lookup<AuthSchemeProvider> authRegistry = RegistryBuilder.<AuthSchemeProvider>create() .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true, true)).build(); HttpClient client = HttpClients.custom().setDefaultAuthSchemeRegistry(authRegistry).build(); BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new KerberosCredentials(credential)); URL url = new URL(getServerURL(server), "/echo?a=b"); context.setTargetHost(new HttpHost(url.getHost(), url.getPort())); context.setCredentialsProvider(credentialsProvider); context.setAuthSchemeRegistry(authRegistry); HttpGet get = new HttpGet(url.toURI()); return client.execute(get, context); } }); assertNotNull(resp); assertEquals(HttpURLConnection.HTTP_OK, resp.getStatusLine().getStatusCode()); assertEquals("a:b", EntityUtils.toString(resp.getEntity()).trim()); }
From source file:com.esri.gpt.control.webharvest.client.waf.FtpClientRequest.java
/** * Creates instance of the request.//from w w w.ja v a 2s. co m * @param url url * @param cp credential provider */ public FtpClientRequest(URL url, CredentialProvider cp) { this.protocol = Val.chkStr(url.getProtocol()); this.host = Val.chkStr(url.getHost()); this.port = url.getPort() >= 0 ? url.getPort() : 21; this.root = Val.chkStr(url.getPath()).replaceAll("/$", ""); this.cp = cp; }
From source file:com.gargoylesoftware.htmlunit.javascript.host.worker.DedicatedWorkerGlobalScope.java
/** * Constructor.//ww w . j a v a 2 s . c o m * @param browserVersion the simulated browser version * @param worker the started worker * @throws Exception in case of problem */ DedicatedWorkerGlobalScope(final Window owningWindow, final Context context, final BrowserVersion browserVersion, final Worker worker) throws Exception { context.initStandardObjects(this); final ClassConfiguration config = AbstractJavaScriptConfiguration .getClassConfiguration(DedicatedWorkerGlobalScope.class, browserVersion); final HtmlUnitScriptable prototype = JavaScriptEngine.configureClass(config, null, browserVersion); setPrototype(prototype); owningWindow_ = owningWindow; final URL currentURL = owningWindow.getWebWindow().getEnclosedPage().getUrl(); origin_ = currentURL.getProtocol() + "://" + currentURL.getHost() + ':' + currentURL.getPort(); worker_ = worker; }