XFire Sample

XFire is a next-generation Java SOAP framework from Codehaus. It makes the service-oriented development approachable through its easy-to-use APIs and the support of the Web Service standards. Using XFire framework to develop clients for Web Service requires JDK 5.0 or higher. Additionally, XFire provides the tools to generate Java code from WSDL files or a URL.

In the following tutorial, we use Eclipse as the development tools with XFire plug-ins. The XFire plug-ins can be downloaded from http://xfire.codehaus.org/Eclipse+Plugin. To develop a client application with WebExronos service requires two steps:

Import WSDL

Step 1: Create a new project or select a current project. The designated project will be the client of WebExronos service.

Step 2: Import the WSDL file from the URL using XFire tools. The tool will create the client classes according to the WSDL file. If you have installed the XFire plug-ins for Eclipse, it is easy to import the WSDL file to generate from WSDL document.

  • Select code generation from WSDL document
  • Input the file name or URL
  • Click the finish button. The tool will import the WSDL to local Java files. The structure of the local file will look like this screen below:

Code Sample

After the WSDL file is imported and the Java files are created, you can use them as normal local Java files and invoke them easily. Below is a code sample for the login invoke:

       // Create the service port
       CronosClient client = new CronosClient();
       CronosPortType service = client.getCronosHttpPort();

      
// Create the ObjectFactory instance of the
       // com.webex.webapp.webexronos.bean.ObjectFactory
       ObjectFactory of = new ObjectFactory();

      
// Login to the service
       // Construct the request object

       LoginInfo info = of.createLoginInfo();
       info.setAccount(of.createLoginInfoAccount(
"demo"));
       info.setPassword(of.createLoginInfoPassword(
"demo"));

      
// Call the service and get the return result
       LoginResult result = service.login(info);

      
// Check the result
       if (!result.isOpSuccess().booleanValue()) {
          
// Error
           return ;
       }

      
// Get the success result
       String identity = result.getIdentity().getValue();

Below is a code sample for the schedule function:

       // Schedule a trigger
       // Create and fill the request object
       TimeSchedule schedule = of.createTimeSchedule();
       schedule.setCronExpression(of
              .createTimeScheduleCronExpression("* 0/15 * * * ?"));

       CallBack callBack = of.createCallBack();
       callBack.setCallBackType(of.createCallBackCallBackType("HTTP"));
       KeyPair pair = of.createKeyPair();
       pair.setKey(of.createKeyPairKey("urlString"));
       pair.setValue(of.createKeyPairValue("http://www.samples.com"));
       ArrayOfKeyPair aok = of.createArrayOfKeyPair();
       aok.getKeyPair().add(pair);
       callBack.setCallBackParams(of.createCallBackCallBackParams(aok));

       // Call the service and fetch the result
       ScheduleResult result = service.schedule(schedule, callBack, identity);

       // Get the return information from result
       String jobName = result.getJobName().getValue();