/*
* Copyright © 2004-2007 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.
*
*/
package com.sap.mdm.examples;
import com.sap.mdm.commands.CommandException;
import com.sap.mdm.net.ConnectionException;
import com.sap.mdm.net.SimpleConnection;
import com.sap.mdm.net.SimpleConnectionFactory;
import com.sap.mdm.server.commands.GetServerVersionCommand;
/**
* This example shows you how to create a simple connection and
* execute the session-less command GetServerVersionCommand.
*
* The first thing the program does is to create a connection using the getInstance()
* method of the SimpleConnectionFactory class.
* This method requires a string argument as a ConnectionTag.
* The ConnectionTag is the host name of the MDM Server, plus an optional TCP/IP port number
* on which the server listens. The format is <host name or IP address>[;<port number>].
* If no port number is given, the default port 59950 is used.
* Examples for ConnectionTag:
* localhost – connection the locally installed MDM server is created, using the default port.
* some.server.com;41003 – connection using the non standard port 41003.
* Note: Configuring the MDM Server to listen on a different port than the default port is not yet available.
*
* If for any reason the connection can not be established, the factory class throws a ConnectionException.
*
* Then an instance of the command GetServerVersionCommand is created.
* As for any command, the constructor requires the used connection as an argument.
* Since this command does not need any further arguments, the execute() method is called,
* which sends the command to the server and waits for the result.
*
* Any error after the calling of the execute() method will result in an CommandException being thrown.
*
* Finally the result can be retrieved from the command using the getVersion() method,
* which returns the build version of the MDM Server as a string.
*
*
* Source code for GetServerVersion.java
*/
public class GetServerVersion {
private GetServerVersion() {
}
public static void main(String[] args) {
// Create a connection to the MDM Server on
// the local host by requesting a ConnectionAccessor from
// the SimpleConnectionFactory using the getInstance() method.
String connectionTag = "LOCALHOST";
SimpleConnection connection = null;
try {
connection = SimpleConnectionFactory.getInstance(connectionTag);
} catch (ConnectionException e) {
e.printStackTrace();
return;
}
// Instantiate a GetServerVersionCommand. As for every command
// the constructor requires the connection to be used as an argument.
// There is no need establich a session, since this is one of the
// few commands that do not require a session.
GetServerVersionCommand cmd = new GetServerVersionCommand(connection);
try {
// Execute the command
cmd.execute();
} catch (CommandException e) {
e.printStackTrace();
return;
}
// Retrieve the result of the command - the version of the MDM Server -
// using the getVersion() method
System.out.println("MDM server version: " + cmd.getVersion());
}
}