2 Replies Latest reply on Jun 1, 2012 4:39 AM by sarahfr

    Problem with JNDI/ JDK

    sarahfr Newbie

      Hi,

      I try compile this class and Ihave errors

      I have a problem reported on the version of jdk (at compile time I used the version 1.6.0_25).

      I didn't know what version of jdk I need to use.

      thanks for your help

       

       

      package com.accesscommerce.cart.util;

       

       

      import java.io.IOException;

      import java.io.Serializable;

      import java.net.MalformedURLException;

      import java.util.HashMap;

      import java.util.Vector;

       

       

      import javax.management.InstanceNotFoundException;

      import javax.management.MBeanException;

      import javax.management.MBeanServerConnection;

      import javax.management.MalformedObjectNameException;

      import javax.management.ObjectName;

      import javax.management.ReflectionException;

      import javax.management.remote.JMXConnector;

      import javax.management.remote.JMXConnectorFactory;

      import javax.management.remote.JMXServiceURL;

      import javax.naming.NamingException;

       

       

      import com.accesscommerce.cart.CartSettings;

      import com.accesscommerce.cart.connector.ConnectorFactory;

      import com.accesscommerce.cart.connector.ConnectorFactoryException;

      import com.accesscommerce.cart.connector.ConnectorJMXIdentification;

       

       

      /**

      * This class supplies general facilities for sharing objects

      * between web applications.

      * @author rgibault@access-commerce.com

      * @version 2006-09-04

      */

      public final class ShareUtil implements Serializable

      {

                /** Repository */

                private static javax.management.MBeanServerConnection  repository=null;

                /** Server */

                private static javax.management.ObjectName serverName =null;

       

       

                /**

                 * Constructor.

                 */

                private ShareUtil() {}

       

                /**

                 * Initialize connections to the repository server and get

                 * reference to the share server

                 * @throws IOException

                 */

                private static void init() throws IOException

                {

                          try

                          {

                                    final ConnectorFactory factory = new ConnectorFactory(CartSettings.getInstance());

                                    try

                                    {

                                              final ConnectorJMXIdentification jmxIdentification = factory.createConnectorJMXIdentification();

                                              jmxIdentification.verifyJMXIdentification();

                                    }

                                    catch (ConnectorFactoryException e)

                                    {

                                              e.printStackTrace();

                                    }

                                    /**

                                     * final javax.naming.InitialContext ctx= new javax.naming.InitialContext();

                                     * repository = (javax.management.MBeanServerConnection) ctx.lookup("jmx/rmi/RMIAdaptor");

                                    **/

                                    String serverURL = "service:jmx:rmi:///jndi/rmi://127.0.0.1:1090/jmxrmi";

                                    JMXServiceURL url = new JMXServiceURL(serverURL);

                                    serverName = new javax.management.ObjectName("cic:type=CICObjectShare");

                                     HashMap environment = new HashMap(); 

                               String[] credentials = new String[]{"admin", "password"}; 

                               environment.put(JMXConnector.CREDENTIALS, credentials); 

                               JMXConnector jmxc = JMXConnectorFactory.connect(url, environment); 

                               MBeanServerConnection repository = jmxc.getMBeanServerConnection(); 

       

                                    final String tmp = CartSettings.getInstance().getProperty("sharedObjectsTimeout", "0");

                                    final int sharedObjectsTimeout = cic.CICTools.parseInt(tmp);

                                    if (sharedObjectsTimeout>0)

                                              cic.CICObjectShare.TIMEOUT = sharedObjectsTimeout;

                          } catch (MalformedObjectNameException e) {

                                    e.printStackTrace();

                          } catch (NullPointerException e) {

                                    e.printStackTrace();

                          }

                }

                /**

                 * Get repository

                 * @return repository

                 * @throws IOException

                 */

                private static MBeanServerConnection getRepository() throws IOException

                {

                          if (repository==null)

                                    init();

                          return repository;

                }

                /**

                 * Get share server name

                 * @return share server name

                 * @throws IOException

                 */

                private static ObjectName getServerName() throws IOException

                {

                          if (serverName==null)

                                    init();

                          return serverName;

                }

       

       

                /**

                 * Add object into a repository shared by all web applications running on the WebApp server

                 * @param ref reference to the shared object

                 * @param sharedObject shared object

                 * @throws IOException

                 */

                public static void addObject(Object ref,Object sharedObject) throws IOException

                {

                          final ConnectorFactory factory = new ConnectorFactory(CartSettings.getInstance());

                          try

                          {

                                    final ConnectorJMXIdentification jmxIdentification = factory.createConnectorJMXIdentification();

                                    jmxIdentification.verifyJMXIdentification();

                          }

                          catch (ConnectorFactoryException e)

                          {

                                    e.printStackTrace();

                          }

                          final MBeanServerConnection repository=getRepository();

                          final javax.management.ObjectName serverName = getServerName();

                          final String[] signature1 = {java.lang.Object.class.getName(),java.lang.Object.class.getName()};

                          final java.lang.Object[] params1 = new java.lang.Object[2];

              params1[0] = ref;

              params1[1] = sharedObject;

              try {

                                    repository.invoke(serverName, "addObject", params1, signature1);

                          } catch (InstanceNotFoundException e) {

                                    e.printStackTrace();

                          } catch (MBeanException e) {

                                    e.printStackTrace();

                          } catch (ReflectionException e) {

                                    e.printStackTrace();

                          } catch (IOException e) {

                                    e.printStackTrace();

                          }

                }

                /**

                 * Get object from a repository shared by all web applications running on the WebApp server

                 * @param ref reference to the shared object

                 * @return shared object

                 * @throws IOException

                 */

                public static Object removeObject(Object ref) throws IOException

                {

                          final ConnectorFactory factory = new ConnectorFactory(CartSettings.getInstance());

                          try

                          {

                                    final ConnectorJMXIdentification jmxIdentification = factory.createConnectorJMXIdentification();

                                    jmxIdentification.verifyJMXIdentification();

                          }

                          catch (ConnectorFactoryException e)

                          {

                                    e.printStackTrace();

                          }

                          final MBeanServerConnection repository=getRepository();

                          final javax.management.ObjectName serverName = getServerName();

                          final String[] signature1 = {java.lang.Object.class.getName()};

                          final java.lang.Object[] params1 = new java.lang.Object[1];

              params1[0] = ref;

              try {

                                    return repository.invoke(serverName, "removeObject", params1, signature1);

                          } catch (InstanceNotFoundException e) {

                                    e.printStackTrace();

                          } catch (MBeanException e) {

                                    e.printStackTrace();

                          } catch (ReflectionException e) {

                                    e.printStackTrace();

                          } catch (IOException e) {

                                    e.printStackTrace();

                          }

                          return null;

                }

       

                /**

                 * removeAllObject

                 * @param key keyCommon for objects

                 * @throws IOException

                 */

                public static void removeAllObjectPrefixedBy(String key) throws IOException

                {

                          final ConnectorFactory factory = new ConnectorFactory(CartSettings.getInstance());

                          try

                          {

                                    final ConnectorJMXIdentification jmxIdentification = factory.createConnectorJMXIdentification();

                                    jmxIdentification.verifyJMXIdentification();

                          }

                          catch (ConnectorFactoryException e)

                          {

                                    e.printStackTrace();

                          }

                          final MBeanServerConnection repository=getRepository();

                          final javax.management.ObjectName serverName = getServerName();

                          final String[] signatureListKeys = {java.lang.String.class.getName()};

                          final String[] signature1 = {java.lang.Object.class.getName()};

                          final java.lang.String[] paramsListKeys = new java.lang.String[1];

                          final java.lang.Object[] params1 = new java.lang.Object[1];

                          try

                          {

                                    paramsListKeys[0] = key;

                                    final Vector<String> objectList = (Vector<String>) repository.invoke(serverName, "listKeys", paramsListKeys, signatureListKeys);

                                    for (String object : objectList)

                                    {

                                              params1[0] = object;

                                              repository.invoke(serverName, "removeObject", params1, signature1);

                                    }

                          }

                          catch (InstanceNotFoundException e)

                          {

                                    e.printStackTrace();

                          }

                          catch (MBeanException e)

                          {

                                    e.printStackTrace();

                          }

                          catch (ReflectionException e)

                          {

                                    e.printStackTrace();

                          }

                          catch (IOException e)

                          {

                                    e.printStackTrace();

                          }

                }

      }

        • 1. Re: Problem with JNDI/ JDK
          Wolf-Dieter Fink Master

          Could you  add the compiler error and point to the line where the failure is?

          • 2. Re: Problem with JNDI/ JDK
            sarahfr Newbie

            hi,

            I have a problem with JNDI


            code java:

             

            private static void init() throws IOException

                      {

                                try

                                {

                                          final ConnectorFactory factory = new ConnectorFactory(CartSettings.getInstance());

                                          try

                                          {

                                                    final ConnectorJMXIdentification jmxIdentification = factory.createConnectorJMXIdentification();

                                                    jmxIdentification.verifyJMXIdentification();

             

                                          } catch (ConnectorFactoryException e) {

                                                    e.printStackTrace();

                                          }

             

                                              JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://127.0.0.1:1090/jmxrmi"); 

                             

                                        HashMap environment = new HashMap(); 

                                        String[] credentials = new String[]{"cameleon", "leon"}; 

                                        environment.put(JMXConnector.CREDENTIALS, credentials); 

                                        JMXConnector jmxc = JMXConnectorFactory.connect(url, environment); 

                                           repository = jmxc.getMBeanServerConnection();

                                       

                                     serverName = new javax.management.ObjectName("cic:type=CICObjectShare");

             

                                          final String tmp = CartSettings.getInstance().getProperty("sharedObjectsTimeout", "0");

                                          final int sharedObjectsTimeout = cic.CICTools.parseInt(tmp);

                                          if (sharedObjectsTimeout>0)

                                                    cic.CICObjectShare.TIMEOUT = sharedObjectsTimeout;

             

                                } catch (MalformedObjectNameException e) {

                                          e.printStackTrace();

                                } catch (NullPointerException e) {

                                          e.printStackTrace();

                                }

                      }

             

            I shows the following error in jboss 7.1 (standalone mode)

             

            10:28:37,539 ERROR [stderr] (http--127.0.0.1-8180-1) java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.NameNotFoundException: rmi://127.0.0.1:1090/jmxrmi -- service jboss.naming.context.java.rmi:."127.0.0.1:1090".jmxrmi

            10:28:37,541 ERROR [stderr] (http--127.0.0.1-8180-1)    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:340)

            10:28:37,542 ERROR [stderr] (http--127.0.0.1-8180-1)    at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)

            10:28:37,543 ERROR [stderr] (http--127.0.0.1-8180-1)    at com.accesscommerce.cart.util.ShareUtil.init(ShareUtil.java:80)

            10:28:37,544 ERROR [stderr] (http--127.0.0.1-8180-1)    at com.accesscommerce.cart.util.ShareUtil.getRepository(ShareUtil.java:104)

            10:28:37,545 ERROR [stderr] (http--127.0.0.1-8180-1)    at com.accesscommerce.cart.util.ShareUtil.removeObject(ShareUtil.java:177)

            10:28:37,546 ERROR [stderr] (http--127.0.0.1-8180-1)    at com.accesscommerce.cart.util.ShareUtilManager$ShareUtilAS.removeObject(ShareUtilManager.java:133)

            10:28:37,547 ERROR [stderr] (http--127.0.0.1-8180-1)    at com.accesscommerce.cart.util.ShareUtilManager.removeObject(ShareUtilManager.java:69)

            10:28:37,548 ERROR [stderr] (http--127.0.0.1-8180-1)    at com.accesscommerce.cart.CartSessionListener.sessionCreated(CartSessionListener.java:38)

            10:28:37,549 ERROR [stderr] (http--127.0.0.1-8180-1)    at org.apache.catalina.session.StandardSession.tellNew(StandardSession.java:374)

            10:28:37,550 ERROR [stderr] (http--127.0.0.1-8180-1)    at org.apache.catalina.session.StandardSession.setId(StandardSession.java:344)

            10:28:37,551 ERROR [stderr] (http--127.0.0.1-8180-1)    at org.apache.catalina.session.ManagerBase.createSession(ManagerBase.java:506)

             

            thanks for your help