As shown in the figure, the test is successful in soapUI, but how to add the three parameters of username, password and wss-password type in properties in Java code...
At present, I use:Java code connects with WSDL to send soapmessage in soapconnection. call(soapMessage,URL) mode
this is wsdl:
<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions.....
......
<wsdl:service name="MyService">
<wsdl:port binding="tns:MyServiceSoapBinding" name="MyServicePort">
<soap12:address location="http://test.caaxxx.com/lxs-ws/MyService"/>
</wsdl:port>
</wsdl:service>
<wsp:Policy xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702" wsu:Id="MyPolicy">
<sp:SupportingTokens wsp:Optional="true">
<wsp:Policy>
<sp:UsernameToken sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient"/>
</wsp:Policy>
</sp:SupportingTokens>
</wsp:Policy>
this is SOAPConnection.call() mode.I guess the model needs properties,as username、password、wss-password type:
public class SoapAPIInvoker03 {
public static void main(String[] args) throws Exception {
String ixml = FileHelper.copyToString(SoapAPIInvoker03.class.getResourceAsStream("result.xml"));
StreamSource xmlSource1 = new StreamSource(new StringReader(iataxml));
SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
SOAPConnection connection = sfc.createConnection();
SOAPMessage soapMessage = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
soapPart.setContent(xmlSource1);
SoapMessage message = connection.call(soapMessage,new URL("http://......"))
}
}
And,this is cxf mode,bu it has another error:
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
MyService service = null;
factory.setServiceClass(MyService.class);
factory.setServiceName(new QName("http://www.unixxxx.com/lxs","MyService"));
factory.setWsdlURL("http://test.caaxxx.com/xxxs-ws/MyService?wsdl");
factory.setEndpointName(new QName("http://www.unixxx.com/lxs","MyServicePort"));
service = (MyService) factory.create();
String str = service.send(new Object()); // error sp:UsernameToken/wsp:Policy must have a value
//Caused by: javax.xml.ws.soap.SOAPFaultException: sp:UsernameToken/wsp:Policy must have a value
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:158)
at com.sun.proxy.$Proxy28.invokeAWBService(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.doInvoke(JaxWsPortClientInterceptor.java:520)
at org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.doInvoke(JaxWsPortClientInterceptor.java:494)
... 5 more
Caused by: java.lang.IllegalArgumentException: sp:UsernameToken/wsp:Policy must have a value
at org.apache.cxf.ws.security.policy.builders.UsernameTokenBuilder.build(UsernameTokenBuilder.java:63)
at org.apache.cxf.ws.security.policy.builders.UsernameTokenBuilder.build(UsernameTokenBuilder.java:40)
at org.apache.neethi.AssertionBuilderFactoryImpl.invokeBuilder(AssertionBuilderFactoryImpl.java:138)
at org.apache.neethi.AssertionBuilderFactoryImpl.build(AssertionBuilderFactoryImpl.java:117)
at org.apache.neethi.PolicyBuilder.processOperationElement(PolicyBuilder.java:224)
at org.apache.neethi.PolicyBuilder.getPolicyOperator(PolicyBuilder.java:174)
at org.apache.neethi.PolicyBuilder.getPolicy(PolicyBuilder.java:124)
.......
Aucun commentaire:
Enregistrer un commentaire