Question

I hava a proxy class in my Eclipse project for project to consume a web service. The proxy class looks like this (auto-generated code from the wizard)

public class WebServiceUpg2SoapProxy implements org.uppgift2.www.WebServiceUpg2Soap {
private String _endpoint = null;
private org.uppgift2.www.WebServiceUpg2Soap webServiceUpg2Soap = null;

public WebServiceUpg2SoapProxy() {
    _initWebServiceUpg2SoapProxy();
}

public WebServiceUpg2SoapProxy(String endpoint) {
    _endpoint = endpoint;
    _initWebServiceUpg2SoapProxy();
}

private void _initWebServiceUpg2SoapProxy() {
try {
    webServiceUpg2Soap = (new org.uppgift2.www.WebServiceUpg2Locator()).getWebServiceUpg2Soap();
    if (webServiceUpg2Soap != null) {
    if (_endpoint != null)
    ((javax.xml.rpc.Stub)webServiceUpg2Soap)._setProperty("javax.xml.rpc.service.endpoint.address", _endpoint);
    else
    _endpoint = (String)((javax.xml.rpc.Stub)webServiceUpg2Soap)._getProperty("javax.xml.rpc.service.endpoint.address");
}

}
catch (javax.xml.rpc.ServiceException serviceException) {}
}

public String getEndpoint() {
    return _endpoint;
}

public void setEndpoint(String endpoint) {
    _endpoint = endpoint;
    if (webServiceUpg2Soap != null)
    ((javax.xml.rpc.Stub)webServiceUpg2Soap)._setProperty("javax.xml.rpc.service.endpoint.address", _endpoint);

}

public org.uppgift2.www.WebServiceUpg2Soap getWebServiceUpg2Soap() {
    if (webServiceUpg2Soap == null)
    _initWebServiceUpg2SoapProxy();
    return webServiceUpg2Soap;
}

public org.uppgift2.www.ObjectOwner[] getObjectOwner() throws java.rmi.RemoteException{
    if (webServiceUpg2Soap == null)
    _initWebServiceUpg2SoapProxy();
    return webServiceUpg2Soap.getObjectOwner();
}

public org.uppgift2.www.RealEstateBroker[] getRealEstateBroker() throws java.rmi.RemoteException{
    if (webServiceUpg2Soap == null)
    _initWebServiceUpg2SoapProxy();
    return webServiceUpg2Soap.getRealEstateBroker();
}

public org.uppgift2.www.Showing[] getShowing() throws java.rmi.RemoteException{
    if (webServiceUpg2Soap == null)
    _initWebServiceUpg2SoapProxy();
    return webServiceUpg2Soap.getShowing();
}

public org.uppgift2.www.ProspectiveBuyer[] getProspectiveBuyers() throws java.rmi.RemoteException{
    if (webServiceUpg2Soap == null)
    _initWebServiceUpg2SoapProxy();
    return webServiceUpg2Soap.getProspectiveBuyers();
}

public org.uppgift2.www.RealEstateObject[] getRealEstateObjects() throws java.rmi.RemoteException{
    if (webServiceUpg2Soap == null)
    _initWebServiceUpg2SoapProxy();
    return webServiceUpg2Soap.getRealEstateObjects();
    }
}

I have a method in another class that creates an instance of the proxy class and calls it methods

public TableModel getObjectOwner() {
WebServiceUpg2SoapProxy proxy2 = new WebServiceUpg2SoapProxy();

    List<ObjectOwner> oo = null;
    try {
        oo = proxy2.getObjectOwner();
    } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return buildTableModel(oo);     
}

This gives me an error saying

Type mismatch: cannot convert from ObjectOwner[] to List

my question is; how do I change the return type of the proxy from ObjectOwner[] to List? Can this be done in a wizard?

I know that in Visual Studio you can simply right click on the server reference in the solution explorer and go configure reference and then change it in the prompt window. Can this be done in Eclipse?

Thanks in advance.

Was it helpful?

Solution

The error is very specific: You cannot assign an ObjectOwner[] (an array) to a List<ObjectOwner> (instance of a class that implements List interface). Instead, you can change your code to adapt this array and convert it into a list using Arrays#asList:

oo = Arrays.asList(proxy2.getObjectOwner());

Note that by doing this you cannot add new elements in this list. If you want to modify the state of the list, it would be better creating a new ArrayList (or another desired implementation of List interface) and add the elements in the array:

//Since Java 7 
oo = new ArrayList<>(Arrays.asList(proxy2.getObjectOwner()));

//For Java 5 and 6
oo = new ArrayList<ObjectOwner>(Arrays.asList(proxy2.getObjectOwner()));

OTHER TIPS

I guess, you are looking for this:

List size will used to form the new ObjectOwner, Later it is converted using toArray method for the desired result.

ObjectOwner[] ow= list.toArray(new ObjectOwner[list.size()]);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top