NetBeans webservice client stubs - incompatible type?

I generated my client side stubs for a NetBeans webservice.

The webservice implementation uses a local POJO from my project. The generated stubs have created a revision of this POJO for use. When I'm using the service, I want to use the original POJO, not the generated type..? Type casting doesn't work.

i.e. (note the packages)

package adiib.ws.harmoniser;

@WebMethod(operationName = "getStartupLogMessages")
public ArrayList<LogMessage> getStartupLogMessages() {
    return startupLogMessages;
}

The POJO LogMessage reads:

package adiib.shared;

public class LogMessage implements Serializable 
{    
    private static final long serialVersionUID = 8379681391654158512L;

    private String exceptionMessage;
    private String customMessage;
    private String stackTrace;
    private LogMessageEnum classification;
    private String effectiveTime;
    private String exceptionClassName;
    private String throwerClassName;

    public LogMessage(){}

    public LogMessage(String exceptionMessage, String customMessage,
        String stackTrace, LogMessageEnum classification, String effectiveTime,
        String exceptionClassName, String throwerClassName)
    {
        this.exceptionMessage = exceptionMessage;
        this.customMessage = customMessage;
        this.stackTrace = stackTrace;
        this.classification = classification;
        this.effectiveTime = effectiveTime;
        this.exceptionClassName = exceptionClassName;
        this.throwerClassName = throwerClassName;
    }

    public String getCustomMessage() {
        return customMessage;
    }

    public void setCustomMessage(String customMessage) {
        this.customMessage = customMessage;
    }

    public String getExceptionMessage() {
        return exceptionMessage;
    }

    public void setExceptionMessage(String exceptionMessage) {
        this.exceptionMessage = exceptionMessage;
    }

    public LogMessageEnum getClassification() {
        return classification;
    }

    public void setClassification(LogMessageEnum classification) {
        this.classification = classification;
    }

    public String getEffectiveTime() {
        return effectiveTime;
    }

    public void setEffectiveTime(String effectiveTime) {
        this.effectiveTime = effectiveTime;
    }

    public String getStackTrace() {
        return stackTrace;
    }

    public void setStackTrace(String stackTrace) {
        this.stackTrace = stackTrace;
    }

    public String getExceptionClassName() {
        return exceptionClassName;
    }

    public void setExceptionClassName(String exceptionClassName) {
        this.exceptionClassName = exceptionClassName;
    }

    public String getThrowerClassName() {
        return throwerClassName;
    }

    public void setThrowerClassName(String throwerClassName) {
        this.throwerClassName = throwerClassName;
    }    
}

Now, on the client side when I'm trying to use the webservice method like so:

package adiib.server;

private void getStartupLogMessages() {

private static List<LogMessage> logMessages = new ArrayList<LogMessage>();

    dsto.adiib.ws.client.harmoniser.AdiibHarmoniser_Service service = new dsto.adiib.ws.client.harmoniser.AdiibHarmoniser_Service();
    dsto.adiib.ws.client.harmoniser.AdiibHarmoniser port = service.getAdiibHarmoniserPort();

    List<dsto.adiib.ws.client.harmoniser.LogMessage> startupLogMessages = port.getStartupLogMessages();
    for (adiib.ws.client.harmoniser.LogMessage logMessage : startupLogMessages) {
        /* 
         * this fails becuase it's looking for adiib.ws.client.harmoniser.LogMessage
         * not adiib.shared.LogMessage; adiib.ws.client.harmoniser.LogMessage is the
         * generated type..
         */
        logMessages.add((LogMessage) logMessage);
    }
}

Any ideas? All I can think is creating a conversion method.. that seems wrong.

WulfgarPro

Answers


The classes generated by the tool are not the same as the original ones you have. So you have to use the tool generated ones in your client side to communicate with the web service. You cannot replace it with the ones you wrote for your server side.

For example, consider JAX-WS built client side DTOs. If you open up the source code, you will see that the auto-generated ones (using wsimport) contains annotations which may not be present (unless you manually wrote) in your server side classes. Therefore, as of my understanding, you have to go with the tool generated ones.

You might have to write methods to transform your DTOs to the tool generated one before web service is invoked. If your generated classes have the same set of properties (type and naming has not been altered by the tool when generating client DTOs), then probably you could use something like Apache Commons BeanUtils (see http://commons.apache.org/beanutils/) to aid in transformation. You can simply call BeanUtils.copyProperties() and pass in your source DTO (your own type) and the target DTO (WS generated) and get it transformed.


Need Your Help

Ruby: Interpolate strings in hash creation

ruby

I'm currently trying to write a small script which parses weekly reports(e-mails) and stores the data I want in variables, so I can handle them further.

Express, body-parser not parsing form data + object (using Angular.js $recourse)

angularjs node.js parsing express body-parser

I'm learning angular.js $resource. As in example in docs I have custom method

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.