Wss4j和soaphandler在调用Web服务两次时出错

问题描述:

我在使用wss4j验证服务器上SOAP请求的安全性时遇到了问题,下面是我用来验证安全性头文件的代码部分SOAP请求(我在SOAPHandler实现的方法的handleMessage):Wss4j和soaphandler在调用Web服务两次时出错

// get the crypto file to retrieve dedicated certificate 
final Crypto iCertificateStore = WSKeystoreManagement.getCryptoFile(); 
final WSSecurityEngine iEngine = new WSSecurityEngine(); 
// Add the default config file to the engine 
final WSSConfig iConfig = WSSConfig.getNewInstance(); 
iEngine.setWssConfig(iConfig); 

try { 

    // check security header 
    final List<WSSecurityEngineResult> iSecurityParts = 
    iEngine.processSecurityHeader(aDocument, null, null, iCertificateStore); 


} catch (final WSSecurityException iException) { ...} 

在要求有签名和时间戳,当我调用Web服务第一,一切都ok了,请求被处理,我使用一个小的Java项目来调用我的Web服务,程序检索答案并正确完成。但后来我再次启动程序,但这次在服务器端检查不起作用。我一直在寻找在WSS4J代码,看看哪里的问题从何而来,我在这里抵达DOMReference.validate方法,其中:

 if (validateContext == null) { 
     throw new NullPointerException("validateContext cannot be null"); 
    } 
    if (validated) { 
     return validationStatus; 
    } 
    Data data = dereference(validateContext); 
    calcDigestValue = transform(data, validateContext); 

    if (log.isDebugEnabled()) { 
     log.debug("Expected digest: " + Base64.encode(digestValue)); 
     log.debug("Actual digest: " + Base64.encode(calcDigestValue)); 
    } 

这一次的calcDigestValue是不同的,我找不到为什么...有人知道这件事吗?

谢谢。

编辑:我一直在我的研究进展,问题来自这样一个事实,即请求信封的主体在客户端和服务器之间的某处发生了更改...我检查了客户端,我是几乎可以肯定身体没有改变那里。这些变化只出现在第二次调用,仍然不知道为什么?

+0

你在第二个请求中看到了什么行为?你是否遇到异常?这两个请求之间你看到了什么变化? – Pace 2013-02-27 14:41:45

我已经找到了finnaly问题,我在客户端和服务器端使用的对象之间存在差异(不要问我为什么),而当服务器端的传输层检索信封时,它是将名称空间放在主体中的这些对象上,导致摘要检查在签名上失败。