如何在与客户机连接时浏览服务器的文件系统(java)

如何在与客户机连接时浏览服务器的文件系统(java),java,web-services,client-server,java-web-start,Java,Web Services,Client Server,Java Web Start,我正在进行概念验证,以便将业务代码与ps3媒体服务器的gui分离(http://www.ps3mediaserver.org/). 为此,我在SourceForge主持了一个项目(http://sourceforge.net/projects/pms-remote/). 客户端应该是一个简单的前端,用于从网络中具有连接到服务器权限的任何位置配置服务器 在服务器端,所有服务都是使用javax.jws公开的,客户端代理是使用wsimport生成的 当前特性的一个特性(实际上是唯一的阻塞特性)是定义将

我正在进行概念验证,以便将业务代码与ps3媒体服务器的gui分离(http://www.ps3mediaserver.org/). 为此,我在SourceForge主持了一个项目(http://sourceforge.net/projects/pms-remote/). 客户端应该是一个简单的前端,用于从网络中具有连接到服务器权限的任何位置配置服务器

在服务器端,所有服务都是使用javax.jws公开的,客户端代理是使用wsimport生成的

当前特性的一个特性(实际上是唯一的阻塞特性)是定义将由服务器共享的文件夹。由于客户机和服务器现在作为单个应用程序在同一台机器上运行,因此浏览其文件系统是很简单的

问题:我想通过web服务公开服务器机器的文件系统。这将允许任何客户机(我当前使用的客户机与使用JavaSwing的原始客户机相同)显示可用文件夹,并选择媒体服务器将显示的文件夹。最后,我唯一感兴趣的是绝对文件夹路径(字符串)

我想我会找到一个库给我这个功能,但找不到任何。 使用UNC路径浏览文件并访问远程机器似乎不可行,因为这对用户来说是不透明的

现在我不想担心安全问题,一旦其他问题可行,我会解决这些问题

如果您有任何意见,我将不胜感激。
谢谢,Philippe,从客户端,您可能能够利用的输出。在服务器上,一个合适的服务器可能就可以了。

我最终创建了一个非常简单的web服务,可以列出给定路径的所有根文件夹或所有子文件夹。 现在由客户端使用(GUI)浏览器来访问此服务

package net.pms.plugin.webservice.filesystem;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

import net.pms.plugin.webservice.ServiceBase;

@WebService(serviceName = "FileSystem", targetNamespace = "http://ps3mediaserver.org/filesystem")
public class FileSystemWebService extends ServiceBase {

    @WebMethod()
    public List<String> getRoots() {
        List<String> roots = new ArrayList<String>();
        for(File child : File.listRoots()) {
            roots.add(child.getAbsolutePath());
        }
        return roots;
    }

    @WebMethod()
    public List<String> getChildFolders(@WebParam(name="folderPath") String folderPath) throws FileNotFoundException {
        List<String> children = new ArrayList<String>();
        File d = new File(folderPath);
        if(d.isDirectory()) {
            for(File child : d.listFiles()) {
                if(child.isDirectory() && !child.isHidden()) {
                    children.add(child.getAbsolutePath());
                }
            }
        } else {
            throw new FileNotFoundException();
        }
        return children;
    }
}

似乎应该有更优雅的东西。这更优雅。你能详细说明一下上下文吗?谢谢。客户机必须具有更多的智能,因为它必须创建文件夹树本身,但这是解决方案的固有特性,客户机可以使用不同的技术(java、net、web、rich…)。我需要能够从可能在远程机器上运行的客户端配置共享文件夹(位于服务器上)。这是你根据上下文所说的吗?间接地;我把
javax.jws
中的
jws
部分误认为是JavaWebStart,而不是Java(基于XML的)Web服务。我将添加标签。
package net.pms.plugin.webservice;

import javax.xml.ws.Endpoint;

import org.apache.log4j.Logger;

public abstract class ServiceBase {
    private static final Logger log = Logger.getLogger(ServiceBase.class);
    protected boolean isInitialized;

    /**
     * the published endpoint
     */
    private Endpoint endpoint = null;

    /**
     * 
     * Start to listen for remote requests
     * 
     * @param host ip or host name
     * @param port port to use
     * @param path name of the web service
     */
    public void bind(String host, int port, String path) {
        String endpointURL = "http://" + host + ":" + port + "/" + path;
        try {
            endpoint = Endpoint.publish(endpointURL, this);
            isInitialized = true;
            log.info("Sucessfully bound enpoint: " + endpointURL);
        } catch (Exception e) {
            log.error("Failed to bind enpoint: " + endpointURL, e);
        }
    }

    /**
     * Stop the webservice
     */
    public void shutdown() {
        log.info("Shut down " + getClass().getName());
        if (endpoint != null)
            endpoint.stop();
        endpoint = null;
    }

}