Advertisement
ossiejhmoore

Simple Java Client to Test Content Server Web Services

Dec 11th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.00 KB | None | 0 0
  1. package com.kw.ecm.cs.util;
  2.  
  3. import com.opentext.livelink.service.core.Authentication;
  4. import com.opentext.livelink.service.core.Authentication_Service;
  5. import java.net.URL;
  6. import javax.xml.ws.BindingProvider;
  7. import javax.xml.ws.soap.SOAPFaultException;
  8.  
  9. public class CSWSTestClient {
  10.  
  11.     @SuppressWarnings("CallToPrintStackTrace")
  12.     public static void main(String[] args) {
  13.  
  14.         try {
  15.            
  16.             String urlAuthentication = getParameter("Authentication URL:");
  17.             String username = getParameter("Username:");
  18.             String password = getPassword("Password: (will not echo keystrokes)");
  19.            
  20.             final String authToken;
  21.             final Authentication_Service authService = new Authentication_Service(new URL(urlAuthentication));
  22.             final Authentication authClient = authService.getBasicHttpBindingAuthentication();
  23.             ((BindingProvider) authClient).getRequestContext().put(
  24.                     BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
  25.                     urlAuthentication
  26.             );
  27.             try {
  28.                 authToken = authClient.authenticateUser(username, password);
  29.                 System.out.printf("Authentication Token: %s%n", authToken);
  30.             } catch (SOAPFaultException e) {
  31.                 final String msg = String.format("%s : %s", e.getFault().getFaultCode(), e.getMessage());
  32.                 throw new RuntimeException(msg, e);
  33.             }
  34.         } catch (Throwable t) {
  35.             System.err.println(t.getLocalizedMessage());
  36.             t.printStackTrace();
  37.         } finally {
  38.             //do nothing at the moment
  39.         }
  40.  
  41.     }
  42.  
  43.     private static String getParameter(String msg) {
  44.         System.out.println(msg);
  45.         String parm = System.console().readLine();
  46.         return parm;
  47.     }
  48.  
  49.     private static String getPassword(String msg) {
  50.         System.out.println(msg);
  51.         String pass = new String(System.console().readPassword());
  52.         return pass;
  53.     }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement