Skip to main content

Two classes have the same XML type name - problem

2 replies [Last post]
laban
Offline
Joined: 2007-09-27

Jaxws does something that i find a bit strange when it generates the webservice, f.e:

public DoSomethingResponse doSomething(String data);

This code won't work for me , i get the "Two classes..." error when running wsgen. This problem occurs because jaxws generates a class for each method (haven't got anything to do with the object that's returned afaics) and that class is calles "method" + Response, in the case above, DoSomethingResponse. The same as the name of the response object. And thus, the "Two classes..." error.

There are of course solutions, the ones that i know of are:

1: make sure that the names of the response object and method doesn't match, f.e rename the responseobject to DoSomethingResponseVO or rename the method to executeSomething
3: add the @XmlType (namespace="http://namespacethatsnotthesameasthegenerated") annotation in each response class.

It's simple to fix the problem but i don't understand why jaxws couldn't just name the generated classes to something completely different. F.e doSomethingResponse__JaxwsImpl or something like that.

Anyone here that knows something about this ? Or perhaps yet another solution to avoid the problem above, f.e parameter when executing wsgen ?

I kinda like the DoSomethingResonse doSomething naming convention :-)

/Laban

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
linkamp
Offline
Joined: 2009-01-27

i solve this problem with annotations in the web method like this. For example
/**
*
* @param req1 {@link Request1}
* @param req2 {@link Request2}
*/
@WebMethod
@RequestWrapper(localName = "objectRequets", targetNamespace = "http://webservices.com/", className = "SameClass")
@ResponseWrapper(localName = "objectResponse", targetNamespace = "http://webservices.com/", className = "SameClass")
public void doSomething( @WebParam(name = "req1", targetNamespace = "", mode = WebParam.Mode.INOUT), @WebParam(name = "req2", targetNamespace = "", mode = WebParam.Mode.INOUT){
//Make action.....
}

Message was edited by: linkamp

brian_of_fortent
Offline
Joined: 2008-04-11

I went with the XmlType.name workaround, but it feels like a hack...

    import javax.xml.bind.annotation.XmlType;

    @XmlType( name="ResponseImpl" )
    public class Response {
    };