List of usage examples for org.springframework.util ResourceUtils CLASSPATH_URL_PREFIX
String CLASSPATH_URL_PREFIX
To view the source code for org.springframework.util ResourceUtils CLASSPATH_URL_PREFIX.
Click Source Link
From source file:com.taobao.itest.listener.ResourceLocationProcessingUtil.java
public static String[] generateDefaultLocations(Class<?> clazz, String suffix) { return new String[] { ResourceUtils.CLASSPATH_URL_PREFIX + "/" + clazz.getName().replace('.', '/') + suffix }; }
From source file:com.taobao.itest.listener.ResourceLocationProcessingUtil.java
public static String[] modifyLocations(Class<?> clazz, String... locations) { String[] modifiedLocations = new String[locations.length]; for (int i = 0; i < locations.length; i++) { String path = locations[i]; if (path.startsWith("/")) { modifiedLocations[i] = ResourceUtils.CLASSPATH_URL_PREFIX + path; } else if (!ResourcePatternUtils.isUrl(path)) { modifiedLocations[i] = ResourceUtils.CLASSPATH_URL_PREFIX + "/" + StringUtils.cleanPath(ClassUtils.classPackageAsResourcePath(clazz) + "/" + path); } else {// ww w. j a v a 2 s . co m modifiedLocations[i] = StringUtils.cleanPath(path); } } return modifiedLocations; }
From source file:cn.digirun.frame.payment.wxpay.util.ClientCustomSSL.java
public static String doRefund(String url, String data) throws Exception { /**/*from w w w. j av a2 s.c o m*/ * ?PKCS12? ?-- API */ KeyStore keyStore = KeyStore.getInstance("PKCS12"); /** * ? */ //ResourceUtils.getFile(ResourceUtils.CLASSPATH_URL_PREFIX+ ""); // FileInputStream instream = new FileInputStream(new File("D:/Program Files/MyEclipse 6.5/workspace/weidian/WebRoot/cer/apiclient_cert.p12"));//P12 FileInputStream instream = new FileInputStream( ResourceUtils.getFile(ResourceUtils.CLASSPATH_URL_PREFIX + WxpayConfig.cert_path)); try { /** * ? * MCHID * */ keyStore.load(instream, WxpayConfig.mch_id.toCharArray()); } finally { instream.close(); } SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, WxpayConfig.mch_id.toCharArray())//? .build(); // Allow TLSv1 protocol only SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); try { HttpPost httpost = new HttpPost(url); // ?? httpost.addHeader("Connection", "keep-alive"); httpost.addHeader("Accept", "*/*"); httpost.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); httpost.addHeader("Host", "api.mch.weixin.qq.com"); httpost.addHeader("X-Requested-With", "XMLHttpRequest"); httpost.addHeader("Cache-Control", "max-age=0"); httpost.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) "); httpost.setEntity(new StringEntity(data, "UTF-8")); CloseableHttpResponse response = httpclient.execute(httpost); try { HttpEntity entity = response.getEntity(); String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8"); EntityUtils.consume(entity); return jsonStr; } finally { response.close(); } } finally { httpclient.close(); } }
From source file:com.github.jknack.handlebars.springmvc.SpringTemplateLoader.java
@Override public String resolve(final String location) { String protocol = null;// w w w . j ava 2s .com if (location.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) { protocol = ResourceUtils.CLASSPATH_URL_PREFIX; } else if (location.startsWith(ResourceUtils.FILE_URL_PREFIX)) { protocol = ResourceUtils.FILE_URL_PREFIX; } if (protocol == null) { return super.resolve(location); } return protocol + super.resolve(location.substring(protocol.length())); }
From source file:spring.osgi.utils.OsgiResourceUtilsTest.java
@Test public void testGetSearchTypeBundleClassSpace() { assertEquals(OsgiResourceUtils.PREFIX_TYPE_CLASS_SPACE, OsgiResourceUtils.getSearchType(ResourceUtils.CLASSPATH_URL_PREFIX + "path")); }
From source file:edu.amc.sakai.user.JLDAPDirectoryProviderIntegrationTestSupport.java
ConfigurableApplicationContext newTestApplicationContext(ApplicationContext parent) { List existingFiles = new ArrayList(); for (String fileName : TEST_CONTEXT_CONFIG_FILE_NAMES) { try {//from w ww .ja v a 2s .co m ResourceUtils.getFile(ResourceUtils.getURL(ResourceUtils.CLASSPATH_URL_PREFIX + fileName)); existingFiles.add(fileName); } catch (FileNotFoundException e) { // } } String[] existingFilesArray = new String[existingFiles.size()]; return new ClassPathXmlApplicationContext((String[]) existingFiles.toArray(existingFilesArray), parent); }
From source file:com.excilys.ebi.utils.spring.log.logback.test.LogbackConfigurerTestExecutionListener.java
/** * Generates the default classpath resource location based on the supplied * class./*from w w w .j a v a2 s .c o m*/ * <p> * For example, if the supplied class is <code>com.example.MyTest</code>, * the generated location will be a string with a value of * "classpath:/com/example/<code><suffix></code>", where * <code><suffix></code> is the value of the * {@link #getResourceName() resource name} string. * <p> * Subclasses can override this method to implement a different * <em>default location generation</em> strategy. * * @param clazz * the class for which the default locations are to be generated * @return an array of default application context resource locations * @see #getResourceSuffix() */ private String generateDefaultLocation(Class<?> clazz) { Assert.notNull(clazz, "Class must not be null"); return ResourceUtils.CLASSPATH_URL_PREFIX + StringUtils.cleanPath(ClassUtils.classPackageAsResourcePath(clazz) + "/" + getResourceName()); }
From source file:com.excilys.ebi.spring.dbunit.test.conventions.DefaultConfigurationConventions.java
/** * Generate a modified version of the supplied location and returns it. * <p>/*from w w w . java 2s . c om*/ * A plain path, e.g. "myDataSet.xml", will be treated as a classpath resource from the same package in * which the specified class is defined. A path starting with a slash is treated as a fully qualified class path * location, e.g.: "/com/example/whatever/foo.xml". A path which references a URL (e.g., a path prefixed * with {@link ResourceUtils#CLASSPATH_URL_PREFIX classpath:}, {@link ResourceUtils#FILE_URL_PREFIX file:}, * <code>http:</code>, etc.) will be added to the results unchanged. * <p> * Subclasses can override this method to implement a different <em>location modification</em> strategy. * * @param clazz the class with which the locations are associated * @param locations the resource location to be modified * @return the modified application context resource location */ private String getRealLocationByConventions(Class<?> clazz, String location) { String modifiedLocation = null; if (location.startsWith("/")) { modifiedLocation = ResourceUtils.CLASSPATH_URL_PREFIX + location; } else if (!isUrl(location)) { modifiedLocation = ResourceUtils.CLASSPATH_URL_PREFIX + cleanPath(classPackageAsResourcePath(clazz) + "/" + location); } else { modifiedLocation = cleanPath(location); } return modifiedLocation; }
From source file:com.excilys.ebi.utils.spring.log.logback.test.LogbackConfigurerTestExecutionListener.java
/** * Generate a modified version of the supplied location and returns it. * <p>/* w ww. j av a 2 s .c o m*/ * A plain path, e.g. "context.xml", will be treated as a * classpath resource from the same package in which the specified class is * defined. A path starting with a slash is treated as a fully qualified * class path location, e.g.: "/com/example/whatever/foo.xml". A * path which references a URL (e.g., a path prefixed with * {@link ResourceUtils#CLASSPATH_URL_PREFIX classpath:}, * {@link ResourceUtils#FILE_URL_PREFIX file:}, <code>http:</code>, etc.) * will be added to the results unchanged. * <p> * Subclasses can override this method to implement a different * <em>location modification</em> strategy. * * @param clazz * the class with which the locations are associated * @param locations * the resource location to be modified * @return the modified application context resource location */ protected String modifyLocation(Class<?> clazz, String location) { String modifiedLocation = null; if (location.startsWith("/")) { modifiedLocation = ResourceUtils.CLASSPATH_URL_PREFIX + location; } else if (!ResourcePatternUtils.isUrl(location)) { modifiedLocation = ResourceUtils.CLASSPATH_URL_PREFIX + StringUtils.cleanPath(ClassUtils.classPackageAsResourcePath(clazz) + "/" + location); } else { modifiedLocation = StringUtils.cleanPath(location); } return modifiedLocation; }
From source file:com.excilys.ebi.spring.dbunit.test.conventions.DefaultConfigurationConventions.java
/** * Generates the default classpath resource location based on the supplied class. * <p>// w w w.j a va 2 s. c o m * For example, if the supplied class is <code>com.example.MyTest</code>, the generated location will be a string * with a value of "classpath:/com/example/<code><suffix></code>", where <code><suffix></code> * is the value of the {@link #getResourceName() resource name} string. * <p> * Subclasses can override this method to implement a different <em>default location generation</em> strategy. * * @param clazz the class for which the default locations are to be generated * @param defaultResourceName the default resource name * @return an array of default application context resource locations * @see #getResourceSuffix() */ private String getDefaultLocationByConventions(Class<?> clazz, final String defaultResourceName) { StringBuilder builder = new StringBuilder(); builder.append(ResourceUtils.CLASSPATH_URL_PREFIX); builder.append(cleanPath(classPackageAsResourcePath(clazz))); builder.append("/"); builder.append(defaultResourceName); return builder.toString(); }