List of usage examples for java.net URI toASCIIString
public String toASCIIString()
From source file:com.netflix.genie.agent.execution.services.impl.FetchingCacheServiceImpl.java
private void lookupOrDownload(final URI sourceFileUri, final File destinationFile) throws DownloadException, IOException { final String uriString = sourceFileUri.toASCIIString(); log.debug("Lookup: {}", uriString); // Unique id to store the resource on local disk final String resourceCacheId = getResourceCacheId(sourceFileUri); // Get a handle to the resource final Resource resource = resourceLoader.getResource(uriString); if (!resource.exists()) { throw new DownloadException("Resource not found: " + uriString); }//from w w w . j a va2 s .c o m final long resourceLastModified = resource.lastModified(); //Handle to resourceCacheId/version final File cacheResourceVersionDir = getCacheResourceVersionDir(resourceCacheId, resourceLastModified); //Create the resource version dir in cache if it does not exist createDirectoryStructureIfNotExists(cacheResourceVersionDir); try (CloseableLock lock = fileLockFactory .getLock(touchCacheResourceVersionLockFile(resourceCacheId, resourceLastModified));) { //Critical section begin lock.lock(); //Handle to the resource cached locally final File cachedResourceVersionDataFile = getCacheResourceVersionDataFile(resourceCacheId, resourceLastModified); if (!cachedResourceVersionDataFile.exists()) { log.debug("Cache miss: {} (id: {})", uriString, resourceCacheId); // Download the resource into the download file in cache // resourceCacheId/version/data.tmp final File cachedResourceVersionDownloadFile = getCacheResourceVersionDownloadFile(resourceCacheId, resourceLastModified); try (InputStream in = resource.getInputStream(); OutputStream out = new FileOutputStream(cachedResourceVersionDownloadFile)) { FileCopyUtils.copy(in, out); Files.move(cachedResourceVersionDownloadFile, cachedResourceVersionDataFile); } } else { log.debug("Cache hit: {} (id: {})", uriString, resourceCacheId); } //Copy from cache data file resourceCacheId/version/DATA_FILE_NAME to targetFile Files.copy(cachedResourceVersionDataFile, destinationFile); //Critical section end } catch (LockException e) { throw new DownloadException("Error downloading dependency", e); } //Clean up any older versions cleanUpTaskExecutor.execute(new CleanupOlderVersionsTask(resourceCacheId, resourceLastModified)); }
From source file:pt.webdetails.di.baserver.utils.inspector.Inspector.java
private boolean inspectEndpoints(final String moduleName) { String endpointUrl;/* w ww. j av a2 s .c om*/ if (moduleName.equals("platform")) { endpointUrl = getBaseUrl(this.serverUrl) + "/application.wadl"; } else { endpointUrl = getBaseUrl(this.serverUrl, moduleName) + "/application.wadl"; } URI uri = null; try { uri = new URI(endpointUrl); } catch (URISyntaxException e) { // do nothing } if (uri != null) { Response response = null; try { response = HttpConnectionHelper.callHttp(uri.toASCIIString(), this.userName, this.password); } catch (IOException e) { // do nothing } catch (KettleStepException e) { // do nothing } if (response != null && response.getStatusCode() == HttpStatus.SC_OK) { SAXReader reader = new SAXReader(); InputStream inputStream = new ByteArrayInputStream(response.getResult().getBytes()); WadlParser parser = new WadlParser(); try { Document doc = reader.read(inputStream); TreeMap<String, LinkedList<Endpoint>> endpointMap = new TreeMap<String, LinkedList<Endpoint>>(); for (Endpoint endpoint : parser.getEndpoints(doc)) { final String path = endpoint.getPath(); if (!endpointMap.containsKey(path)) { endpointMap.put(path, new LinkedList<Endpoint>()); } endpointMap.get(path).add(endpoint); } this.endpoints.put(moduleName, endpointMap); return true; } catch (DocumentException e) { // do nothing } } } return false; }
From source file:at.uni_salzburg.cs.ckgroup.cpcc.engmap.EngMapServlet.java
private void registerMySelfWithMe() throws IOException { URI baseUrl = configuration.getWebApplicationBaseUrl(); if (baseUrl == null) { LOG.error("Web application URL is not configured!"); return;//from w ww . ja v a 2 s. co m } String engineUri = baseUrl.toASCIIString(); if (configuration.isPilotAvailable() && configuration.getPilotUrl() == null) { LOG.error("Pilot URL is not configured!"); return; } String pilotUri = configuration.isPilotAvailable() ? configuration.getPilotUrl().toASCIIString() : null; Set<String> availableSensors; Map<String, String> pilotConfig; try { availableSensors = configuration.isPilotAvailable() ? sensorProxy.getAvailableSensors() : null; pilotConfig = configuration.isPilotAvailable() ? sensorProxy.getPilotConfig() : null; } catch (ParseException e) { throw new IOException(e); } IZone assignedZone = null; for (IZone z : configuration.getZoneSet()) { if (z.getZoneGroup() == Group.LOCAL) { assignedZone = z; break; } } RegData rd = new RegData(engineUri, pilotUri, null, availableSensors, pilotConfig, assignedZone); regdata.put(engineUri, rd); }
From source file:org.apache.olingo.ext.proxy.commons.EntityInvocationHandler.java
public String readEntityReferenceID() { URI id = getEntity() == null ? null : getEntity().getId(); return id == null ? null : id.toASCIIString(); }
From source file:com.yunmall.ymsdk.net.http.AsyncHttpClient.java
/** * Will encode url, if not disabled, and adds params on the end of it * * @param url String with URL, should be valid URL without params * @param params RequestParams to be appended on the end of URL * @param shouldEncodeUrl whether url should be encoded (replaces spaces with %20) * @return encoded url if requested with params appended if any available *///from w w w . java 2s . c o m public static String getUrlWithQueryString(boolean shouldEncodeUrl, String url, RequestParams params) { if (url == null) { return null; } if (shouldEncodeUrl) { try { String decodedURL = URLDecoder.decode(url, "UTF-8"); URL _url = new URL(decodedURL); URI _uri = new URI(_url.getProtocol(), _url.getUserInfo(), _url.getHost(), _url.getPort(), _url.getPath(), _url.getQuery(), _url.getRef()); url = _uri.toASCIIString(); } catch (Exception ex) { // Should not really happen, added just for sake of validity YmLog.e(LOG_TAG, "getUrlWithQueryString encoding URL", ex); } } if (params != null) { // Construct the query string and trim it, in case it // includes any excessive white spaces. String paramString = params.getParamString().trim(); // Only add the query string if it isn't empty and it // isn't equal to '?'. if (!paramString.equals("") && !paramString.equals("?")) { url += url.contains("?") ? "&" : "?"; url += paramString; } } url = url.replaceAll(" ", "%20"); return url; }
From source file:com.whizzosoftware.hobson.wemo.WeMoPlugin.java
protected String minifyURI(URI uri) { if ("http".equals(uri.getScheme()) && uri.getPath().endsWith("setup.xml")) { if (uri.getPort() == 49153) { return uri.getHost(); } else {/*from w w w. j a v a 2 s . com*/ return uri.getHost() + ":" + uri.getPort(); } } else { return uri.toASCIIString(); } }
From source file:eu.planets_project.tb.gui.backing.data.DigitalObjectTreeNode.java
/** * @return a TB download URI:/*from w w w .j av a 2 s. c o m*/ */ public String getDownloadUri() { if (this.getUri() == null) return null; try { URI duri = dh.get(this.getUri().toString()).getDownloadUri(); log.debug("Returning download location: " + duri); if (duri == null) return null; return duri.toASCIIString(); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:org.apache.fop.layoutmgr.ExternalDocumentLayoutManager.java
/** {@inheritDoc} */ public void activateLayout() { initialize();//from ww w .j a v a 2 s. c om FOUserAgent userAgent = pageSeq.getUserAgent(); ImageManager imageManager = userAgent.getFactory().getImageManager(); String uri = URISpecification.getURL(getExternalDocument().getSrc()); Integer firstPageIndex = ImageUtil.getPageIndexFromURI(uri); boolean hasPageIndex = (firstPageIndex != null); try { ImageInfo info = imageManager.getImageInfo(uri, userAgent.getImageSessionContext()); Object moreImages = info.getCustomObjects().get(ImageInfo.HAS_MORE_IMAGES); boolean hasMoreImages = moreImages != null && !Boolean.FALSE.equals(moreImages); Dimension intrinsicSize = info.getSize().getDimensionMpt(); ImageLayout layout = new ImageLayout(getExternalDocument(), this, intrinsicSize); PageSequence pageSequence = new PageSequence(null); transferExtensions(pageSequence); areaTreeHandler.getAreaTreeModel().startPageSequence(pageSequence); if (log.isDebugEnabled()) { log.debug("Starting layout"); } makePageForImage(info, layout); if (!hasPageIndex && hasMoreImages) { if (log.isTraceEnabled()) { log.trace("Starting multi-page processing..."); } URI originalURI; try { originalURI = new URI(URISpecification.escapeURI(uri)); int pageIndex = 1; while (hasMoreImages) { URI tempURI = new URI(originalURI.getScheme(), originalURI.getSchemeSpecificPart(), "page=" + Integer.toString(pageIndex + 1)); if (log.isTraceEnabled()) { log.trace("Subimage: " + tempURI.toASCIIString()); } ImageInfo subinfo = imageManager.getImageInfo(tempURI.toASCIIString(), userAgent.getImageSessionContext()); moreImages = subinfo.getCustomObjects().get(ImageInfo.HAS_MORE_IMAGES); hasMoreImages = moreImages != null && !Boolean.FALSE.equals(moreImages); intrinsicSize = subinfo.getSize().getDimensionMpt(); layout = new ImageLayout(getExternalDocument(), this, intrinsicSize); makePageForImage(subinfo, layout); pageIndex++; } } catch (URISyntaxException e) { getResourceEventProducer().uriError(this, uri, e, getExternalDocument().getLocator()); } } } catch (FileNotFoundException fnfe) { getResourceEventProducer().imageNotFound(this, uri, fnfe, getExternalDocument().getLocator()); } catch (IOException ioe) { getResourceEventProducer().imageIOError(this, uri, ioe, getExternalDocument().getLocator()); } catch (ImageException ie) { getResourceEventProducer().imageError(this, uri, ie, getExternalDocument().getLocator()); } }
From source file:com.wangzhe.autojoin.wangfw.server.jetty9.JettyRunner.java
/** * Create Default Servlet (must be named "default") *//*from w w w .ja v a 2 s .co m*/ private ServletHolder defaultServletHolder(URI baseUri) { ServletHolder holderDefault = new ServletHolder("default", DefaultServlet.class); if (ObjectUtil.isNotEmpty(baseUri)) { LOG.info("Base URI: " + baseUri); holderDefault.setInitParameter("resourceBase", baseUri.toASCIIString()); } else { holderDefault.setInitParameter("resourceBase", param.getWebDir()); } holderDefault.setInitParameter("dirAllowed", "true"); return holderDefault; }
From source file:com.microsoft.tfs.client.common.ui.protocolhandler.ProtocolHandler.java
private boolean tryParseTfsLink(final String tfsLink) { final String decodedTfsLink; try {// w w w . j av a2s.co m decodedTfsLink = new String(Base64.decodeBase64(tfsLink), "UTF-8"); //$NON-NLS-1$ } catch (final UnsupportedEncodingException e) { log.error("Incorrectly encoded the tfslink query parameter in the protocol handler URI", e); //$NON-NLS-1$ return false; } final String[] tfsLinkItems = decodedTfsLink.split("&"); //$NON-NLS-1$ Map<String, AtomicReference<String>> tfsLinkItemMap = prepareTfsLinkItemMap(); for (final String tfsLinkItem : tfsLinkItems) { final int idx = tfsLinkItem.indexOf("="); //$NON-NLS-1$ final String itemName; final String itemValue; if (idx < 0) { itemName = tfsLinkItem; itemValue = StringUtil.EMPTY; } else { itemName = tfsLinkItem.substring(0, idx); itemValue = tfsLinkItem.substring(idx + 1); } if (tfsLinkItemMap.containsKey(itemName)) { log.info(MessageFormat.format(" {0}={1}", //$NON-NLS-1$ itemName, itemValue)); tfsLinkItemMap.get(itemName).set(itemValue); } } if (tfsLinkItemMap.get(PROTOCOL_HANDLER_SERVER_URL_ITEM).get() != null) { /* * A temporary patch. Should be removed after the TFS server is * fixed and sends a collection URL instead of server URL and * collection ID. */ final URI cloneUrl = URIUtils.newURI(tfsLinkItemMap.get(PROTOCOL_HANDLER_CLONE_URL_ITEM).get()); if (ServerURIUtils.isHosted(cloneUrl)) { final URI uriCandidate = URIUtils.newURI(cloneUrl.getScheme(), cloneUrl.getAuthority()); tfsLinkItemMap.get(PROTOCOL_HANDLER_COLLECTION_URL_ITEM).set(uriCandidate.toASCIIString()); } } if (tfsLinkItemMap.get(PROTOCOL_HANDLER_COLLECTION_URL_ITEM).get() == null) { tfsLinkItemMap.remove(PROTOCOL_HANDLER_COLLECTION_URL_ITEM); isCollectionUrlAvailable = false; } else { tfsLinkItemMap.remove(PROTOCOL_HANDLER_COLLECTION_ID_ITEM); tfsLinkItemMap.remove(PROTOCOL_HANDLER_SERVER_URL_ITEM); isCollectionUrlAvailable = true; } for (final AtomicReference<String> value : tfsLinkItemMap.values()) { if (value.get() == null) { return false; } } return true; }