[jboss-user] [JBoss Seam] - Re: MDB initialized too early?
svadu
do-not-reply at jboss.com
Mon Nov 19 05:51:53 EST 2007
Thanks for the quick response! Here are the sources (I had to 'censor' it for obvious reasons):
MDB:
@MessageDriven(name = "Processor", activationConfig = {
| @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
| @ActivationConfigProperty(propertyName = "destination", propertyValue = "myqueue"),
| @ActivationConfigProperty(propertyName = "providerAdapterJNDI", propertyValue="java:/TIBCOJMSProvider")
| })
| public class Receiver implements MessageListener {
|
| @Resource
| private MessageDrivenContext context;
|
| /**
| * Controller does the actual processing
| * of the incoming message
| */
| @EJB
| private Creator creator;
|
| /**
| * @see javax.jms.MessageListener#onMessage(javax.jms.Message)
| */
| public void onMessage(Message msg) {
| try {
| TextMessage txtMsg = (TextMessage)msg;
| String text = txtMsg.getText();
| creator.process(text);
| } catch (JMSException e) {
| e.printStackTrace();
| context.setRollbackOnly();
| } catch (ValidationException e) {
| e.printStackTrace();
| context.setRollbackOnly();
| }
| }
|
| /**
| * @param creator the controller to set
| */
| public void setCreator(Creator creator) {
| this.creator = creator;
| }
|
| /**
| * @param context the context to set
| */
| public void setContext(MessageDrivenContext context) {
| this.context = context;
| }
|
| }
|
SLSB Local interface:
| @Local
| public interface Creator {
|
| /**
| * Processed an incoming message bus from a message bus
| * and stores it in database.
| *
| * @param text
| * @throws ValidationException
| * @return an instance of saved entity
| */
| public Entiteit process(String text) throws ValidationException;
|
| /**
| * Sets entity manager
| * @param em
| */
| public void setDatabase(EntityManager em);
|
| /**
| * Retrieves entity manager
| * @return entity manager instance
| */
| public EntityManager getDatabase();
|
| }
SLSB itself:
| /**
| * Processes entities
| *
| */
| @Stateless
| @Name("Creator")
| public class CreatorBean implements Creator {
|
| private EntityManager em;
|
| /**
| * Sets entity manager
| * @param em
| */
| @PersistenceContext
| public void setDatabase(EntityManager em){
| this.em = em;
| }
|
| /**
| * Retrieves entity manager
| * @return entity manager instance
| */
| public EntityManager getDatabase() {
| return this.em;
| }
|
| /**
| * Processes the entities from xml and stores it in database.
| * It also performs checking on existing records end replaces them if found.
| * @throws ValidationException
| */
| public Entiteit process(String xmlText) throws ValidationException {
| Entiteit en = null;
|
| try {
| IBindingFactory bfact = BindingDirectory.getFactory(Entiteit.class);
| IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
|
| StringReader sr = new StringReader(xmlText);
|
| en = (Entiteit) uctx.unmarshalDocument( sr, null);
|
| em.persist(en);
|
|
| } catch (JiBXException e) {
| throw new ValidationException("Error processing incoming entity", e);
| }
|
| return en;
| }
|
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4105970#4105970
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4105970
More information about the jboss-user
mailing list