View Javadoc
1   package ca.uhn.hl7v2.examples.hoh;
2   
3   import java.io.IOException;
4   
5   import ca.uhn.hl7v2.DefaultHapiContext;
6   import ca.uhn.hl7v2.HL7Exception;
7   import ca.uhn.hl7v2.app.Connection;
8   import ca.uhn.hl7v2.app.DefaultApplication;
9   import ca.uhn.hl7v2.app.SimpleServer;
10  import ca.uhn.hl7v2.hoh.llp.Hl7OverHttpLowerLayerProtocol;
11  import ca.uhn.hl7v2.hoh.util.ServerRoleEnum;
12  import ca.uhn.hl7v2.llp.LLPException;
13  import ca.uhn.hl7v2.llp.LowerLayerProtocol;
14  import ca.uhn.hl7v2.model.Message;
15  import ca.uhn.hl7v2.model.v25.message.ADT_A01;
16  import ca.uhn.hl7v2.parser.PipeParser;
17  
18  public class HohLlpExample {
19  
20  	public void receiveMessage() {
21  		
22  // START SNIPPET: server 
23  /*
24   * Sending a message with HAPI and HL7 over HTTP. First
25   * an LLP instance is created. Note that you must tell
26   * the LLP class whether it will be used in a client
27   * or a server.
28   */
29  LowerLayerProtocol llp;
30  llp = new Hl7OverHttpLowerLayerProtocol(ServerRoleEnum.SERVER);
31  
32  /* 
33   * Create the server, and pass in the HoH LLP instance
34   * 
35   * Note that the HoH LLP implementation will not
36   * work in two-socket servers
37   */
38  PipeParser parser = PipeParser.getInstanceWithNoValidation();
39  int port = 8080;
40  SimpleServertml#SimpleServer">SimpleServer server = new SimpleServer(port, llp, parser);
41  
42  // Register an application to the server, and start it
43  // You are now ready to receive HL7 messages!
44  server.registerApplication("*", "*", new DefaultApplication());
45  server.start();
46  // END SNIPPET: server 
47  
48  		
49  	}
50  	
51  	@SuppressWarnings("unused")
52     public void sendMessage() throws HL7Exception, IOException, LLPException {
53  		
54  // START SNIPPET: client 
55  /*
56   * Sending a message with HAPI and HL7 over HTTP. First
57   * an LLP instance is created. Note that you must tell
58   * the LLP class whether it will be used in a client
59   * or a server.
60   */
61  DefaultHapiContextml#DefaultHapiContext">DefaultHapiContext ctx = new DefaultHapiContext();
62  
63  // Create an HoH LLP for the context
64  LowerLayerProtocol llp = new Hl7OverHttpLowerLayerProtocol(ServerRoleEnum.CLIENT);
65  ctx.setLowerLayerProtocol(llp);
66  
67  // Use the LLP in a HapiContext to get a client connection
68  String host = "localhost";
69  int port = 8080;
70  boolean tls = false;
71  Connection connection = ctx.newClient(host, port, tls);
72  
73  // Create a message to send
74  ADT_A01age/ADT_A01.html#ADT_A01">ADT_A01 message = new ADT_A01();
75  message.initQuickstart("ADT", "A01", "P");
76  // ... populate message ...
77  
78  // Send the message
79  Message response = connection.getInitiator().sendAndReceive(message);
80  // END SNIPPET: client 
81  	
82  	}
83  	
84  }