2016-06-01 2 views
0

Ich möchte Subklassen von MyCustomException zu werfen, aber für die Oberklasse über den Web-Service übertragen werden; stattdessen wird stattdessen die Unterklasse übertragen. Ich habe versucht, die Annotation WebFault zu den Klassen ohne Effekt hinzuzufügen. Ich habe ein Beispiel dafür gegeben, was gerade passiert und ein Beispiel dafür, was ich stattdessen tun möchte.JAX-WS-Fehler: Oberklasse der Ausnahme übergeben

Die Ausnahmen.

public class MyCustomException extends Exception { 

    String text; 

    public static class CustomInner extends MyCustomException { 
     public CustomInner1() { 
      super("inner"); 
     } 
    } 

    public MyCustomException(String text) { 
     this.text = text; 
    } 

    public String getText() { 
     return text; 
    } 
} 

Die Implementierung Web-Service. NB: Ich möchte nicht ändern, was hier geworfen wird.

@Stateless(name = "MyService", mappedName = "MyService") 
@LocalBean 
@WebService(targetNamespace = "http://my.org/ns/") 
public class MyService { 

    @WebMethod 
    public String throwCustomInnerException() throws MyCustomException { 
     throw new MyCustomException.CustomInner(); 
    } 

    @WebMethod 
    public String throwCustomException() throws MyCustomException { 
     throw new MyCustomException("text"); 
    } 

} 

Die XML für throwCustomException() Aufruf des Web-Service.

<?xml version='1.0' encoding='UTF-8'?> 
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> 
    <S:Body> 
     <S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope"> 
      <faultcode>S:Server</faultcode> 
      <faultstring>pack.MyCustomException</faultstring> 
      <detail> 
       <ns2:MyCustomException xmlns:ns2="http://my.org/ns/"> 
        <text>text</text> 
       </ns2:MyCustomException> 
      </detail> 
     </S:Fault> 
    </S:Body> 
</S:Envelope> 

Die XML für throwCustomInnerException() Aufruf des Web-Service.

<?xml version='1.0' encoding='UTF-8'?> 
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> 
    <S:Body> 
     <S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope"> 
      <faultcode>S:Server</faultcode> 
      <faultstring>pack.CustomInner</faultstring> 
     </S:Fault> 
    </S:Body> 
</S:Envelope> 

Was ich will geschehen ist folgende, wenn throwCustomInnerException() den Web-Service aufgerufen wird:

<?xml version='1.0' encoding='UTF-8'?> 
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> 
    <S:Body> 
     <S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope"> 
      <faultcode>S:Server</faultcode> 
      <faultstring>pack.MyCustomException</faultstring> 
      <detail> 
       <ns2:MyCustomException xmlns:ns2="http://my.org/ns/"> 
        <text>inner1</text> 
       </ns2:MyCustomException> 
      </detail> 
     </S:Fault> 
    </S:Body> 
</S:Envelope> 

Antwort

0

Sie die Methode ändern können:

@WebMethod 
public String throwCustomInnerException() throws MyCustomException { 
    throw new MyCustomException.CustomInner(); 
} 

zu:

@WebMethod 
public String throwCustomInnerException() throws MyCustomException { 
    throw new MyCustomException(CustomInner.getClass().getSimpleName()); 
} 
+0

Ich möchte eigentlich nicht ändern, was geworfen wird (da dies eine vereinfachte Version des eigentlichen Codes ist). –

Verwandte Themen