Example usage for java.net URL setURLStreamHandlerFactory

List of usage examples for java.net URL setURLStreamHandlerFactory

Introduction

In this page you can find the example usage for java.net URL setURLStreamHandlerFactory.

Prototype

public static void setURLStreamHandlerFactory(URLStreamHandlerFactory fac) 

Source Link

Document

Sets an application's URLStreamHandlerFactory .

Usage

From source file:org.springframework.yarn.configuration.ConfigurationFactoryBean.java

@Override
public void afterPropertiesSet() throws Exception {
    internalConfig = createConfiguration(configuration);

    internalConfig.setClassLoader(beanClassLoader);
    if (resources != null) {
        for (Resource resource : resources) {
            internalConfig.addResource(resource.getURL());
        }//from  www  . j ava  2s .  co  m
    }

    ConfigurationUtils.addProperties(internalConfig, properties);

    // set hdfs / fs URI last to override all other properties
    if (StringUtils.hasText(fsUri)) {
        log.info("Overwriting fsUri=[" + internalConfig.get(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY)
                + "] with fsUri=[" + fsUri.trim() + "]");
        internalConfig.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, fsUri.trim());
    }

    if (StringUtils.hasText(rmAddress)) {
        log.info("Overwriting rmAddress=[" + internalConfig.get(YarnConfiguration.RM_ADDRESS)
                + "] with rmAddress=[" + rmAddress.trim() + "]");
        internalConfig.set(YarnConfiguration.RM_ADDRESS, rmAddress.trim());
    }

    if (StringUtils.hasText(schedulerAddress)) {
        internalConfig.set(YarnConfiguration.RM_SCHEDULER_ADDRESS, schedulerAddress.trim());
    }

    if (initialize) {
        internalConfig.size();
    }

    if (registerJvmUrl) {
        try {
            // force UGI init to prevent infinite loop - see SHDP-92
            UserGroupInformation.setConfiguration(internalConfig);
            URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory(getObject()));
            log.info("Registered HDFS URL stream handler");
        } catch (Error err) {
            log.warn("Cannot register Hadoop URL stream handler - one is already registered");
        }
    }
}

From source file:org.talend.components.marketo.MarketoRuntimeInfoTest.java

@BeforeClass
public static void setupMavenUrlHandler() {
    try {// w w w  .j  a v a 2s. c o m
        new URL("mvn:foo/bar");
    } catch (MalformedURLException e) {
        // handles mvn local repository
        String mvnLocalRepo = System.getProperty("maven.repo.local");
        LOG.info("local repos {}", mvnLocalRepo);
        if (mvnLocalRepo != null) {
            System.setProperty("org.ops4j.pax.url.mvn.localRepository", mvnLocalRepo);
        }
        URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() {

            @Override
            public URLStreamHandler createURLStreamHandler(String protocol) {
                if (ServiceConstants.PROTOCOL.equals(protocol)) {
                    return new Handler();
                } else {
                    return null;
                }
            }
        });
    }
}

From source file:ste.xtest.net.BugFreeURL.java

@BeforeClass
public static void before_class() throws Exception {
    URL.setURLStreamHandlerFactory(new StubStreamHandlerFactory());
}