2014-02-06 2 views
0

Как я использую ограничение в моем определении WSDL, как:Ловля неисправность с помощью Axis2 с ограничением в WSDL

<simpleType name="id"> 
    <annotation> 
    <documentation>Identifiant</documentation> 
    </annotation> 
    <restriction base="string"> 
    <pattern value="[0-9]{16}"/> 
    </restriction> 
</simpleType> 

wsdl2java генерации:

public class IunType implements org.apache.axis2.databinding.ADBBean { 
    public void setId(java.lang.String param) { 
    if (org.apache.axis2.databinding.utils.ConverterUtil.convertToString(param).matches("[0-9]{16}")) { 
     this.localId = param; 
    } else { 
     throw new java.lang.RuntimeException(); 
    } 
    } 
} 

И я не нашел способ поймать это исключение в мои бизнес-классы, если в моем запросе «id» есть «999999», например.

Цель состоит в том, чтобы вернуть ответ, а не неисправность. Является ли это возможным ?

Дополнительная информация:

ответ

0

Это не может быть сделано в сгенерированном коде ... поэтому наилучшим решением является установить сообщение в RuntimeException и использовать его в ответе SOAP.

В общественном классе HelloWorldService1MessageReceiverInOut

public class HelloWorldService1MessageReceiverInOut extends 
    org.apache.axis2.receivers.AbstractInOutMessageReceiver { 
    @Override 
    public void invokeBusinessLogic(
     org.apache.axis2.context.MessageContext msgContext, 
     org.apache.axis2.context.MessageContext newMsgContext) 
     throws org.apache.axis2.AxisFault { 

/* ... */ 

      www.helloworldws.DireBonjourResponse direBonjourResponse2 = null; 
      try { 
      www.helloworldws.DireBonjourRequest wrappedParam = (www.helloworldws.DireBonjourRequest) fromOM(
       msgContext.getEnvelope().getBody().getFirstElement(), 
       www.helloworldws.DireBonjourRequest.class, 
       getEnvelopeNamespaces(msgContext.getEnvelope())); 
      direBonjourResponse2 = skel.direBonjour(wrappedParam); 
      } catch (AxisFault e) { 
      logger.info(e.getCause() + ", " + e.getMessage()); 
      DireBonjourResponse direBonjourResponse = new DireBonjourResponse(); 
      direBonjourResponse.setAge(0); 
      direBonjourResponse.setSalutations("[AxisFault] " + e.getMessage()); // Use of the message setted in the RuntimeException 
      direBonjourResponse2 = direBonjourResponse; 
      } 

      envelope = toEnvelope(getSOAPFactory(msgContext), 
       direBonjourResponse2, false, new javax.xml.namespace.QName(
        "http://www.example.fr/helloworldws/", "direBonjour")); 

/* ... */ 

    } 
} 
Смежные вопросы