Faire sa propre exception
Bonjour.
J'essaye de créer ma propre exception dans un service web (que je souhaite renvoyer pour une authentification raté ou des parametres non valides etc)
Coté serveur tout a l'air de bien se passer mais coté client impossible de récupérer la bonne exception.
Voici mon code (sans les packages et les imports pour réduire un peu) :
Le service web
Code:
1 2 3 4 5 6 7 8 9
| public class Classe {
public eltClasse getClasse(String classe) throws MyCustomException {
if (!classe.equalsIgnoreCase("0") ) {
eltClasse lElt = new eltClasse(classe);
return lElt;
} else throw new MyCustomException("GENEX002","Cette classe est interdite");
}
} |
Mon exception custom
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| public class MyCustomException extends Exception {
private String errorCode;
private String errorDescription;
public MyCustomException(String errorCode,
String errorDescription){
super();
this.setErrorCode(errorCode);
this.setErrorDescription(errorDescription);
}
public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}
public String getErrorCode() {
return errorCode;
}
public void setErrorDescription(String errorDescription) {
this.errorDescription = errorDescription;
}
public String getErrorDescription() {
return errorDescription;
}
} |
Et mon client :
Citation:
public class client {
public static void main(String[] args) {
ClassePortType service = new Classe().getClasseHttpSoap11Endpoint();
try {
EltClasse lRetour = service.getClasse("0");
System.out.println("-------");
System.out.println("code classe = "+lRetour.getClasse().getValue());
}catch (MyCustomException_Exception ex) {
System.out.println("Exception !");
MyCustomException ex1 = ex.getFaultInfo();
System.out.println(ex1.getMyCustomException().getValue().getErrorCode());
}catch (Exception ex2) {
System.out.println("Exception ?");
}
}
}
Je n'arrive JAMAIS dans la partie MyCustomException_Exception mais toujours dans la partie Exception (du coup je perds les infos...)
Niveau wsdl ca donne ca :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| <xs:complexType name="Exception">
<xs:sequence>
<xs:element minOccurs="0" name="Exception" nillable="true" type="xs:anyType" />
</xs:sequence>
</xs:complexType>
<xs:element name="MyCustomException">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="MyCustomException" nillable="true" type="ax28:MyCustomException" />
</xs:sequence>
</xs:complexType>
</xs:element> |
J'utilise eclipse galiléo, tomcat 5.0, axis derniere version, apache 2.0 et jaxws-ri 2.1.7 pour le client java.
La j'avoue que je vois pas ce qui se passe...
Si quelqu'un peut m'aiguiller...