List of usage examples for org.apache.http.client.utils URIUtils extractHost
public static HttpHost extractHost(final URI uri)
From source file:com.github.caldav4j.CalDAVCalendarCollectionBase.java
public HttpHost getDefaultHttpHost(URI path) { if (httpHost == null) return URIUtils.extractHost(path); return httpHost; }
From source file:io.fabric8.maven.support.Apps.java
/** * Posts a file to the git repository//from w ww.j av a 2s. co m */ public static HttpResponse postFileToGit(File file, String user, String password, String consoleUrl, String branch, String path, Logger logger) throws URISyntaxException, IOException { HttpClientBuilder builder = HttpClients.custom(); if (Strings.isNotBlank(user) && Strings.isNotBlank(password)) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope("localhost", 443), new UsernamePasswordCredentials(user, password)); builder = builder.setDefaultCredentialsProvider(credsProvider); } CloseableHttpClient client = builder.build(); try { String url = consoleUrl; if (!url.endsWith("/")) { url += "/"; } url += "git/"; url += branch; if (!path.startsWith("/")) { url += "/"; } url += path; logger.info("Posting App Zip " + file.getName() + " to " + url); URI buildUrl = new URI(url); HttpPost post = new HttpPost(buildUrl); // use multi part entity format FileBody zip = new FileBody(file); HttpEntity entity = MultipartEntityBuilder.create().addPart(file.getName(), zip).build(); post.setEntity(entity); // post.setEntity(new FileEntity(file)); HttpResponse response = client.execute(URIUtils.extractHost(buildUrl), post); logger.info("Response: " + response); if (response != null) { int statusCode = response.getStatusLine().getStatusCode(); if (statusCode < 200 || statusCode >= 300) { throw new IllegalStateException("Failed to post App Zip to: " + url + " " + response); } } return response; } finally { Closeables.closeQuietly(client); } }
From source file:org.yamj.api.common.http.HttpClientWrapper.java
protected static HttpHost determineTarget(HttpUriRequest request) throws ClientProtocolException { HttpHost target = null;//from w w w .j a v a 2 s.c om URI requestURI = request.getURI(); if (requestURI.isAbsolute()) { target = URIUtils.extractHost(requestURI); if (target == null) { throw new ClientProtocolException("URI does not specify a valid host name: " + requestURI); } } return target; }
From source file:com.github.woki.payments.adyen.ClientConfig.java
/** * Constructor//from ww w. ja v a 2 s. c o m * * @param endpoint the endpoint; {@link APUtil#TEST_ENDPOINT} / {@link APUtil#LIVE_ENDPOINT} * * @throws IllegalArgumentException on invalid URI */ public ClientConfig(final String endpoint) { if (StringUtils.isBlank(endpoint)) { throw new IllegalArgumentException("Invalid endpoint: " + endpoint); } endpointHost = URIUtils.extractHost(URI.create(endpoint)); if (endpointHost == null) { throw new IllegalArgumentException("Invalid endpoint: " + endpoint); } this.endpoint = endpoint; }
From source file:com.predic8.membrane.servlet.embedded.HopsServletHandler.java
public HopsServletHandler(HttpServletRequest request, HttpServletResponse response, Transport transport, URI targetUriObj) throws IOException { super(transport); this.request = request; this.response = response; this.targetUriObj = targetUriObj; this.targetHost = URIUtils.extractHost(targetUriObj); exchange = new Exchange(this); exchange.setProperty(Exchange.HTTP_SERVLET_REQUEST, request); }
From source file:org.artifactory.webapp.wicket.util.validation.UriValidator.java
@Override protected void onValidate(IValidatable validatable) { String uri = (String) validatable.getValue(); if (!PathUtils.hasText(uri)) { addError(validatable, "The URL cannot be empty"); return;/* ww w . j a v a 2 s . c o m*/ } try { URI parsedUri = new URIBuilder(uri).build(); String scheme = parsedUri.getScheme(); if (!anySchemaAllowed() && StringUtils.isBlank(scheme)) { addError(validatable, String.format( "Url scheme cannot be empty. The following schemes are allowed: %s. " + "For example: %s://host", Arrays.asList(allowedSchemes), allowedSchemes[0])); } else if (!allowedSchema(scheme)) { addError(validatable, String.format("Scheme '%s' is not allowed. The following schemes are allowed: %s", scheme, Arrays.asList(allowedSchemes))); } HttpHost host = URIUtils.extractHost(parsedUri); if (host == null) { addError(validatable, "Cannot resolve host from url: " + uri); } } catch (URISyntaxException e) { addError(validatable, String.format("'%s' is not a valid url", uri)); } }
From source file:com.gsma.mobileconnect.utils.RestClient.java
/** * Build a HttpClientContext that will preemptively authenticate using Basic Authentication * * @param username Username for credentials * @param password Password for credentials * @param uriForRealm uri used to determine the authentication realm * @return A HttpClientContext that will preemptively authenticate using Basic Authentication *///from w w w .j av a 2 s. c o m public HttpClientContext getHttpClientContext(String username, String password, URI uriForRealm) { String host = URIUtils.extractHost(uriForRealm).getHostName(); int port = uriForRealm.getPort(); if (port == -1) { if (Constants.HTTP_SCHEME.equalsIgnoreCase(uriForRealm.getScheme())) { port = Constants.HTTP_PORT; } else if (Constants.HTTPS_SCHEME.equalsIgnoreCase(uriForRealm.getScheme())) { port = Constants.HTTPS_PORT; } } CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(host, port), new UsernamePasswordCredentials(username, password)); AuthCache authCache = new BasicAuthCache(); authCache.put(new HttpHost(host, port, uriForRealm.getScheme()), new BasicScheme()); HttpClientContext context = HttpClientContext.create(); context.setCredentialsProvider(credentialsProvider); context.setAuthCache(authCache); return context; }
From source file:com.github.caldav4j.CalDAVCalendarCollectionBase.java
/** * Sets base path. Also set the host, based on if the path was Absolute * @param path Calendar Collection Root//w w w . j av a 2 s. co m */ public void setCalendarCollectionRoot(String path) { URI temp = URI.create(path); if (temp.isAbsolute()) setHttpHost(URIUtils.extractHost(temp)); this.calendarCollectionRoot = UrlUtils.removeDoubleSlashes(UrlUtils.ensureTrailingSlash(temp.getPath())); }
From source file:org.apache.sling.hapi.client.impl.AbstractHtmlClientImpl.java
public AbstractHtmlClientImpl(String baseUrl, String user, String password) throws URISyntaxException { this.baseUrl = new URI(baseUrl); HttpHost targetHost = URIUtils.extractHost(this.baseUrl); BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(user, password)); this.client = HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider) .setRedirectStrategy(new LaxRedirectStrategy()).build(); }