![](/img/trans.png)
[英]Generating web service proxy classes using wsdl2java/Apache CXF
[英]How connect to the workday account using java classes created from WSDL using eclipse and Apache CXF
無法使用Java程序連接到工作日帳戶。 我們需要測試的功能是“獲取帳戶詳細信息,獲取工作人員詳細信息”等。
我們已經從一位客戶那里收到了特定於租戶的工作日WSDL文件。 使用eclipse和Apache CXF 2.3.1生成了所有的Java類和客戶端類。 客戶端類具有main方法。 但是,當我運行客戶端類時,出現錯誤。
公共最終課程HumanResourcesPort_HumanResources_Client {
private static final QName SERVICE_NAME = new QName("urn:com.workday/bsvc/Human_Resources", "Human_ResourcesService");
private HumanResourcesPort_HumanResources_Client() {
}
public static void main(String args[]) throws Exception {
org.apache.cxf.jaxws.JaxWsProxyFactoryBean factory = new org.apache.cxf.jaxws.JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
// Utilize the class which was auto-generated by Apache CXF wsdl2java for service interface
factory.setServiceClass(HumanResourcesService.class);
factory.setAddress("https://wd9-impl-services23.workday.com/ccx/service/abc/Human_Resources/v32.1");
long timeout = 10000L;
org.apache.cxf.transports.http.configuration.HTTPClientPolicy policy = new org.apache.cxf.transports.http.configuration.HTTPClientPolicy();
policy.setConnectionTimeout(timeout);
policy.setReceiveTimeout(timeout);
URL wsdlURL = HumanResourcesService.WSDL_LOCATION;
if (args.length > 0) {
File wsdlFile = new File(args[0]);
try {
if (wsdlFile.exists()) {
wsdlURL = wsdlFile.toURI().toURL();
} else {
wsdlURL = new URL(args[0]);
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
HumanResourcesService ss = new HumanResourcesService(wsdlURL, SERVICE_NAME);
HumanResourcesPort port = ss.getHumanResources();
org.apache.cxf.endpoint.Client client = org.apache.cxf.frontend.ClientProxy.getClient(port);
org.apache.cxf.transport.http.HTTPConduit httpConduit = (org.apache.cxf.transport.http.HTTPConduit) client.getConduit();
org.apache.cxf.configuration.security.AuthorizationPolicy authorization = httpConduit.getAuthorization();
authorization.setUserName("UserName12357@abc");
authorization.setPassword("Passw0rd@123#");
httpConduit.setClient(policy);
getservertime(port);
System.exit(0);
}
公共靜態無效getservertime(HumanResourcesPort端口)
{
System.out.println("Invoking getServerTimestamp...");
workday.com.bsvc.ServerTimestampGetType _getServerTimestamp_body = new workday.com.bsvc.ServerTimestampGetType();
_getServerTimestamp_body.setVersion("Version-202634838");
try {
workday.com.bsvc.ServerTimestampType _getServerTimestamp__return = port.getServerTimestamp(_getServerTimestamp_body);
System.out.println("getServerTimestamp.result=" + _getServerTimestamp__return);
} catch (ValidationFaultMsg e) {
System.out.println("Expected exception: Validation_FaultMsg has occurred.");
System.out.println(e.toString());
} catch (ProcessingFaultMsg e) {
System.out.println("Expected exception: Processing_FaultMsg has occurred.");
System.out.println(e.toString());
}
}
}
預期結果:Java程序應該能夠連接到Workday帳戶,並且應該能夠正確使用Web服務。
實際結果 :
調用getServerTimestamp ...線程“主”中的異常javax.xml.ws.soap.SOAPFaultException:com.sun.proxy上的org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:146)上的用戶名或密碼無效。$ Proxy32.getServerTimestamp(未知源)位於workday.com.bsvc.human_resources.HumanResourcesPort_HumanResources_Client.getservertime(HumanResourcesPort_HumanResources_Client.java:89)at workday.com.bsvc.human_resources.HumanResourcesPort_HumanReClients(Client_RemansResources_Client.Client org.apache.cxf.binding.soap.SoapFault:org.apache.cxf.binding.soap上的org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:75)處的用戶名或密碼無效。攔截器.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:46)
也許設置用戶名和密碼的模式是錯誤的。 如果可以,請測試此模式。
HumanResourcesPort port = ss.getHumanResources();
BindingProvider prov = (BindingProvider) port;
prov.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "username");
prov.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "password");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.