List of usage examples for org.apache.commons.httpclient URI URI
public URI(URI base, URI relative) throws URIException
From source file:org.andrewberman.sync.InheritMe.java
static String escapeURL(String url) throws Exception { /*/* w w w .j av a 2 s . c om*/ * UPDATE 2008-03-08: Changed the constructor from new URI(url,false) to URI(url,true). * * Seems to work with fancy ACM links, but not sure whether I'm breaking something else... */ URI newURL; try { newURL = new URI(url, true); } catch (Exception e) { newURL = new URI(url, false); } return newURL.getEscapedURI(); }
From source file:org.andrewberman.sync.InheritMe.java
static String relativeToAbsoluteURL(String base, String href) throws Exception { // System.out.println(href); href = StringEscapeUtils.unescapeHtml(href); // System.out.println(href); href = urlEncoder.decode(href);/* w w w. j a v a2s .co m*/ // System.out.println(href); base = StringEscapeUtils.unescapeHtml(base); base = urlEncoder.decode(base); URI baseURI = new URI(base, false); URI childURI = new URI(baseURI, href, false); // System.out.println(childURI.toString()); return childURI.getURI(); // return childURI.toString(); }
From source file:org.apache.any23.servlet.Servlet.java
private boolean isValidIRI(String s) { try {// ww w. jav a 2s .c o m URI uri = new URI(s, false); if (!"http".equals(uri.getScheme()) && !"https".equals(uri.getScheme())) { return false; } } catch (Exception e) { return false; } return true; }
From source file:org.apache.any23.source.HTTPDocumentSource.java
private String normalize(String uri) throws URISyntaxException { try {//from w w w . j a va 2 s.com URI normalized = new URI(uri, DefaultHTTPClient.isUrlEncoded(uri)); normalized.normalize(); return normalized.toString(); } catch (URIException e) { LOG.warn("Invalid uri: {}", uri); LOG.error("Can not convert URL", e); throw new URISyntaxException(uri, e.getMessage()); } }
From source file:org.apache.hadoop.hbase.rest.client.Client.java
/** * Execute a transaction method given only the path. Will select at random * one of the members of the supplied cluster definition and iterate through * the list until a transaction can be successfully completed. The * definition of success here is a complete HTTP transaction, irrespective * of result code. //from w w w. ja v a 2 s .c o m * @param cluster the cluster definition * @param method the transaction method * @param headers HTTP header values to send * @param path the properly urlencoded path * @return the HTTP response code * @throws IOException */ public int executePathOnly(Cluster cluster, HttpMethod method, Header[] headers, String path) throws IOException { IOException lastException; if (cluster.nodes.size() < 1) { throw new IOException("Cluster is empty"); } int start = (int) Math.round((cluster.nodes.size() - 1) * Math.random()); int i = start; do { cluster.lastHost = cluster.nodes.get(i); try { StringBuilder sb = new StringBuilder(); sb.append("http://"); sb.append(cluster.lastHost); sb.append(path); URI uri = new URI(sb.toString(), true); return executeURI(method, headers, uri.toString()); } catch (IOException e) { lastException = e; } } while (++i != start && i < cluster.nodes.size()); throw lastException; }
From source file:org.apache.hadoop.mapred.JobEndNotifier.java
private static int httpNotification(String uri) throws IOException { URI url = new URI(uri, false); HttpClient m_client = new HttpClient(); HttpMethod method = new GetMethod(url.getEscapedURI()); method.setRequestHeader("Accept", "*/*"); return m_client.executeMethod(method); }
From source file:org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.java
public RepositoryServiceImpl(String uri, IdFactory idFactory, NameFactory nameFactory, PathFactory pathFactory, QValueFactory qValueFactory) throws RepositoryException { if (uri == null || "".equals(uri)) { throw new RepositoryException("Invalid repository uri '" + uri + "'."); }/*w w w . ja v a 2 s . c om*/ if (idFactory == null || qValueFactory == null) { throw new RepositoryException("IdFactory and QValueFactory may not be null."); } this.idFactory = idFactory; this.nameFactory = nameFactory; this.pathFactory = pathFactory; this.qValueFactory = qValueFactory; try { domFactory = DomUtil.BUILDER_FACTORY.newDocumentBuilder().newDocument(); } catch (ParserConfigurationException e) { throw new RepositoryException(e); } try { URI repositoryUri = new URI((uri.endsWith("/")) ? uri : uri + "/", true); hostConfig = new HostConfiguration(); hostConfig.setHost(repositoryUri); nsCache = new NamespaceCache(); uriResolver = new URIResolverImpl(repositoryUri, this, domFactory); NamePathResolver resolver = new NamePathResolverImpl(nsCache); valueFactory = new ValueFactoryQImpl(qValueFactory, resolver); } catch (URIException e) { throw new RepositoryException(e); } connectionManager = new MultiThreadedHttpConnectionManager(); }
From source file:org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.java
/** * Compute the repository URI (while dealing with trailing / and port number * defaulting)//from w ww. j ava2s .c o m */ public static URI computeRepositoryUri(String uri) throws URIException { URI repositoryUri = new URI((uri.endsWith("/")) ? uri : uri + "/", true); // workaround for JCR-3228: normalize default port numbers because of // the weak URI matching code elsewhere (the remote server is unlikely // to include the port number in URIs when it's the default for the // protocol) boolean useDefaultPort = ("http".equalsIgnoreCase(repositoryUri.getScheme()) && repositoryUri.getPort() == 80) || (("https".equalsIgnoreCase(repositoryUri.getScheme()) && repositoryUri.getPort() == 443)); if (useDefaultPort) { repositoryUri = new URI(repositoryUri.getScheme(), repositoryUri.getUserinfo(), repositoryUri.getHost(), -1, repositoryUri.getPath(), repositoryUri.getQuery(), repositoryUri.getFragment()); } return repositoryUri; }
From source file:org.apache.jmeter.protocol.http.control.TestCacheManager.java
@Override public void setUp() throws Exception { super.setUp(); this.cacheManager = new CacheManager(); this.currentTimeInGMT = makeDate(new Date()); this.uri = new URI(LOCAL_HOST, false); this.url = new URL(LOCAL_HOST); this.urlConnection = new URLConnectionStub(this.url.openConnection()); this.httpMethod = new HttpMethodStub(); this.httpUrlConnection = new HttpURLConnectionStub(this.httpMethod, this.url); this.sampleResultOK = getSampleResultWithSpecifiedResponseCode("200"); }
From source file:org.apache.jmeter.protocol.http.control.TestCacheManagerUrlConnectionBase.java
@Override public void setUp() throws Exception { super.setUp(); this.uri = new URI(LOCAL_HOST, false); this.urlConnection = new URLConnectionStub(this.url.openConnection()); this.httpMethod = new HttpMethodStub(); this.httpUrlConnection = new HttpURLConnectionStub(this.httpMethod, this.url); this.httpMethod.setURI(this.uri); }