[jboss-cvs] JBossAS SVN: r87926 - in projects/ejb-book/trunk/ch05-encryption/src/main: resources/META-INF and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Apr 28 03:08:45 EDT 2009


Author: ALRubinger
Date: 2009-04-28 03:08:45 -0400 (Tue, 28 Apr 2009)
New Revision: 87926

Added:
   projects/ejb-book/trunk/ch05-encryption/src/main/java/org/jboss/ejb3/examples/ch05/encryption/EncryptionException.java
Modified:
   projects/ejb-book/trunk/ch05-encryption/src/main/java/org/jboss/ejb3/examples/ch05/encryption/EncryptionBean.java
   projects/ejb-book/trunk/ch05-encryption/src/main/java/org/jboss/ejb3/examples/ch05/encryption/EncryptionCommonBusiness.java
   projects/ejb-book/trunk/ch05-encryption/src/main/resources/META-INF/ejb-jar.xml
Log:
[EJBBOOK-4] Added an ApplicationException to the example

Modified: projects/ejb-book/trunk/ch05-encryption/src/main/java/org/jboss/ejb3/examples/ch05/encryption/EncryptionBean.java
===================================================================
--- projects/ejb-book/trunk/ch05-encryption/src/main/java/org/jboss/ejb3/examples/ch05/encryption/EncryptionBean.java	2009-04-28 07:05:16 UTC (rev 87925)
+++ projects/ejb-book/trunk/ch05-encryption/src/main/java/org/jboss/ejb3/examples/ch05/encryption/EncryptionBean.java	2009-04-28 07:08:45 UTC (rev 87926)
@@ -123,7 +123,7 @@
 
    /**
     * SessionContext of this EJB; this will be injected by the EJB 
-    * Container as it's marked w/ @Resource
+    * Container because it's marked w/ @Resource
     */
    @Resource
    private SessionContext context;
@@ -169,7 +169,6 @@
     * Initializes this service before it may handle requests
     * 
     * @throws Exception If some unexpected error occurred
-    * @throws IllegalStateException If one of the required ciphers was not available
     */
    @PostConstruct
    public void initialize() throws Exception
@@ -230,7 +229,7 @@
     * @see org.jboss.ejb3.examples.ch05.encryption.EncryptionCommonBusiness#compare(java.lang.String, java.lang.String)
     */
    @Override
-   public boolean compare(final String hash, final String input) throws IllegalArgumentException
+   public boolean compare(final String hash, final String input) throws IllegalArgumentException, EncryptionException
    {
       // Precondition checks
       if (hash == null)
@@ -256,7 +255,8 @@
     * @see org.jboss.ejb3.examples.ch05.encryption.EncryptionCommonBusiness#decrypt(java.lang.String)
     */
    @Override
-   public String decrypt(final String input) throws IllegalArgumentException, IllegalStateException
+   public String decrypt(final String input) throws IllegalArgumentException, IllegalStateException,
+         EncryptionException
    {
       // Get the cipher
       final Cipher cipher = this.decryptionCipher;
@@ -274,7 +274,7 @@
       }
       catch (final Throwable t)
       {
-         throw new RuntimeException("Error in decryption", t);
+         throw new EncryptionException("Error in decryption", t);
       }
       final String result = this.byteArrayToString(resultBytes);
 
@@ -289,7 +289,7 @@
     * @see org.jboss.ejb3.examples.ch05.encryption.EncryptionCommonBusiness#encrypt(java.lang.String)
     */
    @Override
-   public String encrypt(final String input) throws IllegalArgumentException
+   public String encrypt(final String input) throws IllegalArgumentException, EncryptionException
    {
       // Get the cipher
       final Cipher cipher = this.encryptionCipher;
@@ -309,7 +309,7 @@
       }
       catch (final Throwable t)
       {
-         throw new RuntimeException("Error in encryption of: " + input, t);
+         throw new EncryptionException("Error in encryption of: " + input, t);
       }
 
       // Log
@@ -333,7 +333,7 @@
     * @see org.jboss.ejb3.examples.ch05.encryption.EncryptionCommonBusiness#hash(java.lang.String)
     */
    @Override
-   public String hash(final String input) throws IllegalArgumentException
+   public String hash(final String input) throws IllegalArgumentException, EncryptionException
    {
       // Precondition check
       if (input == null)
@@ -468,7 +468,7 @@
       Object lookupValue = null;
       try
       {
-         lookupValue = this.context.lookup(envEntryName);
+         lookupValue = context.lookup(envEntryName);
          log.debug("Obtained environment entry \"" + envEntryName + "\": " + lookupValue);
       }
       catch (final IllegalArgumentException iae)

Modified: projects/ejb-book/trunk/ch05-encryption/src/main/java/org/jboss/ejb3/examples/ch05/encryption/EncryptionCommonBusiness.java
===================================================================
--- projects/ejb-book/trunk/ch05-encryption/src/main/java/org/jboss/ejb3/examples/ch05/encryption/EncryptionCommonBusiness.java	2009-04-28 07:05:16 UTC (rev 87925)
+++ projects/ejb-book/trunk/ch05-encryption/src/main/java/org/jboss/ejb3/examples/ch05/encryption/EncryptionCommonBusiness.java	2009-04-28 07:08:45 UTC (rev 87926)
@@ -42,8 +42,9 @@
     * @param input
     * @return
     * @throws IllegalArgumentException If no input was provided (null)
+    * @throws EncryptionException If some problem occurred with encryption
     */
-   String encrypt(String input) throws IllegalArgumentException;
+   String encrypt(String input) throws IllegalArgumentException, EncryptionException;
 
    /**
     * Decrypts the specified String, returning the result.  The general
@@ -54,8 +55,9 @@
     * @param input
     * @return
     * @throws IllegalArgumentException If no input was provided (null)
+    * @throws EncryptionException If some problem occurred with decryption
     */
-   String decrypt(String input) throws IllegalArgumentException;
+   String decrypt(String input) throws IllegalArgumentException, EncryptionException;
 
    /**
     * Returns a one-way hash of the specified argument.  Useful
@@ -64,8 +66,9 @@
     * @param input
     * @return
     * @throws IllegalArgumentException If no input was provided (null)
+    * @throws EncryptionException If some problem occurred making the hash
     */
-   String hash(String input) throws IllegalArgumentException;
+   String hash(String input) throws IllegalArgumentException, EncryptionException;
 
    /**
     * Returns whether or not the specified input matches the specified 
@@ -76,9 +79,10 @@
     * @param input
     * @return
     * @throws IllegalArgumentException If either the hash or input is not provided (null)
+    * @throws EncryptionException If some problem occurred making the hash
     */
-   boolean compare(String hash, String input) throws IllegalArgumentException;
-   
+   boolean compare(String hash, String input) throws IllegalArgumentException, EncryptionException;
+
    /*
     * This comment applies to all below this marker.
     * 

Added: projects/ejb-book/trunk/ch05-encryption/src/main/java/org/jboss/ejb3/examples/ch05/encryption/EncryptionException.java
===================================================================
--- projects/ejb-book/trunk/ch05-encryption/src/main/java/org/jboss/ejb3/examples/ch05/encryption/EncryptionException.java	                        (rev 0)
+++ projects/ejb-book/trunk/ch05-encryption/src/main/java/org/jboss/ejb3/examples/ch05/encryption/EncryptionException.java	2009-04-28 07:08:45 UTC (rev 87926)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.ejb3.examples.ch05.encryption;
+
+import javax.ejb.ApplicationException;
+
+/**
+ * EncryptionException
+ * 
+ * A checked Application Exception denoting
+ * some unexpected problem with Encryption operations
+ *
+ * @author <a href="mailto:alr at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at ApplicationException
+// Explicit annotation, though this is inferred as default because we extend Exception
+public class EncryptionException extends Exception
+{
+
+   // ---------------------------------------------------------------------------||
+   // Class Members -------------------------------------------------------------||
+   // ---------------------------------------------------------------------------||
+
+   /**
+    * To satisfy explicit serialization hints to the JVM
+    */
+   private static final long serialVersionUID = 1L;
+
+   // ---------------------------------------------------------------------------||
+   // Constructors --------------------------------------------------------------||
+   // ---------------------------------------------------------------------------||
+
+   /*
+    * All constructors will delegate to the superclass implementation
+    */
+
+   public EncryptionException()
+   {
+      super();
+   }
+
+   public EncryptionException(String message, Throwable cause)
+   {
+      super(message, cause);
+   }
+
+   public EncryptionException(String message)
+   {
+      super(message);
+   }
+
+   public EncryptionException(Throwable cause)
+   {
+      super(cause);
+   }
+
+}

Modified: projects/ejb-book/trunk/ch05-encryption/src/main/resources/META-INF/ejb-jar.xml
===================================================================
--- projects/ejb-book/trunk/ch05-encryption/src/main/resources/META-INF/ejb-jar.xml	2009-04-28 07:05:16 UTC (rev 87925)
+++ projects/ejb-book/trunk/ch05-encryption/src/main/resources/META-INF/ejb-jar.xml	2009-04-28 07:08:45 UTC (rev 87926)
@@ -22,14 +22,14 @@
       -->
       <ejb-name>EncryptionEJB</ejb-name>
 
-      <!-- Override the ciphers passphrase -->
+      <!-- Override the ciphers' default  passphrase -->
       <env-entry>
         <env-entry-name>ciphersPassphrase</env-entry-name>
         <env-entry-type>java.lang.String</env-entry-type>
         <env-entry-value>OverriddenPassword</env-entry-value>
       </env-entry>
 
-      <!-- Override the one-way hash MessageDigest algorithm -->
+      <!-- Override the default unidirectional hash MessageDigest algorithm -->
       <env-entry>
         <env-entry-name>messageDigestAlgorithm</env-entry-name>
         <env-entry-type>java.lang.String</env-entry-type>




More information about the jboss-cvs-commits mailing list