Example usage for java.net URI getAuthority

List of usage examples for java.net URI getAuthority

Introduction

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

Prototype

public String getAuthority() 

Source Link

Document

Returns the decoded authority component of this URI.

Usage

From source file:org.apache.hadoop.fs.FileSystem.java

/** Returns the FileSystem for this URI's scheme and authority.  The scheme
 * of the URI determines a configuration property name,
 * <tt>fs.<i>scheme</i>.class</tt> whose value names the FileSystem class.
 * The entire URI is passed to the FileSystem instance's initialize method.
 *///from   ww w . j av a  2s .c  o m
public static FileSystem get(URI uri, Configuration conf) throws IOException {
    String scheme = uri.getScheme();
    String authority = uri.getAuthority();

    if (scheme == null) { // no scheme: use default FS
        return get(conf);
    }

    if (authority == null) { // no authority
        URI defaultUri = getDefaultUri(conf);
        if (scheme.equals(defaultUri.getScheme()) // if scheme matches default
                && defaultUri.getAuthority() != null) { // & default has authority
            return get(defaultUri, conf); // return default
        }
    }

    String disableCacheName = String.format("fs.%s.impl.disable.cache", scheme);
    if (conf.getBoolean(disableCacheName, false)) {
        return createFileSystem(uri, conf);
    }

    return CACHE.get(uri, conf);
}

From source file:org.eclipse.orion.internal.server.servlets.xfer.ClientImport.java

private void setResponseLocationHeader(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException {
    URI requestURI = ServletResourceHandler.getURI(req);
    String responsePath = "/" + new Path(requestURI.getPath()).segment(0) + "/import/" + id; //$NON-NLS-1$ //$NON-NLS-2$
    URI responseURI;/*  ww w .  j  a v  a2s.  c o  m*/
    try {
        responseURI = new URI(requestURI.getScheme(), requestURI.getAuthority(), responsePath, null, null);
    } catch (URISyntaxException e) {
        //should not be possible
        throw new ServletException(e);
    }
    resp.setHeader(ProtocolConstants.HEADER_LOCATION,
            ServletResourceHandler.resovleOrionURI(req, responseURI).toString());
}

From source file:org.orbeon.oxf.processor.xmldb.XMLDBProcessor.java

protected Collection getCollection(Datasource datasource, String collection) {
    ensureDriverRegistered(datasource);/*from w ww.j  av a2 s .c  om*/
    try {
        String datasourceURI = datasource.getUri();
        if (!datasourceURI.startsWith(XMLDB_URI_PREFIX))
            throw new OXFException("Invalid XML:DB URI: " + datasourceURI);
        if (!collection.startsWith("/"))
            throw new OXFException("Collection name must start with a '/': " + collection);

        // This makes sure that we have a correct URI syntax
        URI uri = new URI(datasourceURI.substring(XMLDB_URI_PREFIX.length()));

        // Rebuild a URI string
        String xmldbCollectionName = XMLDB_URI_PREFIX + uri.getScheme() + "://"
                + (uri.getAuthority() == null ? "" : uri.getAuthority())
                + (uri.getPath() == null ? "" : uri.getPath());
        if (xmldbCollectionName.endsWith("/"))
            xmldbCollectionName = xmldbCollectionName.substring(0, xmldbCollectionName.length() - 1);
        xmldbCollectionName = xmldbCollectionName + collection;

        return DatabaseManager.getCollection(xmldbCollectionName, datasource.getUsername(),
                datasource.getPassword());
    } catch (Exception e) {
        throw new OXFException(e);
    }
}

From source file:stargate.commons.recipe.DataObjectPath.java

private void initialize(URI uri) {
    if (uri == null) {
        throw new IllegalArgumentException("uri is null");
    }//from   w  ww.j  a  v  a2  s  . c  o  m

    String scheme = uri.getScheme();
    if (scheme != null && !scheme.equalsIgnoreCase(STARGATE_SCHEME)) {
        throw new IllegalArgumentException("uri scheme is not stargate scheme (" + scheme + " was given)");
    }

    String authority = uri.getAuthority();
    if (authority == null || authority.isEmpty()) {
        throw new IllegalArgumentException("authority of given uri is empty or null");
    }

    this.uri = createPathUri(authority, uri.getPath());
}

From source file:hsyndicate.fs.SyndicateFSPath.java

public SyndicateFSPath(SyndicateFSPath parent, SyndicateFSPath child) {
    if (parent == null)
        throw new IllegalArgumentException("Can not resolve a path from a null parent");
    if (child == null)
        throw new IllegalArgumentException("Can not resolve a path from a null child");

    URI parentUri = parent.uri;
    if (parentUri == null)
        throw new IllegalArgumentException("Can not resolve a path from a null parent URI");

    String parentPath = parentUri.getPath();

    if (!(parentPath.equals("/") || parentPath.equals(""))) {
        // parent path is not empty -- need to parse
        try {//from  w w  w  .  j  ava2  s. c  om
            parentUri = new URI(parentUri.getScheme(), parentUri.getAuthority(), parentUri.getPath() + "/",
                    null, parentUri.getFragment());
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException(e);
        }
    }

    URI resolved = parentUri.resolve(child.uri);

    // assign resolved uri to member field
    this.uri = createPathUri(resolved.getScheme(), resolved.getAuthority(), normalizePath(resolved.getPath()));
    //LOG.info("path - " + uri.toString());
}

From source file:talend.core.transformer.plugin.v2.tiscall.TISCallTransformerPluginBean.java

/**
 * @throws XtentisException/*from  w ww . ja  v  a2  s  .  c  om*/
 * @ejb.interface-method view-type = "local"
 * @ejb.facade-method
 */
@Override
public void init(TransformerPluginContext context, String parameters) throws XtentisException {
    try {
        if (!configurationLoaded) {
            loadConfiguration();
        }

        compiledParameters = CompiledParameters.deserialize(parameters);

        // set the parameters
        JobInvokeConfig jobInvokeConfig;
        URI uri = URI.create(compiledParameters.getUrl());
        String protocol = uri.getScheme();
        String jobName = uri.getHost();
        if (jobName == null) {
            jobName = uri.getAuthority();
        }
        String jobVersion = uri.getPath().substring(1);

        if (LTJ_PROTOCOL.equals(protocol)) {
            jobInvokeConfig = new JobInvokeConfig();
            jobInvokeConfig.setJobName(jobName);
            jobInvokeConfig.setJobVersion(jobVersion);
            context.put(INVOKE_CONFIG, jobInvokeConfig);
        } else if (HTTP_PROTOCOL.equalsIgnoreCase(protocol)) {
            throw new NotImplementedException(); // TODO (rewrite -> HTTP call heavily depended on JBoss classes).
        } else {
            throw new IllegalArgumentException("Protocol '" + protocol + "' is not supported.");
        }

        context.put(CONTENT_TYPE, compiledParameters.getContentType());
        context.put(TIS_VARIABLE_NAME, compiledParameters.getTisVariableName());
    } catch (XtentisException xe) {
        throw (xe);
    } catch (Exception e) {
        String err = "Could not init the TISCall plugin:" + e.getClass().getName() + ": "
                + e.getLocalizedMessage();
        LOGGER.error(err, e);
        throw new XtentisException(e);
    }

}

From source file:com.tripit.auth.OAuthCredential.java

public boolean validateSignature(URI requestUri)
        throws URISyntaxException, UnsupportedEncodingException, InvalidKeyException, NoSuchAlgorithmException {
    List<NameValuePair> argList = URLEncodedUtils.parse(requestUri, "UTF-8");
    SortedMap<String, String> args = new TreeMap<String, String>();
    for (NameValuePair arg : argList) {
        args.put(arg.getName(), arg.getValue());
    }//from w  w  w  . jav  a  2s  .co  m

    String signature = args.remove("oauth_signature");

    String baseUrl = new URI(requestUri.getScheme(), requestUri.getUserInfo(), requestUri.getAuthority(),
            requestUri.getPort(), requestUri.getPath(), null, requestUri.getFragment()).toString();

    return (signature != null && signature.equals(generateSignature(baseUrl, args)));
}

From source file:org.apache.solr.client.solrj.io.sql.DriverImpl.java

public Connection connect(String url, Properties props) throws SQLException {
    if (!acceptsURL(url)) {
        return null;
    }//w w  w. java 2s . co  m

    URI uri = processUrl(url);

    loadParams(uri, props);

    if (!props.containsKey("collection")) {
        throw new SQLException(
                "The connection url has no connection properties. At a mininum the collection must be specified.");
    }
    String collection = (String) props.remove("collection");

    if (!props.containsKey("aggregationMode")) {
        props.setProperty("aggregationMode", "facet");
    }

    // JDBC requires metadata like field names from the SQLHandler. Force this property to be true.
    props.setProperty("includeMetadata", "true");

    String zkHost = uri.getAuthority() + uri.getPath();

    return new ConnectionImpl(url, zkHost, collection, props);
}

From source file:org.eclipse.orion.internal.server.servlets.workspace.ProjectParentDecorator.java

private void addParents(URI resource, JSONObject representation, ProjectInfo project, IPath resourcePath)
        throws JSONException {
    //start at parent of current resource
    resourcePath = resourcePath.removeLastSegments(1).addTrailingSeparator();
    JSONArray parents = new JSONArray();
    //for all but the project we can just manipulate the path to get the name and location
    while (resourcePath.segmentCount() > 2) {
        try {//from ww  w.  j a v a2 s . c  o  m
            URI uri = resource.resolve(new URI(null, null, resourcePath.toString(), null));
            addParent(parents, resourcePath.lastSegment(), new URI(resource.getScheme(),
                    resource.getAuthority(), uri.getPath(), uri.getQuery(), uri.getFragment()));
        } catch (URISyntaxException e) {
            //ignore this parent
            LogHelper.log(e);
        }
        resourcePath = resourcePath.removeLastSegments(1);
    }
    //add the project
    if (resourcePath.segmentCount() == 2) {
        try {
            URI uri = resource.resolve(new URI(null, null, resourcePath.toString(), null));
            addParent(parents, project.getFullName(), new URI(resource.getScheme(), resource.getAuthority(),
                    uri.getPath(), uri.getQuery(), uri.getFragment()));
        } catch (URISyntaxException e) {
            //ignore this project
            LogHelper.log(e);
        }
    }
    representation.put(ProtocolConstants.KEY_PARENTS, parents);
}

From source file:org.apache.hadoop.fs.s3native.NativeS3FileSystem.java

@Override
public void initialize(URI uri, Configuration conf) throws IOException {
    super.initialize(uri, conf);
    if (store == null) {
        store = createDefaultStore(conf);
    }/*from   w w w  .j a  v  a  2 s  .  co  m*/
    store.initialize(uri, conf);
    setConf(conf);
    this.uri = URI.create(uri.getScheme() + "://" + uri.getAuthority());
    this.workingDir = new Path("/user", System.getProperty("user.name")).makeQualified(this);
}