List of usage examples for java.net URI getPath
public String getPath()
From source file:com.subgraph.vega.impl.scanner.handlers.DirIPSCheck.java
private HttpUriRequest createRequest(IPathState ps, String query) { final URI baseUri = ps.getPath().getUri(); try {/* w w w. jav a 2s.co m*/ final URI newUri = new URI(baseUri.getScheme(), baseUri.getAuthority(), baseUri.getPath(), query, null); return new HttpGet(newUri); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
From source file:org.apache.drill.exec.ref.rse.FileSystemRSE.java
public FileSystemRSE(FileSystemRSEConfig engineConfig, DrillConfig dConfig) throws SetupException { this.dConfig = dConfig; try {//ww w . j a v a 2s . co m URI u = new URI(engineConfig.root); String path = u.getPath(); if (path.charAt(path.length() - 1) != '/') throw new SetupException(String.format( "The file root provided of %s included a file '%s'. This must be a base path.", engineConfig.root, u.getPath())); fs = FileSystem.get(u, new Configuration()); basePath = new Path(u.getPath()); } catch (URISyntaxException | IOException e) { throw new SetupException("Failure while reading setting up file system root path.", e); } }
From source file:com.bazaarvoice.seo.sdk.util.BVUtilty.java
public static String removeBVQuery(String queryUrl) { final URI uri; try {/*from ww w. j ava 2 s. c om*/ uri = new URI(queryUrl); } catch (URISyntaxException e) { return queryUrl; } try { String newQuery = null; if (uri.getQuery() != null && uri.getQuery().length() > 0) { List<NameValuePair> newParameters = new ArrayList<NameValuePair>(); List<NameValuePair> parameters = URLEncodedUtils.parse(uri.getQuery(), Charset.forName("UTF-8")); List<String> bvParameters = Arrays.asList("bvrrp", "bvsyp", "bvqap", "bvpage"); for (NameValuePair parameter : parameters) { if (!bvParameters.contains(parameter.getName())) { newParameters.add(parameter); } } newQuery = newParameters.size() > 0 ? URLEncodedUtils.format(newParameters, Charset.forName("UTF-8")) : null; } return new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), newQuery, null).toString(); } catch (URISyntaxException e) { return queryUrl; } }
From source file:corner.hadoop.services.impl.LocalFileAccessorProxy.java
public LocalFileAccessorProxy(String basePath) { URI uri; try {// ww w . java 2s . c o m uri = new URI(basePath); this.path = uri.getPath(); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
From source file:org.xwiki.contrib.repository.bintray.internal.BintrayMavenExtensionRepository.java
private void populateSubjectRepoFields(URI uri) { String[] pathElements = uri.getPath().split("/"); subject = pathElements[1];//ww w. j a va 2s.co m repo = pathElements[2]; }
From source file:com.twitter.distributedlog.TestDistributedLogBase.java
protected void ensureURICreated(ZooKeeper zkc, URI uri) throws Exception { try {/*from w w w . j av a 2 s.c om*/ zkc.create(uri.getPath(), new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } catch (KeeperException.NodeExistsException nee) { // ignore } }
From source file:edu.ucsb.eucalyptus.cloud.ws.HttpTransfer.java
public HttpMethodBase constructHttpMethod(String verb, String addr, String eucaOperation, String eucaHeader) { String date = new Date().toString(); String httpVerb = verb;// w w w . java 2 s .c om String addrPath; try { java.net.URI addrUri = new URL(addr).toURI(); addrPath = addrUri.getPath().toString(); String query = addrUri.getQuery(); if (query != null) { addrPath += "?" + query; } } catch (Exception ex) { LOG.error(ex, ex); return null; } String data = httpVerb + "\n" + date + "\n" + addrPath + "\n"; HttpMethodBase method = null; if (httpVerb.equals("PUT")) { method = new PutMethodWithProgress(addr); } else if (httpVerb.equals("DELETE")) { method = new DeleteMethod(addr); } else { method = new GetMethod(addr); } method.setRequestHeader("Authorization", "Euca"); method.setRequestHeader("Date", date); //method.setRequestHeader("Expect", "100-continue"); method.setRequestHeader(StorageProperties.EUCALYPTUS_OPERATION, eucaOperation); if (eucaHeader != null) { method.setRequestHeader(StorageProperties.EUCALYPTUS_HEADER, eucaHeader); } try { PrivateKey ccPrivateKey = SystemCredentials.lookup(Storage.class).getPrivateKey(); Signature sign = Signature.getInstance("SHA1withRSA"); sign.initSign(ccPrivateKey); sign.update(data.getBytes()); byte[] sig = sign.sign(); method.setRequestHeader("EucaSignature", new String(Base64.encode(sig))); } catch (Exception ex) { LOG.error(ex, ex); } return method; }
From source file:lucee.commons.net.http.httpclient.HTTPResponse4Impl.java
public URL getTargetURL() { URL start = getURL();//from w w w.j a v a 2 s. c om HttpUriRequest req = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); URI uri = req.getURI(); String path = uri.getPath(); String query = uri.getQuery(); if (!StringUtil.isEmpty(query)) path += "?" + query; URL _url = start; try { _url = new URL(start.getProtocol(), start.getHost(), start.getPort(), path); } catch (MalformedURLException e) { } return _url; }
From source file:eu.asterics.mw.services.ResourceRegistry.java
/** * Returns a File object representing the given URI if possible. * This only works if the given URI is a relative path or is a path with a file scheme (starting with: file) * @param uri/*from w ww.j a va 2 s . c o m*/ * @return * @throws URISyntaxException */ public static File toFile(URI uri) throws URISyntaxException { String scheme = uri.getScheme(); if (scheme != null && !scheme.startsWith("file")) { throw new URISyntaxException(uri.toString(), "The uri does not start with the scheme <file>"); } File f = new File(uri.getPath()); return f; }
From source file:org.ambraproject.wombat.service.remote.AbstractRemoteService.java
@Override public CloseableHttpResponse getResponse(HttpUriRequest target) throws IOException { // Don't close the client, as this shuts down the connection pool. Do close every response or its entity stream. CloseableHttpClient client = createClient(); // We want to return an unclosed response, so close the response only if we throw an exception. boolean returningResponse = false; CloseableHttpResponse response = null; try {//ww w. j a v a2 s .c o m try { response = client.execute(target); } catch (HttpHostConnectException e) { throw new ServiceConnectionException(e); } StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (isErrorStatus(statusCode)) { URI targetUri = target.getURI(); String address = targetUri.getPath(); if (!Strings.isNullOrEmpty(targetUri.getQuery())) { address += "?" + targetUri.getQuery(); } if (statusCode == HttpStatus.NOT_FOUND.value()) { throw new EntityNotFoundException(address); } else { String responseBody = IOUtils.toString(response.getEntity().getContent()); String message = String.format("Request to \"%s\" failed (%d): %s.", address, statusCode, statusLine.getReasonPhrase()); throw new ServiceRequestException(statusCode, message, responseBody); } } returningResponse = true; return response; } finally { if (!returningResponse && response != null) { response.close(); } } }