Skip to content

Usage with Java

There are numerous ways to consume a Web Service with Java since there are many Web Services APIs available for it.

In this Example below, we will use JAX-WS, which ships with a utility, wsimport, that uses WSDL to generate Java classes in support of the programming a client against the service described in the WSDL.

Here is how the utility can be used for the Infor EAM Web Service in TEST Environment:

wsimport –p infor –clientjar https://cmmsx-test.cern.ch/WSHub/SOAP?wsdl

The –p flag stands for "package": the utility created a Directory called infor and puts the generated Java Code in this directory/package.

Two of these files however are of special interest: InforWSService and WSHub. The first one is the class represents to the client the deployed Web Service. The second one is the interface that declares the invocation Syntax for each Operation available.

The following Java Code invokes the Web Service to update the description of the Work Order.

import ch.cern.cmms.infor.InforWSService;
import ch.cern.cmms.infor.WSHub;
import ch.cern.cmms.infor.wshub.Credentials;
import ch.cern.cmms.infor.wshub.WorkOrder;
import javax.xml.ws.BindingProvider;


public class MainTest {

     public static void main(String[] args) {

          // Initialize the service class and corresponding interface
          InforWSService service = new InforWSService();
          WSHub middleTier = service.getInforWSPort();

          // Change the address
          BindingProvider inforWSBindingProvider = (BindingProvider) middleTier;
          inforWSBindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://cmmsx-test.cern.ch/WSHub/SOAP ");

          // Credentials
          Credentials credentials = new Credentials();
          credentials.setUsername("RESPOSIT");
          credentials.setPassword("NICE_PASSWORD");        

          // Create WO object
          WorkOrder workOrder = new WorkOrder();
          workOrder.setDescription("New Description");
          workOrder.setNumber("1235429");

          // Call Infor Web Service to update the Work order
          try {   
              middleTier.updateWorkOrder(workOrder, credentials, null);
              System.out.println("Work Order updated!");
          } catch (Exception e) {
              System.out.println("Something went wrong: " + e.getMessage());
          }   
     }
}

Next Section

Comments from Sara

Show what happens when we use this functions maybe??


Last update: July 8, 2022