7 Replies Latest reply on Jul 15, 2004 9:47 AM by adrian.brock

    JBoss 3.2.5 Oracle Datasource Problem

    kyriakost

      Hi.

      I am trying to use JBoss 3.2.5 instead of 3.2.1 that I was using before. When I try to use Oracle datasource, I get the following error :

      12:37:34,760 INFO [STDOUT] java.lang.SecurityException: Failed to create Statement proxy: java.lang.ClassFormatError: oracle/jdbc/driver/$Proxy198 (Repetitive interface name)
      12:37:34,761 INFO [STDOUT] at org.jboss.resource.adapter.jdbc.WrappedStatement.(WrappedStatement.java:51)
      12:37:34,762 INFO [STDOUT] at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.(WrappedPreparedStatement.java:45)
      12:37:34,762 INFO [STDOUT] at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:208)

      I am using JDK 1.4.1_03 on Suse 9.
      The datasource descriptor is exactly as the one given in the JBoss examples (oracle-ds.xml).

      I have made BOLD the line where the error occurs :

       Context ctx = null;
       DataSource ds = null;
       java.sql.Connection dbConnection = null;
       PreparedStatement ps = null;
      
       try {
       try {
       ctx = new InitialContext();
       ds = (DataSource)ctx.lookup("java:/OracleDS");
      
       dbConnection = ds.getConnection();
       dbConnection.setAutoCommit(false);
       String query = "INSERT INTO ADAPTER_CONTRACTS (ADAPTER_ID) VALUES(?)";
      
       ps = dbConnection.prepareStatement(query);
      
       for(int i=1; i<10; i++) {
       ps.setInt(1, i);
       ps.addBatch();
       }
      
       ps.executeBatch();
      
       if ( fail ) {
       Hashtable h = new Hashtable();
       h.put("key", "value");
       Integer failInt = (Integer) h.get("key");
       }
      
       dbConnection.commit();
      
       }
       catch (Exception ex) {
       ex.printStackTrace();
       dbConnection.rollback();
       }
       ps.close();
       dbConnection.close();
       }
       catch (Exception ex) {
       ex.printStackTrace();
       }
      


      Any ideas ?

      Thanks

        • 1. Re: JBoss 3.2.5 Oracle Datasource Problem

          There is a patch on sourceforge that includes the missing class:
          http://prdownloads.sourceforge.net/jboss/jboss-common-jdbc-wrapper-bug988031.jar?download
          See the updated release notes for more info.

          • 2. Re: JBoss 3.2.5 Oracle Datasource Problem
            kyriakost

            I have already installed the patch. It solved the missing class error. What I have posted is another error...

            • 3. Re: JBoss 3.2.5 Oracle Datasource Problem

              You *replaced* the previous jar or do you now have two copies with different contents?

              • 4. Re: JBoss 3.2.5 Oracle Datasource Problem
                kyriakost

                I replaced it...

                • 5. Re: JBoss 3.2.5 Oracle Datasource Problem

                  Ok, I see the problem.
                  I modified the BuildProxyAction to use a HashSet rather than an ArrayList.
                  This will eliminate duplicate interfaces.

                  The other alternative is to not install a security manager, then the
                  PrivilegedProxy isn't even used.

                  /*
                   * JBoss, the OpenSource J2EE webOS
                   *
                   * Distributable under LGPL license.
                   * See terms of license at gnu.org.
                   *
                   */
                  package org.jboss.resource.adapter.jdbc;
                  
                  import java.lang.reflect.InvocationHandler;
                  import java.lang.reflect.InvocationTargetException;
                  import java.lang.reflect.Method;
                  import java.lang.reflect.Proxy;
                  import java.security.PrivilegedExceptionAction;
                  import java.security.AccessController;
                  import java.security.PrivilegedActionException;
                  import java.util.HashSet;
                  
                  /** A PrivilegedExceptionAction that proxies whatever interfaces the target
                   * object supports. When an invocation through an interface method is done,
                   * the is executed via reflection in a PrivilegedExceptionAction to run
                   * at the privilege level of this codebase.
                   *
                   * @author Scott.Stark@jboss.org
                   * @version $Revison:$
                   */
                  public class PrivilegedProxy
                   implements InvocationHandler, PrivilegedExceptionAction
                  {
                   private Object target;
                   private Method method;
                   private Object[] args;
                  
                   public Object run() throws Exception
                   {
                   Object value = null;
                   try
                   {
                   value = method.invoke(target, args);
                   }
                   catch(InvocationTargetException e)
                   {
                   throw (Exception) e.getTargetException();
                   }
                   return value;
                   }
                  
                   PrivilegedProxy(Object target)
                   {
                   this.target = target;
                   }
                  
                   Object getProxy() throws Exception
                   {
                   BuildProxyAction action = new BuildProxyAction(target, this);
                   Object proxy = null;
                   try
                   {
                   proxy = AccessController.doPrivileged(action);
                   }
                   catch(PrivilegedActionException e)
                   {
                   throw e.getException();
                   }
                   return proxy;
                   }
                  
                   public Object invoke(Object proxy, Method method, Object[] args)
                   throws Throwable
                   {
                   this.method = method;
                   this.args = args;
                   Object value = null;
                   try
                   {
                   value = AccessController.doPrivileged(this);
                   }
                   catch(PrivilegedActionException e)
                   {
                   throw e.getException();
                   }
                   return value;
                   }
                  
                   private static class BuildProxyAction implements PrivilegedExceptionAction
                   {
                   Object target;
                   InvocationHandler handler;
                   BuildProxyAction(Object target, InvocationHandler handler)
                   {
                   this.target = target;
                   this.handler = handler;
                   }
                   public Object run() throws Exception
                   {
                   HashSet tmp = new HashSet();
                   // Get all interfaces
                   Class c = target.getClass();
                   do
                   {
                   Class[] ifaces = c.getInterfaces();
                   for(int i = 0; i < ifaces.length; i ++)
                   tmp.add(ifaces);
                   c = c.getSuperclass();
                   } while( c != null );
                  
                   Class[] ifaces = new Class[tmp.size()];
                   tmp.toArray(ifaces);
                   ClassLoader loader = Thread.currentThread().getContextClassLoader();
                   return Proxy.newProxyInstance(loader, ifaces, handler);
                   }
                   }
                   }
                  


                  • 6. Re: JBoss 3.2.5 Oracle Datasource Problem
                    kyriakost

                    Hi again.

                    I just tried the version you posted, keeping the security manager.

                    It now gives the error :


                    16:15:18,764 INFO [STDOUT] java.lang.SecurityException: Failed to create Statement proxy: null
                    16:15:18,766 INFO [STDOUT] at org.jboss.resource.adapter.jdbc.WrappedStatement.(WrappedStatement.java:51)
                    16:15:18,766 INFO [STDOUT] at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.(WrappedPreparedStatement.java:45)
                    16:15:18,766 INFO [STDOUT] at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:208)
                    16:15:18,767 INFO [STDOUT] at com.intracom.sw.adapters.messagehandle.utils.MessageHandler.testDatasourceRollback(MessageHandler.java:62)


                    Thank you very much for your time so far !!


                    • 7. Re: JBoss 3.2.5 Oracle Datasource Problem

                      Now your security policy is incorrect.

                      I'd suggest you don't use a security manager.
                      An incorrectly configured security manager is far worse than no
                      security manager at all.

                      e.g. It allows clients to upload and run code on the server which will
                      let them to do horrible things unless your policy stops them.
                      No security manager means they cannot upload code at all.