List of usage examples for java.lang ClassLoader getResource
public URL getResource(String name)
From source file:com.cloudera.nav.sdk.client.SSLUtilsTest.java
@Test public void testGetTrustManager() throws Exception { // From config ClassLoader classLoader = getClass().getClassLoader(); config.setSSLTrustStoreLocation(classLoader.getResource("trust.jks").getFile()); config.setSSLTrustStorePassword("trustP"); TrustManager trustManager = SSLUtils.getTrustManager(config); assertTrue(trustManager instanceof X509TrustManager); ((X509TrustManager) trustManager) .checkClientTrusted(certs.values().toArray(new X509Certificate[certs.size()]), "RSA"); // Override//from ww w . j a v a 2 s . c o m config.setOverrideTrustManager(new TestTrustManager()); trustManager = SSLUtils.getTrustManager(config); assertTrue(trustManager instanceof TestTrustManager); // Disabled config.setDisableSSLValidation(true); trustManager = SSLUtils.getTrustManager(config); assertTrue(trustManager instanceof SSLUtils.AcceptAllTrustManager); }
From source file:org.callistasoftware.netcare.mvk.authentication.service.impl.MvkTokenServiceImpl.java
private PushIdInterface getService(final String address) { try {// w w w. j a v a 2 s. c o m final ClassLoader loader = Thread.currentThread().getContextClassLoader(); final URL wsdl = loader .getResource("schemas/SSO/interactions/pushid/Mvk_SSOService_CertAuth_PushId_Cert_Facade.wsdl"); final ExportsPushIdCertFacadePushIdInterfaceHttpService service = new ExportsPushIdCertFacadePushIdInterfaceHttpService( wsdl); final PushIdInterface serviceInterface = service.getExportsPushIdCertFacadePushIdInterfaceHttpPort(); ((BindingProvider) serviceInterface).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address); return serviceInterface; } catch (final Exception e) { throw new RuntimeException(e); } }
From source file:business.SmallExcerptListTests.java
@Test(groups = "request", dependsOnMethods = "approveRequest") public void uploadExcerptList() throws IOException { UserAuthenticationToken palga = getPalga(); SecurityContext securityContext = SecurityContextHolder.getContext(); securityContext.setAuthentication(palga); RequestRepresentation representation = requestController.getRequestById(palga, processInstanceId); log.info("Status: " + representation.getStatus()); log.info("Activity: " + representation.getActivityId()); if (representation.getActivityId() == null) { for (Task task : taskService.createTaskQuery().list()) { log.info("Task " + task.getId() + ", process instance: " + task.getProcessInstanceId() + ", name: " + task.getName() + ", key: " + task.getTaskDefinitionKey()); }/*ww w. j a v a 2 s . co m*/ } log.info("uploadExcerptList: processInstanceId = " + processInstanceId); representation = requestController.claim(palga, processInstanceId, representation); ClassLoader classLoader = getClass().getClassLoader(); URL resource = classLoader.getResource("test/Example excerptlist.csv"); InputStream input = resource.openStream(); MultipartFile file = new MockMultipartFile(resource.getFile(), input); Integer flowTotalChunks = 1; Integer flowChunkNumber = 1; String flowIdentifier = "flow"; int entryCount = requestController.uploadExcerptList(palga, processInstanceId, resource.getFile(), flowTotalChunks, flowChunkNumber, flowIdentifier, file); assertEquals(3, entryCount); SecurityContextHolder.clearContext(); }
From source file:com.viddu.handlebars.HandlebarsMojoTest.java
protected Scriptable loadHandlebarsLibrary() throws FileNotFoundException { ClassLoader ccl = Thread.currentThread().getContextClassLoader(); Context handlebarContext = Context.enter(); URL handleBarsUrl = ccl.getResource("handlebars-1.0.rc.1.js"); Scriptable globalScope = handlebarContext.initStandardObjects(); Reader handlebarsReader = new FileReader(new File(handleBarsUrl.getPath())); try {//from w w w . java2 s . com handlebarContext.evaluateReader(globalScope, handlebarsReader, "Handlebars 1_0", 0, null); } catch (IOException e) { throw new RuntimeException("Exception loading handlebars Library"); } finally { Context.exit(); } return globalScope; }
From source file:business.LargerExcerptListTests.java
@Test(groups = "request", dependsOnMethods = "approveRequest") public void uploadExcerptList() throws IOException { UserAuthenticationToken palga = getPalga(); SecurityContext securityContext = SecurityContextHolder.getContext(); securityContext.setAuthentication(palga); RequestRepresentation representation = requestController.getRequestById(palga, processInstanceId); log.info("Status: " + representation.getStatus()); log.info("Activity: " + representation.getActivityId()); if (representation.getActivityId() == null) { for (Task task : taskService.createTaskQuery().list()) { log.info("Task " + task.getId() + ", process instance: " + task.getProcessInstanceId() + ", name: " + task.getName() + ", key: " + task.getTaskDefinitionKey()); }//ww w . j a v a 2 s. co m } log.info("uploadExcerptList: processInstanceId = " + processInstanceId); representation = requestController.claim(palga, processInstanceId, representation); ClassLoader classLoader = getClass().getClassLoader(); URL resource = classLoader.getResource("test/Example excerptlist 20150521 v2.csv"); InputStream input = resource.openStream(); MultipartFile file = new MockMultipartFile(resource.getFile(), input); Integer flowTotalChunks = 1; Integer flowChunkNumber = 1; String flowIdentifier = "flow"; int entryCount = requestController.uploadExcerptList(palga, processInstanceId, resource.getFile(), flowTotalChunks, flowChunkNumber, flowIdentifier, file); assertEquals(6, entryCount); SecurityContextHolder.clearContext(); }
From source file:com.itemanalysis.jmetrik.data.JmetrikFileImporterTest.java
@Test public void genericImportTest() { System.out.println("JmetrikFileImporterTest: Importing ./data/example-import-file.txt"); ClassLoader classLoader = getClass().getClassLoader(); File f = new File(classLoader.getResource("data/example-import-file.txt").getFile()); String fileName = f.getAbsolutePath(); ImportDataCommand command = new ImportDataCommand(); command.setDataFileOption(fileName); command.setDelimiter("comma"); String[] selectAllOptions = { "header", "overwrite" }; command.setOptionsOption(selectAllOptions); JmetrikFileImporter fileImporter = new JmetrikFileImporter(command); fileImporter.doInBackground();// ww w. j a v a2s .c o m }
From source file:de.hasait.genesis.scriptgen.ScriptGenProcessor.java
private void processScriptGen(final ScriptGen pScriptGenAnnotation, final GeneratorEnv pGeneratorEnv) throws Exception { final String scriptResourcePath = pScriptGenAnnotation.script(); if (StringUtils.isBlank(scriptResourcePath)) { pGeneratorEnv.printError("Parameter \"script\" must not be blank"); return;// ww w.jav a 2 s .c om } final ClassLoader classLoader = getClass().getClassLoader(); URL scriptFileURL = classLoader.getResource(scriptResourcePath); if (scriptFileURL == null) { for (final String scriptLocationString : _locations) { scriptFileURL = classLoader.getResource(scriptLocationString + "/" + scriptResourcePath); if (scriptFileURL != null) { break; } } } if (scriptFileURL == null) { pGeneratorEnv.printError("Script \"%s\" not found", scriptResourcePath); return; } final int indexOfDot = scriptResourcePath.indexOf('.'); if (indexOfDot <= 1) { pGeneratorEnv.printError("Script name \"%s\" must have an extension", scriptResourcePath); return; } final String scriptFileExtension = scriptResourcePath.substring(indexOfDot + 1); final ScriptEngine engine = determineScriptEngine(scriptFileExtension, classLoader); if (engine == null) { pGeneratorEnv.printError("Script extension \"%s\" unsupported", scriptFileExtension); return; } try (InputStream scriptFileIn = scriptFileURL.openStream(); Reader scriptFileR = new InputStreamReader(scriptFileIn)) { engine.eval(scriptFileR); final ScriptEnv scriptEnv = new ScriptEnv(pGeneratorEnv, scriptFileURL, pScriptGenAnnotation.args()); ((Invocable) engine).invokeFunction("generate", scriptEnv); } }
From source file:de.stefanheintz.log.jmxservice.LoggingConfigImpl.java
public void resetConfiguration() { ClassLoader cl = getClass().getClassLoader(); LogManager.resetConfiguration(); URL log4jprops = cl.getResource("log4j.properties"); if (log4jprops != null) { PropertyConfigurator.configure(log4jprops); sendNotification(NotificationType.RESET_CONFIGURATION, "used file: " + log4jprops.getFile()); }//from w ww .jav a 2 s .c o m }
From source file:com.h3xstream.findbugs.test.BaseDetectorTest.java
/** * The test dependencies are added by default to avoid ClassNotFoundException when analyzing the test sample. * Those classes are required if the inheritance hierarchy is analyzed. * @return The path to either the compiled directory of the project or its jar. *//*w w w . j a v a 2 s. co m*/ private String getPluginDepsJarPath() { ClassLoader cl = getClass().getClassLoader(); String url = cl.getResource("PluginDepsClassPathFinder.class").toExternalForm(); String separateFile = "/target/classes/PluginDepsClassPathFinder.class"; //In the IDE, the compiled directory are used. String insideJar = "!/PluginDepsClassPathFinder.class"; //With Maven, the jar will be reference. for (String suffix : Arrays.asList(separateFile, insideJar)) { if (url.endsWith(suffix)) { String filename = url.substring(0, url.length() - suffix.length()); if (suffix == separateFile) { filename += "/target/classes/"; //This part of the suffix need to be kept } //FindBugs will open file handle (java.io.File). The protocol file: need to be removed. for (String prefix : Arrays.asList("file:", "jar:file:")) { if (filename.startsWith(prefix)) { filename = filename.substring(prefix.length()); } } return filename; } } throw new RuntimeException("Unable to locate the dependencies for test in the classpath."); }
From source file:com.itemanalysis.jmetrik.data.JmetrikFileImporterTest.java
@Test public void exam1ImportTest() { System.out.println("JmetrikFileImporterTest: Importing ./data/exam1-raw-data.csv"); ClassLoader classLoader = getClass().getClassLoader(); File f = new File(classLoader.getResource("data/exam1-raw-data.csv").getFile()); String path = f.getParent();//www . j a v a2 s.co m File outputFile = new File(path + File.separator + "exam1.jmetrik"); try { outputFile.createNewFile(); } catch (IOException ex) { ex.printStackTrace(); } ImportDataCommand command = new ImportDataCommand(); command.setDataFileOption(f.getAbsolutePath()); command.setOutfileOption(outputFile.getAbsolutePath()); command.setDelimiter("comma"); String[] selectAllOptions = { "header", "overwrite" }; command.setOptionsOption(selectAllOptions); JmetrikFileImporter fileImporter = new JmetrikFileImporter(command); fileImporter.doInBackground(); }