3

We have a Web Service implementation that throws a custom SecurityException.

public class SecurityException extends Exception {

The service is then transformed into a wsdl using the maven plugin java2ws. The resulting .wsdl file contains

  <xs:element name="SecurityException" type="tns:SecurityException"/>
  <xs:complexType name="SecurityException">
  ...
  <wsdl:message name="SecurityException">
    <wsdl:part name="SecurityException" element="tns:SecurityException">
    </wsdl:part>
  </wsdl:message>

Now if I run wsdl2java on the .wsdl file I get a SecurityException file:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SecurityException")
public class SecurityException {


}

and a SecurityException_Exception file:

@WebFault(name = "SecurityException", targetNamespace = "http://service...../")
public class SecurityException_Exception extends Exception {


private ....SecurityException securityException;

public SecurityException_Exception() {
    super();
}

public SecurityException_Exception(String message) {
    super(message);
}

public SecurityException_Exception(String message, Throwable cause) {
    super(message, cause);
}

public SecurityException_Exception(String message, ....SecurityException securityException) {
    super(message);
    this.securityException = securityException;
}

public SecurityException_Exception(String message, ....SecurityException securityException, Throwable cause) {
    super(message, cause);
    this.securityException = securityException;
}

public ....SecurityException getFaultInfo() {
    return this.securityException;
}
}

How can I avoid the unneccessairy class? Why is it even generated? Why can't it just recreate the old class?

SecurityException extends Exception

(we're using cxf version 2.5 so the <2.3 bug with superclasses that I found googleing doesn't seem to apply)

Pete
  • 10,720
  • 25
  • 94
  • 139

2 Answers2

1

Figured it out.. Appearently you can't avoid the helper class as Exceptions have to be wrapped when used in a web service because they are not serializable.

Pete
  • 10,720
  • 25
  • 94
  • 139
0

I'm using JAXB built in maven (jaxws-maven-plugin / wsimport goal), but I had the same problem. (It generated BusinessException and BusinessException_Exception).

My fix was to put the exception in another namespace. So now I have two BusinessException files, generated in two different folders, and the one is an exception that takes the other as its parameter. Compiles ok, and no Exception_Exception ugliness.

djb
  • 1,635
  • 3
  • 26
  • 49