Package ca.uhn.hl7v2.app

Examples of ca.uhn.hl7v2.app.ConnectionHub


public class HL7Sender {

    public void send(String host, int port) throws HL7Exception {
        System.out.println("[ Executing HL7Sender : HOST:" + host + "  ;port :" + port + " ]");
        // The connection hub connects to listening servers
        ConnectionHub connectionHub = ConnectionHub.getInstance();
        // A connection object represents a socket attached to an HL7 server
        Connection connection = connectionHub
                .attach(host, port, new PipeParser(), MinLowerLayerProtocol.class);

        // The initiator is used to transmit unsolicited messages
        Initiator initiator = connection.getInitiator();
        HL7Message sampleMessage = new HL7Message();

        //send
        Message response = null;
        try {
            response = initiator.sendAndReceive(sampleMessage.getHL7Message());
            PipeParser parser = new PipeParser();
            String responseString = parser.encode(response);
            System.out.println("Received response:\n" + responseString);
        } catch (LLPException e) {
            System.out.println("Error : " + e);
        } catch (IOException e) {
            System.out.println("Error : " + e);
        }

        // Close the connection and server
        connectionHub.discard(connection);
    }
View Full Code Here


        Map<String,String> params = getURLParameters(targetEPR);

        try {
            Message message = parser.parse(xmlFormat);
            ConnectionHub connectionHub = ConnectionHub.getInstance();
            Connection connection = getConnection(targetEPR, connectionHub);
            Initiator initiator = connection.getInitiator();
            String timeout = params.get(HL7Constants.TIMEOUT_PARAM);
            if (timeout != null) {
                initiator.setTimeoutMillis(Integer.parseInt(timeout));
            } else {
                initiator.setTimeoutMillis(HL7Constants.DEFAULT_TIMEOUT);
            }

            returnMsg = initiator.sendAndReceive(message);
            connectionHub.detach(connection);

            if (log.isDebugEnabled()) {
                log.debug("HL7 message successfully dispatched to URL " + targetEPR);
                log.debug("Response message received from target EP : " + returnMsg.toString());
            }
View Full Code Here

                + "IN1||022254P|4558PD|BLUE CROSS|STREET^OTHER STREET^CITY^ST^00990||(333)333-6666||221K|LENIX|||19980515|19990515|||PATIENT01 TEST D||||||||||||||||||02LL|022LP554";
        Parser p = new GenericParser();
        Message adt = p.parse(msg);

        // The connection hub connects to listening servers
        ConnectionHub connectionHub = ConnectionHub.getInstance();

        // A connection object represents a socket attached to an HL7 server
        Connection connection = connectionHub
                .attach("localhost", port, new PipeParser(), MinLowerLayerProtocol.class);

        // The initiator is used to transmit unsolicited messages
        Initiator initiator = connection.getInitiator();
        Message response = initiator.sendAndReceive(adt);

        String responseString = parser.encode(response);
        System.out.println("Received response:\n" + responseString);

        /*
         * MSH|^~\&|||||20070218200627.515-0500||ACK|54|P|2.2 MSA|AA|12345
         */

        // Close the connection and server
        connectionHub.discard(connection);
        server.stop();

    }
View Full Code Here

    FileReader reader = new FileReader("message_file.txt");
   
    // Create an iterator to iterate over all the messages
    Hl7InputStreamMessageIterator iter = new Hl7InputStreamMessageIterator(reader);
   
    ConnectionHub connectionHub = ConnectionHub.getInstance();
    Connection conn = null;
   
    while (iter.hasNext()) {
     
      Message next = iter.next();
     
      /* If we don't already have a connection, create one.
       * Note that unless something goes wrong, it's very common
       * to keep reusing the same connection until we are done
       * sending messages. Many systems keep a connection open
       * even if a long period will pass between messages being
       * sent. This is good practice, as it is much faster than
       * creating a new connection each time.
       */
      if (conn == null) {
        conn = connectionHub.attach("localhost", 8888, new PipeParser(), MinLowerLayerProtocol.class);
      }
     
      Message response;
      try {
        response = conn.getInitiator().sendAndReceive(next);
      } catch (IOException e) {
        System.out.println("Didn't send out this message!");
        e.printStackTrace();
       
        // Since we failed, return the connection to the ConnectionHub so that it can
        // discard it, and make sure we're going to create a new one next time around
        connectionHub.discard(conn);
        conn = null;
        continue;
      }
     
      System.out.println("Sent message. Response was " + response.encode());
     
    }
   
    // When we're totally done, give the connection back. This allows the
    // connection hub to either give it to someone else, or close it.
    if (conn != null) {
      connectionHub.detach(conn);
    }
   
  }
View Full Code Here

                + "IN1||022254P|4558PD|BLUE CROSS|STREET^OTHER STREET^CITY^ST^00990||(333)333-6666||221K|LENIX|||19980515|19990515|||PATIENT01 TEST D||||||||||||||||||02LL|022LP554";
        Parser p = new GenericParser();
        Message adt = p.parse(msg);

        // The connection hub connects to listening servers
        ConnectionHub connectionHub = ConnectionHub.getInstance();

        // A connection object represents a socket attached to an HL7 server
        Connection connection = connectionHub
                .attach("localhost", port, new PipeParser(), MinLowerLayerProtocol.class);

        // The initiator is used to transmit unsolicited messages
        Initiator initiator = connection.getInitiator();
        Message response = initiator.sendAndReceive(adt);

        String responseString = parser.encode(response);
        System.out.println("Received response:\n" + responseString);

        /*
         * MSH|^~\&|||||20070218200627.515-0500||ACK|54|P|2.2 MSA|AA|12345
         */

        /*
         * Close the connection and server. Note that this method may close
         * the connection. If you are designing a system which will continuously
         * send out messages, you may want to consider keeping a copy of the
         * Connection object between messages. That way, the same connection
         * will be reused.
         *
         * See
         * http://hl7api.sourceforge.net/xref/ca/uhn/hl7v2/examples/SendLotsOfMessages.html
         * for an example of this.
         */
        connectionHub.discard(connection);
       
        // Stop the receiving server and client
        server.stopAndWait();
        ConnectionHub.shutdown();

View Full Code Here

        // A connection object represents a socket attached to an HL7 server
        Connection connection = connectionHub
                .attach(host, port, new PipeParser(), MinLowerLayerProtocol.class);

        // The initiator is used to transmit unsolicited messages
        Initiator initiator = connection.getInitiator();
        HL7Message sampleMessage = new HL7Message();

        //send
        Message response = null;
        try {
            response = initiator.sendAndReceive(sampleMessage.getHL7Message());
            PipeParser parser = new PipeParser();
            String responseString = parser.encode(response);
            System.out.println("Received response:\n" + responseString);
        } catch (LLPException e) {
            System.out.println("Error : " + e);
View Full Code Here

        try {
            Message message = parser.parse(xmlFormat);
            ConnectionHub connectionHub = ConnectionHub.getInstance();
            Connection connection = getConnection(targetEPR, connectionHub);
            Initiator initiator = connection.getInitiator();
            String timeout = params.get(HL7Constants.TIMEOUT_PARAM);
            if (timeout != null) {
                initiator.setTimeoutMillis(Integer.parseInt(timeout));
            } else {
                initiator.setTimeoutMillis(HL7Constants.DEFAULT_TIMEOUT);
            }

            returnMsg = initiator.sendAndReceive(message);
            connectionHub.detach(connection);

            if (log.isDebugEnabled()) {
                log.debug("HL7 message successfully dispatched to URL " + targetEPR);
                log.debug("Response message received from target EP : " + returnMsg.toString());
View Full Code Here

    private SimpleServer server;

    public HL7Server(int port) {
        LowerLayerProtocol llp = LowerLayerProtocol.makeLLP(); // The transport protocol
        PipeParser parser = new PipeParser();
        server = new SimpleServer(port, llp, parser);
    }
View Full Code Here

    @Override
    protected void startEndpoint(HL7Endpoint endpoint) throws AxisFault {
        LowerLayerProtocol llp = LowerLayerProtocol.makeLLP();
        PipeParser parser = new PipeParser();
        SimpleServer server = new SimpleServer(endpoint.getPort(), llp, parser);
        Application callback = new HL7MessageProcessor(endpoint);
        server.registerApplication("*", "*", callback);
        server.start();
        serverTable.put(endpoint, server);

        log.info("Started HL7 endpoint on port: " + endpoint.getPort());
    }
View Full Code Here

        log.info("Started HL7 endpoint on port: " + endpoint.getPort());
    }

    @Override
    protected void stopEndpoint(HL7Endpoint endpoint) {
        SimpleServer server = serverTable.remove(endpoint);
        if (server != null) {
            server.stop();
        }

        log.info("Stopped HL7 endpoint on port: " + endpoint.getPort());
    }
View Full Code Here

TOP

Related Classes of ca.uhn.hl7v2.app.ConnectionHub

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.