如何解决JAVA SOAP:与签名SOAP消息有关的问题
我在使用证书签署SOAP消息时遇到问题。 在HTTP Base Authentication之上,还有cert的问题。 假设我只有一个文件
cert.pxf
和密码到该文件
passPhrase123
我有这样的代码:
public class ClientTest {
public static void main(String[] args) {
SomeService ss = new SomeService();
SSPortType ssPortType = ss.getSSPortType();
BindingProvider provider = (BindingProvider) ssPortType;
provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,"https://193.105.143.152:8001/ws/zus.channel.gabinetoweV2:zla");
provider.getRequestContext().put(BindingProvider.USERNAME_PROPERTY,"ezla_ag");
provider.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY,"ezla_ag");
Binding binding = provider.getBinding();
List<Handler> handlerList = binding.getHandlerChain();
handlerList.add(new CertHandler());
binding.setHandlerChain(handlerList);
String str = ssPortType.rpcCall();
System.out.println(str);
}
}
用于处理签名SOAP消息的LogicalHandler:
public class CertHandler implements LogicalHandler<LogicalMessageContext> {
public Set<QName> getHeaders() {
return Collections.EMPTY_SET;
}
public boolean handleMessage(LogicalMessageContext context) {
Boolean isOutbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (isOutbound.booleanValue()) {
System.out.println("I've got an outbound message");
LogicalMessage msg = context.getMessage();
Source src = msg.getPayload();
try {
Node root = null;
Document doc = null;
System.out.println("Try to get body");
if (src instanceof DOMSource) {
System.out.println("Hello DOM src");
root = ((DOMSource)src).getNode();
}
else if (src instanceof SAXSource) {
System.out.println("Hello SAX src");
SAXSource saxSource = (SAXSource) src;
InputSource inSource = saxSource.getInputSource();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
doc = db.parse(inSource);
root = (Node) doc.getDocumentElement();
}
//Deal with signing a root
}
catch (SAXException se) {
System.out.println("se: " + se.getMessage());
}
catch (ParserConfigurationException pce) {
System.out.println("pce: " + pce.getMessage());
}
catch (IOException ioe) {
System.out.println("ioe: " + ioe.getMessage());
}
catch (IllegalArgumentException iae) {
System.out.println("iae: " + iae.getMessage());
System.out.println(iae.getLocalizedMessage());
}
}
else {
System.out.println("I've got an incoming message");
}
return false;
}
public boolean handleFault(LogicalMessageContext context) {
return true;
}
public void close(MessageContext context) {
}
}
不幸的是,我总是收到一遍又一遍:
I've got an outbound message
Try to get body
Hello SAX src
ioe: null
我完全被困住了... 请帮忙。 :)
您能给我粘贴一个带有解决方案的小代码段,还是向我指出可以帮助的地方? 预先感谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。