Appendix B. Stateless Session EJB: Encryption Example


The stateless session bean is a fantastic implementation choice for business processes which require no server-side state to be retained in between client invocations. If all information needed to process a request can be found in the request itself, the SLSB may be used as a highly efficient endpoint. In this example we build an encryption service capable of performing both one-way hashing and encryption/decryption operations.

Additionally, we show here that SLSBs may indeed have their own internal state, so long as that it’s not leaked out to the client during requests. Finally, we introduce the use of XML via environment entries to externalize configurable elements of the service.

Source Listing

Following is a full listing of all source code used in this runnable example.

Implementation Resources

package org.jboss.ejb3.examples.ch05.encryption; import; import; import; import; import; import javax.annotation.PostConstruct; import javax.annotation.Resource; import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; ...

Get Enterprise JavaBeans 3.1, 6th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.