无法使用 java 程序连接到工作日帐户。我们需要测试的功能是“获取帐户详细信息,获取工人详细信息”等。
我们从我们的一位客户那里收到了一个特定于租户的工作日 WSDL 文件。使用 eclipse 和 Apache CXF 2.3.1 生成了所有的 java 类和客户端类。客户端类具有主要方法。但是当我运行客户端类时,我得到了一个错误。
公共最终类 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);
}
public static void 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... 线程“main”中的异常 javax.xml.ws.soap.SOAPFaultException:com.sun.proxy 的 org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:146) 的用户名或密码无效.$Proxy32.getServerTimestamp(Unknown Source) at workday.com.bsvc.human_resources.HumanResourcesPort_HumanResources_Client.getservertime(HumanResourcesPort_HumanResources_Client.java:89) at workday.com.bsvc.human_resources.HumanResourcesPort_HumanResources_Client.main(HumanResourcesPort_HumanResources_Client.java:78) org.apache.cxf.binding.soap.SoapFault:org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:75) 中的用户名或密码无效。拦截器.Soap11FaultInInterceptor。处理消息(Soap11FaultInInterceptor.java:46)