package com.sap.mdm.examples;
import com.sap.mdm.commands.AuthenticateServerSessionCommand;
import com.sap.mdm.commands.CommandException;
import com.sap.mdm.commands.CreateServerSessionCommand;
import com.sap.mdm.net.ConnectionException;
import com.sap.mdm.net.ConnectionPool;
import com.sap.mdm.net.ConnectionPoolFactory;
import com.sap.mdm.server.commands.StopServerCommand;
/*
* Copyright © 2004-2006 by SAP AG.
* All Rights Reserved.
*
* SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP
* products and services mentioned herein as well as their respective logos are
* trademarks or registered trademarks of SAP AG in Germany and in several other
* countries all over the world. All other product and service names mentioned
* are the trademarks of their respective companies. Data contained in this
* document serves informational purposes only. National product specifications
* may vary.
*
* These materials are subject to change without notice. These materials are
* provided by SAP AG and its affiliated companies (SAP Group) for informational
* purposes only, without representation or warranty of any kind, and SAP Group
* shall not be liable for errors or omissions with respect to the materials.
* The only warranties for SAP Group products and services are those that are
* set forth in the express warranty statements accompanying such products and
* services, if any. Nothing herein should be construed as constituting an
* additional warranty.
*
*/
/**
* This example demonstrates shutting down the MDM server. The steps are:
* <ol>
* <li>Establishes connection with the MDM server</li>
* <li>Creates a server session</li>
* <li>Authenticates the server session</li>
* <li>Stops the MDM server</li>
* </ol>
* Commands used:<br>
* <code>CreateServerSessionCommand</code><br>
* <code>AuthenticateServerSessionCommand</code><br>
* <code>StopServerCommand</code><br>
* <br>
* <a href="StopServer.java">Source code for StopServer.java</a>
*/
public class StopServer {
private StopServer() {
}
public static void main(String[] args) {
// create connection pool
String connectionTag = "LOCALHOST";
ConnectionPool connections = null;
try {
connections = ConnectionPoolFactory.getInstance(connectionTag);
} catch (ConnectionException e) {
e.printStackTrace();
return;
}
// create server session
CreateServerSessionCommand sessionCommand = new CreateServerSessionCommand(connections);
try {
sessionCommand.execute();
} catch (CommandException e) {
e.printStackTrace();
return;
}
String sessionId = sessionCommand.getSession();
// authenticate the repository session
String userName = "Admin";
String userPassword = "";
AuthenticateServerSessionCommand authCommand = new AuthenticateServerSessionCommand(connections);
authCommand.setSession(sessionId);
authCommand.setUserName(userName);
authCommand.setUserPassword(userPassword);
try {
authCommand.execute();
} catch (CommandException e) {
e.printStackTrace();
return;
}
// stop the MDM server
StopServerCommand stopServerCommand = new StopServerCommand(connections);
stopServerCommand.setSession(sessionId);
try {
stopServerCommand.execute();
} catch (CommandException e) {
e.printStackTrace();
return;
}
}
}