Example usage for java.net URISyntaxException getCause

List of usage examples for java.net URISyntaxException getCause

Introduction

In this page you can find the example usage for java.net URISyntaxException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:com.taobao.datax.plugins.common.DFSUtils.java

/**
 * Get {@link Configuration}.//from   w  ww .j av a  2 s . co m
 * 
 * @param dir
 *            directory path in hdfs
 * 
 * @param ugi
 *            hadoop ugi
 * 
 * @param conf
 *            hadoop-site.xml path
 * 
 * @return {@link Configuration}
 * 
 * @throws java.io.IOException*/

public static Configuration getConf(String dir, String ugi, String conf) throws IOException {

    URI uri = null;
    Configuration cfg = null;
    String scheme = null;
    try {
        uri = new URI(dir);
        scheme = uri.getScheme();
        if (null == scheme) {
            throw new IOException("HDFS Path missing scheme, check path begin with hdfs://ip:port/ .");
        }

        cfg = confs.get(scheme);
    } catch (URISyntaxException e) {
        throw new IOException(e.getMessage(), e.getCause());
    }

    if (cfg == null) {
        cfg = new Configuration();

        cfg.setClassLoader(DFSUtils.class.getClassLoader());

        List<String> configs = new ArrayList<String>();
        if (!StringUtils.isBlank(conf) && new File(conf).exists()) {
            configs.add(conf);
        } else {
            /*
             * For taobao internal use e.g. if bazhen.csy start a new datax
             * job, datax will use /home/bazhen.csy/config/hadoop-site.xml
             * as configuration xml
             */
            String confDir = System.getenv("HADOOP_CONF_DIR");

            if (null == confDir) {
                //for taobao internal use, it is ugly
                configs.add(System.getProperty("user.home") + "/config/hadoop-site.xml");
            } else {
                //run in hadoop-0.19
                if (new File(confDir + "/hadoop-site.xml").exists()) {
                    configs.add(confDir + "/hadoop-site.xml");
                } else {
                    configs.add(confDir + "/core-default.xml");
                    configs.add(confDir + "/core-site.xml");
                }
            }
        }

        for (String config : configs) {
            log.info(String.format("HdfsReader use %s for hadoop configuration .", config));
            cfg.addResource(new Path(config));
        }

        /* commented by bazhen.csy */
        // log.info("HdfsReader use default ugi " +
        // cfg.get(ParamsKey.HdfsReader.ugi));

        if (uri.getScheme() != null) {
            String fsname = String.format("%s://%s:%s", uri.getScheme(), uri.getHost(), uri.getPort());
            log.info("fs.default.name=" + fsname);
            cfg.set("fs.default.name", fsname);
        }
        if (ugi != null) {
            cfg.set("hadoop.job.ugi", ugi);

            /*
             * commented by bazhen.csy log.info("use specification ugi:" +
             * cfg.get(ParamsKey.HdfsReader.ugi));
             */
        }
        confs.put(scheme, cfg);
    }

    return cfg;
}

From source file:info.rmapproject.auth.service.UserRMapAgentServiceImpl.java

/**
 * Compares the user in the user database to the Agents in RMap. If the Agent is already in RMap
 * and details that have changed are updated. If the Agent is not in RMap it is created.
 *
 * @param userId the User record ID//w w  w . j a v  a2 s .co m
 * @return the RMap Event
 * @throws RMapAuthException the RMap Auth exception
 */
public RMapEvent createOrUpdateAgentFromUser(int userId) throws RMapAuthException {
    RMapEvent event = null;

    User user = userService.getUserById(userId);
    if (user == null) {
        throw new RMapAuthException(ErrorCode.ER_USER_AGENT_NOT_FORMED_IN_DB.getMessage());
    }

    if (!user.isDoRMapAgentSync()) {
        //no need to update
        return null;
    }

    //we are permitted to synchronize the user in rmap... proceed...
    try {
        String sAgentId = user.getRmapAgentUri();
        if (sAgentId == null) {
            throw new RMapAuthException(ErrorCode.ER_USER_AGENT_NOT_FORMED_IN_DB.getMessage());
        }
        URI uAgentId = new URI(sAgentId);

        //get other properties we need to create/update the agent
        String agentAuthId = user.getAuthKeyUri();
        String name = user.getName();

        List<UserIdentityProvider> userIdProviders = userIdProvidersService
                .getUserIdProviders(user.getUserId());
        String primaryIdProvider = "";
        //TODO: this will just handle the first one for now -- need to make it support multiple idproviders
        for (UserIdentityProvider userIdProvider : userIdProviders) {
            primaryIdProvider = userIdProvider.getIdentityProvider();
            break;
        }

        //check the required properties are populated
        if (agentAuthId == null || agentAuthId.length() == 0 || primaryIdProvider == null
                || primaryIdProvider.length() == 0) {
            throw new RMapAuthException(ErrorCode.ER_USER_AGENT_NOT_FORMED_IN_DB.getMessage());
        }

        //if agent isn't in the triplestore, create it!  otherwise, update it
        RMapRequestAgent reqAgent = new RMapRequestAgent(uAgentId);
        if (rmapService.isAgentId(uAgentId)) {
            //rmap agent exists - but has there been a change?
            RMapAgent origAgent = rmapService.readAgent(uAgentId);
            String oAuthId = origAgent.getAuthId().toString();
            String oName = origAgent.getName().toString();
            String oIdProvider = origAgent.getIdProvider().toString();
            if (!oAuthId.equals(user.getAuthKeyUri()) || !oName.equals(user.getName())
                    || !oIdProvider.equals(primaryIdProvider)) {

                //something has changed, do update
                event = rmapService.updateAgent(uAgentId, name, new URI(primaryIdProvider),
                        new URI(agentAuthId), reqAgent);
            }
        } else {
            //id generated but no record created yet - create agent
            event = rmapService.createAgent(uAgentId, name, new URI(primaryIdProvider), new URI(agentAuthId),
                    reqAgent);
        }
        userService.updateUser(user);

    } catch (URISyntaxException uriEx) {
        throw new RMapAuthException(ErrorCode.ER_USER_AGENT_NOT_FORMED_IN_DB.getMessage(), uriEx.getCause());
    } catch (RMapException | RMapDefectiveArgumentException ex) {
        throw new RMapAuthException(ErrorCode.ER_USER_AGENT_NOT_FORMED_IN_DB.getMessage(), ex.getCause());
    } finally {
        if (rmapService != null) {
            rmapService.closeConnection();
        }
    }

    return event;

}

From source file:ch.cyberduck.core.azure.AzureSession.java

@Override
protected void login(LoginController controller, Credentials credentials) throws IOException {
    // http://*.blob.core.windows.net
    try {/*ww  w .  j a va  2  s. c  om*/
        client = new BlobStorageRest(new URI(host.getProtocol().getScheme() + "://" + host.getHostname()),
                false, credentials.getUsername(), credentials.getPassword());
    } catch (URISyntaxException e) {
        log.error("Failure parsing URI:" + e.getMessage());
        IOException failure = new IOException(e.getMessage());
        failure.initCause(e);
        throw failure;
    }
    client.setTimeout(TimeSpan.fromMilliseconds(this.timeout()));
    try {
        this.getContainers(true);
    } catch (StorageServerException e) {
        if (this.isLoginFailure(e)) {
            this.message(Locale.localizedString("Login failed", "Credentials"));
            controller.fail(host.getProtocol(), credentials);
            this.login();
        } else {
            IOException failure = new IOException(e.getCause().getMessage());
            failure.initCause(e);
            throw failure;
        }
    }
}

From source file:com.googlecode.jdeltasync.DeltaSyncClient.java

private <T> T post(final IDeltaSyncSession session, String uri, final String userAgent,
        final String contentType, final byte[] data, final UriCapturingResponseHandler<T> handler)
        throws DeltaSyncException, IOException {

    final HttpPost post = createHttpPost(uri, userAgent, contentType, data);
    final HttpContext context = new BasicHttpContext();
    context.setAttribute(HttpClientContext.COOKIE_STORE, session.getCookieStore());

    try {//from  w  w  w  . ja v  a2s.  co  m

        return httpClient.execute(post, new ResponseHandler<T>() {
            public T handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
                try {
                    if (isRedirect(response)) {
                        URI redirectUri = getRedirectLocationURI(session, post, response, context);
                        return post(session, redirectUri.toString(), userAgent, contentType, data, handler);
                    }

                    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                        throw new HttpException(response.getStatusLine().getStatusCode(),
                                response.getStatusLine().getReasonPhrase());
                    }

                    HttpRequest request = (HttpRequest) context.getAttribute(HttpCoreContext.HTTP_REQUEST);
                    HttpHost host = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
                    URI uri;
                    try {
                        if (request instanceof HttpUriRequest) {
                            uri = ((HttpUriRequest) request).getURI();
                        } else {
                            uri = new URI(request.getRequestLine().getUri());
                        }
                        if (!uri.isAbsolute()) {
                            uri = URIUtils.rewriteURI(uri, host);
                        }
                    } catch (URISyntaxException e) {
                        throw new DeltaSyncException(e);
                    }
                    return handler.handle(uri, response);
                } catch (DeltaSyncException e) {
                    throw new RuntimeException(e);
                }
            }
        }, context);

    } catch (RuntimeException e) {
        Throwable t = e.getCause();
        while (t != null) {
            if (t instanceof DeltaSyncException) {
                throw (DeltaSyncException) t;
            }
            t = t.getCause();
        }
        throw e;
    }
}

From source file:com.couchbase.jdbc.core.ProtocolImpl.java

public CBResultSet query(CBStatement statement, String sql) throws SQLException {

    Instance instance = getNextEndpoint();

    @SuppressWarnings("unchecked")
    Map<String, String> parameters = new HashMap();

    parameters.put(STATEMENT, sql);/*from   w  w w . ja v  a 2 s .co m*/
    addOptions(parameters);

    List<NameValuePair> parms = new ArrayList<NameValuePair>();

    for (String parameter : parameters.keySet()) {
        parms.add(new BasicNameValuePair(parameter, parameters.get(parameter)));
    }

    while (true) {
        String url = instance.getEndpointURL(ssl);
        logger.trace("Using endpoint {}", url);

        URI uri = null;
        try {
            uri = new URIBuilder(url).addParameters(parms).build();
        } catch (URISyntaxException ex) {
            logger.error("Invalid request {}", url);
        }

        HttpGet httpGet = new HttpGet(uri);

        httpGet.setHeader("Accept", "application/json");
        logger.trace("Get request {}", httpGet.toString());

        try {

            CloseableHttpResponse response = httpClient.execute(httpGet);
            return new CBResultSet(statement, handleResponse(sql, response));

        } catch (ConnectTimeoutException cte) {
            logger.trace(cte.getLocalizedMessage());

            // this one failed, lets move on
            invalidateEndpoint(instance);
            // get the next one
            instance = getNextEndpoint();
            if (instance == null) {
                throw new SQLException("All endpoints have failed, giving up");
            }

        } catch (IOException ex) {
            logger.error("Error executing query [{}] {}", sql, ex.getMessage());
            throw new SQLException("Error executing update", ex.getCause());
        }
    }
}

From source file:com.docuware.dev.Extensions.ServiceConnection.java

private URI buildUri(Object parameters, String template) {
    try {/*from ww w . j a  v  a  2s  .  c  o m*/
        return new URI(this.getServiceDescription().getProxy().getBaseAddress().getScheme() + "://"
                + this.getServiceDescription().getProxy().getBaseAddress().getHost()
                + this.createTemplateUri(template, parameters));
    } catch (URISyntaxException ex) {
        throw new RuntimeException(ex.getCause());
    }
}

From source file:org.apache.hadoop.hdfs.KeyProviderCache.java

private URI createKeyProviderURI(Configuration conf) {
    final String providerUriStr = conf.getTrimmed(DFSConfigKeys.DFS_ENCRYPTION_KEY_PROVIDER_URI, "");
    // No provider set in conf
    if (providerUriStr.isEmpty()) {
        LOG.error("Could not find uri with key [" + DFSConfigKeys.DFS_ENCRYPTION_KEY_PROVIDER_URI
                + "] to create a keyProvider !!");
        return null;
    }//  www.  j  a v a 2s  .  com
    final URI providerUri;
    try {
        providerUri = new URI(providerUriStr);
    } catch (URISyntaxException e) {
        LOG.error("KeyProvider URI string is invalid [" + providerUriStr + "]!!", e.getCause());
        return null;
    }
    return providerUri;
}