Thanks Christian, every little bit might help me.
What I posted was several failed iterations on, and you have certainly shown
that I am getting very confused.
I have refactored, hopefully to come into line with the suggestions you are
making, and this certainly makes the code look a bit cleaner.
This version doesn't work, and the most frequent basis of the problem appears
to be the resource instantiation.
One note, my IDE will not let me get away without instantiating the HAPI
Application implementation.
On deployment of this code, as it loads and starts up, the Application section
fails with null pointer exception on the cfHl7In QueueConnectionFactory
object. This has been a most consistent issue throughout my attempts to get
this working. By the time I get into the Application implementation, an
injected instance of the desired destination seems to be lost or non-existent.
Revised code is show below.
BTW, where could I find a discussion on the correct implementation of an HAPI
Application object? I'm not real happy with the way I have just made the
canProcess method return true.
Thanks
Ian
-------
The bean
-------
/*
* 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.ejb.Singleton;
import javax.ejb.Startup;
/**
*
* @author Ian
*/
@Startup
@Singleton
public class Hl7InBean {
private SimpleServer ss = null;
private static final Logger logger =
Logger.getLogger(Hl7InBean.class.getName());
@PostConstruct
public void StartListening() {
logger.log(Level.INFO, "Inbound session has started");
Hl7InProcessor processor = new Hl7InProcessor();
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 Hl7InProcessor that implements messages
ss.registerApplication("*", "*", processor);
ss.start();
}
@PreDestroy
public void Cleanup() {
ss.stop();
}
}
----
The Application implementation
----
/*
* 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.model.Message;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import ca.uhn.hl7v2.app.Application;
import javax.annotation.Resource;
import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.QueueConnectionFactory;
import javax.jms.Session;
import javax.jms.TextMessage;
/**
*
* @author Ian
*/
public class Hl7InProcessor implements Application {
private static final Logger logger =
Logger.getLogger(Hl7InProcessor.class.getName());
@Resource(mappedName = "jms/qHl7InboundConnectionFactory")
private QueueConnectionFactory cfHl7In;
@Resource(mappedName = "jms/qHl7Inbound")
private Queue qHl7Inbound;
private Connection hl7Connection;
private Session hl7Session;
private MessageProducer messageProducer;
public Hl7InProcessor() {
try {
logger.log(Level.INFO, "Hl7InProcessor is being constructed");
this.hl7Connection = cfHl7In.createConnection();
this.hl7Session = hl7Connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
this.messageProducer = hl7Session.createProducer(qHl7Inbound);
} catch (JMSException ex) {
logger.log(Level.SEVERE, null, ex);
}
}
@Override
public Message processMessage(Message msg) {
Message ack = null;
try {
logger.log(Level.INFO, "Received Message");
logger.log(Level.INFO, msg.encode());
logger.log(Level.INFO,"About to attempt send to queue");
TextMessage textMessage = hl7Session.createTextMessage();
textMessage.setText(msg.encode());
messageProducer.send(textMessage);
logger.log(Level.INFO,"It's supposed to have been sent");
ack = msg.generateACK();
} catch (JMSException ex) {
Logger.getLogger(Hl7InProcessor.class.getName()).log(Level.SEVERE,
null, ex);
} catch (IOException ex) {
logger.log(Level.SEVERE, null, ex);
} catch (HL7Exception ex) {
logger.log(Level.SEVERE, null, ex);
}
return ack;
}
@Override
public boolean canProcess(Message msg) {
return true;
}
}
>>> christian ohr <christian....@icw.de> 11/01/12 2:26 >>>
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
********************************************************************************
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.
**********************************************************************************
------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual
desktops for less than the cost of PCs and save 60% on VDI infrastructure
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Hl7api-devel mailing list
Hl7api-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hl7api-devel