简体   繁体   English

如何使用通过eclipse和Apache CXF从WSDL创建的Java类连接到工作日帐户

[英]How connect to the workday account using java classes created from WSDL using eclipse and Apache CXF

Not able to connect to the workday account using java program. 无法使用Java程序连接到工作日帐户。 Functionalities which we need to test is "Get account details, get worker details" etc. 我们需要测试的功能是“获取帐户详细信息,获取工作人员详细信息”等。

We have received a tenant-specific workday WSDL file from one of our customers. 我们已经从一位客户那里收到了特定于租户的工作日WSDL文件。 using eclipse and Apache CXF 2.3.1 generated all the java classes and client class. 使用eclipse和Apache CXF 2.3.1生成了所有的Java类和客户端类。 Client class is having the main method. 客户端类具有main方法。 But when I am running the client class I am getting an error. 但是,当我运行客户端类时,出现错误。

public final class HumanResourcesPort_HumanResources_Client { 公共最终课程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 port) 公共静态无效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());
    }

}        

} }

Expected result: Java program should be able to connect to the Workday account and should be able to use the web services properly. 预期结果:Java程序应该能够连接到Workday帐户,并且应该能够正确使用Web服务。

Actual result : 实际结果 :

Invoking getServerTimestamp... Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: invalid username or password at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:146) at com.sun.proxy.$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) Caused by: org.apache.cxf.binding.soap.SoapFault: invalid username or password at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:75) at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:46) 调用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)

Maybe the pattern of setting username and password is wrong. 也许设置用户名和密码的模式是错误的。 test this pattern if you can. 如果可以,请测试此模式。

    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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM