Example usage for java.net URI isAbsolute

List of usage examples for java.net URI isAbsolute

Introduction

In this page you can find the example usage for java.net URI isAbsolute.

Prototype

public boolean isAbsolute() 

Source Link

Document

Tells whether or not this URI is absolute.

Usage

From source file:org.neo4j.server.helpers.CommunityServerBuilder.java

public CommunityServerBuilder withRelativeWebDataAdminUriPath(String webAdminDataUri) {
    try {//w  w w. j  av  a 2s .  c  om
        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:clj_httpc.CustomRedirectStrategy.java

public URI getLocationURI(final HttpRequest request, final HttpResponse response, final HttpContext context)
        throws ProtocolException {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }//from   w w  w. j ava 2s  . c o  m
    //get the location header to find out where to redirect to
    Header locationHeader = response.getFirstHeader("location");
    if (locationHeader == null) {
        // got a redirect response, but no location header
        throw new ProtocolException(
                "Received redirect response " + response.getStatusLine() + " but no location header");
    }
    String location = locationHeader.getValue();
    if (this.log.isDebugEnabled()) {
        this.log.debug("Redirect requested to location '" + location + "'");
    }

    URI uri = createLocationURI(location);

    HttpParams params = response.getParams();
    // rfc2616 demands the location value be a complete URI
    // Location       = "Location" ":" absoluteURI
    if (!uri.isAbsolute()) {
        if (params.isParameterTrue(ClientPNames.REJECT_RELATIVE_REDIRECT)) {
            throw new ProtocolException("Relative redirect location '" + uri + "' not allowed");
        }
        // Adjust location URI
        HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
        if (target == null) {
            throw new IllegalStateException("Target host not available " + "in the HTTP context");
        }
        try {
            URI requestURI = new URI(request.getRequestLine().getUri());
            URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, true);
            uri = URIUtils.resolve(absoluteRequestURI, uri);
        } catch (URISyntaxException ex) {
            throw new ProtocolException(ex.getMessage(), ex);
        }
    }

    if (params.isParameterFalse(ClientPNames.ALLOW_CIRCULAR_REDIRECTS)) {

        CustomRedirectLocations redirectLocations = (CustomRedirectLocations) context
                .getAttribute(REDIRECT_LOCATIONS);

        if (redirectLocations == null) {
            redirectLocations = new CustomRedirectLocations();
            context.setAttribute(REDIRECT_LOCATIONS, redirectLocations);
        }

        URI redirectURI;
        if (uri.getFragment() != null) {
            try {
                HttpHost target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
                redirectURI = URIUtils.rewriteURI(uri, target, true);
            } catch (URISyntaxException ex) {
                throw new ProtocolException(ex.getMessage(), ex);
            }
        } else {
            redirectURI = uri;
        }

        if (redirectLocations.contains(redirectURI)) {
            throw new CircularRedirectException("Circular redirect to '" + redirectURI + "'");
        } else {
            int statusCode = response.getStatusLine().getStatusCode();
            redirectLocations.add(redirectURI, statusCode);
        }
    }

    return uri;
}

From source file:org.apache.ode.bpel.compiler.DefaultResourceFinder.java

private InputStream openFileResource(URI uri) throws MalformedURLException, IOException {
    URI absolute = _absoluteDir.toURI();
    if (__log.isDebugEnabled()) {
        __log.debug(/*from  w ww .  j a va  2s. co  m*/
                "openResource: uri=" + uri + " relativeDir=" + _relativeDir + " absoluteDir=" + _absoluteDir);
    }

    if (uri.isAbsolute() && uri.getScheme().equals("file")) {
        try {
            return uri.toURL().openStream();
        } catch (Exception except) {
            __log.debug("openResource: unable to open file URL " + uri + "; " + except.toString());
            return null;
        }
    }

    // Note that if we get an absolute URI, the relativize operation will simply
    // return the absolute URI.
    URI relative = _relativeDir.toURI().relativize(uri);
    if (relative.isAbsolute() && !(relative.getScheme().equals("urn"))) {
        __log.fatal("openResource: invalid scheme (should be urn:)  " + uri);
        return null;
    }

    File f = new File(absolute.getPath(), relative.getPath());
    if (f.exists()) {
        return new FileInputStream(f);
    } else {
        if (__log.isDebugEnabled()) {
            __log.debug("fileNotFound: " + f);
        }
        return null;
    }
}

From source file:com.gooddata.gdc.DataStoreService.java

private UriPrefixer getPrefixer() {
    if (prefixer == null) {
        final String uriString = gdcService.getRootLinks().getUserStagingUri();
        final URI uri = URI.create(uriString);
        prefixer = new UriPrefixer(uri.isAbsolute() ? uri : gdcUri.resolve(uriString));
        sardine.enablePreemptiveAuthentication(prefixer.getUriPrefix().getHost());
    }/*from  w  w  w .j a v a  2s  . c  o  m*/
    return prefixer;
}

From source file:com.collaborne.jsonschema.validator.plugin.ValidateMojo.java

@VisibleForTesting
protected URITranslatorConfigurationBuilder addSchemaMappings(URITranslatorConfigurationBuilder builder)
        throws MojoExecutionException {
    for (DirectoryURIMapping schemaMapping : schemaMappings) {
        URI uri = schemaMapping.uri;
        if (uri.getFragment() != null) {
            throw new MojoExecutionException("URI " + uri + " must not contain a fragment");
        }//from  w  w  w .j  a va 2 s . com
        if (!uri.isAbsolute()) {
            throw new MojoExecutionException("URI " + uri + " must be absolute");
        }
        // Check the path (and fix it up for the obvious issues)
        String path = uri.getPath();
        if (path == null) {
            path = "/";
        }
        if (!path.endsWith("/")) {
            getLog().warn("URI " + uri + " does not end with '/'");
            path += "/";
            try {
                uri = new URI(uri.getScheme(), uri.getAuthority(), path, uri.getQuery(), uri.getFragment());
            } catch (URISyntaxException e) {
                // Basically impossible: it was (syntactically) valid before that.
                throw new MojoExecutionException("Cannot construct fixed URI", e);
            }
        }
        getLog().debug("Mapping " + schemaMapping.directory + " to " + uri);
        builder.addPathRedirect(uri, schemaMapping.directory.toURI());
    }
    return builder;
}

From source file:org.semanticweb.owlapi.model.IRI.java

/**
 * @param s the IRI stirng to be resolved
 * @return s resolved against this IRI (with the URI::resolve() method, unless this IRI is
 *         opaque)//from  ww w  .j av  a 2  s  .co m
 */
public IRI resolve(String s) {
    // shortcut: checking absolute and opaque here saves the creation of an
    // extra URI object
    URI uri = URI.create(s);
    if (uri.isAbsolute() || uri.isOpaque()) {
        return create(uri);
    }
    return create(toURI().resolve(uri));
}

From source file:ru.histone.HistoneBuilder.java

/**
 * Builds new Histone engine using current HistoneBuilder settings/resources loaders/etc<br/>
 * This method creates new Histone template engine
 *
 * @return Histone engine instance/*from   w w w.  java 2s  .c  om*/
 * @throws HistoneException if error during histone initialization occurs
 */
public Histone build() throws HistoneException {
    log.debug("Building new Histone template engine");

    TokenizerFactory tokenizerFactory = new TokenizerFactory(HistoneTokensHolder.getTokens());
    OldParser parser = new OldParser(tokenizerFactory, nodeFactory);

    EvaluatorBootstrap evaluatorBootstrap = new EvaluatorBootstrap();
    evaluatorBootstrap.setNodeFactory(nodeFactory);
    evaluatorBootstrap.setParser(parser);
    URI baseURI = extractBaseURI(globalProperties);
    if (baseURI != null) {
        if (!baseURI.isAbsolute()) {
            throw new HistoneException(
                    String.format("baseURI = '%s' and it's not absolute URI!", baseURI.toString()));
        }
        if (baseURI.isOpaque()) {
            throw new HistoneException(
                    String.format("baseURI = '%s' and it's opaque URI!", baseURI.toString()));
        }
    }
    GlobalFunctionsManager globalFunctionsManager = new GlobalFunctionsManager(globalFunctions);
    NodeFunctionsManager nodeFunctionsManager = new NodeFunctionsManager(nodeFunctions);

    if (resourceLoader instanceof DefaultResourceLoader) {
        ((DefaultResourceLoader) resourceLoader).setHttpClientConnectionManager(httpClientConnectionManager);
    }
    evaluatorBootstrap.setResourceLoader(resourceLoader);
    evaluatorBootstrap.setGlobalFunctionsManager(globalFunctionsManager);
    evaluatorBootstrap.setNodeFunctionsManager(nodeFunctionsManager);

    GlobalObjectNode global = new GlobalObjectNode(nodeFactory);
    for (Map.Entry<GlobalProperty, Node> entry : globalProperties.entrySet()) {
        global.add(entry.getKey().getName(), entry.getValue());
    }
    evaluatorBootstrap.setGlobal(global);

    Evaluator evaluator = new Evaluator(evaluatorBootstrap);

    AstImportResolver astImportResolver = new AstImportResolver(parser, resourceLoader, nodeFactory);

    HistoneBootstrap histoneBootstrap = new HistoneBootstrap();
    histoneBootstrap.setNodeFactory(nodeFactory);
    histoneBootstrap.setParser(parser);
    histoneBootstrap.setEvaluator(evaluator);
    histoneBootstrap.setResourceLoader(new DefaultResourceLoader());

    return new Histone(histoneBootstrap);
}

From source file:org.wso2.carbon.identity.application.authentication.framework.listener.AuthenticationEndpointTenantActivityListener.java

/**
 * Initialize listener//from w ww  .j  av a  2  s . co  m
 */
private synchronized void init() {
    try {
        tenantDataReceiveURLs = ConfigurationFacade.getInstance().getTenantDataEndpointURLs();

        if (!tenantDataReceiveURLs.isEmpty()) {

            serverURL = IdentityUtil.getServerURL("");
            int index = 0;

            for (String tenantDataReceiveUrl : tenantDataReceiveURLs) {
                URI tenantDataReceiveURI = new URI(tenantDataReceiveUrl);

                if (log.isDebugEnabled()) {
                    log.debug("Tenant list receiving url added : " + tenantDataReceiveUrl);
                }

                if (!tenantDataReceiveURI.isAbsolute()) {
                    // Set the absolute URL for tenant list receiving endpoint
                    tenantDataReceiveURLs.set(index, serverURL + tenantDataReceiveUrl);
                }
                index++;
            }
            RealmService realmService = (RealmService) PrivilegedCarbonContext.getThreadLocalCarbonContext()
                    .getOSGiService(RealmService.class);

            if (realmService != null) {
                tenantManager = realmService.getTenantManager();
            }
            initialized = true;
        } else {
            if (log.isDebugEnabled()) {
                log.debug("TenantDataListenerURLs are not set in configuration");
            }
        }
    } catch (URISyntaxException e) {
        log.error("Error while getting TenantDataListenerURLs", e);
    }
}

From source file:org.fcrepo.http.api.ExternalContentPathValidator.java

/**
 * Validates that an external path is valid. The path must be an HTTP or file URI within the allow list of paths,
 * be absolute, and contain no relative modifier.
 *
 * @param extPath external binary path to validate
 * @throws ExternalMessageBodyException thrown if the path is invalid.
 *///from   w  w  w. j a  v a  2 s. c o  m
public void validate(final String extPath) throws ExternalMessageBodyException {
    if (allowedList == null || allowedList.size() == 0) {
        throw new ExternalMessageBodyException("External content is disallowed by the server");
    }

    if (isEmpty(extPath)) {
        throw new ExternalMessageBodyException("External content path was empty");
    }

    final String path = normalizePath(extPath.toLowerCase());
    if (RELATIVE_MOD_PATTERN.matcher(path).matches()) {
        throw new ExternalMessageBodyException("Path was not absolute: " + extPath);
    }

    final URI uri;
    try {
        uri = new URI(path);
    } catch (final URISyntaxException e) {
        throw new ExternalMessageBodyException("Path was not a valid URI: " + extPath);
    }
    if (!uri.isAbsolute()) {
        throw new ExternalMessageBodyException("Path was not absolute: " + extPath);
    }
    if (!ALLOWED_SCHEMES.contains(uri.getScheme())) {
        throw new ExternalMessageBodyException("Path did not provide an allowed scheme: " + extPath);
    }

    if (allowedList.stream().anyMatch(allowed -> path.startsWith(allowed))) {
        return;
    }
    throw new ExternalMessageBodyException("Path did not match any allowed external content paths: " + extPath);
}

From source file:org.trancecode.xproc.binding.DataPortBinding.java

private void writeContent(final SaxonBuilder builder) {
    final URI uri = URI.create(href);
    if (uri.getScheme() != null && !StringUtils.equals("file", uri.getScheme())
            && !StringUtils.equals("http", uri.getScheme())) {
        throw XProcExceptions.xd0012(this.getLocation(), uri.toASCIIString());
    }//from w w w. j ava 2 s .  c o m
    try {
        final URL url;
        if (uri.isAbsolute()) {
            url = uri.toURL();
        } else {
            url = node.getBaseURI().resolve(uri).toURL();
        }
        final QName contentTypeAtt = (wrapper == null) ? XProcXmlModel.Attributes.CONTENT_TYPE
                : XProcXmlModel.Attributes.C_CONTENT_TYPE;
        final QName encodingAtt = (wrapper == null) ? XProcXmlModel.Attributes.ENCODING
                : XProcXmlModel.Attributes.C_ENCODING;
        final URLConnection urlConnection = url.openConnection();
        final ContentType guessContentType;
        if (StringUtils.equals("http", url.getProtocol())) {
            guessContentType = Steps.getContentType(urlConnection.getContentType(), node);
        } else {
            if (contentType != null) {
                guessContentType = contentType;
            } else {
                guessContentType = Steps
                        .getContentType("application/octet-stream ; encoding=" + Steps.ENCODING_BASE64, node);
            }
        }
        final Charset charset;
        if (contentType != null && contentType.getParameter("charset") != null) {
            charset = Charset.forName(contentType.getParameter("charset"));
        } else {
            charset = Charset.forName("UTF-8");
        }

        final InputStream stream = urlConnection.getInputStream();
        builder.attribute(contentTypeAtt, Steps.contentTypeToString(guessContentType));
        if (StringUtils.equals("text", guessContentType.getPrimaryType())
                || StringUtils.contains(guessContentType.getSubType(), "xml")) {
            if (guessContentType.getParameter("encoding") != null) {
                builder.attribute(encodingAtt, guessContentType.getParameter("encoding"));
            }
            builder.startContent();
            builder.text(IOUtils.toString(stream, charset.name()));
        } else {
            builder.attribute(encodingAtt, Steps.ENCODING_BASE64);
            builder.startContent();
            builder.text(Base64.encodeBytes(IOUtils.toByteArray(stream), Base64.DO_BREAK_LINES));
        }
    } catch (final IOException ioe) {
        throw XProcExceptions.xd0029(this.getLocation());
    }
}