Java Client example

Sample code illustrates how to use the Java Client library classes and methods to connect to the system and print the product version number.

  1. BanterServerWebService_ServiceLocator bnsLocator = new BanterServerWebService_ServiceLocator();
  2. java.net.URL bnsURL;
  3. try {
  4. bnsURL = new java.net.URL ("http://localhost:18087");
  5. } catch (java.net.MalformedURLException e) {
  6. // Error handling
  7. }
  8. BanterServerWebServicePortType bnsServer = getBanterServerWebService (bnsURL);
  9. BanterServerWebService_BindingStub bnsServerStub = (BanterServerWebService_BindingStub)bnsServer;
  10. bnsServerStub.setUsername ("");
  11. bnsServerStub.setPassword ("");
  12. try {
  13. com.banter.bns.Version bnsVersion = bnsServer.validateConnection();
  14. System.out.println ("Server version = " + bnsVersion.getVerMajor() + "." + bnsVersion.getVerMinor());
  15. } catch (java.rmi.RemoteException e) {
  16. StringBuffer errDescription;
  17. int errNumber = BnsErrorLookup.getErrorDescription (e, errDescription);
  18. // Error handling
  19. } catch (Exception e) {
  20. // Error handling
  21. }

The purpose of each section of the preceding code is shown in the following list, by line numbers:

1
Allocates a locator (com.banter.bns.BanterServerWebService_ServiceLocator) object.
4
Allocates a URL (java.net.URL) object, given a string URL.
5-7
Error handling for the URL creation.
8
Retrieves a reference to a BanterServerWebServicePortType.
9-11
For future use. Sets the credential for connecting to the Listener virtual directory, by downcasting the port type to a binding stub.
14
Calls the server method validateConnection.
15
Prints the product version number.
16-22
Error handling for the method validateConnection.