[jboss-cvs] JBossAS SVN: r89614 - in projects/ejb-book/trunk/ch06-filetransfer/src: test/java/org/jboss/ejb3/examples/ch06/filetransfer and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jun 1 13:29:44 EDT 2009
Author: ALRubinger
Date: 2009-06-01 13:29:43 -0400 (Mon, 01 Jun 2009)
New Revision: 89614
Modified:
projects/ejb-book/trunk/ch06-filetransfer/src/main/java/org/jboss/ejb3/examples/ch06/filetransfer/FileTransferBean.java
projects/ejb-book/trunk/ch06-filetransfer/src/main/java/org/jboss/ejb3/examples/ch06/filetransfer/FileTransferException.java
projects/ejb-book/trunk/ch06-filetransfer/src/test/java/org/jboss/ejb3/examples/ch06/filetransfer/FileTransferUnitTestCase.java
Log:
[EJBBOOK-8] Do not depend upon "transient" keyword for SFSB, instead null out in @PrePassivate
Modified: projects/ejb-book/trunk/ch06-filetransfer/src/main/java/org/jboss/ejb3/examples/ch06/filetransfer/FileTransferBean.java
===================================================================
--- projects/ejb-book/trunk/ch06-filetransfer/src/main/java/org/jboss/ejb3/examples/ch06/filetransfer/FileTransferBean.java 2009-06-01 17:10:27 UTC (rev 89613)
+++ projects/ejb-book/trunk/ch06-filetransfer/src/main/java/org/jboss/ejb3/examples/ch06/filetransfer/FileTransferBean.java 2009-06-01 17:29:43 UTC (rev 89614)
@@ -22,6 +22,7 @@
package org.jboss.ejb3.examples.ch06.filetransfer;
import java.io.IOException;
+import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
@@ -48,7 +49,7 @@
*/
@Stateful(name = FileTransferBean.EJB_NAME)
@Remote(FileTransferRemoteBusiness.class)
-public class FileTransferBean implements FileTransferRemoteBusiness
+public class FileTransferBean implements FileTransferRemoteBusiness, Serializable
{
//-------------------------------------------------------------------------------------||
@@ -56,6 +57,11 @@
//-------------------------------------------------------------------------------------||
/**
+ * Serial Version UID
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
* Logger
*/
private static final Logger log = Logger.getLogger(FileTransferBean.class);
@@ -80,13 +86,12 @@
//-------------------------------------------------------------------------------------||
/**
- * The underlying FTP Client. We mark this
- * as transient because we don't want its state
+ * The underlying FTP Client. We don't want its state
* getting Serialized during passivation. We'll
* reinitialize this client and its connections
* upon activation.
*/
- private transient FTPClient client;
+ private FTPClient client;
/**
* The name of the host to which we'll connect.
@@ -157,6 +162,9 @@
{
log.warn("Exception encountered in disconnecting the FTP client", ioe);
}
+
+ // Null out the client so it's not serialized
+ this.client = null;
}
}
}
Modified: projects/ejb-book/trunk/ch06-filetransfer/src/main/java/org/jboss/ejb3/examples/ch06/filetransfer/FileTransferException.java
===================================================================
--- projects/ejb-book/trunk/ch06-filetransfer/src/main/java/org/jboss/ejb3/examples/ch06/filetransfer/FileTransferException.java 2009-06-01 17:10:27 UTC (rev 89613)
+++ projects/ejb-book/trunk/ch06-filetransfer/src/main/java/org/jboss/ejb3/examples/ch06/filetransfer/FileTransferException.java 2009-06-01 17:29:43 UTC (rev 89614)
@@ -21,19 +21,15 @@
*/
package org.jboss.ejb3.examples.ch06.filetransfer;
-import javax.ejb.ApplicationException;
-
/**
* FileTransferException
*
* Exception to indicate that a problem has occurred during
- * a file transfer operation. Will rollback the current transaction
- * if encountered.
+ * a file transfer operation.
*
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
- at ApplicationException(rollback = true)
public class FileTransferException extends RuntimeException
{
Modified: projects/ejb-book/trunk/ch06-filetransfer/src/test/java/org/jboss/ejb3/examples/ch06/filetransfer/FileTransferUnitTestCase.java
===================================================================
--- projects/ejb-book/trunk/ch06-filetransfer/src/test/java/org/jboss/ejb3/examples/ch06/filetransfer/FileTransferUnitTestCase.java 2009-06-01 17:10:27 UTC (rev 89613)
+++ projects/ejb-book/trunk/ch06-filetransfer/src/test/java/org/jboss/ejb3/examples/ch06/filetransfer/FileTransferUnitTestCase.java 2009-06-01 17:29:43 UTC (rev 89614)
@@ -21,6 +21,14 @@
*/
package org.jboss.ejb3.examples.ch06.filetransfer;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutput;
+import java.io.ObjectOutputStream;
+
import javax.ejb.PostActivate;
import javax.ejb.PrePassivate;
@@ -214,16 +222,32 @@
final String pwdBefore = client.pwd();
TestCase.assertEquals("Present working directory should be set to home", home, pwdBefore);
- // Mock passivation
- log.info("Mock passivation");
+ // Mock @PrePassivate
+ log.info("Mock @" + PrePassivate.class.getName());
client.disconnect();
+ // Mock passivation
+ log.info("Mock passivation");
+ final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+ final ObjectOutput objectOut = new ObjectOutputStream(outStream);
+ objectOut.writeObject(client);
+ objectOut.close();
+
// Mock activation
log.info("Mock activation");
- client.connect();
+ final InputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
+ final ObjectInput objectIn = new ObjectInputStream(inStream);
+ // Get a new client from passivation/activation roundtrip
+ final FileTransferCommonBusiness serializedClient = (FileTransferCommonBusiness) objectIn.readObject();
+ objectIn.close();
+
+ // Mock @PostActivate
+ log.info("Mock @" + PostActivate.class.getName());
+ serializedClient.connect();
+
// Test the pwd
- final String pwdAfter = client.pwd();
+ final String pwdAfter = serializedClient.pwd();
TestCase.assertEquals("Present working directory should be the same as before passivation/activation", home,
pwdAfter);
}
More information about the jboss-cvs-commits
mailing list