我使用Apache CXF wsdl2java功能使用Eclipse Mars生成客户端代码。我使用的是CXF 2.4版。当尝试执行客户端代码时,我得到以下异常。
org.apache.cxf.interceptor.Fault: None of the policy alternatives can be satisfied.
at org.apache.cxf.ws.policy.AbstractPolicyInterceptor.handleMessage(AbstractPolicyInterceptor.java:47)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:519)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:449)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:352)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:304)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:88)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)
at com.sun.proxy.$Proxy29.zCustomerInvoiceERPByIDorDTQueryResponseIn(Unknown Source)
at com.scmworx.xi.appl.se.ZCustomerInvoiceERPByIDorDTQueryResponseIn_BNCustomerInvoiceERPByIDorDTQueryResponseIn_Client.main(ZCustomerInvoiceERPByIDorDTQueryResponseIn_BNCustomerInvoiceERPByIDorDTQueryResponseIn_Client.java:106)
Caused by: org.apache.cxf.ws.policy.PolicyException: None of the policy alternatives can be satisfied.
at org.apache.cxf.ws.policy.EffectivePolicyImpl.chooseAlternative(EffectivePolicyImpl.java:155)
at org.apache.cxf.ws.policy.EffectivePolicyImpl.initialise(EffectivePolicyImpl.java:88)
at org.apache.cxf.ws.policy.PolicyEngineImpl.getEffectiveClientRequestPolicy(PolicyEngineImpl.java:202)
at org.apache.cxf.ws.policy.PolicyOutInterceptor.handle(PolicyOutInterceptor.java:111)
at org.apache.cxf.ws.policy.AbstractPolicyInterceptor.handleMessage(AbstractPolicyInterceptor.java:45)
... 9 more
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: None of the policy alternatives can be satisfied.
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:156)
at com.sun.proxy.$Proxy29.zCustomerInvoiceERPByIDorDTQueryResponseIn(Unknown Source)
at com.scmworx.xi.appl.se.ZCustomerInvoiceERPByIDorDTQueryResponseIn_BNCustomerInvoiceERPByIDorDTQueryResponseIn_Client.main(ZCustomerInvoiceERPByIDorDTQueryResponseIn_BNCustomerInvoiceERPByIDorDTQueryResponseIn_Client.java:106)
Caused by: org.apache.cxf.ws.policy.PolicyException: None of the policy alternatives can be satisfied.
at org.apache.cxf.ws.policy.EffectivePolicyImpl.chooseAlternative(EffectivePolicyImpl.java:155)
at org.apache.cxf.ws.policy.EffectivePolicyImpl.initialise(EffectivePolicyImpl.java:88)
at org.apache.cxf.ws.policy.PolicyEngineImpl.getEffectiveClientRequestPolicy(PolicyEngineImpl.java:202)
at org.apache.cxf.ws.policy.PolicyOutInterceptor.handle(PolicyOutInterceptor.java:111)
at org.apache.cxf.ws.policy.AbstractPolicyInterceptor.handleMessage(AbstractPolicyInterceptor.java:45)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:519)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:449)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:352)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:304)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:88)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)
我正在使用eclipse生成的相同客户端主要方法。以下是我的客户代码。
try {
SVCustomerInvoiceERPByIDorDTQueryResponseIn document = new SVCustomerInvoiceERPByIDorDTQueryResponseIn();
ZCustomerInvoiceERPByIDorDTQueryResponseIn port = document.getBNCustomerInvoiceERPByIDorDTQueryResponseInSOAP12();
Map<String, Object> req_ctx = ((BindingProvider) port).getRequestContext();
req_ctx.put(BindingProvider.USERNAME_PROPERTY, "user");
req_ctx.put(BindingProvider.PASSWORD_PROPERTY, "password");
req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://servertm.onlinesapaccess.com:8004/sap/bc/srt/xip/sap/zzcustomerinvoiceerpbyidordtqu/800/sv_customerinvoiceerpbyidordtque/bn_customerinvoiceerpbyidordtqueryresponse_in");
ZCustomerInvoiceERPByIDorDTQueryMessageSync idQuery = new ZCustomerInvoiceERPByIDorDTQueryMessageSync();
ZCustInvcERPByIDQrySCustInvcSelByIDorDate inputs = new ZCustInvcERPByIDQrySCustInvcSelByIDorDate();
CustomerInvoiceID id = new CustomerInvoiceID();
idQuery.setCustInvcSelByIDorDate(inputs);
List<CustomerInvoiceERPByIDResponseMessageSync> invoiceDataList = port.zCustomerInvoiceERPByIDorDTQueryResponseIn(idQuery).getCustomerInvoices();
} catch (DatatypeConfigurationException ex) {
ex.printStackTrace();
} catch (StandardMessageFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
答案 0 :(得分:0)
try {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(ZCustomerInvoiceERPByIDorDTQueryResponseIn.class);
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setAddress("http://servertm.onlinesapaccess.com:8004/sap/bc/srt/xip/sap/ zzcustomerinvoiceerpbyidordtqu/800/sv_customerinvoiceerpbyidordtque/bn_customerinvoiceerpbyidordtqueryresponse_in");
ZCustomerInvoiceERPByIDorDTQueryResponseIn port = (ZCustomerInvoiceERPByIDorDTQueryResponseIn) factory.create();
Client client = ClientProxy.getClient(port);
HTTPConduit http = (HTTPConduit) client.getConduit();
http.getAuthorization().setUserName("ECC0412");
http.getAuthorization().setPassword("Interface");
ZCustomerInvoiceERPByIDorDTQueryMessageSync idQuery = new ZCustomerInvoiceERPByIDorDTQueryMessageSync();
ZCustInvcERPByIDQrySCustInvcSelByIDorDate inputs = new ZCustInvcERPByIDQrySCustInvcSelByIDorDate();
CustomerInvoiceID id = new CustomerInvoiceID();
idQuery.setCustInvcSelByIDorDate(inputs);
List<CustomerInvoiceERPByIDResponseMessageSync> invoiceDataList = port.zCustomerInvoiceERPByIDorDTQueryResponseIn(idQuery).getCustomerInvoices();
} catch (DatatypeConfigurationException ex) {
ex.printStackTrace();
} catch (StandardMessageFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
更改此类代码后,它正在运行。