本文整理汇总了Java中org.apache.http.client.utils.URIUtils.extractHost方法的典型用法代码示例。如果您正苦于以下问题:Java URIUtils.extractHost方法的具体用法?Java URIUtils.extractHost怎么用?Java URIUtils.extractHost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.client.utils.URIUtils
的用法示例。
在下文中一共展示了URIUtils.extractHost方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: OTSUri
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
public OTSUri(String endpoint, String action) {
this.action = action;
final String delimiter = "/";
if (!endpoint.endsWith(delimiter)) {
endpoint += delimiter;
}
// keep only one '/' in the end
int index = endpoint.length() - 1;
while (index > 0 && endpoint.charAt(index - 1) == '/') {
index--;
}
endpoint = endpoint.substring(0, index + 1);
try {
this.uri = new URI(endpoint + action);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("The endpoint is invalid.", e);
}
this.host = URIUtils.extractHost(uri);
}
示例2: initTarget
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
protected void initTarget() throws ServletException {
// TODO - should get the Kibana URI from Settings.java
// targetUri = Settings.getKibanaUri();
targetUri = settings.getYarnWebUIAddress();
if (!targetUri.contains("http://")) {
targetUri = "http://" + targetUri;
}
if (targetUri == null) {
throw new ServletException(P_TARGET_URI + " is required.");
}
//test it's valid
try {
targetUriObj = new URI(targetUri);
} catch (Exception e) {
throw new ServletException("Trying to process targetUri init parameter: "
+ e, e);
}
targetHost = URIUtils.extractHost(targetUriObj);
}
示例3: initTarget
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
protected void initTarget() throws ServletException {
// TODO - should get the Kibana URI from Settings.java
// targetUri = Settings.getKibanaUri();
targetUri = getConfigParam(P_TARGET_URI);
if (targetUri == null) {
throw new ServletException(P_TARGET_URI + " is required.");
}
//test it's valid
try {
targetUriObj = new URI(targetUri);
} catch (Exception e) {
throw new ServletException("Trying to process targetUri init parameter: "
+ e, e);
}
targetHost = URIUtils.extractHost(targetUriObj);
}
示例4: createSession
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
public void createSession(String alias, String url, Map<String, String> headers, Authentication auth, String verify,
Boolean debug, String loggerClass, String password, boolean verifyHost, boolean selfSigned, Proxy proxy) {
HostnameVerifier defaultHostnameVerifier = verifyHost ? null : NoopHostnameVerifier.INSTANCE;
TrustStrategy trustStrategy = selfSigned ? new TrustSelfSignedStrategy() : null;
if (!loggerClass.isEmpty()) {
System.setProperty("org.apache.commons.logging.Log", loggerClass);
System.setProperty("org.apache.commons.logging.robotlogger.log.org.apache.http", debug ? "DEBUG" : "INFO");
}
HttpHost target;
try {
target = URIUtils.extractHost(new URI(url));
} catch (URISyntaxException e) {
throw new RuntimeException("Parsing of URL failed. Error message: " + e.getMessage());
}
Session session = new Session();
session.setProxy(proxy);
session.setContext(this.createContext(auth, target));
session.setClient(this.createHttpClient(auth, verify, target, false, password, null, null, proxy));
session.setUrl(url);
session.setHeaders(headers);
session.setHttpHost(target);
session.setVerify(verify);
session.setAuthentication(auth);
session.setPassword(password);
session.setHostnameVerifier(defaultHostnameVerifier);
session.setTrustStrategy(trustStrategy);
sessions.put(alias, session);
}
示例5: determineTarget
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
public static HttpHost determineTarget(final HttpUriRequest request) throws ClientProtocolException {
// A null target may be acceptable if there is a default target.
// Otherwise, the null target is detected in the director.
HttpHost target = null;
final 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;
}
示例6: determineTarget
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
private static HttpHost determineTarget(HttpUriRequest request) throws ClientProtocolException {
// A null target may be acceptable if there is a default target.
// Otherwise, the null target is detected in the director.
HttpHost target = null;
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;
}
示例7: getHttpHost
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
public static HttpHost getHttpHost(String serverUrl) {
HttpHost host = null;
//determine host name
HttpGet serverGet = new HttpGet(serverUrl);
final URI requestURI = serverGet.getURI();
if (requestURI.isAbsolute()) {
host = URIUtils.extractHost(requestURI);
}
return host;
}
示例8: configureDomainForCookie
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
/**
* It configures the cookie domain with the domain of the Apache CloudStack that is being accessed.
* The domain is extracted from {@link #url} variable.
*/
protected void configureDomainForCookie(BasicClientCookie cookie) {
try {
HttpHost httpHost = URIUtils.extractHost(new URI(url));
String domain = httpHost.getHostName();
cookie.setDomain(domain);
} catch (URISyntaxException e) {
throw new ApacheCloudStackClientRuntimeException(e);
}
}
示例9: determineTarget
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
private static HttpHost determineTarget(final HttpUriRequest request) throws ClientProtocolException {
// A null target may be acceptable if there is a default target.
// Otherwise, the null target is detected in the director.
HttpHost target = null;
final 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;
}
示例10: determineTarget
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
private static HttpHost determineTarget(final HttpUriRequest request) throws ClientProtocolException {
HttpHost target = null;
final 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;
}
示例11: ClientConfig
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
/**
* Constructor
*
* @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;
}
示例12: HopsServletHandler
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
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);
}
示例13: initTarget
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
protected void initTarget() throws ServletException {
// TODO - should get the Kibana URI from Settings.java
// targetUri = Settings.getKibanaUri();
targetUri = settings.getHDFSWebUIAddress();
if (targetUri == null) {
throw new ServletException(P_TARGET_URI + " is required.");
}
if (settings.getHopsRpcTls()) {
if (!targetUri.contains("https://")) {
targetUri = "https://" + targetUri;
}
} else {
if (!targetUri.contains("http://")) {
targetUri = "http://" + targetUri;
}
}
//test it's valid
try {
targetUriObj = new URI(targetUri);
} catch (Exception e) {
throw new ServletException("Trying to process targetUri init parameter: "
+ e, e);
}
targetHost = URIUtils.extractHost(targetUriObj);
}
示例14: initTarget
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
protected void initTarget() throws ServletException {
targetUri = getConfigParam(P_TARGET_URI);
if (targetUri == null)
throw new ServletException(P_TARGET_URI + " is required.");
// test it's valid
try {
targetUriObj = new URI(targetUri);
} catch (Exception e) {
throw new ServletException("Trying to process targetUri init parameter: " + e, e);
}
targetHost = URIUtils.extractHost(targetUriObj);
}
示例15: validate
import org.apache.http.client.utils.URIUtils; //导入方法依赖的package包/类
/**
* Validates URI
*
* @param url
* @throws UrlValidationException is thrown when URL is in illegal form.
*/
public void validate(String url) throws UrlValidationException {
if (!PathUtils.hasText(url)) {
throw new RuntimeException("The URL cannot be empty");
}
try {
URI parsedUri = new URIBuilder(url).build();
String scheme = parsedUri.getScheme();
if (!isAnySchemaAllowed() && StringUtils.isBlank(scheme)) {
throw new UrlValidationException(String.format(
"Url scheme cannot be empty. The following schemes are allowed: %s. " +
"For example: %s://host",
Arrays.asList(allowedSchemes), allowedSchemes[0]
));
} else if (!isAllowedSchema(scheme)) {
throw new UrlValidationException(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) {
throw new UrlValidationException("Cannot resolve host from url: " + url);
}
} catch (URISyntaxException e) {
throw new UrlValidationException(String.format("'%s' is not a valid url", url));
}
}