Deployment Issue with MDM Java API exposed as Webservice using EJBS

Hi Experts,
I am implementing MDM Java APIS in Stateless session bean.Exposed that bean as Webservice and using that webservice in
Webdynpro through Adaptive Webservice Model.
I am facing following issue:
Webservice works fine after deployment,after some number of execution webservice stops working and gives exception.After
Redeployment of the Webservice, it starts working again works fine some number of execution.
I am Using new MDMJava API.
MDM Server Details: MDM 5.5 SP06
I am using following code for connetion
//////////////*************Getting Connection************///////
          ConnectionPool pool = null;
          String sessionId = null;
          try {
               pool = ConnectionPoolFactory.getInstance("Server Ip");
          } catch (ConnectionException e1) {
               System.out.println(e1.getMessage());
//////////////*************Repository Session************///////
CreateRepositorySessionCommand repSeession =
               new CreateRepositorySessionCommand(p_pool);
          repSeession.setRepositoryIdentifier(p_repId);
          try {
               repSeession.execute();
          } catch (CommandException e2) {
               System.out.println(e2.getMessage().toString());
          String repIID = repSeession.getRepositorySession();
          //     Authenticate Repository
          AuthenticateRepositorySessionCommand autRepSeesion =
               new AuthenticateRepositorySessionCommand(p_pool);
          try {
               autRepSeesion.setSession(repSeession.getRepositorySession());
               autRepSeesion.setUserName(p_user);
               autRepSeesion.setUserPassword(p_Password);
               autRepSeesion.execute();
          } catch (CommandException e3) {
               System.out.println(
                    "RepSession Seesion" + e3.getMessage().toString());
          return autRepSeesion.getSession();
//////////////*************user Session************///////
GetRepositoryRegionListCommand regionListCommand =
               new GetRepositoryRegionListCommand(p_pool);
          regionListCommand.setRepositoryIdentifier(p_repId);
          try {
               regionListCommand.execute();
          } catch (CommandException e) {
               System.out.println(e.getMessage().toString());
          RegionProperties[] regions = regionListCommand.getRegions();
          //                                 create a user session
          CreateUserSessionCommand UsersessionCommand =
               new CreateUserSessionCommand(p_pool);
          UsersessionCommand.setRepositoryIdentifier(p_repId);
          UsersessionCommand.setDataRegion(regions[0]);
          // use the first region
          try {
               UsersessionCommand.execute();
          } catch (CommandException e) {
               System.out.println("UserSession" + e.getMessage().toString());
          String UsersessionId2 = UsersessionCommand.getUserSession();
AuthenticateUserSessionCommand authUserCommand =
               new AuthenticateUserSessionCommand(p_pool);
          authUserCommand.setSession(UsersessionCommand.getUserSession());
          authUserCommand.setUserName(p_userId);
          authUserCommand.setUserPassword(p_password);
          try {
               authUserCommand.execute();
          } catch (CommandException e) {
               System.out.println("User Seesion" + e.getMessage().toString());
          return authUserCommand.getSession();
//////////////*************Destroy Session************///////
     DestroySessionCommand destroySessionCommand =
               new DestroySessionCommand(p_pool);
          destroySessionCommand.setSession(p_repsession);
          try {
               destroySessionCommand.execute();
          } catch (CommandException e) {
               e.printStackTrace();
          destroySessionCommand.setSession(p_Uesrsession);
               try {
                    destroySessionCommand.execute();
               } catch (CommandException e) {
                    e.printStackTrace();
Do we need to relase the connection pool object also?
Can anyone help me with the code how that can be achived?
Please Reply if anyone has come accross similar issue or know what can be the solution.
Thanks in Advance.
Regards Shruti
Edited by: Shruti Shah on Dec 18, 2008 12:52 PM

Hi Nitin,
Thanks for the prompt Response.
Even I am guessing that its becose of Connection pool.
I am destroying session as follows
               DestroySessionCommand destroySessionCommand =
               new DestroySessionCommand(p_pool);
          destroySessionCommand.setSession(p_repsession);
          try {
               destroySessionCommand.execute();
          } catch (CommandException e) {
               e.printStackTrace();
          destroySessionCommand.setSession(p_Uesrsession);
               try {
                    destroySessionCommand.execute();
               } catch (CommandException e) {
                    e.printStackTrace();
But I didnot find any method by which i can close realsse connection from connection pool.
It would be great if you can help me how close or realese those connection.In MDM Console i am able to see those sessions even after destroying them.
Regards Shruti.

Similar Messages

  • Critical issue with Berkeley Java API

    Hi
    While using Java API to access BDB, and when multiple requests are made at the same time, I am getting the following error:
    unable to allocate memory for mutex; resize mutex region
    Exception in thread "main" java.lang.OutOfMemoryError: Cannot allocate
    memory: unable to allocate memory for mutex; resize mutex region
    at com.sleepycat.db.internal.db_javaJNI.DbEnv_open(Native Method)
    at com.sleepycat.db.internal.DbEnv.open(DbEnv.java:317)
    at
    com.sleepycat.db.EnvironmentConfig.openEnvironment(EnvironmentConfig.java:3886)
    at com.sleepycat.db.Environment.<init>(Environment.java:93)
    at com.yht.util.BDBReader.createPrimaryDatabase(BDBReader.java:78)
    at com.yht.util.class5.cdr.CdrReader.<init>(CdrReader.java:78)
    at com.yht.util.class5.cdr.CdrReader.main(CdrReader.java:233)

    Hi,
    Is this issue critical enough not to [run a search on the forum|http://forums.oracle.com/forums/ann.jspa?annID=244] for the "unable to allocate memory for mutex; resize mutex region" error?
    Database in memory causing exception
    Re: Error message "Not Enough Space"
    Problem: unable to allocate memory for mutex; resize mutex region
    unable to allocate memory for mutex; resize mutex region
    The problem is caused by the incorrect configuration of the mutex region size. Increasing the number of mutexes by calling one of the two methods should fix it:
    http://www.oracle.com/technology/documentation/berkeley-db/db/java/com/sleepycat/db/EnvironmentConfig.html#setMutexIncrement%28int%29
    http://www.oracle.com/technology/documentation/berkeley-db/db/java/com/sleepycat/db/EnvironmentConfig.html#setMaxMutexes%28int%29
    Thanks,
    Bogdan Coman

  • Issue with ENEQuery java api and searching terms with accented characters

    Hi,
    we are using ENEQuery to query the mdex engine. When search terms contain accented characters (like á,í etc), even though the terms are decoded (using java.net.URLDecoder), the term gets send to dgraph is encoded. for e.g a search for "sofá", from the dgraph logs "sof%c3%a1" and fetch in 0 results
    ENEQuery query = new ENEQuery();
    final ERecSearchList searches = new ERecSearchList();
    final ERecSearch eRecSearch = new ERecSearch("search interface name", "term");
    searches.add(eRecSearch);
    query.setNavERecSearches(searches);
    Any suggestions?
    Thanks

    Hi,
    Does your indexed data (which you hope to match) contain "sofá" or "sofa" (no diacritic)? If the latter, and in-general, you may benefit from the dgidx flag --diacritic-folding* as described in documentation "Mapping accented characters to unaccented characters".  If you are running the latest version, this is all that should be required to generate a match.
    Best
    Brett

  • Migration from MDM 4J to MDM Java API

    Hi,
    Can anyone send me details on the migration of MDM 4J to MDM Java API .
    Any document on the differences between the two will be really appreciated.
    Best Regards
    Sid

    Hi Siddharth,
    MDM4J was the old jar files which has been shipped by SAP. In earlier, for customization of any user requirement which is not avialable in MDM, In this case, we can use the MDM JAVA API. for using the same, we need to deploy the MDM4J.jar file then we can use.
    Now, SAP has replaced the old MDM API file name as "MDM4J.jar" with "MDM Java API.jar".
    the only difference between two is that they have added some new jar files to do the specific work with the MDM4J.jar itself. you can find the name as below:
    MDM4J.jar
    mdm-protocol.jar
    mdm-data.jar
    mdm-core.jar
    mdm-common.jar
    mdm-admin.jar
    they have removed some old functionality from MDM4J.jar file itself and added so many new functionality with it.
    for example: by using old java api, we can not get the password of any user but it is possible by new java API jar file. like this they have added so many new fuctionality which we can perform on the MDM Console and MDM Data manager.
    for further info about the MDM JAVA API, you can just refer the following links:
    http://help.sap.com/saphelp_mdmgds55/helpdata/EN/index.htm
    in the left pane,go to programming interface, the required java apis documents is there.
    All the documentation is available on the MDM documentation center on SAP Service Marketplace:
    http://service.sap.com/installMDM
    But for this you need valid service market place id and pwd.
    Hope this will help you.
    Regards,
    Saurabh...
    Reward with points if found useful.
    Edited by: Saurabh Kumar Sahu on Jan 29, 2008 3:19 PM

  • Attachments using MDM java API

    Hi
    How to store attachments in MDM repository using MDM java API.
    Could you please suggest us.
    Thanks
    Sowmya

    Hi Sowmya,
    You can store attachments using MDM Java API. You can use the following piece of code.
    BinaryBlobRecord record2 = RecordFactory.createEmptyBinaryObjectRecord(tableID);
    //Attachment to be saved
    String filePath = wdContext.currentContextElement().getVa_Resource().getUrl(0);
    IWDResource resource = wdContext.currentContextElement().getVa_Resource();
    FileInputStream stream = (FileInputStream)resource.read(true);
    int length = 0;
    while(stream.read() != -1)
         length++;
    byte[] b = new byte[(int) length];
    stream.read(b);
    stream.close();
    record.setName(new StringValue("filename"));
    record.setOriginalName(new StringValue("filename"));
    record.setHasOriginal(new BooleanValue(true);
    RetrieveGroupTreeCommand groupTreeCommand = new    RetrieveGroupTreeCommand(wdContext.currentContextElement().getVa_ConnectionStr());
    groupTreeCommand.setSession(wdContext.currentContextElement().getVa_SessionID());
    groupTreeCommand.setGroupType(GroupTypes.DATA_GROUP_TYPE);
    groupTreeCommand.execute();
    //Set data location and data group ID
    record.setDataLocationId(new GroupNodeId("GN2"));
    record.setDataGroupId(new GroupNodeId("GN2"));
    record.setBinary(new BinaryValue(b));
    CreateRecordCommand createRecComm =
                             new CreateRecordCommand(wdContext.currentContextElement().getVa_ConnectionStr());
    createRecComm.setSession(wdContext.currentContextElement().getVa_SessionID());
    createRecComm.setRecord(record);
    createRecComm.execute();
    //Link this record to the main table record
    Record QRec = RecordFactory.createEmptyRecord(mainTable);
    //Setting the above created record in main table record object
    QRec.setFieldValue(attachmentField, new LookupValue(record.getId()));
    CreateRecordCommand createRecComm =
                        new CreateRecordCommand(wdContext.currentContextElement().getVa_ConnectionStr());
    createRecComm.setSession(wdContext.currentContextElement().getVa_SessionID());
    createRecComm.setRecord(QRec);
    createRecComm.execute();
    Now the main table record is created with an attachment.
    Hope this helps you.
    Regards,
    Sruti

  • MDM JAVA API ERROR

    Hi,
    we are calling mdm java methods from webdynpro code.
    We are executing java successfully from main method. but,when we try to execute it from webdynpro we are getting the follwing error.
    What this exception means to mdm?
    Unexpected exception:Unexpected field type -1

    Hi Ramu,
    the specified exception may be due to wrong fieldCode or Table Code in MDM Java API which you are using ;
    As per my understanding, you might be searching for MDM data from WebDynpro,so look at your resultset or Search object building , some where you coded with wrong FieldCode;
    problem may not be at your WebDynpro but may be at your MDM JAVA API Code;
    give detail information on your question, if you have still problem on that;
    regards
    Rajasekhar k

  • Inetgrating MDM Java API's with Java proxies on XI side

    Hello friends
    Can anyone help me on integrating MDM JAVA API's used for talking to MDM Server and the Javaproxies we generate from the XI side.I am having an application class inside the Java API's (it contains the main function)which triggers the functionality on the MDM side.But how to trigger it from the Java proxies side??I can get the different fields that I have to send  in the impl.java program of my generated proxy,but how to trigger the MDM Java API's from inside this.Also there is one problem I needed to pass the datatype fields from the Javaproxy(XI)side to the CRUDMAINTABLERecord program..Since importing the javaproxy package is giving me an error(I don't know why)I don't know how to pass these datatypes to the CRUD program.Please help me out on this urgently.Thank you all in advance.

    Hi Deepthi,
    I had used the below code for retrieving the workflow's id's
      RetrieveWorkflowsCommand RetriveworksFlows = new RetrieveWorkflowsCommand(connections);
    RetriveworksFlows.setSession(session);
    try{
        RetriveworksFlows.execute();
    catch(Exception e)
    WorkflowProperties[] workflowpro = RetriveworksFlows.getWorkflows();
    WorkflowId[] workflowid = new WorkflowId[workflowpro.length];
    for(int n=0;n<workflowpro.length;n++)
    workflowid[n] = workflowpro[n].getId();
    String workfloName = workflowpro[n].getLaunchType()+"";
    System.out.println("id--"workflowid"name"+workfloName);
    and for creating the workflow job id i had written the below code
    CreateWorkflowJobCommand workflowjobcommand = new CreateWorkflowJobCommand(connections);
    workflowjobcommand.setWorkflowId(workflowid[0]);
    workflowjobcommand.setRecordIds(recordId);
    workflowjobcommand.setSession(session);
    try{
        workflowjobcommand.execute();
    catch(Exception e)
    then to start the workflow what  i  have to do .
    please expain me

  • How and where to install MDM Connector and MDM Java API

    Hi all
    I am installing MDM Server 5.5 and refering to Installation gude
    MDM 5.5 SP06 installation guide (Document Version 1.1 – December 10, 2007).  While installing Development and Portal components , We have to install MDM Connector and MDM JAVA API. I want to know whether the file JAVAAPI<version>.sca file is to extracted on MDM Server or SRM Server ( Using SDM). Please let me know
    Thanks in advance.
    Vitthal prabhu

    Hi Vitthal,
                 We have to install MDM Connector and MDM JAVA API.
    All these sca files that u got along with the business content needs to be deployed onto Web Application Server (recommended WAS 7.0 ).
    U can deploy these files with the help of SDM.
    Hope dis solves ur problem.
    Regards Tejas..............

  • Install MDM JAVA API

    Hi,
    I am using SAP MDM 5.5 SP05. Can someone guide me on how to install MDM Java API.
    I referred to many threads on SDN but couldn't get through any.
    I have already downloaded the java API which has one .sca file and two folders, each has some .jar files and javadoc folder.
    Kindly help on how should i go with it.
    Regards,
    Chintan Sheth

    Hi Chintan,
    You wont install MDM Java API as u install your MDM server or client.
    <b>What the use of the MDM Java API?</b>
    1. Stand-alone Java Applications.
    U can use MDM java API for your stand-alone applications that runs locally on your PC etc... For this you can import the MDM Java jar file into to the library of yourstand alone java application project.
    2. J2EE Application or custom MDM iview in EP or SAP Webdynpro Apllication.
    U can deploy the .sca file in the SAP WAS Java using the SDM client and u can extend the MDM Java API in your J2EE Application or custom MDM iview in EP or SAP Webdynpro Apllication
    get back for help...
    Regards,
    Vijay

  • MDM 7.1 SCA files +MDM java apis required

    Hi experts,
    I have installed MDM 7.1 but now i want to deploy the SCA files so that i can integrate EP with MDM 7.1
    i searched over market place but cpould not able to find SCA files/MDM java apis for MDM 7.1
    any pointer in this regards shall be highly aprreciated.
    regards
    narendra

    Hi Narendra,
    Go to https://websmp210.sap-ag.de/bosap-support
    in that select downloads tab ->
    Support Packages and Patches - Entry by Application Group -> SAP NetWeaver ->  SAP MDM -> SAP NETWEAVER MDM 7.1
    Here you will find all suporting files including your required MDM Java & .sca files.
    You need a valid Service market place user ID to access these contents.
    Regards,
    Abhijeet
    Edited by: abhijeet more on Apr 15, 2009 2:27 PM

  • MDM Java API (Creation of table)

    Hi,
    can anyone help me for  creation of tables in repository using MDM java API .
    Can u Provide sample code for this.
    Edited by: Srikanth Josyula on Jun 26, 2008 8:52 AM

    Hi Srikanth,
    Check with this code.It may be useful.
    createflattable.java
    Created on June 25, 2008, 5:08 PM
    To change this template, choose Tools | Options and locate the template under
    the Source Creation and Management node. Right-click the template and choose
    Open. You can then make changes to the template in the Source Editor.
    package tabletype;
    import com.sap.mdm.commands.AuthenticateRepositorySessionCommand;
    import com.sap.mdm.commands.CommandException;
    import com.sap.mdm.commands.CreateRepositorySessionCommand;
    import com.sap.mdm.commands.GetRepositoryRegionListCommand;
    import com.sap.mdm.data.MultilingualString;
    import com.sap.mdm.data.RegionProperties;
    import com.sap.mdm.data.RegionalString;
    import com.sap.mdm.net.ConnectionException;
    import com.sap.mdm.net.ConnectionPool;
    import com.sap.mdm.net.ConnectionPoolFactory;
    import com.sap.mdm.schema.TableProperties;
    import com.sap.mdm.schema.commands.CreateTableCommand;
    import com.sap.mdm.schema.commands.GetFieldListCommand;
    import com.sap.mdm.schema.commands.GetTableListCommand;
    import com.sap.*;
    import com.sap.mdm.server.DBMSType;
    import com.sap.mdm.server.RepositoryIdentifier;
    import java.util.Locale;
    public class createflattable {
        /** Creates a new instance of createflattable */
        public createflattable() {
            private static MultilingualString createMultilingualString(RegionProperties[] regionPropertiesList, String baseString)
            MultilingualString mlString = new MultilingualString();
            for (int i = 0; i < regionPropertiesList.length; i++)
                Locale locale = regionPropertiesList<i>.getLocale();
                //Locale locale = regionPropertiesList<i>.getLocale();
                String regionCode = regionPropertiesList<i>.getRegionCode();
                String string = baseString + "_" + locale.getLanguage() + "_" + locale.getCountry();
                RegionalString regionalstring = new RegionalString(string, regionCode);
                mlString.set(regionalstring);
            return mlString;
        private static TableProperties createFlatTable(RegionProperties[] regionPropertiesList)
            //MultilingualString tableName = createMultilingualString(regionPropertiesList, "NewTable" + System.currentTimeMillis());
    MultilingualString tableName = createMultilingualString(regionPropertiesList, "first"+System.currentTimeMillis());
    System.out.println("table is" +tableName);
            TableProperties table = new TableProperties(TableProperties.FLAT);       
            table.setName(tableName);
            table.setCode("NewCode" + System.currentTimeMillis());
            table.setKeyMappable(true);
            table.setDescription("");
            return table;
          public static void main(String[] args) {
                // System Name
         String tag = "";
        ConnectionPool connections = null;
    try {
        connections = ConnectionPoolFactory.getInstance(tag);
    catch (ConnectionException e)
    e.printStackTrace();
    return;
    //////////////// specify the repository to use
    //RepositoryName
    String repositoryName = "";
    //DataBase Name
    String dbmsName = "";
    RepositoryIdentifier  reposId = new RepositoryIdentifier(repositoryName, dbmsName, DBMSType.MS_SQL);
    /////// create a repository session
    CreateRepositorySessionCommand sessionCommand = new CreateRepositorySessionCommand(connections);
    sessionCommand.setRepositoryIdentifier(reposId);
    try {
    sessionCommand.execute();
    catch (CommandException e) {
    e.printStackTrace();
    return;
    System.out.println("Currently connected to "+reposId);
    String sessionId = sessionCommand.getRepositorySession();
    /////////// authenticate the repository session
    String userName = "";
    String userPassword = "";
    AuthenticateRepositorySessionCommand authCommand = new AuthenticateRepositorySessionCommand(connections);
    authCommand.setSession(sessionId);
    authCommand.setUserName(userName);
    authCommand.setUserPassword(userPassword);
    try {
    authCommand.execute();
    catch (CommandException e) {
    e.printStackTrace();
    return;
    //////////////////// retrieve the list of tables
    GetTableListCommand tableListCommand = new GetTableListCommand(connections);
    tableListCommand.setSession(sessionId);
    try {
    tableListCommand.execute();
    catch (CommandException e) {
    e.printStackTrace();
    return;
    // get change stamp
      // this is required when we make any kind of changes to the repository
         int changeStamp = tableListCommand.getChangeStamp();
         //////get repository regionlist
    //A command for retrieving the list of regions supported by the repository.
          // retrieve the available regions (languages) for the repository
          // we need this to set up the table name for each region
      GetRepositoryRegionListCommand gm =  new GetRepositoryRegionListCommand(connections);
       gm.setRepositoryIdentifier(reposId);
            try {
               gm.execute();
            catch (CommandException e) {
                e.printStackTrace();
                return;
       //   RegionProperties[] rs = gm.getRegions();
    RegionProperties[] regionPropertiesList = gm.getRegions();
          TableProperties newtable = createFlatTable(regionPropertiesList);
          CreateTableCommand c = new CreateTableCommand (connections);
            c.setSession(sessionId);
          c.setTable(newtable);
       c.setInChangeStamp(changeStamp);
            try {
                 c.execute();
                System.out.println("sdf");
            catch (CommandException e) {
                e.printStackTrace();
                return;

  • How to start to work on MDM JAVA API by using webdynpro for java

    Hi all
    I have basic idea on MDM business package thru portal by using standard iViews.
    now i am planning to work on MDM JAVA APIs by using Webdynpro for Java as UI.
    1) can you please share the required documents on the same. how to start working on this by using MDM JAVA APIs in webdynpro for java
    2) what are the JARs files are required and how to integrate those jar files into webdynpro for java application.
    3)  is there any SDN help on MDM JAVA API with webdynpro for java? . can you please send the link on the same.
    4) can you please help by providing sample code on how to use JAVA APIs for retrieving,deleting,inserting and Updating the data in the database.
    if anybody helps on the same then it is the great help to me.
    points are always rewardable...
    Regards
    Suresh babu

    Hi Suresh,
    You can have the MDM JAVA API javadocs from the link
    http://help.sap.com/javadocs/MDM/SP06P2/index.html
    There you can see a package named com.sap.mdm.examples.The classes in it contains some examples using which you can start understanding the code.
    You need to have MDM JAR files for it. And these JAR files to be used at build time can be added to the project thru :-
    Right click on project-> properties->Java Build Path - > Add external JARs
    At run time you can add them the reference in
    Right click on project-> properties->web dynpro references->library reference.
    Thanks
    Namrata

  • Can I create a cert with the Java API only?

    I'm building a client/server app that will use SSL and client certs for authenticating the client to the server. I'd like for each user to be able to create a keypair and an associated self-signed cert that they can provide to the server through some other means, to be included in the server's trust store.
    I know how to generate a key pair with an associated self-signed cert via keytool, but I'd prefer to do it directly with the Java APIs. From looking at the Javadocs, I can see how to generate a keypair and how to generate a cert object using an encoded representation of the cert ( e.g. java.security.cert.CertificateFactory.generateCertififcate() ).
    But how can I create this encoded representation of the certificate that I need to provide to generateCertificate()? I could do it with keytool and export the cert to a file, but is there no Java API that can accomplish the same thing?
    I want to avoid having the user use keytool. Perhaps I can execute the appropriate keytool command from the java code, using Runtime.exec(), but again a pure java API approach would be better. Is there a way to do this all with Java? If not, is executing keytool via Runtime.exec() the best approach?

    There is no solution available with the JDK. It's rather deficient wrt certificate management, as java.security.cert.CertificateFactory is a factory that only deals in re-treads. That is, it doesn't really create certs. Rather it converts a DER encoded byte stream into a Java Certificate object.
    I found two ways to create a certificate from scratch. The first one is an all Java implementation of what keytool does. The second is to use Runtime.exec(), which you don't want to do.
    1. Use BouncyCastle, a free open source cryptography library that you can find here: http://www.bouncycastle.org/ There are examples in the documentation that show you how to do just about anything you want to do. I chose not to use it, because my need was satisfied with a lighter approach, and I didn't want to add a dependency unnecessarily. Also Bouncy Castle requires you to use a distinct version with each version of the JDK. So if I wanted my app to work with JDK 1.4 or later, I would have to actually create three different versions, each bundled with the version of BouncyCastle that matches the version of the target JDK.
    2. I created my cert by using Runtime.exec() to invoke the keytool program, which you say you don't want to do. This seemed like a hack to me, so I tried to avoid it; but actually I think it was the better choice for me, and I've been happy with how it works. It may have some backward compatibility issues. I tested it on Windows XP and Mac 10.4.9 with JDK 1.6. Some keytool arguments changed with JDK versions, but I think they maintained backward compatibility. I haven't checked it, and I don't know if I'm using the later or earlier version of the keytool arguments.
    Here's my code.
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.security.KeyStore;
    import java.security.KeyStoreException;
    import java.security.NoSuchAlgorithmException;
    import java.security.cert.CertificateException;
    import javax.security.auth.x500.X500Principal;
    import javax.swing.JOptionPane;
    public class CreateCertDemo {
         private static void createKey() throws IOException,
          KeyStoreException, NoSuchAlgorithmException, CertificateException{
         X500Principal principal;
         String storeName = ".keystore";
         String alias = "keyAlias";
         principal = PrincipalInfo.getInstance().getPrincipal();
         String validity = "10000";
         String[] cmd = new String[]{ "keytool", "-genKey", "-alias", alias, "-keyalg", "RSA",
            "-sigalg", "SHA256WithRSA", "-dname", principal.getName(), "-validity",
            validity, "-keypass", "keyPassword", "-keystore",
            storeName, "-storepass", "storePassword"};
         int result = doExecCommand(cmd);
         if (result != 0){
              String msg = "An error occured while trying to generate\n" +
                                  "the private key. The error code returned by\n" +
                                  "the keytool command was " + result + ".";
              JOptionPane.showMessageDialog(null, msg, "Key Generation Error", JOptionPane.WARNING_MESSAGE);
         KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
         ks.load(new FileInputStream(storeName), "storePassword".toCharArray());
            //return ks from the method if needed
    public static int doExecCommand(String[] cmd) throws IOException{
              Runtime r = Runtime.getRuntime();
              Process p = null;
              p = r.exec(cmd);
              FileOutputStream outFos = null;
              FileOutputStream errFos = null;
              File out = new File("keytool_exe.out");
              out.createNewFile();
              File err = new File("keytool_exe.err");
              err.createNewFile();
              outFos = new FileOutputStream(out);
              errFos = new FileOutputStream(err);
              StreamSink outSink = new StreamSink(p.getInputStream(),"Output", outFos );
              StreamSink errSink = new StreamSink(p.getErrorStream(),"Error", errFos );
              outSink.start();
              errSink.start();
              int exitVal = 0;;
              try {
                   exitVal = p.waitFor();
              } catch (InterruptedException e) {
                   return -100;
              System.out.println (exitVal==0 ?  "certificate created" :
                   "A problem occured during certificate creation");
              outFos.flush();
              outFos.close();
              errFos.flush();
              errFos.close();
              out.delete();
              err.delete();
              return exitVal;
         public static void main (String[] args) throws
              KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException{
              createKey();
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.io.PrintWriter;
    //Adapted from Mike Daconta's StreamGobbler at
    //http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=4
    public class StreamSink extends Thread
        InputStream is;
        String type;
        OutputStream os;
        public StreamSink(InputStream is, String type)
            this(is, type, null);
        public StreamSink(InputStream is, String type, OutputStream redirect)
            this.is = is;
            this.type = type;
            this.os = redirect;
        public void run()
            try
                PrintWriter pw = null;
                if (os != null)
                    pw = new PrintWriter(os);
                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader br = new BufferedReader(isr);
                String line=null;
                while ( (line = br.readLine()) != null)
                    if (pw != null)
                        pw.println(line);
                    System.out.println(type + ">" + line);   
                if (pw != null)
                    pw.flush();
            } catch (IOException ioe)
                ioe.printStackTrace(); 
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import javax.security.auth.x500.X500Principal;
    public class PrincipalInfo {
         private static String defInfoString = "CN=Name, O=Organization";
         //make it a singleton.
         private static class PrincipalInfoHolder{
              private static PrincipalInfo instance = new PrincipalInfo();
         public static PrincipalInfo getInstance(){
              return PrincipalInfoHolder.instance;
         private PrincipalInfo(){
         public X500Principal getPrincipal(){
              String fileName = "principal.der";
              File file = new File(fileName);
              if (file.exists()){
                   try {
                        return new X500Principal(new FileInputStream(file));
                   } catch (FileNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        return null;
              }else{
                   return new X500Principal(defInfoString);
         public void savePrincipal(X500Principal p) throws IOException{
              FileOutputStream fos = new FileOutputStream("principal.der");
              fos.write(p.getEncoded());
              fos.close();
    }Message was edited by:
    MidnightJava
    Message was edited by:
    MidnightJava

  • How to access the SAP MDM destinations using mdm java api in 7.1

    hi,
    I have SAP MDM 7.1 SP11 and SAP Portal 7.3 and developing the custom webdynpro application using the  JAVA MDM API. I want configure the SAP MDM destinations in SAP Portal .
    How to access the MDM destinations in java code using API? and how to create the connection with MDM using the MDM destinations.
    Please provide the code for access the SAP MDM destinations in java code using MDM java api and creating the connection to MDM.
    Thanks

    Jun,
    Thanks for the reply and api information.
    I have got this api information from the following sap documentation. But i am looking for the code by implementing this class and creating the mdm connection.
    Creating an MDM Connection Using Java Code - SAP NetWeaver Master Data Management (MDM) - SAP Library
    if any thing can you share it.
    Thanks

  • MDM JAVA API beginners queries

    Hi,
    I am a beginner for Web Dynpro. I am working on MDM and i need to use the MDM JAVA API
    I have downloaded the zip files and reading the documentation.
    I need guidance on how to proceed. Kindly help
    thank you
    bhakti

    Hi Rita,
    You can follow the below likns which will guide you on how to go about using JAVA Apis with MDM:
    How to start to work on MDM JAVA API by using webdynpro for java
    Re: MDM Java Tutorial
    Standard practise to make the APIs reusable ?
    MDM Java API Samples Framework
    Sample code required to Create,Update,Delete,Read & Search for records MDM
    Sample code is required on MDM JAVA APIs thru Webdynpro for java
    Hope It Helped
    Thanks & Regards
    Simona Pinto
    Hope It Helped
    Thanks & Regards
    Simona Pinto

Maybe you are looking for

  • Reformatting Computer's Hardrive: Need help with Backup and Restore?

    Hi, I'm getting ready to reformat my hardrive and I'm backing up all of my files. All apps will be reinstalled after the drive is formatted. I have a ton of music that I've purchased from itunes and mp3s that I've ripped from my CDs in my main itunes

  • Please can I have my music back? After all, I did buy it!

    I recently upgraded my PC and so had to re-load my iTunes software. I've since re-loaded my music, but iTunes will no longer let me play music which I had purchased previously from iTunes. Can anyone tell me why this is, and what I can do about it? I

  • Oracle Error on 7.5 Install

    I am trying to install ZAM Inventory 7.5 on a Windows 2003 server connecting to an Oracle 10G database. The install repeatedly errors out after encountering this error: PL/SQL procedure successfully completed. from all_tables ERROR at line 6: ORA-065

  • DBMS_XMLDOM.getdocumentelement failing...

    Hi, I have written a generic function which takes 2 XMLType as input (parent, child) and returns a XMLType by appending child inside parent. I am using dbms_XMLDOM for this. eg. if parent = <a></a> and child <b></b> then output would be <a><b></b></a

  • Pooled table and clustred table

    pooled table and clustred table