Example usage for java.io File toURL

List of usage examples for java.io File toURL

Introduction

In this page you can find the example usage for java.io File toURL.

Prototype

@Deprecated
public URL toURL() throws MalformedURLException 

Source Link

Document

Converts this abstract pathname into a file: URL.

Usage

From source file:org.apache.axis2.scripting.ScriptDeploymentEngine.java

/**
 * Creates an Axis2 service for the script
 *//*  w w  w  .j  av  a 2s .  c om*/
protected AxisService createService(File wsdlFile, File scriptFile) {
    AxisService axisService = null;
    try {

        InputStream definition;
        try {
            definition = wsdlFile.toURL().openStream();
        } catch (Exception e) {
            throw new AxisFault("exception opening wsdl", e);
        }

        WSDLToAxisServiceBuilder builder = new WSDL11ToAxisServiceBuilder(definition);
        builder.setServerSide(true);
        axisService = builder.populateService();

        //axisService.setScope(Constants.SCOPE_APPLICATION);
        Parameter userWSDL = new Parameter("useOriginalwsdl", "true");
        axisService.addParameter(userWSDL);

        Parameter scriptSrc = new Parameter(ScriptReceiver.SCRIPT_SRC_PROP, readScriptSource(scriptFile));
        axisService.addParameter(scriptSrc);

        ScriptReceiver scriptReceiver = new ScriptReceiver();
        axisService.addMessageReceiver("http://www.w3.org/2004/08/wsdl/in-out", scriptReceiver);

        // TODO: Shouldn't this be done by WSDLToAxisServiceBuilder.populateService?
        for (Iterator it = axisService.getOperations(); it.hasNext();) {
            AxisOperation operation = (AxisOperation) it.next();
            operation.setMessageReceiver(scriptReceiver);
        }

        Parameter scriptParam = new Parameter(ScriptReceiver.SCRIPT_ATTR, scriptFile.toString());
        axisService.addParameter(scriptParam);

        axisService.setName(scriptFile.getName().substring(0, scriptFile.getName().lastIndexOf('.')));

    } catch (Throwable e) {
        log.warn("AxisFault creating script service", e);
        e.printStackTrace();
    }

    return axisService;
}

From source file:org.onecmdb.core.internal.job.workflow.sample.DirectoryImportProcess.java

@Override
public void run() throws Throwable {
    this.terminate = false;
    for (String path : importPaths) {

        File pathFile = new File(path);
        if (!pathFile.isDirectory()) {
            log.warn("Path '" + path + "' is not a directory, will skip.");
            continue;
        }/*from  w w  w  .ja  va 2 s .  com*/
        log.info("Process directory '" + path + "'");
        File files[] = pathFile.listFiles();
        for (File f : files) {
            if (terminate) {
                throw new InterruptedException("Iport operation interrupted");
            }
            log.info("Process file '" + f.getName() + "' in directory '" + path + "'");
            XmlParser xmlProvider = new XmlParser();
            xmlProvider.setURL(f.toURL().toExternalForm());

            // Process beans
            ProcessBeanProvider importBeans = new ProcessBeanProvider();
            WorkflowParameter par = new WorkflowParameter();
            par.put("provider", xmlProvider);
            par.put("validation", "false");
            importBeans.setInParameter(par);
            importBeans.setRelevantData(data);
            importBeans.run();

            // Commit
            BeanScope scope = (BeanScope) importBeans.getOutParameter().get("scope");
            List<IRFC> rfcs = scope.getRFCs();

            CommitRfcProcess commit = new CommitRfcProcess();
            WorkflowParameter par1 = new WorkflowParameter();
            System.out.println(rfcs.size() + " Rfc's generated ");
            par1.put("rfcs", rfcs);
            commit.setInParameter(par1);
            commit.setRelevantData(data);
            commit.run();
            String ok = (String) commit.getOutParameter().get("ok");
            String cause = (String) commit.getOutParameter().get("cause");
        }
    }

}

From source file:com.impetus.kundera.classreading.ClasspathReader.java

/**
 * Scan class resource in the provided urls with the additional Class-Path
 * of each jar checking//from w ww. ja v a 2 s.  c  o m
 * 
 * @param classRelativePath
 *            relative path to a class resource
 * @param urls
 *            urls to be checked
 * @return list of class path included in the base package
 */
private URL[] findResourcesInUrls(String classRelativePath, URL[] urls) {
    List<URL> list = new ArrayList<URL>();
    for (URL url : urls) {
        if (AllowedProtocol.isValidProtocol(url.getProtocol().toUpperCase())
                && url.getPath().endsWith(".jar")) {
            try {
                JarFile jarFile = new JarFile(URLDecoder.decode(url.getFile(), Constants.CHARSET_UTF8));

                // Checking the dependencies of this jar file
                Manifest manifest = jarFile.getManifest();
                if (manifest != null) {
                    String classPath = manifest.getMainAttributes().getValue("Class-Path");
                    // Scan all entries in the classpath if they are
                    // specified in the jar
                    if (!StringUtils.isEmpty(classPath)) {
                        List<URL> subList = new ArrayList<URL>();
                        for (String cpEntry : classPath.split(" ")) {
                            try {
                                subList.add(new URL(cpEntry));
                            } catch (MalformedURLException e) {
                                URL subResources = ClasspathReader.class.getClassLoader().getResource(cpEntry);
                                if (subResources != null) {
                                    subList.add(subResources);
                                }
                                // logger.warn("Incorrect URL in the classpath of a jar file ["
                                // + url.toString()
                                // + "]: " + cpEntry);
                            }
                        }
                        list.addAll(Arrays.asList(findResourcesInUrls(classRelativePath,
                                subList.toArray(new URL[subList.size()]))));
                    }
                }
                JarEntry present = jarFile.getJarEntry(classRelativePath + ".class");
                if (present != null) {
                    list.add(url);
                }
            } catch (IOException e) {
                logger.warn("Error during loading from context , Caused by:" + e.getMessage());
            }

        } else if (url.getPath().endsWith("/")) {
            File file = new File(url.getPath() + classRelativePath + ".class");
            if (file.exists()) {
                try {
                    list.add(file.toURL());
                } catch (MalformedURLException e) {
                    throw new ResourceReadingException(e);
                }
            }
        }

    }
    return list.toArray(new URL[list.size()]);
}

From source file:com.impetus.kundera.classreading.ClasspathReader.java

/**
 * Uses the java.class.path system property to obtain a list of URLs that
 * represent the CLASSPATH/*from  w  w w.jav a  2s. com*/
 * 
 * @return the URl[]
 */
@SuppressWarnings("deprecation")
@Override
public final URL[] findResourcesByClasspath() {
    List<URL> list = new ArrayList<URL>();
    String classpath = System.getProperty("java.class.path");
    StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator);

    while (tokenizer.hasMoreTokens()) {
        String path = tokenizer.nextToken();

        File fp = new File(path);
        if (!fp.exists())
            throw new ResourceReadingException("File in java.class.path does not exist: " + fp);
        try {
            list.add(fp.toURL());
        } catch (MalformedURLException e) {
            throw new ResourceReadingException(e);
        }
    }
    return list.toArray(new URL[list.size()]);
}

From source file:org.deegree.ogcwebservices.wass.wss.operation.WSSOperationTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();
    try {/*from  ww w .  j  av a  2  s.  c  om*/
        resourceLocation = Configuration.getResourceDir().getFile() + "wass/wss/example/deegree/";
        // hardcoded, but not to the local file system ;-)
        File file = new File(resourceLocation + "example_wss_capabilities.xml");
        URL url = file.toURL();
        WASServiceFactory.setConfiguration(url);
        service = WASServiceFactory.getUncachedWSService();
        LOG.logInfo("Setting up WSS...done.");
    } catch (OGCWebServiceException e) {
        skip = true;
    } catch (Exception e) {
        throw e;
    }
}

From source file:org.deegree.ogcwebservices.wass.wss.operation.WSSOperationTest.java

/**
 * @throws Exception//  w  ww  . j a va 2 s .  c o  m
 */
public void testGetSession() throws Exception {
    if (skip) {
        LOG.logInfo("Skipping WSS service test (no database available?).");
        return;
    }
    LOG.logInfo("\n\nTesting GetSession with xml_examplefile");
    assertNotNull("Service not initialized", service);
    SessionOperationsDocument doc = new SessionOperationsDocument();
    assertNotNull("Could not create empty GetSession document", doc);
    File xml = new File(resourceLocation + "requests/GetSession/GetSessionExample_1.xml");
    doc.load(xml.toURL());
    GetSession request = doc.parseGetSession("1", doc.getRootElement());
    doGetSession(request);
}

From source file:org.rhq.core.pc.plugin.FileSystemPluginFinder.java

/**
 * Loads all plugins found in the given directory.
 *
 * @param  pluginDir//  w  ww  . ja va  2s. c  o  m
 *
 * @return URLs that point to all plugins found in the given directory
 */
private Collection<URL> findPluginsInDirectory(File pluginDir) {
    Collection<URL> pluginUrls = new HashSet<URL>();

    File[] jars = pluginDir.listFiles(JAR_FILTER);

    if (jars == null) {
        return pluginUrls;
    }

    for (File jar : jars) {
        if (pluginModifiedTimes.containsKey(jar) && (jar.lastModified() == pluginModifiedTimes.get(jar))) {
            // Already loaded and has not been modified
            continue;
        }

        pluginModifiedTimes.put(jar, jar.lastModified());

        try {
            URL jarUrl = jar.toURL();
            pluginUrls.add(jarUrl);
        } catch (MalformedURLException e) {
            log.error("Could not get URL for plugin jar: " + jar);
        }
    }

    return pluginUrls;
}

From source file:org.pentaho.reporting.engine.classic.core.modules.parser.extwriter.ReportConverter.java

/**
 * Parses a report from the old version of the XML report format, and writes a file in the new XML report format.
 *
 * @param in/*from  w w w. j  a  v  a2s  .c o  m*/
 *          the input report file.
 * @param out
 *          the output report file.
 * @param encoding
 *          the encoding of the generated file.
 * @throws IOException
 *           if there is an I/O problem.
 * @throws ReportWriterException
 *           if there is a problem writing the report.
 */
public void convertReport(final File in, final File out, final String encoding)
        throws IOException, ReportWriterException {
    final OutputStream base = new FileOutputStream(out);
    final Writer w = new BufferedWriter(new OutputStreamWriter(base, encoding));
    try {
        convertReport(in.toURL(), out.toURL(), w, encoding);
    } finally {
        w.close();
    }
}

From source file:org.wso2.carbon.springservices.ui.SpringServiceMaker.java

public SpringBeansData getSpringBeanNames(String springContextId, String springBeanId,
        ClassLoader bundleClassLoader) throws AxisFault {
    // Manipulation of springContext to ${RepositoryLocation}/spring

    String springContextFilePath = getFilePathFromArchiveId(springContextId);
    String springBeanFilePath = getFilePathFromArchiveId(springBeanId);
    SpringBeansData data = new SpringBeansData();
    data.setSpringContext(springContextId);

    File urlFile = new File(springBeanFilePath);

    ClassLoader prevCl = Thread.currentThread().getContextClassLoader();
    ClassLoader urlCl;/*from ww  w  . j av  a2  s.c om*/
    try {
        URL url = urlFile.toURL();
        urlCl = URLClassLoader.newInstance(new URL[] { url }, bundleClassLoader);

        // Save the class loader so that you can restore it later
        Thread.currentThread().setContextClassLoader(urlCl);

        ApplicationContext aCtx = GenericApplicationContextUtil
                .getSpringApplicationContext(springContextFilePath, springBeanFilePath);
        String[] beanDefintions = aCtx.getBeanDefinitionNames();
        data.setBeans(beanDefintions);
    } catch (Exception e) {
        String msg = bundle.getString("spring.cannot.load.spring.beans");
        handleException(msg, e);
    } finally {
        Thread.currentThread().setContextClassLoader(prevCl);
    }
    return data;
}

From source file:org.deegree.ogcwebservices.wass.wss.operation.WSSOperationTest.java

/**
 * @throws Exception/*from ww w  .ja v a2s. co  m*/
 */
public void testDoService() throws Exception {
    if (skip) {
        LOG.logInfo("Skipping WSS service test (no database available?).");
        return;
    }
    assertNotNull("Service not initialized", service);
    DoServiceDocument doc = new DoServiceDocument();
    assertNotNull("Could not create empty doservice document", doc);
    File[] doServiceExampleFiles = new File(resourceLocation + "requests/DoService/").listFiles();
    for (File f : doServiceExampleFiles) {
        if (f.isFile()) {
            LOG.logInfo("examplefile:" + f.toURL());
            doc.load(f.toURL());
            DoService request = doc.parseDoService("1", doc.getRootElement());
            doDoService(request);
        }
    }
}