Question

As I use restriction in my WSDL definition like :

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

WSDL2JAVA generate :

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();
    }
  }
}

And I did not find a way to catch this exception in my business classes if in my request the "id" is "999999" for example.

The goal is to return a response rather than a fault. Is it possible ?

More information :

Was it helpful?

Solution

It cannot be done in generated code... so best solution is to do set a message to the RuntimeException and use it in the SOAP response.

In the public class 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"));

/* ... */

  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top