简体   繁体   中英

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. 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. using eclipse and Apache CXF 2.3.1 generated all the java classes and client class. Client class is having the main method. But when I am running the client class I am getting an error.

public final class 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)

{
    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.

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)

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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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