List of usage examples for java.net URI getPort
public int getPort()
From source file:com.gooddata.http.client.GoodDataHttpClient.java
@Override public HttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException { final URI uri = request.getURI(); final HttpHost httpHost = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); return execute(httpHost, request, context); }
From source file:com.sina.cloudstorage.util.URIBuilder.java
private void digestURI(final URI uri) { this.scheme = uri.getScheme(); this.schemeSpecificPart = uri.getSchemeSpecificPart(); this.authority = uri.getAuthority(); this.host = uri.getHost(); this.port = uri.getPort(); this.userInfo = uri.getUserInfo(); this.path = uri.getPath(); this.queryParams = parseQuery(uri.getRawQuery(), Consts.UTF_8); this.fragment = uri.getFragment(); }
From source file:com.trickl.crawler.protocol.http.HttpProtocol.java
@Override public boolean isAllowed(URI uri) throws IOException { if (forceAllow) { return forceAllow; }// w w w.j a v a 2s. c o m URI baseURI; try { baseURI = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), "/", null, null); } catch (URISyntaxException ex) { log.error("Unable to determine base URI for " + uri); return false; } NoRobotClient nrc = new NoRobotClient(contentLoader, userAgent); try { nrc.parse(baseURI); } catch (NoRobotException ex) { log.error("Failure parsing robots.txt: " + ex.getMessage()); return false; } boolean test = nrc.isUrlAllowed(uri); if (log.isInfoEnabled()) { log.info(uri + " is " + (test ? "allowed" : "denied")); } return test; }
From source file:org.springframework.cloud.dataflow.rest.util.HttpClientConfigurer.java
/** * Configures the {@link HttpClientBuilder} with a proxy host. If the * {@code proxyUsername} and {@code proxyPassword} are not {@code null} * then a {@link CredentialsProvider} is also configured for the proxy host. * * @param proxyUri Must not be null and must be configured with a scheme (http or https). * @param proxyUsername May be null/* w w w. j a v a 2s. c o m*/ * @param proxyPassword May be null * @return a reference to {@code this} to enable chained method invocation */ public HttpClientConfigurer withProxyCredentials(URI proxyUri, String proxyUsername, String proxyPassword) { Assert.notNull(proxyUri, "The proxyUri must not be null."); Assert.hasText(proxyUri.getScheme(), "The scheme component of the proxyUri must not be empty."); httpClientBuilder.setProxy(new HttpHost(proxyUri.getHost(), proxyUri.getPort(), proxyUri.getScheme())); if (proxyUsername != null && proxyPassword != null) { final CredentialsProvider credentialsProvider = this.getOrInitializeCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(proxyUri.getHost(), proxyUri.getPort()), new UsernamePasswordCredentials(proxyUsername, proxyPassword)); httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider) .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); } return this; }
From source file:com.abiquo.abiserver.pojo.service.RemoteService.java
private boolean modifiedUri() { try {//from ww w .j ava2s .c o m URI u = new URI(uri); return !fixProtocol(u.getScheme()).equals(fixProtocol(protocol)) || !u.getHost().equals(domainName) || u.getPort() != port || !StringUtils.isEmpty(u.getPath()) && !u.getPath().replaceFirst("/", "").equals(serviceMapping); } catch (URISyntaxException e) { return true; } catch (NullPointerException e) { return true; } }
From source file:com.jayway.restassured.internal.http.AuthConfig.java
/** * Set authentication credentials to be used for the current * {@link HTTPBuilder#getUri() default host}. This method name is a bit of * a misnomer, since these credentials will actually work for "digest" * authentication as well./*w ww . ja v a2 s . com*/ * * @param user * @param pass */ public void basic(String user, String pass) { URI uri = ((URIBuilder) builder.getUri()).toURI(); if (uri == null) throw new IllegalStateException("a default URI must be set"); this.basic(uri.getHost(), uri.getPort(), user, pass); }
From source file:net.paoding.spdy.server.tomcat.impl.RequestDecoder.java
private Request decode(SynStream synStream) throws URISyntaxException { Request request = new Request(); request.setStartTime(synStream.getTimestamp()); CoyoteAttributes.setSynStream(request, synStream); ///* w ww . j a va2 s . c o m*/ String method = synStream.getHeader("method"); String url = synStream.getHeader("url"); String version = synStream.getHeader("version"); if (method == null && url == null && version == null) { throw new IllegalArgumentException("method=" + method + "; url=" + url + "; version=" + version); } request.method().setString(method); URI uri = new URI(url); request.protocol().setString(uri.getScheme()); request.requestURI().setString(uri.getPath()); request.query().setString(uri.getQuery()); request.serverName().setString(uri.getHost()); int port = uri.getPort(); request.setServerPort(port > 0 ? port : 80); // copy headers MimeHeaders coyoteHeaders = request.getMimeHeaders(); Map<String, String> headers = synStream.getHeaders(); for (Map.Entry<String, String> header : headers.entrySet()) { MessageBytes val = coyoteHeaders.addValue(header.getKey()); val.setString(header.getValue()); } // body request.setInputBuffer(new SpdyInputBuffer(synStream)); // System.out.println("RequestDecoder.decode: returnrequest " + request.decodedURI()); return request; }
From source file:net.oneandone.sushi.fs.webdav.WebdavFilesystem.java
public WebdavRoot root(URI uri) { WebdavRoot result;//from ww w . j ava 2 s. c o m String info; int port; NetRc.NetRcAuthenticator authenticator; if (uri.getFragment() != null) { throw new IllegalArgumentException(uri.toString()); } // ignores url.getPath() port = uri.getPort(); if (port == -1) { port = "https".equals(uri.getScheme()) ? 443 : 80; } result = new WebdavRoot(this, internalScheme, uri.getHost(), port); info = uri.getUserInfo(); if (info != null) { result.setUserInfo(info); } else { authenticator = getWorld().getNetRc().getAuthenticators(uri.getHost()); if (authenticator != null) { result.setCredentials(authenticator.getUser(), authenticator.getPass()); } } return result; }
From source file:org.apache.jena.atlas.web.auth.AbstractCredentialsAuthenticator.java
@Override public void apply(AbstractHttpClient client, HttpContext context, URI target) { // At least a user name is required or no authentication will be done if (!this.hasUserName(target)) return;/*from ww w . j a va 2 s. c o m*/ // Be careful to scope credentials to the specific URI so that // HttpClient won't try and send them to other servers HttpHost host = new HttpHost(target.getHost(), target.getPort()); CredentialsProvider provider = new BasicCredentialsProvider(); provider.setCredentials(new AuthScope(host), this.createCredentials(target)); client.setCredentialsProvider(provider); }
From source file:com.brightcove.com.uploader.helper.MediaManagerHelper.java
public Long uploadFile(URI uri, File f, DefaultHttpClient client) throws HttpException, IOException, URISyntaxException, ParserConfigurationException, SAXException { mLog.info("using " + uri.getHost() + " on port " + uri.getPort() + " for MM upload"); HttpPost method = new HttpPost(uri); MultipartEntity entityIn = new MultipartEntity(); entityIn.addPart("FileName", new StringBody(f.getName(), Charset.forName("UTF-8"))); FileBody fileBody = null;/*from w w w . j av a2 s. c o m*/ if (f != null) { fileBody = new FileBody(f); } if (f != null) { entityIn.addPart(f.getName(), fileBody); } entityIn.addPart("Upload", new StringBody("Submit Query", Charset.forName("UTF-8"))); method.setEntity(entityIn); if (client != null) { return executeUpload(method, client); } return null; }