我使用代理

时间:2017-02-04 14:21:45

标签: java xml-rpc

我正在尝试使用xml-rpc应用我的第一个websever编程来显示远程文件目录。

需要应用动态代理,但是当我编译它时,有一个。

exception:java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.util.ArrayList
    at com.sun.proxy.$Proxy0.getFilesList(Unknown Source)
    at client.XMLRPCClient.main(XMLRPCClient.java:39)

然而,我认为这条线是正确的。那么你能给我一些建议吗?

这些是代码:

//This is client.Client.java file.

package client;

import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;

import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;
import org.apache.xmlrpc.client.util.ClientFactory;
import ws.IWebService;

 public class XMLRPCClient {

public static void main(String[] args) {
    XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
    try {
        config.setServerURL(new URL("http://127.0.0.1:"
                + Integer.parseInt(args[0]) + "/"));

        XmlRpcClient client = new XmlRpcClient();

        client.setTransportFactory(new XmlRpcCommonsTransportFactory(client));

        config.setEnabledForExceptions(true);

        client.setConfig(config);

        ClientFactory clientFactory = new ClientFactory(client);

        IWebService webService = (IWebService) clientFactory.newInstance(IWebService.class);

        String path,filePath = "public/files";

        ArrayList<String> arrayList = new ArrayList<String>(webService.getFilesList(filePath));

        Iterator<String> iterator = arrayList.iterator();

        while (iterator.hasNext()) {

            path = iterator.next();

            System.out.printf(path + "\n");}

    } catch (Exception e) {
        e.printStackTrace();
    }
}

}

//This is ws.IWebService.java file.
  package ws;

import java.util.ArrayList;
public interface IWebService {

public ArrayList<String>getFilesList(String filePath);

}




//This Iwebserver.class
 package ws;


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



 public class WebService implements IWebService {


 public ArrayList<String>getFilesList(String filePath){


 ArrayList<String> arrayList = new ArrayList<String>();

 String[] paths;


try {

File files = new File(filePath);

paths = files.list();

for(String path:paths){

    arrayList.add(String.valueOf(path));
}



} catch (Exception e) {

arrayList.add(e.getMessage()+" ");

 }

return arrayList;

 }

 }

0 个答案:

没有答案