【问题标题】:Catching fault using Axis2 with restriction in WSDL使用 Axis2 在 WSDL 中进行限制捕获故障
【发布时间】:2014-02-10 21:15:02
【问题描述】:

因为我在我的 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”,我没有找到在我的业务课程中捕获此异常的方法。

目标是返回响应而不是错误。有可能吗?

更多信息:

【问题讨论】:

    标签: java web-services soap wsdl axis2


    【解决方案1】:

    它不能在生成的代码中完成...所以最好的解决方案是为 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"));
    
    /* ... */
    
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-03
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-05
      相关资源
      最近更新 更多