1
我正在使用HAPI爲HL7v2消息編寫一個簡單的客戶端和服務器。客戶端和服務器似乎都能正常工作,但在發送確認消息時會發出關於早期套接字終止的INFO
級別警告。如何修復HAPI早期連接關閉警告?
服務器產生以下:
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();
}