Announcement Announcement Module
Collapse
No announcement yet.
how to reslove special character in expression Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to reslove special character in expression

    Hi Guys,

    i have a int-http:inbound-gateway(it has reply channel). i also defined a filter and filter's discard channel.

    when message goes to discard channel, i directly use <int:transformer expression="'some text...'" /> to define the error text and finally link the transformer to the reply channel, but the text has some special character, like "".
    So the problem is that the "" cannot be shown correctly,it becomes a garbled character.

    i tried this way:
    Code:
    <int:transformer expression="new String(''.getBytes('UTF8'))" />
    or use unicode of "":
    Code:
    <int:transformer expression="new String('\u00EB')" />
    , but it still cannot work.

    Any suggestion?

    Thanks in advance!

  • #2
    This works fine for me...

    Code:
    expression="''"

    Comment


    • #3
      Originally posted by Gary Russell View Post
      This works fine for me...

      Code:
      expression="''"
      Thanks for your reply, Gary.

      I tried only put in expression, but it still cannot work. any possibility that my test machine(centos6) or tomcat itself needs some encode configuration?

      Comment


      • #4
        Can you provide the exact expression you are using and exactly what the "garbled character" contains?

        Comment


        • #5
          Originally posted by Gary Russell View Post
          Can you provide the exact expression you are using and exactly what the "garbled character" contains?
          the expression:
          Code:
          <int:transformer expression="'De opgevraagde patintgegevens komen niet overeen met de gegevens van'" />
          the garbled character:
          Attachment
          Attached Files

          Comment


          • #6
            It might be just that the tool you are using to look at the response doesn't understand how to render this character. I would suggest you take a look with a debugger exactly what's in the String.

            When I pasted your text into a file with an editor that understands UTF-8, the character gets expanded to 2 bytes...

            Code:
            00000000  44 65 20 6f 70 67 65 76  72 61 61 67 64 65 20 70  |De opgevraagde p|
            00000010  61 74 69 c3 ab 6e 74 67  65 67 65 76 65 6e 73 20  |ati..ntgegevens |
            (c3ab)

            This is rendered in the eclipse text editor as "De opgevraagde pati��n..." (2 black ?).

            What else is in the flow, between the transformer and whatever this tool is looking at?

            If you are later converting from the String to byte[], you may need to explicitly use UTF-8.

            Comment


            • #7
              the text can be rendered in eclipse if you configure the "Text file encoding" as UTF-8. I can see it correctly in my STS.
              I saw the "�" in the console of chrome's "developer tool", the tool can directly check the content of request and response.
              Do you mean i should take a look the log of spring integration to see what's in there?

              there is no special thing between transformer, just a chain and int:header-enricher and the transformer, the last step is link the chain to my reply channel of http inbound gateway.

              Code:
              <int:chain input-channel="not-match-channel" output-channel="reply-channel">
                      <int:header-enricher>
                          <int:header name="http_statusCode" value="500" />
                      </int:header-enricher>
                      <int:transformer expression="'De opgevraagde pati�ntgegevens komen niet overeen met de gegevens van'" />
              </int:chain>
              
              <int:channel id="reply-channel" />
              
              <int-http:inbound-gateway path="/***/" request-payload-type="java.lang.String" supported-methods="POST" request-channel="http-inbound-channel" error-channel="http-inbound-error-channel" reply-channel="reply-channel" />

              Comment


              • #8
                Originally posted by Gary Russell View Post
                If you are later converting from the String to byte[], you may need to explicitly use UTF-8.
                besides, what do you mean by this? can you give me a code example?

                Comment


                • #9
                  HTTP doesn't understand Unicode strings; when the String is rendered by the Web infrastructure, the String will be converted to bytes using something like string.getBytes(charset) where charset will default to the platform's charset; if you want it rendered as UTF-8 you'd use string.getBytes("UTF-8").

                  I am not familiar enough with Spring MVC internals to know how you can influence this; maybe setting the content encoding to UTF-8 would work. I'll dig into the code when I get a chance.

                  Comment


                  • #10
                    i already tried this
                    Code:
                    <int:transformer expression="new String(''.getBytes('UTF8'))" />
                    , but it didn't work.

                    thank you for the reply anyway, please leave message here if you find something out later.

                    Comment


                    • #11
                      That's not what I mean; this conversion is back in the inbound gateway when converting the output data to bytes.

                      I looked at the code some more; add a header-enricher to set the content-type header with the required encoding; for example...

                      Code:
                      content-type=text/plain;charset=UTF-8
                      ...will force the StringHttpMessageConverter to use UTF-8 to encode the String.

                      I am guessing that it is currently using some default encoding.

                      Comment

                      Working...
                      X