Hybrid Integration 10.2 | Integrating On-Premises Applications | Guaranteed Delivery | Creating a Java Client that Uses Guaranteed Delivery | Sample Code (Asynchronous Request)
 
Sample Code (Asynchronous Request)
The following example illustrates the steps you take to submit an asynchronous request to the Job Manager. To submit an asynchronous request, you establish a connection and start a transaction just like you do for a synchronous request. However, you submit the request using the submitTX method instead of the invokeTx method. Then, you must retrieve the results of the request using the retrieveIDTx method (to get results as an IData object).
For additional information about TContext and its methods, see the TContext class in the webMethods Integration Server Java API Reference.
/**
* Sample of a Java TContext client that uses SSL to perform a GD transaction */
import com.wm.data.IDataFactory;
import com.wm.data.IData;
 
import com.wm.app.b2b.client.*;
import com.wm.util.*;
import com.wm.app.b2b.client.lic.*;
public class TCSample {
 
  public static void main (String[] args)
  {
   TContext tc = null;
   ClientKeyInfo.setGuaranteedDeliveryLicensed(true);
   String privkey = "./config/privKey1.der";
   String[] certFiles = {"./config/cert1.der","./config/cacert1.der"};
   // initialize TContext and establish connection attributes
   try {
    TContext.init("./jobs", "./tx.log");
    tc = new TContext();
    tc.connect("localhost:5555", "Administrator", "manage");
    tc.setSecure(true);
    tc.setSSLCertificates(privKey,certFiles);
   } catch (ServiceException e) {
    System.err.println("Error: "+e.getMessage());
    System.exit(-1);   }
   // do work with TContext - get tid, call service, end tid
   try {
    String tid = tc.startTx(3);
     
    // Make an asynch call to invoke the specified transaction.
    tc.submitTx(tid, "wm.server", "ping", IDataFactory.create());
 
    // Retrieve the results of an asynch call in blocking mode.
    IData result = tc.retrieveTx(tid);
     
    System.out.println("Result="+result.toString());
    tc.endTx(tid);
   } catch (TXException e) {
    System.err.println("Job Failed: "+e.getMessage());
    System.exit(-1);
   } catch (DeliveryException e) {
    System.err.println("JobMgr Disabled: "+e.getMessage());
    System.exit(-1);
   } catch (AccessException e) {
    System.err.println("Access Denied: "+e.getMessage());
    System.exit(-1);
   } catch (ServiceException e) {
    System.err.println("Error: "+e.getMessage());
    System.exit(-1);
   }
   // release connection and shutdown
   tc.disconnect();
   TContext.shutdown();
  }
}

Copyright © 2015- 2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Innovation Release