Announcement

Collapse

Mirth Connect 3.12.0 Released!

Mirth Connect 3.12.0 is now available as an appliance update and on our GitHub page. This release includes database performance improvements, improves visual HL7 representation, message pruning, keystore handling, PDF generation, community contributions, and fixes several security vulnerabilities. This release also contains many improvements to commercial extensions. See the release notes for the list of fixes and updates.

Download | See What's New | Upgrade Guide | Release Notes

For discussion on this release, see this thread.
See more
See less

LLPlistener timeout when BufferedReader.readLine()

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • LLPlistener timeout when BufferedReader.readLine()

    version: 1.6.1_2750

    I wrote very simple Mirth LLP client for configurations tests (in Java). My client is not goin'g to send any message in future. I used it only for testing LLP listener behavior and diagnose problems with other client software.

    I'm sending (to LLP listener) several HL7 messages one after another in a loop using one connection. LLP listener is configured to send ACK response messages.
    [ol]
    [li]Situation 1.[/li] After sending first message, I'm sending another ones immediately (I don't read response ACK message - skip while loop - see code sample and whole method code at he end). In this case only first message is accepted by Mirth. Rest are ignored (connection seems to be still alive).

    Sample 1.
    Code:
    for (int i = 0; i < str.length; i++) {
        String message = str[i];
        /*WRITING TO SOCKET*/
        out.println(message); 
    }
    [li]Situation 2. After sending first message, I'm reading Mirth ACK response.[/li]
    Option A. Reading response lines until readLine() return null, without checking #28 char at the end of incoming ACK message. This approach causes similar problems like above. Only first message is being accepted by Mirth.
    Problem is that readLine() method tries to read data incoming after #28 char until server timeout. After timeout, readLine() returns null and while loop breaks. Then client tries to send next message. Mirth don't get it.
    In fact I need this version to work fine to be compatible with other software (different producers) sending HL7 messages to Mirth.

    Sample 2.A
    Code:
    for (int i = 0; i < str.length; i++) {
        String message = str[i];
        /*WRITING TO SOCKET*/
        out.println(message);
        try{
           while((fromServer = in.readLine()) != null){
              System.out.println(fromServer);
             /* if(fromServer.indexOf(""+c28)>-1) {
                 System.out.println("Breaking"«»);
                 break;
              } */
           }   
        }catch (SocketTimeoutException e) {
           e.printStackTrace();
        }
    }
    Option B. Reading response lines until #28 char at the end of incoming ACK is found. This option works very well but it seems it is not implemented in other clients (is it right that it isn't?).
    Sample 3.B
    Code:
    for (int i = 0; i < str.length; i++) {
        String message = str[i];
        /*WRITING TO SOCKET*/
        out.println(message);
        try{
          while((fromServer = in.readLine()) != null){
              System.out.println(fromServer);
              if(fromServer.indexOf(""+c28)>-1) {
                 System.out.println("Breaking"«»);
                 break;
              }
           }   
        }catch (SocketTimeoutException e) {
           e.printStackTrace();
        }
    }
    [/ol]

    Whole method (ready to use in some Runnable class)
    Code:
    public void run() {
       Socket socket = null;
       PrintWriter out = null;
       BufferedReader in = null;
       char c11 = (char)0x0B;//11;
       char c13 = (char)0x0D;//13;
       char c28 = (char)0x1C;//28;
       String msg1 = ""+c11+"MSH|^~\\&|aa|aa|bb|bb|20070829143022||MFN^M01|20070829143022.245|P|2.4|||AL|NE"+c13+
          "MFI|BAD||UPD|||AL"+c13+
          "MFE|MAD|200708290208||data"+c13+
          ""+c28+c13;
       String msg2 =  ""+c11+"MSH|^~\\&|aa|aa|bb|bb|2007101611490500||ACK|1819|T|2.3|||||POL||PL|"+c13+
          "MSA|AA|20060921102111383001||"+c13+
          ""+c28+c13;
       String[] str = new String[2];
       str[0] = msg1;
       str[1] = msg2;
       String fromServer;
       try {
          String serverLLP = "192.168.1.2";
          socket = new Socket(serverLLP, 88);
          socket.setSoTimeout(10000);
          out = new PrintWriter(socket.getOutputStream(), true);
          in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
          for (int i = 0; i < str.length; i++) {
             String message = str[i];
             /*WRITING TO SOCKET*/
             out.println(message);
             try{
                while((fromServer = in.readLine()) != null){
                   System.out.println(fromServer);
                   if(fromServer.indexOf(""+c28)>-1) {
                      System.out.println("Breaking"«»);
                      break;
                   }
                }   
             }catch (SocketTimeoutException e) {
                e.printStackTrace();
             }
          }
          System.out.println("END"«»);
          out.close();
          in.close();
          socket.close();
       } catch (UnknownHostException e) {
          System.err.println("Don't know about host"«»);
          System.exit(1);
       } catch (IOException e) {
          System.err.println("Couldn't get I/O for the connection to: taranis."«»);
          System.exit(1);
       }
    }
    Please comment on that and suggest me right approach.

  • #2
    Re:LLPlistener timeout when BufferedReader.readLine()

    HI.

    This seems to be a big work. Could you attach the full code you're using ? This way we could test it deep.

    BTW, Mirth works with the most HL7 engines of the market: TIBCO, Rhapsody, BizTalk, OpenLink, Centricity, and other solutions (HL7Browser, HL7 Inspector).

    If you want to make crude test of MLLP, you can use the simplesender (you can find it at the svn).

    I have't study to the end your code, but perhaps the problem is related to the use of readLine: readLine is a string-oriented function, and MLLP is a byte-oriented protocol.

    Comment

    Working...
    X