Java 引发异常时未调用SOAP处理程序错误
我有一个SOAP句柄类,并添加了一条语句来抛出自定义运行时异常(首先抛出抛出新的IntrusionException,然后捕获它,然后抛出MyRuntimeException) 根据“Implementing the Handler.handleMessage()Method”一节,如果我在处理程序中抛出运行时异常,则应调用handleFault() 我在应用程序中设置了断点,但没有调用该方法。客户端从WS获得的不是Soap错误,而是通常的响应。此外,出于某种原因,日志记录停止工作,调试中也没有在WS类断点处停止,但只要我再次抛出抛出异常语句,日志记录就会再次工作Java 引发异常时未调用SOAP处理程序错误,java,eclipse,soap,soaphandler,Java,Eclipse,Soap,Soaphandler,我有一个SOAP句柄类,并添加了一条语句来抛出自定义运行时异常(首先抛出抛出新的IntrusionException,然后捕获它,然后抛出MyRuntimeException) 根据“Implementing the Handler.handleMessage()Method”一节,如果我在处理程序中抛出运行时异常,则应调用handleFault() 我在应用程序中设置了断点,但没有调用该方法。客户端从WS获得的不是Soap错误,而是通常的响应。此外,出于某种原因,日志记录停止工作,调试中也没有
public class GatewayRequestHandler implements javax.xml.ws.handler.soap.SOAPHandler<SOAPMessageContext> {
// private static final Log LOG =
// LogFactory.getLog(GatewayRequestHandler.class);
private static final Logger LOG = ESAPI.getLogger(GatewayRequestHandler.class.getName());
private static myEsapiValidator esapiValidator = (myEsapiValidator) ESAPI.validator();
@Override
public boolean handleMessage(SOAPMessageContext mc) {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
String outString = null;
SOAPMessage soapMsg = mc.getMessage();
try {
LOG.info(Logger.EVENT_UNSPECIFIED, "WSDL Operation: " + mc.get(MessageContext.WSDL_OPERATION));
soapMsg.writeTo(outStream);
outString = new String(outStream.toByteArray(), "UTF-8");
// validate inbound message
try {
outString = esapiValidator.getValidInput("ResponseDocument", outString, "my.XMLString",
Integer.MAX_VALUE, true, true);
LOG.info(Logger.SECURITY_SUCCESS, "Successfully validated inbound message.");
throw new IntrusionException("Test canonicalization failure","test");
} catch (IntrusionException | ValidationException e) {
String errStr = "Error validating the inbound response message.";
LOG.error(Logger.SECURITY_FAILURE, errStr, e);
// throw new ComponentException(errStr, e);
throw new MyRuntimeException(errStr, e);
}
公共类GatewayRequestHandler实现javax.xml.ws.handler.soap.SOAPHandler{
//私有静态最终日志=
//getLog(GatewayRequestHandler.class);
私有静态最终记录器LOG=ESAPI.getLogger(GatewayRequestHandler.class.getName());
私有静态myEsapiValidator esapiValidator=(myEsapiValidator)ESAPI.validator();
@凌驾
公共布尔handleMessage(SOAPMessageContext mc){
ByteArrayOutputStream outStream=新建ByteArrayOutputStream();
字符串outString=null;
SOAPMessage soapMsg=mc.getMessage();
试一试{
LOG.info(Logger.EVENT_未指定,“WSDL操作:”+mc.get(MessageContext.WSDL_操作));
soapMsg.writeTo(流出);
outString=新字符串(outStream.toByteArray(),“UTF-8”);
//验证入站消息
试一试{
outString=esapiValidator.getValidInput(“ResponseDocument”,outString,“my.XMLString”,
Integer.MAX_值,真,真);
LOG.info(Logger.SECURITY_SUCCESS,“成功验证入站消息”);
抛出新的入侵异常(“测试规范化失败”、“测试”);
}捕获(入侵异常|验证异常e){
String errStr=“验证入站响应消息时出错。”;
LOG.error(Logger.SECURITY\u故障,errStr,e);
//抛出新组件异常(errStr,e);
抛出新的MyRuntimeException(errStr,e);
}
。。。
@凌驾
公共布尔handleFault(SOAPMessageContext mc){您有没有找到解决方案?我遇到了同样的问题。@Olek,我没有。您可以尝试在handleMessage中捕获异常并直接调用handleFault。我想我所做的是执行put()在具有键/值的SOAPMessage上,在web服务类中查找它,并在那里处理它。