package com.kw.ecm.cs.util;
import com.opentext.livelink.service.core.Authentication;
import com.opentext.livelink.service.core.Authentication_Service;
import java.net.URL;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.soap.SOAPFaultException;
public class CSWSTestClient {
@SuppressWarnings("CallToPrintStackTrace")
public static void main(String[] args) {
try {
String urlAuthentication = getParameter("Authentication URL:");
String username = getParameter("Username:");
String password = getPassword("Password: (will not echo keystrokes)");
final String authToken;
final Authentication_Service authService = new Authentication_Service(new URL(urlAuthentication));
final Authentication authClient = authService.getBasicHttpBindingAuthentication();
((BindingProvider) authClient).getRequestContext().put(
BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
urlAuthentication
);
try {
authToken = authClient.authenticateUser(username, password);
System.out.printf("Authentication Token: %s%n", authToken);
} catch (SOAPFaultException e) {
final String msg = String.format("%s : %s", e.getFault().getFaultCode(), e.getMessage());
throw new RuntimeException(msg, e);
}
} catch (Throwable t) {
System.err.println(t.getLocalizedMessage());
t.printStackTrace();
} finally {
//do nothing at the moment
}
}
private static String getParameter(String msg) {
System.out.println(msg);
String parm = System.console().readLine();
return parm;
}
private static String getPassword(String msg) {
System.out.println(msg);
String pass = new String(System.console().readPassword());
return pass;
}
}
Comments