IBM BPM, V8.0.1, All platforms > Programming IBM BPM > Developing using the web service API > Samples
Logging on to Process Server
The following sample shows how to use the web API to log on to the process server.
package teamworks.samples.scenarios; import java.rmi.RemoteException; import javax.xml.rpc.Stub; import teamworks.samples.client.WebAPIFactory; import com.lombardisoftware.webapi.WebAPI; /** * This scenario demonstrates using the WebAPI to login to the Teamworks server. * */ public class Login extends Scenario { public void testScenario() throws Exception { // WebAPIFactory is provided by the client sample to // simplify the process of creating and configuring // a client stub to use to connect to the WebAPI service WebAPIFactory factory = getWebAPIFactory(); // Invoking any operation in the WebAPI will cause the // client to be authenticated using the credentials provided // in the connection properties. // We will illustrate what would happen if the user entered // an incorrect password // Save the valid password from the factory String validPassword = (String) factory.getProperty(Stub.PASSWORD_PROPERTY); // Set a bad password value factory.setProperty(Stub.PASSWORD_PROPERTY, "badpassword"); // Create a new WebAPI client stub WebAPI webAPI = getWebAPIFactory().newWebAPI(); // Before a client actually performs any operations, it is good // to test connectivity with the Teamworks server to ensure // that the connection properties are valid. try { webAPI.testConnection(); fail("TestConnection should have failed"); } catch(RemoteException ex) { // The bad password caused the authentication to fail } // The user enters the correct password factory.setProperty(Stub.PASSWORD_PROPERTY, validPassword); // Create a new WebAPI client stub using the valid password webAPI = getWebAPIFactory().newWebAPI(); // Authentication should succeed webAPI.testConnection(); // The WebAPI instance is now ready for use } }