Example usage for java.net URI getScheme

List of usage examples for java.net URI getScheme

Introduction

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

Prototype

public String getScheme() 

Source Link

Document

Returns the scheme component of this URI.

Usage

From source file:cascading.plumber.grids.AbstractGrid.java

/**
 * Get the {@link TapFactory} associated with the {@link URI}'s scheme. If
 * none, throw an explicit {@link Exception} with the current mapping.
 *///  ww w  .jav a2 s .  c  o m
private TapFactory getTapFactory(URI uri) {
    TapFactory tapFactory = uriSchemeToTap.get(uri.getScheme());
    if (tapFactory == null) {
        StringBuffer buffer = new StringBuffer();
        buffer.append("Unable to find TapFactory for uriScheme '");
        buffer.append(uri.getScheme());
        buffer.append("'. Current mapping is ");
        buffer.append(uriSchemeToTap);
        buffer.append(".");
        throw new IllegalArgumentException(buffer.toString());
    }
    return tapFactory;
}

From source file:org.cloudcrawler.domain.crawler.robotstxt.RobotsTxtService.java

/**
 * This method is used to evaluate if the provided uri is
 * allowed to be crawled against the robots.txt of the website.
 *
 * @param uri/*from  w w  w  .jav  a2s  .co  m*/
 * @return
 * @throws Exception
 */
public boolean isAllowedUri(URI uri) throws Exception {
    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setScheme(uri.getScheme());
    uriBuilder.setHost(uri.getHost());
    uriBuilder.setUserInfo(uri.getUserInfo());
    uriBuilder.setPath("/robots.txt");

    URI robotsTxtUri = uriBuilder.build();
    BaseRobotRules rules = (BaseRobotRules) cache.get(robotsTxtUri.toString());

    if (rules == null) {
        HttpResponse response = httpService.get(robotsTxtUri);

        try {

            // HACK! DANGER! Some sites will redirect the request to the top-level domain
            // page, without returning a 404. So look for a response which has a redirect,
            // and the fetched content is not plain text, and assume it's one of these...
            // which is the same as not having a robotstxt.txt file.

            String contentType = response.getEntity().getContentType().getValue();
            boolean isPlainText = (contentType != null) && (contentType.startsWith("text/plain"));

            if (response.getStatusLine().getStatusCode() == 404 || !isPlainText) {
                rules = robotsTxtParser.failedFetch(HttpStatus.SC_GONE);
            } else {
                StringWriter writer = new StringWriter();

                IOUtils.copy(response.getEntity().getContent(), writer);

                rules = robotsTxtParser.parseContent(uri.toString(), writer.toString().getBytes(),
                        response.getEntity().getContentType().getValue(), httpService.getUserAgent());

            }
        } catch (Exception e) {
            EntityUtils.consume(response.getEntity());
            throw e;
        }

        EntityUtils.consume(response.getEntity());
        cache.set(robotsTxtUri.toString(), 60 * 60 * 24, rules);
    }

    return rules.isAllowed(uri.toString());
}

From source file:org.geosdi.geoplatform.connector.server.security.PreemptiveSecurityConnector.java

protected HttpHost extractHost(URI uri) {
    if (this.httpHost == null) {
        this.httpHost = new HttpHost(uri.getHost(), this.retrieveNoSetPort(uri), uri.getScheme());
    }/*from  w  w w  .  j av  a  2 s . c om*/
    return this.httpHost;
}

From source file:org.apache.hadoop.gateway.dispatch.AppCookieManager.java

/**
 * Fetches hadoop.auth cookie from hadoop service authenticating using SpNego
 * // w w w  .j a  va 2s.c o m
 * @param outboundRequest
 *          out going request
 * @param refresh
 *          flag indicating whether to refresh the cached cookie
 * @return hadoop.auth cookie from hadoop service authenticating using SpNego
 * @throws IOException
 *           in case of errors
 */
public String getAppCookie(HttpUriRequest outboundRequest, boolean refresh) throws IOException {

    URI uri = outboundRequest.getURI();
    String scheme = uri.getScheme();
    String host = uri.getHost();
    int port = uri.getPort();
    if (!refresh) {
        if (appCookie != null) {
            return appCookie;
        }
    }

    DefaultHttpClient client = new DefaultHttpClient();
    SPNegoSchemeFactory spNegoSF = new SPNegoSchemeFactory(/* stripPort */true);
    // spNegoSF.setSpengoGenerator(new BouncySpnegoTokenGenerator());
    client.getAuthSchemes().register(AuthPolicy.SPNEGO, spNegoSF);
    client.getCredentialsProvider().setCredentials(new AuthScope(/* host */null, /* port */-1, /* realm */null),
            EMPTY_JAAS_CREDENTIALS);

    clearAppCookie();
    String hadoopAuthCookie = null;
    HttpResponse httpResponse = null;
    try {
        HttpHost httpHost = new HttpHost(host, port, scheme);
        HttpRequest httpRequest = createKerberosAuthenticationRequest(outboundRequest);
        httpResponse = client.execute(httpHost, httpRequest);
        Header[] headers = httpResponse.getHeaders(SET_COOKIE);
        hadoopAuthCookie = getHadoopAuthCookieValue(headers);
        EntityUtils.consume(httpResponse.getEntity());
        if (hadoopAuthCookie == null) {
            LOG.failedSPNegoAuthn(uri.toString());
            auditor.audit(Action.AUTHENTICATION, uri.toString(), ResourceType.URI, ActionOutcome.FAILURE);
            throw new IOException("SPNego authn failed, can not get hadoop.auth cookie");
        }
    } finally {
        if (httpResponse != null) {
            HttpEntity entity = httpResponse.getEntity();
            if (entity != null) {
                entity.getContent().close();
            }
        }

    }
    LOG.successfulSPNegoAuthn(uri.toString());
    auditor.audit(Action.AUTHENTICATION, uri.toString(), ResourceType.URI, ActionOutcome.SUCCESS);
    hadoopAuthCookie = HADOOP_AUTH_EQ + quote(hadoopAuthCookie);
    setAppCookie(hadoopAuthCookie);
    return appCookie;
}

From source file:se.vgregion.pubsub.push.web.PushController.java

private boolean allowScheme(URI uri) {
    return ALLOWED_SCHEMES.contains(uri.getScheme());
}

From source file:ch.cyberduck.core.proxy.SystemConfigurationProxy.java

@Override
public Proxy find(final Host target) {
    if (!preferences.getBoolean("connection.proxy.enable")) {
        return Proxy.DIRECT;
    }/*from  w  ww .  j  a v  a2 s .c  om*/
    final String route = this.findNative(provider.get(target));
    if (null == route) {
        if (log.isInfoEnabled()) {
            log.info(String.format("No poxy configuration found for target %s", target));
        }
        // Direct
        return Proxy.DIRECT;
    }
    final URI proxy;
    try {
        proxy = new URI(route);
        try {
            return new Proxy(Proxy.Type.valueOf(StringUtils.upperCase(proxy.getScheme())), proxy.getHost(),
                    proxy.getPort());
        } catch (IllegalArgumentException e) {
            log.warn(String.format("Unsupported scheme for proxy %s", proxy));
        }
    } catch (URISyntaxException e) {
        log.warn(String.format("Invalid proxy configuration %s", route));
    }
    return Proxy.DIRECT;
}

From source file:de.betterform.connector.DefaultConnectorFactory.java

/**
 * Creates a new submission handler for the specified URI.
 *
 * @param uri the relative or absolute URI string.
 * @param element the element to start with XML Base resolution for relative
 * URIs./*  w w w  . j  av  a 2s  .co  m*/
 * @return a new submission handler for the specified URI.
 * @throws XFormsException if a relative URI could not be resolved, no
 * submission handler is registered for the specified URI or any error
 * occurred during submission handler creation.
 */
public SubmissionHandler createSubmissionHandler(final String uri, final Element element)
        throws XFormsException {
    URI uriObj = getAbsoluteURI(uri, element);

    String className = Config.getInstance().getSubmissionHandler(uriObj.getScheme());
    if (className == null) {
        throw new XFormsException("no submission handler registered for '" + uri + "'");
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("creating submission handler for '" + uriObj + "' : " + className);
    }

    Object instance = createInstance(className);
    if (!(instance instanceof SubmissionHandler)) {
        throw new XFormsException("object instance of '" + className + "' is no submission handler");
    }

    SubmissionHandler submissionHandler = (SubmissionHandler) instance;
    submissionHandler.setURI(uriObj.toString());
    submissionHandler.setContext(getContext());

    return submissionHandler;
}

From source file:be.fedict.eid.idp.model.bean.AccountingServiceBean.java

private String normalize(String domain) {
    URI uri;
    try {// w w w .jav  a 2  s .c  om
        uri = new URI(domain);
    } catch (URISyntaxException e) {
        return domain;
    }
    String scheme = uri.getScheme();
    if ("http".equals(scheme) || "https".equals(scheme)) {
        return uri.getScheme() + "://" + uri.getHost() + uri.getPath();
    }
    return domain;
}

From source file:com.linkedin.kafka.clients.utils.tests.EmbeddedBroker.java

private void parseConfigs(Map<Object, Object> config) {
    id = Integer.parseInt((String) config.get("broker.id"));
    logDir = new File((String) config.get("log.dir"));

    //bind addresses
    String listenersString = (String) config.get("listeners");
    for (String protocolAddr : listenersString.split("\\s*,\\s*")) {
        try {// w w  w .j  a  va  2s .co m
            URI uri = new URI(protocolAddr.trim());
            SecurityProtocol protocol = SecurityProtocol.forName(uri.getScheme());
            hosts.put(protocol, uri.getHost());
            ports.put(protocol, null); //we get the value after boot
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }
}

From source file:com.subgraph.vega.impl.scanner.forms.FormProcessingState.java

private URI createTargetURI() {
    if (baseURI == null)
        return null;
    if (action == null)
        return baseURI;
    try {//from w w w . j a  v a  2  s  .c  om
        final URI target = baseURI.resolve(action);
        final String scheme = target.getScheme();
        if (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https"))
            return target;
        else
            return null;
    } catch (IllegalArgumentException e) {
        logger.log(Level.WARNING, "Failed to create new URI from base: " + baseURI + " and action=" + action,
                e);
        return null;
    }
}