因为我在我的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 :(得分: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"));
/* ... */
}
}