How can I install a module into iManager...
Articles and Tips: qna
01 Jun 2003
Q.
How can I install a module into iManager programmatically?
A.
Sample code is shown below. Here is what to do before running the code:
iManager must be installed and running.
The certificate from the web server must be imported into the jre/lib/security/cacerts file. (This is done automatically on Nakoma.)
The module to be installed must be placed on the server.
The following errors may occur:
HttpServletResponse.SC_PRECONDITION_FAILED (412): Couldn't open PortalServlet.properties. Portal is probably not configured. HttpServletResponse.SC_FORBIDDEN (403): Authentication failed. AdminDN or AdminPassword are probably wrong. HttpServletResponse.SC_BAD_REQUEST (400): Couldn't find the Module specified. Make sure the module is on the server at the path specified. HttpServletResponse.SC_INTERNAL_SERVER_ERROR (500): There was an error installing the module. Probably a corrupt module. // Use this to test programmatically installing modules. // Portal must be running as specified in constants!!! import java.io.InputStream; import java.io.IOException; import java.net.URL; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLSession; /* import java.io.PrintWriter; */ public class Module { // constants private static String WEB_APP_CONTEXT = "nps/"; private static String SERVLET_MODULE = "servlet/modulemanager"; private static String PARAMETER_MODULE_PATH = "MODULE_PATH"; private static String PARAMETER_ADMIN_DN = "DN"; private static String PARAMETER_ADMIN_PASSWORD = "PASSWORD"; // internal classes private static class SSLHostNameVerifier implements HostnameVerifier { // HostnameVerifier methods public boolean verify(String urlHostname, SSLSession session) { // Just accept everything. return (true); } } // main public static void main(String[] args) { // Values to be gathered. String sAddress = "127.0.0.1"; String sProtocol = "https"; int iPort = 443; String sAdminDN = "cn=admin,o=servers"; String sAdminPassword = "admin"; String sModulePath = "C:\\Temp\\Zip\\Test.npm"; // API to install the module installModule(sProtocol, sAddress, iPort, sModulePath, sAdminDN, sAdminPassword); } // methods public static void installModule(String sProtocol, String sWebServerAddress, int iPort, String sModulePath, String sAdminDN, String sAdminPassword) { try { // Put together the values passed in. String sURL = sProtocol + "://" + sWebServerAddress + ":" + iPort + "/" + WEB_APP_CONTEXT; String sParamModulePath = PARAMETER_MODULE_PATH + "=" + sModulePath; String sParamDN = PARAMETER_ADMIN_DN + "=" + sAdminDN; String sParamPassword = PARAMETER_ADMIN_PASSWORD + "=" + sAdminPassword; // Now put all of those together into one large URL specification. String sSpec = sURL + SERVLET_MODULE + "?" + sParamModulePath + "&" + sParamDN + "&" + sParamPassword; // This will cause the certificate to be accepted, even if it is the wrong host name. HttpsURLConnection.setDefaultHostnameVerifier(new Module.SSLHostNameVerifier()); // Create the URL and open it. URL url = new URL(sSpec); InputStream inputStream = url.openStream(); inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } }
* Originally published in Novell AppNotes
Disclaimer
The origin of this information may be internal or external to Novell. While Novell makes all reasonable efforts to verify this information, Novell does not make explicit or implied claims to its validity.