List of usage examples for java.net URI isAbsolute
public boolean isAbsolute()
From source file:piecework.content.concrete.RemoteContentProvider.java
@Override public ContentResource findByLocation(ContentProfileProvider modelProvider, String location) throws PieceworkException { ContentProfile contentProfile = modelProvider.contentProfile(); // Should never use RemoteContentProvider unless the content profile explicitly // whitelists specific URLs if (contentProfile == null) return null; Set<String> remoteResourceLocations = contentProfile.getRemoteResourceLocations(); URI uri; try {// w w w. java 2 s . com uri = URI.create(location); // Ensure that code does not try to access a local URI if (!uri.isAbsolute()) { LOG.error("Attempting to resolve a relative uri"); throw new ForbiddenError(); } // Ensure that code only tries to access uris with valid schemes ContentUtility.validateScheme(uri, VALID_URI_SCHEMES); ContentUtility.validateRemoteLocation(remoteResourceLocations, uri); return ContentUtility.toContent(client, uri); } catch (IllegalArgumentException iae) { LOG.error("Caught exception trying to find by remote location", iae); return null; } }
From source file:org.jbpm.bpel.xml.ProcessWsdlLocator.java
public InputSource getImportInputSource(String parentLocation, String importLocation) { try {//from ww w . jav a 2 s .c o m // if importLocation is relative, resolve it against parentLocation URI importURI = new URI(importLocation); if (!importURI.isAbsolute()) importLocation = new URI(parentLocation).resolve(importURI).toString(); latestImportURI = importLocation; InputSource inputSource = createInputSource(importLocation); upgradeWsdlDocumentIfNeeded(inputSource); return inputSource; } catch (URISyntaxException e) { log.debug("import location is not a valid URI, returning null source", e); return null; } }
From source file:com.github.ukase.toolkit.WrappedUserAgentCallback.java
@Override public String resolveURI(String uri) { URI resolvingUri = transformUri(uri); if (resolvingUri == null) { return null; }/*from w ww .java 2s. c o m*/ if (resolvingUri.isAbsolute()) { return resolvingUri.toString(); } return resolveUri(resolvingUri); }
From source file:org.apache.cxf.transport.http.asyncclient.CXFHttpAsyncRequestProducer.java
public HttpHost getTarget() { URI uri = request.getURI(); if (uri == null) { throw new IllegalStateException("Request URI is null"); }/*from w w w. jav a2s.c o m*/ if (!uri.isAbsolute()) { throw new IllegalStateException("Request URI is not absolute"); } return new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); }
From source file:com.vmware.appfactory.common.InputFile.java
/** * Multi-purpose function to set either the full URI where this file is * located (if 'location' can be parsed as a URI), or its path relative * to its source./*from ww w. j a va 2 s . c o m*/ * * @param location */ public void setLocation(String location) { try { /* First see if this is an absolute location */ URI uri = new URI(location); if (uri.isAbsolute()) { setURI(uri); return; } } catch (URISyntaxException e) { /* Not a URI? */ } /* Must be a relative path */ setPath(location); }
From source file:net.sourceforge.dita4publishers.tools.dxp.DxpFileOrganizingBosVisitor.java
public void visit(BoundedObjectSet bos) throws Exception { // If there is a root map, then everything is // handled relative to it and there may not be a need // for a manifest, otherwise we need to generate // a manifest map or reorganize the files to put // everything below the root map. BosMember rootMember = bos.getRoot(); if (rootMember != null && rootMember instanceof DitaMapBosMemberImpl) { this.rootMap = rootMember; } else {//from w w w . ja v a2s . c o m this.rootMap = constructDxpManifestMap(bos); } this.rootMapUri = rootMap.getEffectiveUri(); try { this.baseUri = AddressingUtil.getParent(rootMapUri); } catch (URISyntaxException e) { throw new BosException("URI syntax exception calculating base URI for root map: " + e.getMessage()); } catch (MalformedURLException e) { throw new BosException("MalformedURLException calculating base URI for root map: " + e.getMessage()); } catch (IOException e) { throw new BosException("IOException calculating base URI for root map: " + e.getMessage()); } this.rewriteRequired = false; for (BosMember member : bos.getMembers()) { if (member.equals(rootMap)) continue; URI memberUri = member.getEffectiveUri(); URI memberBase = null; try { memberBase = AddressingUtil.getParent(memberUri); } catch (URISyntaxException e) { throw new BosException( "URI syntax exception: " + e.getMessage() + " getting base URI for member " + member); } catch (MalformedURLException e) { throw new BosException( "MalformedURLException: " + e.getMessage() + " getting base URI for member " + member); } catch (IOException e) { throw new BosException("IOException: " + e.getMessage() + " getting base URI for member " + member); } URI relativeUri = baseUri.relativize(memberUri); boolean isAbsolute = relativeUri.isAbsolute(); if (isAbsolute || relativeUri.toString().startsWith("..") || relativeUri.toString().startsWith("/") || memberBase.equals(baseUri)) { // URI is not below the root map, need to rewrite it. rewriteRequired = true; try { URL newUrl = new URL(baseUri.toURL(), "dependencies/" + member.getFileName()); member.setEffectiveUri(newUrl.toURI()); } catch (MalformedURLException e) { throw new BosException("Malformed URL exception: " + e.getMessage() + " constructing new URL for member " + member); } catch (URISyntaxException e) { throw new BosException("URI syntax exception: " + e.getMessage() + " constructing new URI for member " + member); } } } if (rewriteRequired) { UriToUriPointerRewritingBosVisitor rewritingVisitor = new UriToUriPointerRewritingBosVisitor(); rewritingVisitor.visit(bos); } }
From source file:com.navercorp.pinpoint.plugin.httpclient4.interceptor.HttpClientExecuteMethodWithHttpUriRequestInterceptor.java
/** * copy/* w w w . j a v a 2 s . c om*/ * org.apache.http.client.utils.URIUtils#extractHost(java.net.URI) * @param uri * @return */ private NameIntValuePair<String> extractHost(final URI uri) { if (uri == null) { return null; } NameIntValuePair<String> target = null; if (uri.isAbsolute()) { int port = uri.getPort(); // may be overridden later String host = uri.getHost(); if (host == null) { // normal parse failed; let's do it ourselves // authority does not seem to care about the valid character-set // for host names host = uri.getAuthority(); if (host != null) { // Strip off any leading user credentials int at = host.indexOf('@'); if (at >= 0) { if (host.length() > at + 1) { host = host.substring(at + 1); } else { host = null; // @ on its own } } // Extract the port suffix, if present if (host != null) { int colon = host.indexOf(':'); if (colon >= 0) { int pos = colon + 1; int len = 0; for (int i = pos; i < host.length(); i++) { if (Character.isDigit(host.charAt(i))) { len++; } else { break; } } if (len > 0) { try { port = Integer.parseInt(host.substring(pos, pos + len)); } catch (NumberFormatException ignore) { // skip } } host = host.substring(0, colon); } } } } if (host != null) { target = new NameIntValuePair<String>(host, port); } } return target; }
From source file:com.mgmtp.jfunk.data.generator.Generator.java
public void parseXml(final IndexedFields theIndexedFields) throws IOException, JDOMException { this.indexedFields = theIndexedFields; final String generatorFile = configuration.get(GeneratorConstants.GENERATOR_CONFIG_FILE); if (StringUtils.isBlank(generatorFile)) { LOGGER.info("No generator configuration file found"); return;// w ww . j a va 2s . c o m } SAXBuilder builder = new SAXBuilder(); builder.setValidation(true); builder.setIgnoringElementContentWhitespace(false); builder.setFeature("http://apache.org/xml/features/validation/schema/normalized-value", false); builder.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(final String publicId, final String systemId) throws IOException { String resolvedSystemId = configuration.processPropertyValue(systemId); URI uri = URI.create(resolvedSystemId); File file = uri.isAbsolute() ? toFile(uri.toURL()) : new File(uri.toString()); return new InputSource(ResourceLoader.getBufferedReader(file, Charsets.UTF_8.name())); } }); InputStream in = ResourceLoader.getConfigInputStream(generatorFile); Document doc = null; try { String systemId = ResourceLoader.getConfigDir() + '/' + removeExtension(generatorFile) + ".dtd"; doc = builder.build(in, systemId); Element root = doc.getRootElement(); Element charsetsElement = root.getChild(XMLTags.CHARSETS); @SuppressWarnings("unchecked") List<Element> charsetElements = charsetsElement.getChildren(XMLTags.CHARSET); for (Element element : charsetElements) { CharacterSet.initCharacterSet(element); } @SuppressWarnings("unchecked") List<Element> constraintElements = root.getChild(XMLTags.CONSTRAINTS).getChildren(XMLTags.CONSTRAINT); constraints = Lists.newArrayListWithExpectedSize(constraintElements.size()); for (Element element : constraintElements) { constraints.add(constraintFactory.createModel(random, element)); } } finally { closeQuietly(in); } LOGGER.info("Generator was successfully initialized"); }
From source file:org.apache.hise.engine.store.HumanInteractionsCompiler.java
private HumanInteractions compile2(URL resource) throws Exception { Validate.notNull(resource);//from w w w .j a va 2 s . com URL htdXml = resource; THumanInteractions hiDoc; { JAXBContext jaxbContext = JAXBContext.newInstance("org.apache.hise.lang.xsd.htd"); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); hiDoc = ((JAXBElement<THumanInteractions>) unmarshaller.unmarshal(htdXml.openStream())).getValue(); } Set<Definition> definitions = new HashSet<Definition>(); for (TImport tImport : hiDoc.getImport()) { if ("http://schemas.xmlsoap.org/wsdl/".equals(tImport.getImportType())) { try { URI wsdl = new URI(tImport.getLocation()); if (!wsdl.isAbsolute()) { wsdl = htdXml.toURI().resolve(wsdl); } WSDLFactory wsdlf = WSDLFactory.newInstance(); WSDLReader reader = wsdlf.newWSDLReader(); Definition definition = reader.readWSDL(wsdl.toString()); definitions.add(definition); } catch (Exception ex) { log.error("Error during reading wsdl file.", ex); } } } HumanInteractions humanInteractions = new HumanInteractions(); if (hiDoc.getTasks() != null) { for (TTask tTask : hiDoc.getTasks().getTask()) { TaskDefinition taskDefinition = new TaskDefinition(tTask, this.xmlNamespaces, hiDoc.getTargetNamespace()); taskDefinition.setTaskInterface(tTask.getInterface()); QName name = taskDefinition.getTaskName(); if (humanInteractions.getTaskDefinitions().containsKey(name)) { throw new RuntimeException("Duplicate task found, name: " + name + " resource: " + resource); } humanInteractions.getTaskDefinitions().put(name, taskDefinition); QName portTypeName = taskDefinition.getTaskInterface().getPortType(); taskDefinition.setPortType(findPortType(portTypeName, definitions)); } } if (hiDoc.getNotifications() != null) { for (TNotification tnote : hiDoc.getNotifications().getNotification()) { TaskDefinition taskDefinition = new TaskDefinition(tnote, this.xmlNamespaces, hiDoc.getTargetNamespace()); TTaskInterface x = new TTaskInterface(); x.setOperation(tnote.getInterface().getOperation()); x.setPortType(tnote.getInterface().getPortType()); taskDefinition.setTaskInterface(x); QName name = taskDefinition.getTaskName(); if (humanInteractions.getTaskDefinitions().containsKey(name)) { throw new RuntimeException("Duplicate task found, name: " + name + " resource: " + resource); } humanInteractions.getTaskDefinitions().put(name, taskDefinition); QName portTypeName = taskDefinition.getTaskInterface().getPortType(); taskDefinition.setPortType(findPortType(portTypeName, definitions)); } } return humanInteractions; }
From source file:com.granita.icloudcalsync.resource.RemoteCollection.java
Resource.AssetDownloader getDownloader() { return new Resource.AssetDownloader() { @Override/* w w w .j av a2 s .com*/ public byte[] download(URI uri) throws URISyntaxException, IOException, HttpException, DavException { if (!uri.isAbsolute()) throw new URISyntaxException(uri.toString(), "URI referenced from entity must be absolute"); if (uri.getScheme().equalsIgnoreCase(baseURI.getScheme()) && uri.getAuthority().equalsIgnoreCase(baseURI.getAuthority())) { // resource is on same server, send Authorization WebDavResource file = new WebDavResource(collection, uri); file.get("image/*"); return file.getContent(); } else { // resource is on an external server, don't send Authorization return IOUtils.toByteArray(uri); } } }; }