[jboss-cvs] JBossAS SVN: r110843 - in projects/jboss-jca/trunk/core: src/test/java/org/jboss/jca/core/security/reauth and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 7 14:23:08 EST 2011


Author: jesper.pedersen
Date: 2011-03-07 14:23:08 -0500 (Mon, 07 Mar 2011)
New Revision: 110843

Added:
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/CRITestCase.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthSocket.java
Modified:
   projects/jboss-jca/trunk/core/build.xml
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthConnectionImpl.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthManagedConnection.java
   projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthManagedConnectionMetaData.java
Log:
[JBJCA-94] Basic positive CRI test case

Modified: projects/jboss-jca/trunk/core/build.xml
===================================================================
--- projects/jboss-jca/trunk/core/build.xml	2011-03-07 12:46:44 UTC (rev 110842)
+++ projects/jboss-jca/trunk/core/build.xml	2011-03-07 19:23:08 UTC (rev 110843)
@@ -274,6 +274,38 @@
       </fileset>
     </copy>
 
+    <!-- Reauth CRI resource adapter -->
+    <jar destfile="${build.core.dir}/test/reauth-cri.jar"
+         basedir="${build.core.dir}/test"
+         index="true"
+         indexMetaInf="true"
+         update="true"
+         level="9"
+         includes="**/reauth/ra/cri/**">
+      <manifest>
+        <attribute name="Implementation-Title" value="IronJacamar Test - Reauth CRI"/>
+        <attribute name="Implementation-Version" value="${major}.${minor}.${patch}.${type}"/>
+        <attribute name="Implementation-Vendor" value="The IronJacamar project (http://www.jboss.org/ironjacamar)"/>
+        <attribute name="Implementation-Vendor-Id" value="org.jboss"/>
+      </manifest>
+    </jar>
+    <jar destfile="${build.core.dir}/test/reauth-cri.rar"
+         index="true"
+         indexMetaInf="true"
+         update="true"
+         level="9">
+      <manifest>
+        <attribute name="Implementation-Title" value="IronJacamar Test - Reauth CRI RAR"/>
+        <attribute name="Implementation-Version" value="${major}.${minor}.${patch}.${type}"/>
+        <attribute name="Implementation-Vendor" value="The IronJacamar project (http://www.jboss.org/ironjacamar)"/>
+        <attribute name="Implementation-Vendor-Id" value="org.jboss"/>
+      </manifest>
+      <fileset dir="${build.core.dir}/test">
+        <include name="reauth-cri.jar"/>
+      </fileset>
+      <fileset dir="${build.core.dir}/test/rars/security/reauth/cri"/>
+    </jar>
+
   </target>
 
   <!-- ================================= 

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/CRITestCase.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/CRITestCase.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/CRITestCase.java	2011-03-07 19:23:08 UTC (rev 110843)
@@ -0,0 +1,153 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.core.security.reauth;
+
+import org.jboss.jca.core.security.reauth.eis.ReauthServer;
+import org.jboss.jca.core.security.reauth.ra.cri.ReauthConnection;
+import org.jboss.jca.core.security.reauth.ra.cri.ReauthConnectionFactory;
+import org.jboss.jca.embedded.Embedded;
+import org.jboss.jca.embedded.EmbeddedFactory;
+
+import java.net.URL;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.logging.Logger;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * Tests for CRO based reauthentication.
+ * 
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ * @version $Revision: $
+ */
+public class CRITestCase
+{
+
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private static Logger log = Logger.getLogger(CRITestCase.class);
+
+   private static Embedded embedded;
+
+   // EIS server
+   private static String host = "localhost";
+   private static int port = 19000;
+   private static ReauthServer reauthServer = null;
+
+
+   // --------------------------------------------------------------------------------||
+   // Tests --------------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Basic
+    * @throws Throwable throwable exception 
+    */
+   @Test
+   public void testBasic() throws Throwable
+   {
+      Context context = null;
+      URL deployment = null;
+      try
+      {
+         reauthServer = new ReauthServer();
+         reauthServer.setHostName(host);
+         reauthServer.setPort(port);
+         reauthServer.setMaxConnections(1);
+         reauthServer.start();
+
+         deployment = CRITestCase.class.getClassLoader().getResource("reauth-cri.rar");
+
+         embedded.deploy(deployment);
+
+         context = new InitialContext();
+
+         String user = "user";
+         String password = "password";
+
+         ReauthConnectionFactory rcf = (ReauthConnectionFactory)context.lookup("java:/eis/Reauth");
+
+         assertNotNull(rcf);
+
+         ReauthConnection rc = rcf.getConnection(user, password);
+
+         assertNotNull(rc);
+
+         assertEquals(user, rc.getAuth());
+
+         assertTrue(rc.logout());
+      }
+      finally
+      {
+         if (deployment != null)
+         {
+            embedded.undeploy(deployment);
+         }
+
+         if (reauthServer != null)
+         {
+            reauthServer.stop();
+            reauthServer = null;
+         }
+
+         if (context != null)
+         {
+            context.close();
+         }
+      }
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Lifecycle Methods --------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Lifecycle start, before each test is executed
+    * @throws Throwable throwable exception 
+    */
+   @Before
+   public void before() throws Throwable
+   {
+      embedded = EmbeddedFactory.create(true);
+      embedded.startup();
+   }
+
+   /**
+    * Lifecycle stop, after each test is executed
+    * @throws Throwable throwable exception 
+    */
+   @After
+   public void after() throws Throwable
+   {
+      embedded.shutdown();
+      embedded = null;
+   }
+}

Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthConnectionImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthConnectionImpl.java	2011-03-07 12:46:44 UTC (rev 110842)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthConnectionImpl.java	2011-03-07 19:23:08 UTC (rev 110843)
@@ -21,13 +21,6 @@
  */
 package org.jboss.jca.core.security.reauth.ra.cri;
 
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.net.Socket;
-
 import javax.resource.ResourceException;
 
 import org.jboss.logging.Logger;
@@ -42,15 +35,9 @@
    /** The logger */
    private static Logger log = Logger.getLogger(ReauthConnectionImpl.class);
 
-   /** The socket */
-   private Socket socket;
+   /** The reauth socket */
+   private ReauthSocket socket;
 
-   /** Input */
-   private ObjectInputStream ois;
-
-   /** Output */
-   private ObjectOutputStream oos;
-
    /** The CRI */
    private ReauthCri cri;
 
@@ -60,7 +47,7 @@
     * @param cri ConnectionRequestInfo instance
     * @exception ResourceException Thrown if an error occurs
     */
-   public ReauthConnectionImpl(Socket socket, ReauthCri cri) throws ResourceException
+   public ReauthConnectionImpl(ReauthSocket socket, ReauthCri cri) throws ResourceException
    {
       log.tracef("constructor(%s, %s)", socket, cri);
 
@@ -79,19 +66,7 @@
    {
       log.tracef("login(%s, %s)", username, password);
 
-      try
-      {
-         getOutput().writeByte(3);
-         getOutput().writeUTF(username);
-         getOutput().writeUTF(password);
-         getOutput().flush();
-
-         return (String)getInput().readObject();
-      }
-      catch (Throwable t)
-      {
-         throw new ResourceException("Error during login", t);
-      }
+      return socket.login(username, password);
    }
 
    /**
@@ -103,19 +78,7 @@
    {
       log.tracef("logout()");
 
-      try
-      {
-         getOutput().writeByte(4);
-         getOutput().flush();
-
-         Boolean result = (Boolean)getInput().readObject();
-
-         return result.booleanValue();
-      }
-      catch (Throwable t)
-      {
-         throw new ResourceException("Error during logout", t);
-      }
+      return socket.logout();
    }
 
    /**
@@ -127,17 +90,7 @@
    {
       log.tracef("getAuth()");
 
-      try
-      {
-         getOutput().writeByte(5);
-         getOutput().flush();
-
-         return (String)getInput().readObject();
-      }
-      catch (Throwable t)
-      {
-         throw new ResourceException("Error during getAuth", t);
-      }
+      return socket.getAuth();
    }
 
    /**
@@ -148,30 +101,4 @@
    {
       return cri;
    }
-
-   /**
-    * Get input stream
-    * @return The value
-    * @exception IOException Thrown in case of an error
-    */
-   private ObjectInputStream getInput() throws IOException
-   {
-      if (ois == null)
-         ois = new ObjectInputStream(new BufferedInputStream(socket.getInputStream(), 8192));
-      
-      return ois;
-   }
-
-   /**
-    * Get output stream
-    * @return The value
-    * @exception IOException Thrown in case of an error
-    */
-   private ObjectOutputStream getOutput() throws IOException
-   {
-      if (oos == null)
-         oos = new ObjectOutputStream(new BufferedOutputStream(socket.getOutputStream(), 8192));
-      
-      return oos;
-   }
 }

Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthManagedConnection.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthManagedConnection.java	2011-03-07 12:46:44 UTC (rev 110842)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthManagedConnection.java	2011-03-07 19:23:08 UTC (rev 110843)
@@ -21,13 +21,7 @@
  */
 package org.jboss.jca.core.security.reauth.ra.cri;
 
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
 import java.io.PrintWriter;
-import java.net.Socket;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -66,14 +60,8 @@
    private ReauthConnectionImpl connection;
 
    /** The socket */
-   private Socket socket;
+   private ReauthSocket socket;
 
-   /** Input */
-   private ObjectInputStream ois;
-
-   /** Output */
-   private ObjectOutputStream oos;
-
    /**
     * Constructor
     * @param mcf The managed connection factory
@@ -81,32 +69,13 @@
     */
    public ReauthManagedConnection(ReauthManagedConnectionFactory mcf) throws ResourceException
    {
-      try
-      {
-         this.mcf = mcf;
-         this.listeners = new HashSet<ConnectionEventListener>(1);
-         this.logwriter = null;
+      this.mcf = mcf;
+      this.listeners = new HashSet<ConnectionEventListener>(1);
+      this.logwriter = null;
 
-         ReauthResourceAdapter rra = (ReauthResourceAdapter)mcf.getResourceAdapter();
+      ReauthResourceAdapter rra = (ReauthResourceAdapter)mcf.getResourceAdapter();
 
-         // Note, that this socket instance *should really* be guarded against concurrent access
-         this.socket = new Socket(rra.getServer(), rra.getPort());
-         this.ois = null;
-         this.oos = null;
-
-         // Connect
-         getOutput().writeByte(0);
-         getOutput().flush();
-
-         Boolean granted = (Boolean)getInput().readObject();
-         
-         if (!granted.booleanValue())
-            throw new ResourceException("Connection not granted");
-      }
-      catch (Throwable t)
-      {
-         throw new ResourceException("Unable to establish a connection", t);
-      }
+      this.socket = new ReauthSocket(rra.getServer(), rra.getPort());
    }
 
    /**
@@ -179,18 +148,7 @@
 
       // TODO - connection listeners
 
-      try
-      {
-         // Unauth the interaction
-         getOutput().writeByte(4);
-         getOutput().flush();
-
-         socket.close();
-      }
-      catch (Throwable t)
-      {
-         throw new ResourceException("Error during cleanup", t);
-      }
+      socket.cleanup();
    }
 
    /**
@@ -202,18 +160,8 @@
    {
       log.tracef("destroy");
 
-      try
-      {
-         // Close the interaction
-         getOutput().writeByte(1);
-         getOutput().flush();
-
-         socket.close();
-      }
-      catch (Throwable t)
-      {
-         throw new ResourceException("Error during destroy", t);
-      }
+      socket.destroy();
+      socket = null;
    }
 
    /**
@@ -300,30 +248,4 @@
 
       return new ReauthManagedConnectionMetaData(socket);
    }
-
-   /**
-    * Get input stream
-    * @return The value
-    * @exception IOException Thrown in case of an error
-    */
-   private ObjectInputStream getInput() throws IOException
-   {
-      if (ois == null)
-         ois = new ObjectInputStream(new BufferedInputStream(socket.getInputStream(), 8192));
-      
-      return ois;
-   }
-
-   /**
-    * Get output stream
-    * @return The value
-    * @exception IOException Thrown in case of an error
-    */
-   private ObjectOutputStream getOutput() throws IOException
-   {
-      if (oos == null)
-         oos = new ObjectOutputStream(new BufferedOutputStream(socket.getOutputStream(), 8192));
-      
-      return oos;
-   }
 }

Modified: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthManagedConnectionMetaData.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthManagedConnectionMetaData.java	2011-03-07 12:46:44 UTC (rev 110842)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthManagedConnectionMetaData.java	2011-03-07 19:23:08 UTC (rev 110843)
@@ -21,13 +21,6 @@
  */
 package org.jboss.jca.core.security.reauth.ra.cri;
 
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.net.Socket;
-
 import javax.resource.ResourceException;
 import javax.resource.spi.ManagedConnectionMetaData;
 
@@ -44,23 +37,15 @@
    private static Logger log = Logger.getLogger(ReauthManagedConnectionMetaData.class);
 
    /** The socket */
-   private Socket socket;
+   private ReauthSocket socket;
 
-   /** Input */
-   private ObjectInputStream ois;
-
-   /** Output */
-   private ObjectOutputStream oos;
-
    /**
     * Constructor
     * @param socket The socket
     */
-   public ReauthManagedConnectionMetaData(Socket socket)
+   public ReauthManagedConnectionMetaData(ReauthSocket socket)
    {
       this.socket = socket;
-      this.ois = null;
-      this.oos = null;
    }
 
    /**
@@ -101,20 +86,8 @@
    public int getMaxConnections() throws ResourceException
    {
       log.tracef("getMaxConnections()");
-
-      try
-      {
-         getOutput().writeByte(6);
-         getOutput().flush();
-
-         Integer result = (Integer)getInput().readObject();
-
-         return result.intValue();
-      }
-      catch (Throwable t)
-      {
-         throw new ResourceException("Error during getUserName()", t);
-      }
+      
+      return socket.getMaxConnections();
    }
 
    /**
@@ -128,42 +101,6 @@
    {
       log.tracef("getUserName()");
 
-      try
-      {
-         getOutput().writeByte(5);
-         getOutput().flush();
-
-         return (String)getInput().readObject();
-      }
-      catch (Throwable t)
-      {
-         throw new ResourceException("Error during getUserName()", t);
-      }
+      return socket.getAuth();
    }
-
-   /**
-    * Get input stream
-    * @return The value
-    * @exception IOException Thrown in case of an error
-    */
-   private ObjectInputStream getInput() throws IOException
-   {
-      if (ois == null)
-         ois = new ObjectInputStream(new BufferedInputStream(socket.getInputStream(), 8192));
-      
-      return ois;
-   }
-
-   /**
-    * Get output stream
-    * @return The value
-    * @exception IOException Thrown in case of an error
-    */
-   private ObjectOutputStream getOutput() throws IOException
-   {
-      if (oos == null)
-         oos = new ObjectOutputStream(new BufferedOutputStream(socket.getOutputStream(), 8192));
-      
-      return oos;
-   }
 }

Added: projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthSocket.java
===================================================================
--- projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthSocket.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/test/java/org/jboss/jca/core/security/reauth/ra/cri/ReauthSocket.java	2011-03-07 19:23:08 UTC (rev 110843)
@@ -0,0 +1,251 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.core.security.reauth.ra.cri;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.net.Socket;
+
+import javax.resource.ResourceException;
+
+import org.jboss.logging.Logger;
+
+/**
+ * ReauthSocket
+ *
+ * @version $Revision: $
+ */
+public class ReauthSocket
+{
+   /** The logger */
+   private static Logger log = Logger.getLogger(ReauthSocket.class);
+
+   /** The socket */
+   private Socket socket;
+
+   /** Input */
+   private ObjectInputStream ois;
+
+   /** Output */
+   private ObjectOutputStream oos;
+
+   /**
+    * Constructor
+    * @param server The server name
+    * @param port The port
+    * @exception ResourceException Thrown if an error occurs
+    */
+   public ReauthSocket(String server, int port) throws ResourceException
+   {
+      try
+      {
+         this.socket = new Socket(server, port);
+         this.ois = null;
+         this.oos = null;
+
+         // Connect
+         getOutput().writeByte(0);
+         getOutput().flush();
+
+         Boolean granted = (Boolean)getInput().readObject();
+         
+         if (!granted.booleanValue())
+            throw new ResourceException("Connection not granted");
+      }
+      catch (Throwable t)
+      {
+         throw new ResourceException("Unable to establish a connection", t);
+      }
+   }
+
+   /**
+    * Call login
+    * @param username String
+    * @param password String
+    * @return String
+    * @exception ResourceException Thrown if an error occurs
+    */
+   public synchronized String login(String username, String password) throws ResourceException
+   {
+      log.tracef("login(%s, %s)", username, password);
+
+      try
+      {
+         getOutput().writeByte(3);
+         getOutput().writeUTF(username);
+         getOutput().writeUTF(password);
+         getOutput().flush();
+
+         return (String)getInput().readObject();
+      }
+      catch (Throwable t)
+      {
+         throw new ResourceException("Error during login", t);
+      }
+   }
+
+   /**
+    * Call logout
+    * @return boolean
+    * @exception ResourceException Thrown if an error occurs
+    */
+   public synchronized boolean logout() throws ResourceException
+   {
+      log.tracef("logout()");
+
+      try
+      {
+         getOutput().writeByte(4);
+         getOutput().flush();
+
+         Boolean result = (Boolean)getInput().readObject();
+
+         return result.booleanValue();
+      }
+      catch (Throwable t)
+      {
+         throw new ResourceException("Error during logout", t);
+      }
+   }
+
+   /**
+    * get auth
+    * @return String
+    * @throws ResourceException Thrown if an error occurs
+    */
+   public synchronized String getAuth() throws ResourceException
+   {
+      log.tracef("getAuth()");
+
+      try
+      {
+         getOutput().writeByte(5);
+         getOutput().flush();
+
+         return (String)getInput().readObject();
+      }
+      catch (Throwable t)
+      {
+         throw new ResourceException("Error during getAuth", t);
+      }
+   }
+
+   /**
+    * Returns maximum limit on number of active concurrent connections 
+    *
+    * @return Maximum limit for number of active concurrent connections
+    * @throws ResourceException Thrown if an error occurs
+    */
+   public synchronized int getMaxConnections() throws ResourceException
+   {
+      log.tracef("getMaxConnections()");
+
+      try
+      {
+         getOutput().writeByte(6);
+         getOutput().flush();
+
+         Integer result = (Integer)getInput().readObject();
+
+         return result.intValue();
+      }
+      catch (Throwable t)
+      {
+         throw new ResourceException("Error during getUserName()", t);
+      }
+   }
+
+   /**
+    * Application server calls this method to force any cleanup on the ManagedConnection instance.
+    *
+    * @throws ResourceException generic exception if operation fails
+    */
+   public synchronized void cleanup() throws ResourceException
+   {
+      log.tracef("cleanup");
+
+      try
+      {
+         // Unauth the interaction
+         getOutput().writeByte(4);
+         getOutput().flush();
+
+         socket.close();
+      }
+      catch (Throwable t)
+      {
+         throw new ResourceException("Error during cleanup", t);
+      }
+   }
+
+   /**
+    * Destroys the physical connection to the underlying resource manager.
+    *
+    * @throws ResourceException generic exception if operation fails
+    */
+   public synchronized void destroy() throws ResourceException
+   {
+      log.tracef("destroy");
+
+      try
+      {
+         // Close the interaction
+         getOutput().writeByte(1);
+         getOutput().flush();
+
+         socket.close();
+      }
+      catch (Throwable t)
+      {
+         throw new ResourceException("Error during destroy", t);
+      }
+   }
+
+   /**
+    * Get input stream
+    * @return The value
+    * @exception IOException Thrown in case of an error
+    */
+   private ObjectInputStream getInput() throws IOException
+   {
+      if (ois == null)
+         ois = new ObjectInputStream(new BufferedInputStream(socket.getInputStream(), 8192));
+      
+      return ois;
+   }
+
+   /**
+    * Get output stream
+    * @return The value
+    * @exception IOException Thrown in case of an error
+    */
+   private ObjectOutputStream getOutput() throws IOException
+   {
+      if (oos == null)
+         oos = new ObjectOutputStream(new BufferedOutputStream(socket.getOutputStream(), 8192));
+      
+      return oos;
+   }
+}



More information about the jboss-cvs-commits mailing list