Announcement

Collapse
No announcement yet.

HTTP Listener, incoming data format?

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

  • HTTP Listener, incoming data format?

    I'm trying to use an HTTP Listener, but if my client includes XML as the content body of the HTTP request, I get an exception as follows:

    com.webreach.mirth.server.mule.transformers.HttpSt ringToXML: org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified.

    It looks like the HttpStringToXML class tries to encode all the HTTP headers and query parameters into an XML form, and that POSTing straight XML (the message I want processed) in the body of the request is a no go.

    Do I assume from this that you have to put your message into a request parameter?

    In a browser, it would be encoded in a URL something like:

    http://mirthmachine:8081?mymsg=HL7orXMLcontenthere

    Is that correct? If so, that's ugly, since you then have to encode the data.

    Is there any way to avoid using request parameters and just do a POST to the base URL of http://mirthmachine:8081 (in my example) with the raw message data as the content of the POST request?

    Thanks!

  • #2
    Re:HTTP Listener, incoming data format?

    If you are using 1.6.1 - set the option to "Append Payload Variable" to true and optionally set encoding to "Encode"
    Chris Lang

    Comment


    • #3
      Re:HTTP Listener, incoming data format?

      Ah....I had Append Payload Variable set, but not encode. The Encode seemed to to do the trick.

      What exactly does the Encode do that fixed the invalid character error? Did it just do a URL or Base64 encoding?

      Thx!

      Comment


      • #4
        Re:HTTP Listener, incoming data format?

        It performs a URL encoding
        Chris Lang

        Comment


        • #5
          Re:HTTP Listener, incoming data format?

          Yup....I figured that out.

          Now the key question is, I have the payload. It's an XML document, in fact an HL7 2.XML message. But it's now URL encoded.

          There doesn't seem to be any transformer method to URL decode a string that was encoded. There's only Base64 encode/decode available.

          So how do I turn this URL encoded string into an XML representation, so that I can convert it back to HL7 format?

          Can I just use the normal

          SerializerFactory.getHL7Serializer(useStrictParser , useStrictValidation, handleRepetitions).fromXML(message);

          method to convert it to HL7 2.x format?

          Or should I read up more on E4X functions/capabilties to transform this payload string into an XML object?

          Thanks Chris....much appreciate the fast responses!

          Comment


          • #6
            Re:HTTP Listener, incoming data format?

            In your transformer (javascript step):
            Code:
            var nonencodedhl7 = Packages.java.net.URLDecoder.decode(msg['payload']);
            To access the HL7 as a message with e4x
            Code:
            var hl7xml = 
            SerializerFactory.getHL7Serializer(false, false, false).toXML(nonencodedhl7);
            msg = new XML(hl7xml);
            Chris Lang

            Comment


            • #7
              Re:HTTP Listener, incoming data format?

              Doh...now why didn't I think of using the Java class? Thanks for the tip!

              I'm not clear on why you are doing the following:

              Code:
              msg = new XML(hl7xml);
              Two questions here:

              1) Isn't the hl7xml variable already an XML structure, as a result of the parsing? Not sure why you're using it as input to the new XML() constructor.

              2) Does the assignment to msg replace the raw message with the parsed XML? I assume that is what it is doing.

              Thanks for clarifying this for me, Chris!

              Comment


              • #8
                Re:HTTP Listener, incoming data format?

                1) No, you need to pass it into the constructor. It is just the XML string - by doing new XML you create an e4x object
                2) Yes, you can set any variable to that
                Chris Lang

                Comment


                • #9
                  Re:HTTP Listener, incoming data format?

                  Thanks...looks like I'm almost there. Just need to transform the XML HL7 into 2.3.1 message format and I'm golden.

                  Many thanks!

                  Comment

                  Working...
                  X