0

I'm trying to use xml-rpc to apply my first websever programming to show the remote file directory.

It is required to be applied the dynamic proxy but when I compile it, there was one.

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)

However, I thought that this line was correct. So could you give me some suggetions?

These are the code:

//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;

 }

 }
Newd
  • 2,148
  • 2
  • 15
  • 31
Yan Feng
  • 1
  • 1

0 Answers0