1

我正在使用HAPI为 HL7v2 消息传递编写一个简单的客户端和服务器。客户端和服务器似乎都可以工作,但INFO在发送确认消息时会发出有关早期套接字终止的级别警告。

服务器产生以下内容:

2012-09-17 13:36:38,715 INFO  pool-1-thread-1 [MinLLPReader] End of input stream reached.
2012-09-17 13:36:38,718 INFO  pool-1-thread-1 [Receiver] Closing connection (no more messages available).

以及客户端上的补充错误:

2012-09-17 13:36:38,715 INFO  pool-1-thread-1 [MinLLPReader] SocketException on read() attempt.  Socket appears to have been closed: socket closed 
2012-09-17 13:36:38,716 INFO  pool-1-thread-1 [Receiver] Closing connection (no more messages available).

如何阻止这些消息出现?

发送确认的服务器代码如下所示。请注意,由于对 HL7v2 规范的“有趣”解释,我不得不禁用所有可能的消息验证组件:

// HAPI server component
final LowerLayerProtocol llp = LowerLayerProtocol.makeLLP();
final PipeParser parser = new PipeParser();
final SimpleServer server = new SimpleServer(12345, llp, parser, false);

// registers an admission message handler
server.registerApplication("ADT", "A01", new Application() {

    @Override
    public Message processMessage(final Message message) throws ApplicationException, HL7Exception {

        final PipeParser pipeParser = new PipeParser();
        pipeParser.setValidationContext(new NoValidation());
        final String encoded = pipeParser.encode(message);

        final AbstractMessage adtMessage = new ADT_A01();
        adtMessage.setValidationContext(new NoValidation());
        adtMessage.parse(encoded);

        return (ACK) DefaultApplication.makeACK(adtMessage);    
    }

    @Override
    public boolean canProcess(final Message message) {
        return true;
    }
});

// tell HAPI not to try to validate incoming messages
server.registerConnectionListener(new ConnectionListener() {    

    @Override
    public void connectionReceived(final Connection c) {
        c.getParser().setValidationContext(new NoValidation());
    }

    @Override
    public void connectionDiscarded(Connection c) {
        // nothing
    }
}); 

server.start();

和客户:

ConnectionHub hub = null;
Connection conn = null;

try {

    final ADT_A01 adtMessage = new ADT_A01();
    adtMessage.parse(message); // message content as a string

    hub = ConnectionHub.getInstance();
    final PipeParser connParser = new PipeParser();
    connParser.setValidationContext(new NoValidation());

    conn = hub.attach(host, port, connParser, MinLowerLayerProtocol.class);
    final Initiator init = conn.getInitiator();

    final Message response = init.sendAndReceive(adtMessage);
    final String responseString = connParser.encode(response);
    System.out.println("Received response:\n" + responseString);

}
finally {

    if (conn != null) {
        hub.discard(conn);
    }

    ConnectionHub.shutdown();
}
4

1 回答 1

0

不确定您使用哪个记录器实现...对于您提到的两个类(ca.uhn.hl7v2.app.Receiver、ca.uhn.hl7v2.llp.MinLLPReader),只需将日志级别设置为 WARN,消息就会消失。

基督教

于 2012-09-30T18:57:07.427 回答