Skip to main content

XmlHttpProxy throws: Exception with xslt, caused by char coding error

5 replies [Last post]
grigoryev_igor
Offline
Joined: 2007-04-25

Hello,

I'm completely new to jmaki and I'm confused with character coding error in XHP servlet. I experimented with feeds integration, and found much of them (e.g. http://www.artima.com/weblogs/feeds/bloggers/beckel.rss) causing exception in XHP (see below).

ERROR: 'org.xml.sax.SAXException: Attempt to output character of integral value 263 that is not represented in specified output encoding of iso-8859-1.'
XmlHttpProxy: Exception with xslt javax.xml.transform.TransformerException: com.sun.org.apache.xalan.internal.xsltc.TransletException: org.xml.sax.SAXException: Attempt to output character of integral value 263 that is not represented in specified output encoding of iso-8859-1.

Does anybody know what to to with that? I'm using Glassfish + NetBeans, in case this matters.

Igor Grigoryev

Message was edited by: grigoryev_igor

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
grigoryev_igor
Offline
Joined: 2007-04-25

Hello once again Greg,

I have just downloaded jMaki sources from CVS repository and analyzed XHP part.
This is a quotation from file XmlHttpProxy.java doGet(...) method:
---------------SKIP-------------
HttpClient httpclient = new HttpClient(proxyHost, proxyPort, urlString);
in = httpclient.getInputStream();
// read the encoding from the incoming document and default to 8859-1
// if an encoding is not provided
String ce = httpclient.getContentEncoding();
if (ce == null) {
String ct = httpclient.getContentType();
if (ct != null) {
int idx = ct.lastIndexOf("charset=");
if (idx >= 0) {
ce = ct.substring(idx+8);
} else {
ce = "iso-8859-1";
}
} else {
ce = "iso-8859-1";
}
}
try {
byte[] buffer = new byte[1024];
int read = 0;
String cType = null;
// write out hte content type
if (format.equals("json")) {
cType = "text/javascript;charset="+ce;
} else {
cType = "text/xml;charset="+ce;
}
if (xslInputStream == null) {
while (true) {
read = in.read(buffer);
if (read <= 0) break;
out.write(buffer, 0, read );
}
} else {
transform(in, xslInputStream, paramsMap, out, ce);
}
} catch (Exception e) {
getLogger().severe("XmlHttpProxy transformation error: " + e);
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.flush();
out.close();
}
} catch (Exception e) {
// do nothing
}
}
------------------SKIP--------------

From here I see that you assume you can get XML-response encoding from HTTP headers. You are not analyzing XML-response content in search for XML 'encoding' attribute like this one . In case of
encoding was not found you are defaulting to "iso-8859-1" not "UTF-8"! (that is in perfect conformity with my problem)

In practice of real imperfect world I found many resources providing RSS-feeds without content-encoding in HTTP headers. But all of them had encoding attribute set correctly in the XML body. So web-applications like Google Reader can deal with them well.

I think that you should provide XHP with XML-response content-encoding analyzing capability or at least provide a way to force content-encoding setting through XHP request parameter in "xhp.json".

gmurray71
Offline
Joined: 2003-07-31

Hi,

Things make a lot more sense now. You are looking at the old deprecated workspace.

The 1.0 XmlHttpProxy uses UTF-8 by default ;-)

https://ajax.dev.java.net/source/browse/ajax/ws/jmaki/shared/src/java/jm...

The 1.0 release also contains the older com.sun.jmaki.* which is deprecated.

Can you try using the:

jmaki.xhp.XmlHttpProxyServlet instead and let us know if you have problems?

Sorry about all the problems.

-Greg

grigoryev_igor
Offline
Joined: 2007-04-25

Hello Greg,

This makes things clear and covers about half a case. But what about those silly resources that use Windows-1251 encoding without providing content-type information by HTTP?

Defaulting to UTF-8 is great, but It would be truly helpful option to force encoding by hands after all.

Example: (I mean through an argument like )

Thank you for assistance,

Igor

gmurray71
Offline
Joined: 2003-07-31

Hi Igor,

Sorry about the slow response.

I was just looking this issue and not able to replicate it.

I have the following settings in my xhp.json file:

{"id": "rss",
"url":"http://www.artima.com/weblogs/feeds/bloggers/beckel.rss",
"xslStyleSheet": "rss.xsl"
}

Then I am using a jmaki.blockList widget to display the feed:

service="/xhp?id=rss"
/>

The feed displays fine without any errors.

The XHP should use UTF-8 as the default encoding.

How are you accessing the proxy? This could help a bit in debugging this.

-Greg

grigoryev_igor
Offline
Joined: 2007-04-25

Hello Greg,

Excuse me, but I've just found your answer on this forum. I'm continuing to experience this kind of problem now with this URLs:

- http://www.autonews.ru/rss/auto_news.xml
- http://www.drive.ru/export/rss.xml

Server version used:
Sun Java System Application Server Platform Edition 9.0_01 (build )

Errors:

ERROR: 'org.xml.sax.SAXException: Attempt to output character of integral value 1053 that is not represented in specified output encoding of iso-8859-1.'
XmlHttpProxy: Exception with xslt javax.xml.transform.TransformerException: com.sun.org.apache.xalan.internal.xsltc.TransletException: org.xml.sax.SAXException: Attempt to output character of integral value 1053 that is not represented in specified output encoding of iso-8859-1.

ERROR: 'org.xml.sax.SAXException: Attempt to output character of integral value 1059 that is not represented in specified output encoding of iso-8859-1.'
XmlHttpProxy: Exception with xslt javax.xml.transform.TransformerException: com.sun.org.apache.xalan.internal.xsltc.TransletException: org.xml.sax.SAXException: Attempt to output character of integral value 1059 that is not represented in specified output encoding of iso-8859-1.

My xhp.json contains this

{"id": "rss",
"url":"http://www.autonews.ru/rss/auto_news.xml",
"xslStyleSheet": "rss.xsl"
}

index.jsp contains this:

Message was edited by: grigoryev_igor

Message was edited by: grigoryev_igor