<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Problem in retrieving WSDL from remote endpoint
</h3>
<span style="margin-bottom: 10px;">
    reply from <a href="http://community.jboss.org/people/dward">David Ward</a> in <i>JBoss ESB Development</i> - <a href="http://community.jboss.org/message/539893#539893">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>The problem is more pervasive than I realized, but I do have a fix.&#160; There are a couple issues that need to be discussed, however, so in the end it is a good thing that this is in the developer forum.&#160; <span> ;) </span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>First, the fix:</p><ol><li>StreamUtils.readStreamString(stream, charset):String was incorrectly implemented.&#160; It just read in the bytes and created a new String object with the bytes and the specified charset.&#160; This will <em>not</em> convert the bytes into the specified charset.&#160; So, if the bytes you are reading in are character encoded with KOI8-R instead of UTF-8, for example, then when you output that String, the characters will be garbled.&#160; (For example, in Firefox, they will become question marks.)&#160; Unfortunately, there is <em>nothing</em> in the JDK that can determine what character encoding a set of bytes or stream is, and this is paramount to creating a String that can be outputted correctly.&#160; There is InputStreamReader, but you have to know the encoding of the stream first.&#160;&#160; <span> :( </span>&#160; Luckily, there is a utility out there we can use: <a class="jive-link-external-small" href="http://site.icu-project.org/">ICU4J</a>.&#160; What I did to fix the method was call upon a <a class="jive-link-external-small" href="http://icu-project.org/apiref/icu4j/com/ibm/icu/text/CharsetDetector.html#getString(byte[], java.lang.String)">helper method in CharsetDetector</a>.</li><li>Next, the HttpGatewayServlet (which is sometimes used for exposing WSDL via &lt;http-gateway/&gt;, for example, for SOAPProxy) had to be changed to get the now UTF-8 encoded bytes, and output that, making sure to set the Content-Length response header to the length of the byte array, <em>not</em> the length of the String: <a class="jive-link-external-small" href="http://mark.koli.ch/2009/09/remember-kids-an-http-content-length-is-the-number-of-bytes-not-the-number-of-characters.html">http://mark.koli.ch/2009/09/remember-kids-an-http-content-length-is-the-number-of-bytes-not-the-number-of-characters.html</a></li><li>Finally, the contract.jsp page (which is sometimes used for exposing WSDL via &lt;jbr-provider/&gt;) had to be changed to declare &lt;%@page contentType="text/xml; charset=UTF-8"%&gt; at the top of the page, so that &lt;%=contractData=&gt; would be outputted correctly.&#160; See notes on JSP page directive and its effect here: <a class="jive-link-external-small" href="http://www.w3.org/International/O-HTTP-charset">http://www.w3.org/International/O-HTTP-charset</a></li></ol><p>After making the changes above, I tested successfully using both JDK 5 + ESB in AS4, and JDK 6 + ESB in AS 5.&#160; I also ran a clean integration build.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Next, the two issues that have to be discussed:</p><ol><li>Are we allowed to add icu4j-4_4.jar and icu4j-charsets-4_4.jar as project dependencies, and ship them with both our community ESB and supported SOA Platform?&#160; I can't seem to find out what the ICU4J license is...</li><li>While correcting the implementation of StreamUtils.readStreamString(stream, charset):String, any code that called that method will now be guaranteed correct character encoding.&#160; <em>However</em>, any code which calls the underlying StreamUtils.readStream(stream):byte[] method, and decides to create it's <em>own</em> String from the returned byte array (instead of just using readStreamString) could have a misinterpretted character encoding problem.&#160; This is all over the place in our code, and I'm a bit hesitant to go change all of it.&#160; Maybe for the purpose of this bug, we just stick to fixing the WSDL encoding problem?&#160; Luckily, this problem only rears its head if the stream being read contains an extended character set and not UTF-8 (like KOI8-R or cp1251, for example).</li></ol><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Feedback appreciated.&#160; Thanks!</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/539893#539893">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss ESB Development at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2032">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>