Samples
The following Java code example shows how to add a user to TIBCO MFT Command Center by using the Administrator service. Substitute the correct values of your MFT installation to compile and execute this sample.
SoapClient.java
import AdminClient.*;
import java.rmi.RemoteException;
import javax.xml.rpc.Stub;
import javax.xml.rpc.ServiceException;
/*
* This program demonstrates adding a user through the administrative SOAP service. Changes the ADMIN_SERVICE_URL and
* the ADMIN_USER_ID and ADMIN_PASSWORD variables declared below.
*
* COMPILE
* javac -classpath D:\Tomcat5.5\webapps\cfcc\WEB-INF\lib\AdminClient.jar;D:\Tomcat5.5\webapps\cfcc\WEB-INF\lib\jaxrpc.jar;
* D:\Tomcat5.5\webapps\cfcc\WEB-INF\lib\axis.jar SOAPClient.java
*
* RUN
* java -cp .;D:\Tomcat5.5\webapps\cfcc\WEB-INF\lib\AdminClient.jar;D:\Tomcat5.5\webapps\cfcc\WEB-INF\lib\jaxrpc.jar;
* D:\Tomcat5.5\webapps\cfcc\WEB-INF\lib\axis.jar;D:\Tomcat5.5\webapps\cfcc\WEB-INF\lib\commons-logging.jar;
* D:\Tomcat5.5\webapps\cfcc\WEB-INF\lib\commons-discovery.jar;D:\Tomcat5.5\webapps\cfcc\WEB-INF\lib\saaj.jar;
* D:\Tomcat5.5\webapps\cfcc\WEB-INF\lib\wsdl4j.jar;D:\Tomcat5.5\webapps\cfcc\WEB-INF\classes SOAPClient
*
*/
public class SOAPClient
{
private static final String ADMIN_SERVICE_URL = "https://your.mft.com:8443/cfcc/control?view=services/AdministratorService";
private static final String ADMIN_USER_ID = "admin";
private static final String ADMIN_PASSWORD = "admin";
public static void main(String[] args)
{
SOAPClient adminClient = new SOAPClient();
User newUser = new User();
newUser.setId("test01");
newUser.setFullName("Test User 1");
newUser.setPassword("test1234");
DateTime expireDate = new DateTime(); // Dec 31, 2011
expireDate.setYear(2011);
expireDate.setMonth(11); // months are 0 thru 11
expireDate.setDay(31);
newUser.setExpirationDate(expireDate);
try
{
adminClient.addUser(newUser);
}
catch(Exception e)
{
System.out.println("Error adding user, " + e.getMessage());
}
}
public void addUser(User _usr) throws RemoteException, ServiceException
{
System.setProperty("org.apache.axis.components.net.SecureSocketFactory", "com.proginet.sift.soap.fileTransferService.util.CustomAxisSSLSocketFactory");
Stub stub = createProxy(ADMIN_USER_ID, ADMIN_PASSWORD);
stub._setProperty(javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY, ADMIN_SERVICE_URL);
((org.apache.axis.client.Stub)stub).setMaintainSession(true);
AdminService admin=(AdminService)stub; // apache stub
// need session id to make SOAP calls
String sessionId = admin.getSession();
boolean success = admin.addUser(_usr, sessionId);
if (success)
{
System.out.println("Added user successfully.");
}
else
{
System.out.println("Failed to add user.");
}
}
/**
* Create stub to communicate with service.
*
* @param username username set into stub for authentication
* @param password user's passowrd set into stub for authentication
* @return the stub used for communication
*/
protected static Stub createProxy(String _username, String _password) throws ServiceException
{
// apache stub
AdminServiceService adminService = new AdminServiceServiceLocator(); //get service location
AdminService admin = adminService.getAdministratorService(); //get stub instance (already cast)
if (_username == null)
{
_username = "";
}
if (_password == null)
{
_password = "";
}
((Stub)admin)._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY, _username); //down cast to load stub
((Stub)admin)._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY, _password); //username and password
((Stub)admin)._setProperty(javax.xml.rpc.Stub.SESSION_MAINTAIN_PROPERTY, new Boolean(true)); //maintain session
return (Stub)admin;
}
}
This following example uses the Administrator service to create an MFT user ID. It then creates a transfer definition and assigns it to the user ID. The File Transfer service is used to retrieve a list of all files available to the user ID. Substitute the correct values of your MFT installation to compile and execute this sample.
SoapTest.java
package test;
// Admin Service imports
import AdminClient.AdminService;
import AdminClient.AdminServiceService;
import AdminClient.AdminServiceServiceLocator;
import AdminClient.DateTime;
import AdminClient.User;
import AdminClient.Transfer;
// FT Service imports
import FTClient.FTService_PortType;
import FTClient.FTServiceService;
import FTClient.FTServiceServiceLocator;
import FTClient.FileInfo;
// other imports
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Stub;
public class SOAPTest
{
public static void main(String[] args)
{
SOAPAdminService admin = new SOAPAdminService();
admin.addUser();
admin.addInternetTransfer();
admin.cleanup();
SOAPFTService ft = new SOAPFTService();
ft.displayAllTransferIds();
ft.cleanup();
}
}
class SOAPAdminService
{
private static final String SERVER_URL = "https://your.mft.com:8443/cfcc";
private static final String ADMIN_SERVICES_URL = "/control?view=services/AdministratorService";
private String ADMIN_USER_ID = "admin";
private String ADMIN_PASSWORD = "admin";
private String NEW_USER_ID = "test02";
private String NEW_USER_PWD = "test1234";
private String NEW_USER_NAME = "Test User 2";
private AdminService m_adminService;
private String m_sessionId;
public SOAPAdminService()
{
try
{
getAdminService();
}
catch(ServiceException e)
{
e.printStackTrace(System.out);
return;
}
getSessionId();
}
public void cleanup()
{
closeSession();
}
public void addUser()
{
User usr = new User();
usr.setId(NEW_USER_ID);
usr.setFullName(NEW_USER_NAME);
usr.setPassword(NEW_USER_PWD);
DateTime expireDate = new DateTime();
expireDate.setYear(2020);
expireDate.setMonth(11); // months are 0 thru 11
expireDate.setDay(31);
usr.setExpirationDate(expireDate);
try
{
boolean rc = m_adminService.addUser(usr, m_sessionId);
System.out.println("User was added [" + rc + "]");
}
catch(RemoteException e)
{
e.printStackTrace(System.out);
}
}
public void addInternetTransfer()
{
Transfer xfer = new Transfer();
xfer.setClientFileName("C:\\tmp\\localfile.txt");
xfer.setServerFileName("C:\\tmp\\remotefile.txt");
xfer.setDirectoryTransfer("0"); // 0 = no 1 = yes
xfer.setDescription("test upload");
xfer.setAuthUserId(NEW_USER_ID);
xfer.setNodeName("*LOCAL");
xfer.setSendRecvFlag("S"); // S = upload R = download
xfer.setAllowableProtocol("ALL");
xfer.setConversionFlag("0"); // 0 = Ascii to EBCDIC conversion 1 = ASCII to EBCDIC conversion based on local translation table
try
{
String fileId = m_adminService.addTransfer(xfer, m_sessionId);
System.out.println("Transfer was added [" + fileId + "]");
}
catch(RemoteException e)
{
e.printStackTrace(System.out);
}
}
private void getSessionId()
{
try
{
m_sessionId = m_adminService.getSession();
}
catch(RemoteException e)
{
e.printStackTrace(System.out);
}
}
private void closeSession()
{
try
{
m_adminService.closeSession(m_sessionId);
}
catch(RemoteException e)
{
e.printStackTrace(System.out);
}
}
private void getAdminService() throws ServiceException
{
System.setProperty("org.apache.axis.components.net.SecureSocketFactory", "test.CustomAxisSSLSocketFactory");
SOAPServiceFactory serviceFactory = new SOAPServiceFactory();
serviceFactory.setUserId(ADMIN_USER_ID);
serviceFactory.setPassword(ADMIN_PASSWORD);
serviceFactory.setServiceUrl(SERVER_URL + ADMIN_SERVICES_URL);
m_adminService = serviceFactory.getAdminService();
}
}
class SOAPFTService
{
private static final String SERVER_URL = "https://your.mft.com:8443/cfcc";
private static final String FT_SERVICES_URL = "/control?view=services/FTService";
private String XFER_USER_ID = "test02";
private String XFER_PASSWORD = "test1234";
private FTService_PortType m_ftService;
private String m_sessionId;
public SOAPFTService()
{
try
{
getFTService();
}
catch(ServiceException e)
{
e.printStackTrace(System.out);
return;
}
getSessionId();
}
public void cleanup()
{
closeSession();
}
public void displayAllTransferIds()
{
try
{
FileInfo[] files = m_ftService.getAllFilesForUser(m_sessionId);
if (files != null)
{
for (int i = 0; i < files.length; i++)
{
if (files[i] != null)
{
System.out.println(files[i].getId());
}
}
}
}
catch(RemoteException e)
{
e.printStackTrace(System.out);
}
}
private void getSessionId()
{
try
{
m_sessionId = m_ftService.getSession();
}
catch(RemoteException e)
{
e.printStackTrace(System.out);
}
}
private void closeSession()
{
try
{
m_ftService.closeSession(m_sessionId);
}
catch(RemoteException e)
{
e.printStackTrace(System.out);
}
}
private void getFTService() throws ServiceException
{
System.setProperty("org.apache.axis.components.net.SecureSocketFactory", "test.CustomAxisSSLSocketFactory");
SOAPServiceFactory serviceFactory = new SOAPServiceFactory();
serviceFactory.setUserId(XFER_USER_ID);
serviceFactory.setPassword(XFER_PASSWORD);
serviceFactory.setServiceUrl(SERVER_URL + FT_SERVICES_URL);
m_ftService = serviceFactory.getFTService();
}
}
class SOAPServiceFactory
{
private String m_userId;
private String m_password;
private String m_serviceUrl;
private int m_timeout;
private boolean m_maintainSession;
private static final int THIRTY_SECONDS = 1000 * 30;
public SOAPServiceFactory()
{
m_timeout = THIRTY_SECONDS;
m_maintainSession = true;
}
public void setUserId(String _userId)
{
m_userId = _userId;
}
public void setPassword(String _pwd)
{
m_password = _pwd;
}
public void setServiceUrl(String _url)
{
m_serviceUrl = _url;
}
public void setTimeout(int _milliseconds)
{
m_timeout = _milliseconds;
}
public void setMaintainSession(boolean _flag)
{
m_maintainSession = _flag;
}
public AdminService getAdminService() throws ServiceException
{
AdminServiceService serviceLocator = new AdminServiceServiceLocator();
AdminService adminService = serviceLocator.getAdministratorService();
setStubProperties((Stub)adminService);
return adminService;
}
public FTService_PortType getFTService() throws ServiceException
{
FTServiceService serviceLocator = new FTServiceServiceLocator();
FTService_PortType ftService = serviceLocator.getFTService();
setStubProperties((Stub)ftService);
return ftService;
}
private void setStubProperties(Stub _stub)
{
_stub._setProperty(Stub.USERNAME_PROPERTY, m_userId);
_stub._setProperty(Stub.PASSWORD_PROPERTY, m_password);
_stub._setProperty(Stub.SESSION_MAINTAIN_PROPERTY, new Boolean(m_maintainSession));
_stub._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, m_serviceUrl);
_stub.setTimeout(m_timeout);
}
}
Copyright © 2021. Cloud Software Group, Inc. All Rights Reserved.
