List of usage examples for java.net URL getHost
public String getHost()
From source file:com.comcast.cats.provider.VideoRecorderRESTProviderImpl.java
private String substituteFilePath(String filePath) { String retVal = filePath;/*from w w w . ja va 2s . co m*/ try { URL filePathURL = new URL(filePath); String host = filePathURL.getHost(); retVal = StringUtils.replaceOnce(filePath, host, serverHost); } catch (MalformedURLException e) { logger.debug("Provider doesnt know how to parse this syntax"); } return retVal; }
From source file:com.gs.tools.doc.extractor.core.util.HttpUtility.java
public static byte[] getExcelFromPost(String sourceUrl, String postString) throws Exception { byte[] result = null; URL targetUrl = new URL(sourceUrl); /*//from ww w . j av a 2s .com * Create http parameter to set Connection timeout = 300000 Socket/Read * timeout = 300000 Socket Read Buffer = 10485760 */ HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 300000); HttpConnectionParams.setSocketBufferSize(httpParams, 10485760); HttpConnectionParams.setSoTimeout(httpParams, 300000); // set the http param to the DefaultHttpClient HttpClient httpClient = new DefaultHttpClient(httpParams); // create POST method and set the URL and POST data HttpPost post = new HttpPost(targetUrl.toURI()); post.addHeader("Host", targetUrl.getHost()); post.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.0; rv:8.0) Gecko/20100101 Firefox/8.0"); post.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); post.addHeader("Accept-Language", "en-gb,en;q=0.5"); post.addHeader("Accept-Encoding", "gzip, deflate"); post.addHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); post.addHeader("Connection", "keep-alive"); post.addHeader("Content-Type", "application/x-www-form-urlencoded"); post.addHeader("X-Requested-With", "XMLHttpRequest"); StringEntity entity = new StringEntity(postString, "UTF-8"); post.setEntity(entity); logger.info("Execute the POST request with all input data"); // Execute the POST request on the http client to get the response HttpResponse response = httpClient.execute(post, new BasicHttpContext()); if (null != response && response.getStatusLine().getStatusCode() == 200) { HttpEntity httpEntity = response.getEntity(); if (null != httpEntity) { long contentLength = httpEntity.getContentLength(); logger.info("Content length: " + contentLength); logger.info("Content type: " + httpEntity.getContentType().getValue()); // no data, if the content length is insufficient if (contentLength <= 0) { return null; } // read the response to String InputStream responseStream = httpEntity.getContent(); if (null != responseStream) { result = IOUtils.toByteArray(responseStream); } } } logger.info("data read complete :: length " + result.length); return result; }
From source file:org.dasein.cloud.azure.platform.AzureSQLDatabaseSupportRequests.java
private String getEncodedUri(String urlString) throws InternalException { try {// w w w . ja va2 s .c o m URL url = new URL(urlString); return new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()).toString(); } catch (Exception e) { throw new InternalException(e.getMessage()); } }
From source file:net.datacrow.onlinesearch.amazon.SignedRequestsHelper.java
public synchronized String sign(URL url) { String server = url.getHost(); String query = url.getQuery(); Map<String, String> params = createParameterMap(query); // remove old signature information params.remove("AWSAccessKeyId"); params.remove("Timestamp"); params.remove("Signature"); return sign(server, params); }
From source file:com.t2.drupalsdk.ServicesClient.java
public ServicesClient(String urlString) throws DataOutHandlerException, MalformedURLException { if (urlString == null || urlString == "") { throw new DataOutHandlerException("Remote database URL must not be null or blank"); }//w w w . j a va 2 s . c o m // Break down the remote URL string into constituant parts String[] tokens = urlString.split("/"); if (tokens.length < MIN_PARAMETERS) { throw new DataOutHandlerException("Remote database URL incorrectly formatted - " + "must include Drupal service and Drupal Rest Endpoint"); } this.mDrupalRestEndpoint = tokens[INDEX_DRUPAL_REST_ENDPOINT]; this.mDrupalService = tokens[INDEX_DRUPAL_SERVICE]; this.mUrlString = urlString; URL url = new URL(urlString); mProtocol = url.getProtocol(); mHost = url.getHost(); mAsyncHttpClient.setTimeout(60000); }
From source file:com.liferay.httpservice.internal.http.DefaultHttpContextTest.java
protected void getResourceAndVerify(String path) { URL url = _defaultHttpContext.getResource(path); Assert.assertNotNull(url);/*from w ww .j a v a 2s. com*/ Assert.assertEquals(_FILE, url.getFile()); Assert.assertEquals(_HOST, url.getHost()); Assert.assertEquals(_PROTOCOL, url.getProtocol()); }
From source file:org.eclipse.skalli.core.destination.DestinationComponent.java
/** * Returns <code>true</code> if the given URL belongs to the local domain, * i.e. only a host name like <tt>"myhost"</tt> instead of <tt>"myhost.example,org"</tt> * is specified.// www. ja va2s .co m * * @param url the URL to check. */ private boolean isLocalDomain(URL url) { return url.getHost().indexOf('.') < 0; }
From source file:de.digiway.rapidbreeze.server.model.storage.provider.ShareOnlineBiz.java
@Override public boolean canHandle(URL url) { String host = url.getHost().toLowerCase(); if (host.startsWith("www.share-online.biz") || host.startsWith("share-online.biz")) { return true; }/* w ww. ja va 2 s .c o m*/ return false; }
From source file:es.gva.cit.catalog.protocols.HTTPGetProtocol.java
/** * /*from ww w .j a v a 2 s. c om*/ * * * @return * @param url * @param object * @param firstRecord */ public Collection doQuery(URL url, Object object, int firstRecord) { NameValuePair[] parameters = (NameValuePair[]) object; File file = null; String sUrl = "http://" + url.getHost() + ":" + url.getPort() + url.getPath(); sUrl = sUrl + createURLParams(parameters); try { file = Utilities.downloadFile(new URL(sUrl), "catalog-", null); } catch (Exception e) { return null; } Collection col = new java.util.ArrayList(); col.add(XMLTree.xmlToTree(file)); return col; }
From source file:mobi.jenkinsci.server.core.net.PooledHttpClientFactory.java
private CredentialsProvider getCredentialsProvider(final URL url, final String user, final String password) { CredentialsProvider provider = new BasicCredentialsProvider(); provider.setCredentials(new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM, "BASIC"), new UsernamePasswordCredentials(user, password)); return provider; }