Hi,

I'm neither an expert on Glassfish, its JMS implementation nor EJB 3.1 (?)
in general, but to me your code seem to mix up a couple of things regarding
bean instance creation.

By specifying @Singleton @Startup, you instruct the container to instantiate
a session bean instance of class HL7InBean at startup time, but for
HL7InProcessor you only specify @Singleton, which causes the container to
create this at any time. Furthermore you're constructing an additional
(unmanaged!) instance of HL7InProcessor in the @PostConstruct phase of
HL7InBean.
In HL7InProcessor you define your QueueConnectionFactory and QueueConnection
as @Resource, but you set them again manually in the constructor. 

What do you expect the container to do for you, and what do you want to care
of yourself?
Maybe you should take a look at @DependsOn (forcing a certain order in bean
creation) and @EJB references to other beans, or leave HL7InProcessor
unmanaged (i.e. remove @Singleton) and pass all required container
@Resources from HL7InBean to HL7InProcessor.

regards
Christian



Ian Vowles wrote:
> 
> I would really like to get a HAPI Simple Server to write to a Glassfish
> JMS queue, and it's been doing my head in for a couple of days now and I
> just can't seem to join the last dot.
>  
> Please be aware, I am still learning this stuff the hard way, with limited
> experience, and next to no documentation on how these things work.
>  
> The inbound ejbs I am working with are shown below.  The critical problem
> seems to be that when the registered processor fires, the queue objects
> defined have not been instantiated and are null, so the good old null
> pointer exception brings everything to a grinding halt.
>  
> Anyone got any thoughts?
>  
> Anyone got any documentation on how SimpleServer might work in an
> appserver environment?
>  
> Have also investigated running the SimpleServer as a standalone and
> connecting to the Glassfish jms service via it's jndi, and there is quite
> a bit of talk on the interwebs about how hard Glassfish 3.x has made this.
>  
> Thanks
> Ian
>  
> Code:
>  
> ------------------
> HL7InBean Code
> ------------------
>  
> /*
>  * To change this template, choose Tools | Templates
>  * and open the template in the editor.
>  */
> package au.gov.qld.health.sit.hl7tcp;
>  
> import ca.uhn.hl7v2.app.SimpleServer;
> import ca.uhn.hl7v2.llp.LowerLayerProtocol;
> import ca.uhn.hl7v2.parser.PipeParser;
> import ca.uhn.hl7v2.validation.impl.NoValidation;
> import java.util.logging.Level;
> import java.util.logging.Logger;
> import javax.annotation.PostConstruct;
> import javax.annotation.PreDestroy;
> import javax.annotation.Resource;
> import javax.ejb.Singleton;
> import javax.ejb.Startup;
> import javax.jms.Connection;
> import javax.jms.JMSException;
> import javax.jms.MessageProducer;
> import javax.jms.Queue;
> import javax.jms.QueueConnection;
> import javax.jms.QueueConnectionFactory;
> import javax.jms.Session;
>  
> /**
>  *
>  * @author Ian
>  */
> @Startup
> @Singleton
> public class Hl7InBean {
>  
>     @Resource(mappedName = "jms/qHl7InboundConnectionFactory")
>     private QueueConnectionFactory cfHl7In;
>     @Resource(mappedName = "jms/qHl7Inbound")
>     private Queue qHl7Inbound;
>     private SimpleServer ss = null;
>  
>     @PostConstruct
>     public void StartListening() {
>         try {
>         Logger.getLogger(Hl7InBean.class.getName()).log(Level.INFO,
> "Inbound session has started");
>         QueueConnection qConnection = cfHl7In.createQueueConnection();
>  
>         Hl7InProcessor processor = new Hl7InProcessor(qConnection);
>  
>         PipeParser pp = new PipeParser();
>         pp.setValidationContext(new NoValidation());
>         // Create a new SimpleServer that listens on port 8888
>         ss = new SimpleServer(8888, LowerLayerProtocol.makeLLP(), pp);
>         // Create and register some class that implements messages (ORU in
> this example)
>         ss.registerApplication("*", "*", processor);
>         ss.start();
>         Logger.getLogger(Hl7InBean.class.getName()).log(Level.INFO,
> "Message sent, session closed");
>  
>         } catch (JMSException ex) {
>             Logger.getLogger(Hl7InBean.class.getName()).log(Level.SEVERE,
> null, ex);
>         }
>     }
>  
>     @PreDestroy
>     public void Cleanup() {
>     }
> }
>  
> 
> ----------------------------------------------------------------------
> HL7InProcessor (written as an ejb in this case, been tried a few ways)
> ----------------------------------------------------------------------
>  
> 
> /*
>  * To change this template, choose Tools | Templates
>  * and open the template in the editor.
>  */
> package au.gov.qld.health.sit.hl7tcp;
>  
> import ca.uhn.hl7v2.HL7Exception;
> import ca.uhn.hl7v2.app.ApplicationException;
> import ca.uhn.hl7v2.model.Message;
> import java.util.logging.Level;
> import java.util.logging.Logger;
> import javax.ejb.Stateless;
> import javax.ejb.LocalBean;
> import ca.uhn.hl7v2.app.Application;
> import javax.annotation.PreDestroy;
> import javax.annotation.Resource;
> import javax.ejb.Singleton;
> import javax.ejb.Startup;
> import javax.jms.JMSException;
> import javax.jms.MessageProducer;
> import javax.jms.Queue;
> import javax.jms.QueueConnection;
> import javax.jms.QueueConnectionFactory;
> import javax.jms.Session;
>  
> /**
>  *
>  * @author Ian
>  */
> @Singleton
> public class Hl7InProcessor implements Application {
>  
>     @Resource(mappedName = "jms/qHl7InboundConnectionFactory")
>     private QueueConnectionFactory cfHl7In;
>     @Resource(mappedName = "jms/qHl7Inbound")
>     private QueueConnection qConnection;
>     private Queue qHl7Inbound;
>     private Session qSession;
>     
>     
>     private MessageProducer messageProducer;
>     private static final Logger logger =
> Logger.getLogger(Hl7InProcessor.class.getName());
>  
>     public Hl7InProcessor() {
>     }
>     
>     public Hl7InProcessor(QueueConnection qConnection) {
>         try {
>             this.qConnection = qConnection;
>             logger.log(Level.INFO,"Hl7InProcessor is being constructed");
>             qSession = this.qConnection.createSession(false,
> Session.AUTO_ACKNOWLEDGE);
>             messageProducer = qSession.createProducer(qHl7Inbound);
>         } catch (JMSException ex) {
>             logger.log(Level.SEVERE, null, ex);
>         }
>     }
>     
>     @Override
>     public Message processMessage(Message msg) {
>         try {
>             javax.jms.TextMessage out = qSession.createTextMessage();
>             out.setText("This is an example message");
>             messageProducer.send(out);
>             return msg;
>         } catch (JMSException ex1) {
>             logger.log(Level.SEVERE, null, ex1);
>             return msg;
>         }
>     }
>  
>     @Override
>     public boolean canProcess(Message msg) {
>         return true;
>     }
>  
>     @PreDestroy
>     public void cleanup() {
>         try {
>             messageProducer.close();
>             qSession.close();
>             qConnection.close();
>         }
>         catch (JMSException ex) {
>             logger.log(Level.SEVERE, null, ex);
>         }
>         
>     }
>     
> }
>  
>  
>  
>  
> 
> ********************************************************************************
> This email, including any attachments sent with it, is confidential and
> for the sole use of the intended recipient(s). This confidentiality is not
> waived or lost, if you receive it and you are not the intended
> recipient(s), or if it is transmitted/received in error.
> Any unauthorised use, alteration, disclosure, distribution or review of
> this email is strictly prohibited.  The information contained in this
> email, including any attachment sent with it, may be subject to a
> statutory duty of confidentiality if it relates to health service matters.
> If you are not the intended recipient(s), or if you have received this
> email in error, you are asked to immediately notify the sender by
> telephone collect on Australia +61 1800 198 175 or by return email.  You
> should also delete this email, and any copies, from your computer system
> network and destroy any hard copies produced.
> If not an intended recipient of this email, you must not copy, distribute
> or take any action(s) that relies on it; any form of disclosure,
> modification, distribution and/or publication of this email is also
> prohibited.
> Although Queensland Health takes all reasonable steps to ensure this email
> does not contain malicious software, Queensland Health does not accept
> responsibility for the consequences if any person's computer inadvertently
> suffers any disruption to services, loss of information, harm or is
> infected with a virus, other malicious computer programme or code that may
> occur as a consequence of receiving this email.
> Unless stated otherwise, this email represents only the views of the
> sender and not the views of the Queensland Government.
> **********************************************************************************
> 
> 
> ------------------------------------------------------------------------------
> Write once. Port to many.
> Get the SDK and tools to simplify cross-platform app development. Create 
> new or port existing apps to sell to consumers worldwide. Explore the 
> Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
> http://p.sf.net/sfu/intel-appdev
> _______________________________________________
> Hl7api-devel mailing list
> Hl7api-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/hl7api-devel
> 
> 

-- 
View this message in context: 
http://old.nabble.com/HL7Exception-contains-wrong-rep-tp33111371p33112799.html
Sent from the hl7api-devel mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
Hl7api-devel mailing list
Hl7api-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hl7api-devel

Reply via email to