List of usage examples for java.net URI isAbsolute
public boolean isAbsolute()
From source file:org.neo4j.server.helpers.ServerBuilder.java
public ServerBuilder withRelativeWebDataAdminUriPath(String webAdminDataUri) { try {//from w w w . j a v a 2 s. c o m URI theUri = new URI(webAdminDataUri); if (theUri.isAbsolute()) { this.webAdminDataUri = theUri.getPath(); } else { this.webAdminDataUri = theUri.toString(); } } catch (URISyntaxException e) { throw new RuntimeException(e); } return this; }
From source file:org.mycore.common.xml.MCREntityResolver.java
@Override public InputSource resolveEntity(String name, String publicId, String baseURI, String systemId) throws SAXException, IOException { if (LOGGER.isDebugEnabled()) { LOGGER.debug(MessageFormat.format("Resolving: \nname: {0}\npublicId: {1}\nbaseURI: {2}\nsystemId: {3}", name, publicId, baseURI, systemId)); }//from w w w. j av a 2 s . c o m InputSource entity = catalogResolver.resolveEntity(name, publicId, baseURI, systemId); if (entity != null) { return resolvedEntity(entity); } if (systemId == null) { return null; // Use default resolver } if (systemId.length() == 0) { // if you overwrite SYSTEM by empty String in XSL return new InputSource(new StringReader("")); } //resolve against base: URI absoluteSystemId = resolveRelativeURI(baseURI, systemId); if (absoluteSystemId.isAbsolute() && uriExists(absoluteSystemId)) { InputSource inputSource = new InputSource(absoluteSystemId.toString()); inputSource.setPublicId(publicId); return resolvedEntity(inputSource); } //required for XSD files that are usually classpath resources InputSource is = getCachedResource("/" + systemId); if (is == null) { return null; } is.setPublicId(publicId); return resolvedEntity(is); }
From source file:org.apache.gobblin.source.extractor.filebased.FileBasedSource.java
/** * This method is responsible for connecting to the source and taking * a snapshot of the folder where the data is present, it then returns * a list of the files in String format/*from w w w. ja va 2s. c o m*/ * @param state is used to connect to the source * @return a list of file name or paths present on the external data * directory */ public List<String> getcurrentFsSnapshot(State state) { List<String> results = new ArrayList<>(); String path = getLsPattern(state); try { log.info("Running ls command with input " + path); results = this.fsHelper.ls(path); for (int i = 0; i < results.size(); i++) { URI uri = new URI(results.get(i)); String filePath = uri.toString(); if (!uri.isAbsolute()) { File file = new File(state.getProp(ConfigurationKeys.SOURCE_FILEBASED_DATA_DIRECTORY), uri.toString()); filePath = file.getAbsolutePath(); } results.set(i, filePath + this.splitPattern + this.fsHelper.getFileMTime(filePath)); } } catch (FileBasedHelperException | URISyntaxException e) { log.error("Not able to fetch the filename/file modified time to " + e.getMessage() + " will not pull any files", e); } return results; }
From source file:org.apache.woden.internal.resolver.SimpleURIResolver.java
/** * Takes a set of properties representing {resolved-from, resolved-to} URI pairs * and converts to a Hashtable. //from ww w . ja v a2 s .c o m * Any relative resolved-to URIs are "converted ("resolved"!) to absolute location * using the supplied classloader. Any entries for which such a convesion fails are ignored noisily. * * @param p * @param loader - class * @param h * @return HashTable mapping resolved-from URIs to absolute resolved-to URIs * @throws URISyntaxException */ private Hashtable toURI(Properties p, ClassLoader loader, Hashtable h) throws URISyntaxException { // TODO change to throw a WSDLException if (p != null) { Enumeration keys = p.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); String value = p.getProperty(key); try { // if value represents an absolute URL (ie has a scheme) keep as-is // otherwise treat as relative to the URLClassloader search locations. // If the relative resource cannot be located via the class loader, // ignore the entry noisily. URI valueURI = new URI(value); if (!valueURI.isAbsolute()) { // Relative URI so use class loader lookup... URL valueURL = loader.getResource(value); if (valueURL != null) { // lookup successful valueURI = new URI(valueURL.toString()); h.put(new URI(key), valueURI); //TODO - can we replace with java.net.URL's? } else { // Report failed lookup on relative URL on RHS of catalog entry // TODO ignore noisily logger.error("Lookup failed for URL " + value); } } else { // Absolute URI - preserve as-is h.put(new URI(key), valueURI); } } catch (URISyntaxException e) { // TODO ignore noisily logger.error("Invalid URL " + value + ": " + e.getMessage()); } } } return h; }
From source file:com.couchbase.client.vbucket.ConfigurationProviderHTTP.java
/** * Create a URL which has the appropriate headers to interact with the * service. Most exception handling is up to the caller. * * @param resource the URI either absolute or relative to the base for this * ClientManager//from ww w.jav a 2 s . c om * @return * @throws java.io.IOException */ private URLConnection urlConnBuilder(URI base, URI resource) throws IOException { if (!resource.isAbsolute() && base != null) { resource = base.resolve(resource); } URL specURL = resource.toURL(); URLConnection connection = specURL.openConnection(); connection.setRequestProperty("Accept", "application/json"); connection.setRequestProperty("user-agent", "spymemcached vbucket client"); connection.setRequestProperty("X-memcachekv-Store-Client-" + "Specification-Version", CLIENT_SPEC_VER); if (restUsr != null) { try { connection.setRequestProperty("Authorization", buildAuthHeader(restUsr, restPwd)); } catch (UnsupportedEncodingException ex) { throw new IOException("Could not encode specified credentials for " + "HTTP request.", ex); } } return connection; }
From source file:org.dita.dost.ant.PluginInstallTask.java
public void setPluginFile(final String pluginFile) { try {// w w w . j ava 2s. c o m this.pluginFile = Paths.get(pluginFile); } catch (InvalidPathException e) { // Ignore } try { final URI uri = new URI(pluginFile); if (uri.isAbsolute()) { this.pluginUrl = uri.toURL(); } } catch (MalformedURLException | URISyntaxException e) { // Ignore } if (pluginFile.contains("@")) { final String[] tokens = pluginFile.split("@"); pluginName = tokens[0]; pluginVersion = new SemVerMatch(tokens[1]); } else { pluginName = pluginFile; pluginVersion = null; } }
From source file:org.openmidaas.app.activities.MainTabActivity.java
void processUrl(String result) { try {//from w ww . ja v a 2 s . c o m URI uri = new URI(result); if (uri.isAbsolute()) { if (uri.getScheme().equals("http") || uri.getScheme().equals("https")) { //Check for the lock before starting to process if (SessionManager.getBusyness() == false) { AsyncHttpClient client = new AsyncHttpClient(); mProgressDialog.setMessage("Loading..."); mProgressDialog.show(); client.get(uri.toString(), new AsyncHttpResponseHandler() { @Override public void onSuccess(String response) { cancelCurrentProgressDialog(); Intent intent = new Intent(mActivity, AuthorizationActivity.class); intent.putExtra(AuthorizationActivity.REQUEST_BUNDLE_KEY, response); startActivity(intent); } @Override public void onFailure(Throwable e, String response) { cancelCurrentProgressDialog(); DialogUtils.showNeutralButtonDialog(mActivity, "Error", e.getMessage()); } }); } } else { DialogUtils.showNeutralButtonDialog(mActivity, getResources().getString(R.string.invalidURIType), result); } } else { DialogUtils.showNeutralButtonDialog(mActivity, getResources().getString(R.string.invalidURI), getResources().getString(R.string.unknownURIFormat) + " " + result); } } catch (URISyntaxException e) { DialogUtils.showNeutralButtonDialog(mActivity, getResources().getString(R.string.invalidURI), getResources().getString(R.string.invalidURI) + " " + result); } }
From source file:org.apache.taverna.scufl2.rdfxml.WorkflowParser.java
@SuppressWarnings("unchecked") protected void readWorkflow(URI wfUri, URI source) throws ReaderException, IOException { if (source.isAbsolute()) throw new ReaderException("Can't read external workflow source " + source); InputStream bundleStream = getParserState().getUcfPackage().getResourceAsInputStream(source.getRawPath()); JAXBElement<WorkflowDocument> elem; try {/*w w w . j a va2s .co m*/ elem = (JAXBElement<WorkflowDocument>) unmarshaller.unmarshal(bundleStream); } catch (JAXBException e) { throw new ReaderException("Can't parse workflow document " + source, e); } URI base = getParserState().getLocation().resolve(source); if (elem.getValue().getBase() != null) base = base.resolve(elem.getValue().getBase()); if (elem.getValue().getAny().size() != 1) throw new ReaderException("Expects only a <Workflow> element in " + source); org.apache.taverna.scufl2.xml.Workflow workflow = (org.apache.taverna.scufl2.xml.Workflow) elem.getValue() .getAny().get(0); getParserState().setCurrentBase(base); parseWorkflow(workflow, wfUri); }
From source file:com.epam.reportportal.apache.http.impl.execchain.MinimalClientExec.java
public CloseableHttpResponse execute(final HttpRoute route, final HttpRequestWrapper request, final HttpClientContext context, final HttpExecutionAware execAware) throws IOException, HttpException { Args.notNull(route, "HTTP route"); Args.notNull(request, "HTTP request"); Args.notNull(context, "HTTP context"); rewriteRequestURI(request, route);/*from w ww . j a va 2 s. co m*/ final ConnectionRequest connRequest = connManager.requestConnection(route, null); if (execAware != null) { if (execAware.isAborted()) { connRequest.cancel(); throw new RequestAbortedException("Request aborted"); } else { execAware.setCancellable(connRequest); } } final RequestConfig config = context.getRequestConfig(); final HttpClientConnection managedConn; try { final int timeout = config.getConnectionRequestTimeout(); managedConn = connRequest.get(timeout > 0 ? timeout : 0, TimeUnit.MILLISECONDS); } catch (final InterruptedException interrupted) { Thread.currentThread().interrupt(); throw new RequestAbortedException("Request aborted", interrupted); } catch (final ExecutionException ex) { Throwable cause = ex.getCause(); if (cause == null) { cause = ex; } throw new RequestAbortedException("Request execution failed", cause); } final ConnectionHolder releaseTrigger = new ConnectionHolder(log, connManager, managedConn); try { if (execAware != null) { if (execAware.isAborted()) { releaseTrigger.close(); throw new RequestAbortedException("Request aborted"); } else { execAware.setCancellable(releaseTrigger); } } if (!managedConn.isOpen()) { final int timeout = config.getConnectTimeout(); this.connManager.connect(managedConn, route, timeout > 0 ? timeout : 0, context); this.connManager.routeComplete(managedConn, route, context); } final int timeout = config.getSocketTimeout(); if (timeout >= 0) { managedConn.setSocketTimeout(timeout); } HttpHost target = null; final HttpRequest original = request.getOriginal(); if (original instanceof HttpUriRequest) { final URI uri = ((HttpUriRequest) original).getURI(); if (uri.isAbsolute()) { target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); } } if (target == null) { target = route.getTargetHost(); } context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, target); context.setAttribute(HttpCoreContext.HTTP_REQUEST, request); context.setAttribute(HttpCoreContext.HTTP_CONNECTION, managedConn); context.setAttribute(HttpClientContext.HTTP_ROUTE, route); httpProcessor.process(request, context); final HttpResponse response = requestExecutor.execute(request, managedConn, context); httpProcessor.process(response, context); // The connection is in or can be brought to a re-usable state. if (reuseStrategy.keepAlive(response, context)) { // Set the idle duration of this connection final long duration = keepAliveStrategy.getKeepAliveDuration(response, context); releaseTrigger.setValidFor(duration, TimeUnit.MILLISECONDS); releaseTrigger.markReusable(); } else { releaseTrigger.markNonReusable(); } // check for entity, release connection if possible final HttpEntity entity = response.getEntity(); if (entity == null || !entity.isStreaming()) { // connection not needed and (assumed to be) in re-usable state releaseTrigger.releaseConnection(); return Proxies.enhanceResponse(response, null); } else { return Proxies.enhanceResponse(response, releaseTrigger); } } catch (final ConnectionShutdownException ex) { final InterruptedIOException ioex = new InterruptedIOException("Connection has been shut down"); ioex.initCause(ex); throw ioex; } catch (final HttpException ex) { releaseTrigger.abortConnection(); throw ex; } catch (final IOException ex) { releaseTrigger.abortConnection(); throw ex; } catch (final RuntimeException ex) { releaseTrigger.abortConnection(); throw ex; } }
From source file:org.apache.http.HC4.impl.execchain.MinimalClientExec.java
@Override public CloseableHttpResponse execute(final HttpRoute route, final HttpRequestWrapper request, final HttpClientContext context, final HttpExecutionAware execAware) throws IOException, HttpException { Args.notNull(route, "HTTP route"); Args.notNull(request, "HTTP request"); Args.notNull(context, "HTTP context"); rewriteRequestURI(request, route);/* w ww. ja v a 2 s .c om*/ final ConnectionRequest connRequest = connManager.requestConnection(route, null); if (execAware != null) { if (execAware.isAborted()) { connRequest.cancel(); throw new RequestAbortedException("Request aborted"); } else { execAware.setCancellable(connRequest); } } final RequestConfig config = context.getRequestConfig(); final HttpClientConnection managedConn; try { final int timeout = config.getConnectionRequestTimeout(); managedConn = connRequest.get(timeout > 0 ? timeout : 0, TimeUnit.MILLISECONDS); } catch (final InterruptedException interrupted) { Thread.currentThread().interrupt(); throw new RequestAbortedException("Request aborted", interrupted); } catch (final ExecutionException ex) { Throwable cause = ex.getCause(); if (cause == null) { cause = ex; } throw new RequestAbortedException("Request execution failed", cause); } final ConnectionHolder releaseTrigger = new ConnectionHolder(log, connManager, managedConn); try { if (execAware != null) { if (execAware.isAborted()) { releaseTrigger.close(); throw new RequestAbortedException("Request aborted"); } else { execAware.setCancellable(releaseTrigger); } } if (!managedConn.isOpen()) { final int timeout = config.getConnectTimeout(); this.connManager.connect(managedConn, route, timeout > 0 ? timeout : 0, context); this.connManager.routeComplete(managedConn, route, context); } final int timeout = config.getSocketTimeout(); if (timeout >= 0) { managedConn.setSocketTimeout(timeout); } HttpHost target = null; final HttpRequest original = request.getOriginal(); if (original instanceof HttpUriRequest) { final URI uri = ((HttpUriRequest) original).getURI(); if (uri.isAbsolute()) { target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); } } if (target == null) { target = route.getTargetHost(); } context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, target); context.setAttribute(HttpCoreContext.HTTP_REQUEST, request); context.setAttribute(HttpCoreContext.HTTP_CONNECTION, managedConn); context.setAttribute(HttpClientContext.HTTP_ROUTE, route); httpProcessor.process(request, context); final HttpResponse response = requestExecutor.execute(request, managedConn, context); httpProcessor.process(response, context); // The connection is in or can be brought to a re-usable state. if (reuseStrategy.keepAlive(response, context)) { // Set the idle duration of this connection final long duration = keepAliveStrategy.getKeepAliveDuration(response, context); releaseTrigger.setValidFor(duration, TimeUnit.MILLISECONDS); releaseTrigger.markReusable(); } else { releaseTrigger.markNonReusable(); } // check for entity, release connection if possible final HttpEntity entity = response.getEntity(); if (entity == null || !entity.isStreaming()) { // connection not needed and (assumed to be) in re-usable state releaseTrigger.releaseConnection(); return new HttpResponseProxy(response, null); } else { return new HttpResponseProxy(response, releaseTrigger); } } catch (final ConnectionShutdownException ex) { final InterruptedIOException ioex = new InterruptedIOException("Connection has been shut down"); ioex.initCause(ex); throw ioex; } catch (final HttpException ex) { releaseTrigger.abortConnection(); throw ex; } catch (final IOException ex) { releaseTrigger.abortConnection(); throw ex; } catch (final RuntimeException ex) { releaseTrigger.abortConnection(); throw ex; } }