List of usage examples for org.apache.commons.httpclient URI getHost
public String getHost() throws URIException
From source file:com.eviware.soapui.impl.support.HttpUtils.java
public static java.net.URI createUri(URI uri) throws URISyntaxException, URIException { return createUri(uri.getScheme(), uri.getUserinfo(), uri.getHost(), uri.getPort(), uri.getEscapedPath(), uri.getEscapedQuery(), uri.getEscapedFragment()); }
From source file:davmail.http.DavGatewayHttpClientFacade.java
protected static boolean isNoProxyFor(java.net.URI uri) { final String noProxyFor = Settings.getProperty("davmail.noProxyFor"); if (noProxyFor != null) { final String urihost = uri.getHost().toLowerCase(); final String[] domains = noProxyFor.toLowerCase().split(",\\s*"); for (String domain : domains) { if (urihost.endsWith(domain)) { return true; //break; }//from w w w. j a v a 2 s . com } } return false; }
From source file:davmail.http.DavGatewayHttpClientFacade.java
/** * Update http client configuration (proxy) * * @param httpClient current Http client * @param url target url/*from w w w . j a v a 2 s . c o m*/ * @throws DavMailException on error */ public static void configureClient(HttpClient httpClient, String url) throws DavMailException { setClientHost(httpClient, url); /*if (Settings.getBooleanProperty("davmail.enableKerberos", false)) { AuthPolicy.registerAuthScheme("Negotiate", NegotiateScheme.class); ArrayList<String> authPrefs = new ArrayList<String>(); authPrefs.add("Negotiate"); httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); } else */if (!needNTLM) { ArrayList<String> authPrefs = new ArrayList<String>(); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); // exclude NTLM authentication scheme httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); } boolean enableProxy = Settings.getBooleanProperty("davmail.enableProxy"); boolean useSystemProxies = Settings.getBooleanProperty("davmail.useSystemProxies", Boolean.FALSE); String proxyHost = null; int proxyPort = 0; String proxyUser = null; String proxyPassword = null; try { java.net.URI uri = new java.net.URI(url); if (isNoProxyFor(uri)) { LOGGER.debug("no proxy for " + uri.getHost()); } else if (useSystemProxies) { // get proxy for url from system settings System.setProperty("java.net.useSystemProxies", "true"); List<Proxy> proxyList = getProxyForURI(uri); if (!proxyList.isEmpty() && proxyList.get(0).address() != null) { InetSocketAddress inetSocketAddress = (InetSocketAddress) proxyList.get(0).address(); proxyHost = inetSocketAddress.getHostName(); proxyPort = inetSocketAddress.getPort(); // we may still need authentication credentials proxyUser = Settings.getProperty("davmail.proxyUser"); proxyPassword = Settings.getProperty("davmail.proxyPassword"); } } else if (enableProxy) { proxyHost = Settings.getProperty("davmail.proxyHost"); proxyPort = Settings.getIntProperty("davmail.proxyPort"); proxyUser = Settings.getProperty("davmail.proxyUser"); proxyPassword = Settings.getProperty("davmail.proxyPassword"); } } catch (URISyntaxException e) { throw new DavMailException("LOG_INVALID_URL", url); } // configure proxy if (proxyHost != null && proxyHost.length() > 0) { httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort); if (proxyUser != null && proxyUser.length() > 0) { AuthScope authScope = new AuthScope(proxyHost, proxyPort, AuthScope.ANY_REALM); // detect ntlm authentication (windows domain name in user name) int backslashindex = proxyUser.indexOf('\\'); if (backslashindex > 0) { httpClient.getState().setProxyCredentials(authScope, new NTCredentials(proxyUser.substring(backslashindex + 1), proxyPassword, "UNKNOWN", proxyUser.substring(0, backslashindex))); } else { httpClient.getState().setProxyCredentials(authScope, new NTCredentials(proxyUser, proxyPassword, "UNKNOWN", "")); } } } }
From source file:com.silverpeas.openoffice.windows.FileWebDavAccessManager.java
/** * Retrieve the file from distant URL to local temp file. * @param url document url/* w w w . j av a 2s. c o m*/ * @return full path of local temp file * @throws HttpException * @throws IOException */ public String retrieveFile(String url) throws HttpException, IOException { URI uri = getURI(url); WebdavManager webdav = new WebdavManager(uri.getHost(), userName, password); // Let's lock the file lockToken = webdav.lockFile(uri, userName); logger.log(Level.INFO, "{0}{1}{2}", new Object[] { MessageUtil.getMessage("info.webdav.locked"), ' ', lockToken }); String tmpFile = webdav.getFile(uri, lockToken); logger.log(Level.INFO, "{0}{1}{2}", new Object[] { MessageUtil.getMessage("info.webdav.file.locally.saved"), ' ', tmpFile }); return tmpFile; }
From source file:com.silverpeas.openoffice.windows.FileWebDavAccessManager.java
/** * Push back file into remote location using webdav. * @param tmpFilePath full path of local temp file * @param url remote url/*from www .j av a 2 s . com*/ * @throws HttpException * @throws IOException */ public void pushFile(String tmpFilePath, String url) throws HttpException, IOException { URI uri = getURI(url); WebdavManager webdav = new WebdavManager(uri.getHost(), userName, password); logger.log(Level.INFO, "{0}{1}{2}", new Object[] { MessageUtil.getMessage("info.webdav.put"), ' ', tmpFilePath }); webdav.putFile(uri, tmpFilePath, lockToken); logger.log(Level.INFO, "{0}{1}{2}", new Object[] { MessageUtil.getMessage("info.webdav.unlocking"), ' ', uri.getEscapedURI() }); // Let's unlock the file webdav.unlockFile(uri, lockToken); // delete temp file File file = new File(tmpFilePath); file.delete(); file.getParentFile().delete(); logger.log(Level.INFO, MessageUtil.getMessage("info.file.deleted")); logger.log(Level.INFO, MessageUtil.getMessage("info.ok")); }
From source file:com.linkedin.pinot.controller.api.restlet.resources.ServerTableSizeReader.java
public Map<String, List<SegmentSizeInfo>> getSizeDetailsFromServers(BiMap<String, String> serverEndPoints, String table, int timeoutMsec) { List<String> serverUrls = new ArrayList<>(serverEndPoints.size()); BiMap<String, String> endpointsToServers = serverEndPoints.inverse(); for (String endpoint : endpointsToServers.keySet()) { String tableSizeUri = "http://" + endpoint + "/table/" + table + "/size"; serverUrls.add(tableSizeUri);// www . j av a2s. c om } MultiGetRequest mget = new MultiGetRequest(executor, connectionManager); LOGGER.info("Reading segment sizes from servers for table: {}, timeoutMsec: {}", table, timeoutMsec); CompletionService<GetMethod> completionService = mget.execute(serverUrls, timeoutMsec); Map<String, List<SegmentSizeInfo>> serverSegmentSizes = new HashMap<>(serverEndPoints.size()); for (int i = 0; i < serverUrls.size(); i++) { try { GetMethod getMethod = completionService.take().get(); URI uri = getMethod.getURI(); String instance = endpointsToServers.get(uri.getHost() + ":" + uri.getPort()); if (getMethod.getStatusCode() >= 300) { LOGGER.error("Server: {} returned error: {}", instance, getMethod.getStatusCode()); continue; } TableSizeInfo tableSizeInfo = new ObjectMapper().readValue(getMethod.getResponseBodyAsString(), TableSizeInfo.class); serverSegmentSizes.put(instance, tableSizeInfo.segments); } catch (InterruptedException e) { LOGGER.warn("Interrupted exception while reading segment size for table: {}", table, e); } catch (ExecutionException e) { if (Throwables.getRootCause(e) instanceof SocketTimeoutException) { LOGGER.warn("Server request to read table size was timed out for table: {}", table, e); } else if (Throwables.getRootCause(e) instanceof ConnectTimeoutException) { LOGGER.warn("Server request to read table size timed out waiting for connection. table: {}", table, e); } else if (Throwables.getRootCause(e) instanceof ConnectionPoolTimeoutException) { LOGGER.warn( "Server request to read table size timed out on getting a connection from pool, table: {}", table, e); } else { LOGGER.warn("Execution exception while reading segment sizes for table: {}", table, e); } } catch (Exception e) { LOGGER.warn("Error while reading segment sizes for table: {}", table); } } LOGGER.info("Finished reading segment sizes for table: {}", table); return serverSegmentSizes; }
From source file:com.linkedin.pinot.controller.api.resources.ServerTableSizeReader.java
public Map<String, List<SegmentSizeInfo>> getSizeDetailsFromServers(BiMap<String, String> serverEndPoints, String table, int timeoutMsec) { List<String> serverUrls = new ArrayList<>(serverEndPoints.size()); BiMap<String, String> endpointsToServers = serverEndPoints.inverse(); for (String endpoint : endpointsToServers.keySet()) { String tableSizeUri = "http://" + endpoint + "/table/" + table + "/size"; serverUrls.add(tableSizeUri);/* ww w . j a v a 2 s.co m*/ } MultiGetRequest mget = new MultiGetRequest(executor, connectionManager); LOGGER.info("Reading segment sizes from servers for table: {}, timeoutMsec: {}", table, timeoutMsec); CompletionService<GetMethod> completionService = mget.execute(serverUrls, timeoutMsec); Map<String, List<SegmentSizeInfo>> serverSegmentSizes = new HashMap<>(serverEndPoints.size()); for (int i = 0; i < serverUrls.size(); i++) { GetMethod getMethod = null; try { getMethod = completionService.take().get(); URI uri = getMethod.getURI(); String instance = endpointsToServers.get(uri.getHost() + ":" + uri.getPort()); if (getMethod.getStatusCode() >= 300) { LOGGER.error("Server: {} returned error: {}", instance, getMethod.getStatusCode()); continue; } TableSizeInfo tableSizeInfo = new ObjectMapper().readValue(getMethod.getResponseBodyAsString(), TableSizeInfo.class); serverSegmentSizes.put(instance, tableSizeInfo.segments); } catch (InterruptedException e) { LOGGER.warn("Interrupted exception while reading segment size for table: {}", table, e); } catch (ExecutionException e) { if (Throwables.getRootCause(e) instanceof SocketTimeoutException) { LOGGER.warn("Server request to read table size was timed out for table: {}", table, e); } else if (Throwables.getRootCause(e) instanceof ConnectTimeoutException) { LOGGER.warn("Server request to read table size timed out waiting for connection. table: {}", table, e); } else if (Throwables.getRootCause(e) instanceof ConnectionPoolTimeoutException) { LOGGER.warn( "Server request to read table size timed out on getting a connection from pool, table: {}", table, e); } else { LOGGER.warn("Execution exception while reading segment sizes for table: {}", table, e); } } catch (Exception e) { LOGGER.warn("Error while reading segment sizes for table: {}", table); } finally { if (getMethod != null) { getMethod.releaseConnection(); } } } LOGGER.info("Finished reading segment sizes for table: {}", table); return serverSegmentSizes; }
From source file:com.eviware.soapui.impl.wsdl.submit.filters.EndpointRequestFilter.java
@Override public void filterAbstractHttpRequest(SubmitContext context, AbstractHttpRequest<?> request) { HttpRequestBase httpMethod = (HttpRequestBase) context.getProperty(BaseHttpRequestTransport.HTTP_METHOD); String strURL = request.getEndpoint(); strURL = PropertyExpander.expandProperties(context, strURL); try {// www .ja va2s . co m if (StringUtils.hasContent(strURL)) { URI uri = new URI(strURL, request.getSettings().getBoolean(HttpSettings.ENCODED_URLS)); context.setProperty(BaseHttpRequestTransport.REQUEST_URI, uri); httpMethod.setURI(new java.net.URI(uri.getScheme(), uri.getUserinfo(), uri.getHost(), uri.getPort(), (uri.getPath()) == null ? "/" : uri.getPath(), uri.getQuery(), uri.getFragment())); } } catch (Exception e) { SoapUI.logError(e); } }
From source file:com.navercorp.pinpoint.plugin.httpclient3.HttpClient3RequestTrace.java
@Override public String getHost() { try {/*from w w w .j a v a2s . co m*/ final URI uri = this.httpMethod.getURI(); // if uri have schema if (uri.isAbsoluteURI()) { return getEndpoint(uri.getHost(), uri.getPort()); } if (this.httpConnection != null) { final String host = this.httpConnection.getHost(); final int port = getPort(this.httpConnection); return getEndpoint(host, port); } } catch (Exception e) { if (isDebug) { logger.debug("Failed to get host. httpMethod={}", this.httpMethod, e); } } return null; }
From source file:com.navercorp.pinpoint.plugin.httpclient3.interceptor.HttpMethodBaseExecuteMethodInterceptor.java
private String getHost(HttpMethod httpMethod, HttpConnection httpConnection) { try {//from w ww . j av a 2 s . c om final URI uri = httpMethod.getURI(); // if uri have schema if (uri.isAbsoluteURI()) { return HttpClient3RequestWrapper.getEndpoint(uri.getHost(), uri.getPort()); } if (httpConnection != null) { final String host = httpConnection.getHost(); final int port = HttpClient3RequestWrapper.getPort(httpConnection); return HttpClient3RequestWrapper.getEndpoint(host, port); } } catch (Exception e) { if (isDebug) { logger.debug("Failed to get host. httpMethod={}", httpMethod, e); } } return null; }