[jboss-dev-forums] [JBoss ESB Development] New message: "Re: Smooks problem"

Gilles Dupont Tagne Tagne do-not-reply at jboss.com
Wed Jan 20 06:28:49 EST 2010


JBoss development,

A new message was posted in the thread "Smooks problem":

http://community.jboss.org/message/521035#521035

Author  : Gilles Dupont Tagne Tagne
Profile : http://community.jboss.org/people/tagnegilles

Message:
--------------------------------------------------------------
Thanks Maurice for the advices. I changed the GillesSmooksAction.java
 
package de.gilles.projects.splitteresb;
 
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
 
import javax.naming.InitialContext;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
 
import org.jboss.soa.esb.actions.AbstractActionLifecycle;
import org.jboss.soa.esb.actions.ActionLifecycleException;
import org.jboss.soa.esb.actions.ActionProcessingException;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.message.Message;
import org.milyn.Smooks;
import org.milyn.container.ExecutionContext;
import org.milyn.event.report.HtmlReportGenerator;
import org.milyn.persistence.util.PersistenceUtil;
import org.milyn.scribe.adapter.jpa.EntityManagerRegister;
 
public class GillesSmooksAction extends AbstractActionLifecycle {
     
     protected ConfigTree _configTree;
     protected Smooks smooks = null;
     protected EntityManagerFactory emf = null;
     protected String smooksConfigFile = null;
     
     public GillesSmooksAction(ConfigTree configTree){
          _configTree = configTree;
     }
     
     public Message process(Message message) throws ActionProcessingException {
          
          EntityManager em = null;
          StreamResult result = new StreamResult(new ByteArrayOutputStream());
          
          try {
 
               em = emf.createEntityManager();
               ExecutionContext executionContext = smooks.createExecutionContext();
               executionContext.setEventListener(new HtmlReportGenerator("/Users/gilles/Desktop/report/reportjpa.html"));
               PersistenceUtil.setDAORegister(executionContext, new EntityManagerRegister(em));
               EntityTransaction tx = em.getTransaction();
               
               tx.begin();
               smooks.filterSource(executionContext, new StreamSource(new ByteArrayInputStream(((String)message.getBody().get()).getBytes())),result);
               message.getBody().add(result.getOutputStream().toString());
               tx.commit();
               
          } catch (Exception e) {
               
               e.printStackTrace();
               throw new ActionProcessingException(e);               
          } 
          finally{
               
               try {
                    if(em != null) em.close();
               } catch (Exception e2) {}
               
               result = null;
          }
          return message;
     }
     
   public void exceptionHandler(Message message, Throwable exception) {
        logHeader();
        System.out.println("!ERROR!");
        System.out.println(exception.getMessage());
        System.out.println("For Message: ");
        System.out.println(message.getBody().get());
        logFooter();
   }
   
   @Override
     public void initialise() throws ActionLifecycleException {
          super.initialise();
          smooksConfigFile = _configTree.getAttribute("smooksConfig");
          
          try {
               if(smooksConfigFile == null){
                    throw new Exception("The Attribute with the name: 'smooksConfig' doesn't exist." );
               }
               
               InitialContext jndiContext = new InitialContext();
               emf = (EntityManagerFactory) jndiContext.lookup("java:/personDbEntityManagerFactory");               
               smooks = new Smooks(smooksConfigFile);
               
          } catch (Exception e) {
               e.printStackTrace();
               throw new ActionLifecycleException(e);
          }
 
     }
 
   
   @Override
     public void destroy() throws ActionLifecycleException {
          super.destroy();
          
          try {
               if(emf != null) {emf.close(); emf = null;}  
          } catch (Exception e2) {
               
               e2.printStackTrace();
               throw new ActionLifecycleException(e2);
          }
          
          if(smooks != null) {smooks.close(); smooks = null;}          
     }
 
   // This makes it easier to read on the console
   private void logHeader() {
        System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
   }
   private void logFooter() {
        System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n");
   }
   
}
 

 
I have forgotten to mention it. I was obliged to add the *milyn-scribe-core.1.2.4.jar* in the esb.deployer because jboss couldn't found the ObjectStore.class. But i think Tom has already created a Jira to solve the problem https://jira.jboss.org/jira/browse/JBESB-3121. 
Do you think i will give the *reader.pool.size* the value 3?

--------------------------------------------------------------

To reply to this message visit the message page: http://community.jboss.org/message/521035#521035




More information about the jboss-dev-forums mailing list