List of usage examples for org.apache.commons.io FileUtils copyURLToFile
public static void copyURLToFile(URL source, File destination) throws IOException
source
to a file destination
. From source file:org.jbb.lib.logging.LoggingBootstrapper.java
private void copyDefaultConfigurationToFile(File logbackConfigurationFile) { ClassPathResource classPathResource = new ClassPathResource(CLASSPATH_DEFAULT_LOG_CONF_FILE_NAME); try {/* w ww . j a va 2 s .c o m*/ FileUtils.copyURLToFile(classPathResource.getURL(), logbackConfigurationFile); } catch (IOException e) { throw new IllegalStateException("Unexpected error during reading default logging configuration file", e); } }
From source file:org.jbb.lib.properties.FreshInstallPropertiesCreator.java
private static void getDefaultFromClasspath(File propertyFile) { ClassPathResource classPathResource = new ClassPathResource(propertyFile.getName()); try {/*from w ww. java2 s . c o m*/ FileUtils.copyURLToFile(classPathResource.getURL(), propertyFile); } catch (IOException e) { throw new IllegalStateException(e); } }
From source file:org.jbb.lib.properties.FreshInstallPropertiesCreatorTest.java
@Test public void shouldAddMissingPropertiesToTarget_whenPropertyFilesExists_butIsNotComplete() throws Exception { // given// w ww .j a v a 2 s .co m File tempFolder = temp.newFolder(); File targetPropertyFile = new File(tempFolder.getAbsolutePath() + "/test3.properties"); FileUtils.copyURLToFile(new ClassPathResource("test3-missing.properties").getURL(), targetPropertyFile); ClassPathResource referencePropertyFile = new ClassPathResource("test3.properties"); when(propertyFilesResolverMock.resolvePropertyFileNames(TestMissingProperties.class)) .thenReturn(Sets.newHashSet(targetPropertyFile.getAbsolutePath())); // when propertiesCreator.putDefaultPropertiesIfNeeded(TestMissingProperties.class); // then assertThat(targetPropertyFile).exists(); assertThat(targetPropertyFile).hasSameContentAs(referencePropertyFile.getFile()); }
From source file:org.jbb.lib.properties.FreshInstallPropertiesCreatorTest.java
@Test public void shouldDeleteObsoletePropertiesToTarget_whenPropertyFilesExists_butHasOldPropertyKeys() throws Exception { // given//from w w w . jav a2 s . c o m File tempFolder = temp.newFolder(); File targetPropertyFile = new File(tempFolder.getAbsolutePath() + "/test4.properties"); FileUtils.copyURLToFile(new ClassPathResource("test4-obsolete.properties").getURL(), targetPropertyFile); ClassPathResource referencePropertyFile = new ClassPathResource("test4.properties"); when(propertyFilesResolverMock.resolvePropertyFileNames(TestObsoleteProperties.class)) .thenReturn(Sets.newHashSet(targetPropertyFile.getAbsolutePath())); // when propertiesCreator.putDefaultPropertiesIfNeeded(TestObsoleteProperties.class); // then assertThat(targetPropertyFile).exists(); assertThat(targetPropertyFile).hasSameContentAs(referencePropertyFile.getFile()); }
From source file:org.jbb.lib.test.MockCommonsAutoInstallConfig.java
private void copyAutoInstallFile() { String fileName = "jbb-autoinstall.properties"; ClassPathResource autoInstallFile = new ClassPathResource(fileName); File targetFile = new File(jbbHomePath + File.separator + fileName); try {/*from w ww . jav a2s .c o m*/ FileUtils.copyURLToFile(autoInstallFile.getURL(), targetFile); } catch (IOException e) { throw new IllegalStateException(e); } }
From source file:org.jboss.arquillian.container.mobicents.servlet.sip.tomcat.embedded_6.MobicentsSipServletsContainer.java
@Override public void startTomcatEmbedded(Properties sipStackProperties) throws UnknownHostException, org.apache.catalina.LifecycleException, LifecycleException { System.setProperty("javax.servlet.sip.ar.spi.SipApplicationRouterProvider", configuration.getSipApplicationRouterProviderClassName()); if (bindAddress != null) { System.setProperty("org.mobicents.testsuite.testhostaddr", bindAddress); } else {/*from w w w . j a va2 s . co m*/ System.setProperty("org.mobicents.testsuite.testhostaddr", "127.0.0.1"); } // if(MobicentsSipServletsConfiguration.MOBICENTS_DEFAULT_AR_CLASS_NAME.equals(configuration.getSipApplicationRouterProviderClassName())) { // System.setProperty("javax.servlet.sip.dar", Thread.currentThread().getContextClassLoader().getResource("empty-dar.properties").toString()); // } else { // System.setProperty("javax.servlet.sip.dar", Thread.currentThread().getContextClassLoader().getResource("test-dar.properties").toString()); // } //Required in order to read the dar conf of each file //The Router in the arquillian.xml should be <property name="sipApplicationRouterProviderClassName">org.mobicents.servlet.sip.router.DefaultApplicationRouterProvider</property> String darConfiguration = Thread.currentThread().getContextClassLoader().getResource("test-dar.properties") .toString(); if (darConfiguration != null) { System.setProperty("javax.servlet.sip.dar", Thread.currentThread().getContextClassLoader().getResource("test-dar.properties").toString()); } else { System.setProperty("javax.servlet.sip.dar", Thread.currentThread().getContextClassLoader().getResource("empty-dar.properties").toString()); } // creating the tomcat embedded == service tag in server.xml MobicentsSipServletsEmbeddedImpl embedded = new MobicentsSipServletsEmbeddedImpl(); this.embedded = embedded; sipStandardService = new SipStandardService(); sipStandardService .setSipApplicationDispatcherClassName(SipApplicationDispatcherImpl.class.getCanonicalName()); sipStandardService.setCongestionControlCheckingInterval(-1); sipStandardService.setAdditionalParameterableHeaders("additionalParameterableHeader"); sipStandardService.setUsePrettyEncoding(true); sipStandardService.setName(serverName); if (sipStackProperties != null) sipStandardService.setSipStackProperties(sipStackProperties); embedded.setService(sipStandardService); // TODO this needs to be a lot more robust String tomcatHome = configuration.getTomcatHome(); File tomcatHomeFile = null; if (tomcatHome != null) { if (tomcatHome.startsWith(ENV_VAR)) { String sysVar = tomcatHome.substring(ENV_VAR.length(), tomcatHome.length() - 1); tomcatHome = System.getProperty(sysVar); if (tomcatHome != null && tomcatHome.length() > 0 && new File(tomcatHome).isAbsolute()) { tomcatHomeFile = new File(tomcatHome); log.info("Using tomcat home from environment variable: " + tomcatHome); } } else { tomcatHomeFile = new File(tomcatHome); } } if (tomcatHomeFile == null) { tomcatHomeFile = new File(System.getProperty(TMPDIR_SYS_PROP), "mss-tomcat-embedded-6"); } tomcatHomeFile.mkdirs(); embedded.setCatalinaBase(tomcatHomeFile.getAbsolutePath()); embedded.setCatalinaHome(tomcatHomeFile.getAbsolutePath()); // creates the engine, i.e., <engine> element in server.xml Engine engine = embedded.createEngine(); this.engine = engine; engine.setName(serverName); engine.setDefaultHost(bindAddress); engine.setService(sipStandardService); sipStandardService.setContainer(engine); embedded.addEngine(engine); // creates the host, i.e., <host> element in server.xml File appBaseFile = new File(tomcatHomeFile, configuration.getAppBase()); appBaseFile.mkdirs(); //Issue 10: http://code.google.com/p/commtesting/issues/detail?id=10 //Set the default WEB.XML location. This way the DEFAULT servlets (with mapping to "/") will be added URL defaultWebXmlURL = Thread.currentThread().getContextClassLoader().getResource("tomcat-6.0.35-web.xml"); File confBaseFile = new File(tomcatHomeFile, configuration.getConfBase()); confBaseFile.mkdirs(); try { FileUtils.copyURLToFile(defaultWebXmlURL, new File(confBaseFile.getPath() + "/web.xml")); } catch (IOException e) { log.warning("Problem to copy the default web.xml " + e); } StandardHost host = (StandardHost) embedded.createHost(bindAddress, appBaseFile.getAbsolutePath()); this.standardHost = host; if (configuration.getTomcatWorkDir() != null) { host.setWorkDir(configuration.getTomcatWorkDir()); } host.setUnpackWARs(configuration.isUnpackArchive()); engine.addChild(host); // creates an http connector, i.e., <connector> element in server.xml Connector connector = embedded.createConnector(InetAddress.getByName(bindAddress), bindPort, false); embedded.addConnector(connector); connector.setContainer(engine); // starts embedded Mobicents Sip Serlvets embedded.start(); embedded.getService().start(); // creates an sip connector, i.e., <connector> element in server.xml for (SipConnector sipConnector : sipConnectors) { addSipConnector(sipConnector); } wasStarted = true; // System.setProperty("javax.servlet.sip.ar.spi.SipApplicationRouterProvider", configuration.getSipApplicationRouterProviderClassName()); // if(MobicentsSipServletsConfiguration.MOBICENTS_DEFAULT_AR_CLASS_NAME.equals(configuration.getSipApplicationRouterProviderClassName())) { // System.setProperty("javax.servlet.sip.dar", Thread.currentThread().getContextClassLoader().getResource("empty-dar.properties").toString()); // } // // creating the tomcat embedded == service tag in server.xml // MobicentsSipServletsEmbedded embedded= new MobicentsSipServletsEmbedded(); // this.embedded = embedded; // // SipStandardService sipStandardService = new SipStandardService(); // sipStandardService.setSipApplicationDispatcherClassName(SipApplicationDispatcherImpl.class.getCanonicalName()); // sipStandardService.setCongestionControlCheckingInterval(-1); // sipStandardService.setAdditionalParameterableHeaders("additionalParameterableHeader"); // sipStandardService.setUsePrettyEncoding(true); // sipStandardService.setName(serverName); // // // embedded.setService(sipStandardService); // // // TODO this needs to be a lot more robust // String tomcatHome = configuration.getTomcatHome(); // File tomcatHomeFile = null; // if (tomcatHome != null) // { // if (tomcatHome.startsWith(ENV_VAR)) // { // String sysVar = tomcatHome.substring(ENV_VAR.length(), tomcatHome.length() - 1); // tomcatHome = System.getProperty(sysVar); // if (tomcatHome != null && tomcatHome.length() > 0 && new File(tomcatHome).isAbsolute()) // { // tomcatHomeFile = new File(tomcatHome); // log.info("Using tomcat home from environment variable: " + tomcatHome); // } // } // else // { // tomcatHomeFile = new File(tomcatHome); // } // } // // if (tomcatHomeFile == null) // { // tomcatHomeFile = new File(System.getProperty(TMPDIR_SYS_PROP), "tomcat-embedded-6"); // } // // tomcatHomeFile.mkdirs(); // embedded.setCatalinaBase(tomcatHomeFile.getAbsolutePath()); // embedded.setCatalinaHome(tomcatHomeFile.getAbsolutePath()); // // // creates the engine, i.e., <engine> element in server.xml // Engine engine = embedded.createEngine(); // this.engine = engine; // engine.setName(serverName); // engine.setDefaultHost(bindAddress); // engine.setService(sipStandardService); // sipStandardService.setContainer(engine); // embedded.addEngine(engine); // // // creates the host, i.e., <host> element in server.xml // File appBaseFile = new File(tomcatHomeFile, configuration.getAppBase()); // appBaseFile.mkdirs(); // StandardHost host = (StandardHost) embedded.createHost(bindAddress, appBaseFile.getAbsolutePath()); // this.standardHost = host; // if (configuration.getTomcatWorkDir() != null) // { // host.setWorkDir(configuration.getTomcatWorkDir()); // } // host.setUnpackWARs(configuration.isUnpackArchive()); // engine.addChild(host); // // // creates an http connector, i.e., <connector> element in server.xml // Connector connector = embedded.createConnector(InetAddress.getByName(bindAddress), bindPort, false); // embedded.addConnector(connector); // connector.setContainer(engine); // // // starts embedded Mobicents Sip Serlvets // embedded.start(); // // embedded.getService().start(); // // // creates an sip connector, i.e., <connector> element in server.xml // for (SipConnector sipConnector : sipConnectors) { // try { // (sipStandardService).addSipConnector(sipConnector); // // Connector sipConnector = addSipConnector(serverName, bindAddress, bindSipPort, "UDP", null); // } catch (Exception e) { // throw new org.apache.catalina.LifecycleException("Couldn't create the sip connector " + sipConnector, e); // } // } // // wasStarted = true; // // return embedded; }
From source file:org.jboss.as.test.integration.management.api.web.ConnectorTestCase.java
@Test public void testHttpsConnector() throws Exception { FileUtils.copyURLToFile(ConnectorTestCase.class.getResource("test.keystore"), keyStoreFile); if (isNative) addConnector(Connector.HTTPSJIO); else// w ww .ja v a2 s.c o m addConnector(Connector.HTTPS); // check that the connector is live String cURL = "https://" + url.getHost() + ":8181"; HttpClient httpClient = wrapClient(new DefaultHttpClient()); HttpGet get = new HttpGet(cURL); HttpResponse hr = httpClient.execute(get); String response = EntityUtils.toString(hr.getEntity()); assertTrue("Invalid response: " + response, response.indexOf("JBoss") >= 0); if (isNative) removeConnector(Connector.HTTPSJIO); else removeConnector(Connector.HTTPS); if (keyStoreFile.exists()) keyStoreFile.delete(); }
From source file:org.jboss.as.test.integration.management.api.web.ConnectorTestCase.java
@Test public void testHttpsNativeConnector() throws Exception { if (isNative) { FileUtils.copyURLToFile(ConnectorTestCase.class.getResource("newkey.pem"), keyPEMFile); FileUtils.copyURLToFile(ConnectorTestCase.class.getResource("newcert.pem"), certPEMFile); addConnector(Connector.HTTPSNATIVE); // check that the connector is live String cURL = "https://" + url.getHost() + ":8181"; HttpClient httpClient = wrapClient(new DefaultHttpClient()); HttpGet get = new HttpGet(cURL); HttpResponse hr = httpClient.execute(get); String response = EntityUtils.toString(hr.getEntity()); assertTrue("Invalid response: " + response, response.indexOf("JBoss") >= 0); removeConnector(Connector.HTTPSNATIVE); if (keyPEMFile.exists()) keyPEMFile.delete();/* w w w. java2s .c o m*/ if (certPEMFile.exists()) certPEMFile.delete(); } }
From source file:org.jboss.pvt.generic.PVTTestSuite.java
private void init() throws PVTSystemException { if (System.getProperty(PROPERTY_CONFIG) != null && !System.getProperty(PROPERTY_CONFIG).trim().isEmpty()) { configFile = System.getProperty(PROPERTY_CONFIG).trim(); }/*ww w . j a va2 s.c om*/ logger.info("Config file: " + configFile); File confFile = new File(configFile); if (configFile.startsWith("http://")) { try { FileUtils.copyURLToFile(new URL(configFile), confFile); } catch (Exception e) { throw new PVTSystemException(e); } } else { confFile = FileUtils.toFile(PVTTestSuite.class.getResource("/" + configFile)); } logger.info("Config file loaded: " + confFile); configuration = new YAMLConfigurationLoader().loadConfig(confFile); if (System.getProperty(PROPERTY_VERSION) != null && !System.getProperty(PROPERTY_VERSION).trim().isEmpty()) { // override the version defined in config file configuration.setVersion(System.getProperty(PROPERTY_VERSION).trim()); } if (System.getProperty(PROPERTY_TARGET) != null && !System.getProperty(PROPERTY_TARGET).trim().isEmpty()) { // override the version defined in config file configuration.setTarget(System.getProperty(PROPERTY_TARGET).trim()); } // init report report = new Report(configuration); for (Map.Entry<String, TestConfig> entry : configuration.getTests().entrySet()) { report.addTestReport(new TestReport(entry.getKey(), entry.getValue())); } }
From source file:org.jboss.tools.central.internal.CentralHelper.java
public static String getLoadingPageUrl() { Path loadingPage = getLoadingPage(); try {//from w ww . j a v a 2 s. co m if (!Files.exists(loadingPage) //file doesn't exit || loadingPage.getFileName().toString().contains(".qualifier")) { //or during development String packageFolder = CentralHelper.class.getPackage().getName().replace('.', '/'); URL scriptUrl = new URL("platform:/plugin/" + JBossCentralActivator.PLUGIN_ID + "/" + packageFolder //$NON-NLS-1$ + "/loading.html"); URL sourceUrl = FileLocator.resolve(scriptUrl); FileUtils.copyURLToFile(sourceUrl, loadingPage.toFile()); } } catch (IOException e) { JBossCentralActivator.log(e, "Unable to extract loading.html"); return null; } return loadingPage.toUri().toString(); }