[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wsf-java-dev
Subject:    Re: [Dev] Cannot assign UTF-8 encoded characters to Jaggery Response
From:       Supun Sethunga <supuns () wso2 ! com>
Date:       2014-11-28 5:58:32
Message-ID: CAMUGTroYfiR1wjnC4e-Yk5HaBt8b7Y_nt1z5HdJi13CgfS0jBA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi Ruchira,

As per the offline discussion, it seems response.content always takes
ISO-8859-1 as the default encoding when setting the response content.
Replacing that line by print(json); can be used as a workaround.

Please find the JIRA created at [1] ;

[1] https://wso2.org/jira/browse/JAGGERY-398

Thanks,
Supun

On Fri, Nov 28, 2014 at 9:30 AM, Supun Sethunga <supuns@wso2.com> wrote:

> Hi,
> 
> The scenario is, there's an backend OSGI service which reads some data
> from a csv file and sends it to the jaggery. The csv file can contain
> characters in different languages as well, hence it is read with UTF-8
> character encoding. When I try to assign the data received from the osgi
> service to the Jaggery response variable, it throws out the following
> exception saying certain characters are not  ISO 8859-1 encoded.
> 
> 
> > *ERROR {org.jaggeryjs.hostobjects.web.ResponseHostObject} -  Error
> > occurred while reading Servlet OutputStream*
> > *java.io.CharConversionException: Not an ISO 8859-1 character: ư*
> > * at javax.servlet.ServletOutputStream.print(ServletOutputStream.java:76)*
> > * at
> > org.jaggeryjs.hostobjects.web.ResponseHostObject.jsSet_content(ResponseHostObject.java:56)*
> >                 
> > * at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)*
> > * at
> > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)*
> > * at
> > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)*
> >                 
> > * at java.lang.reflect.Method.invoke(Method.java:597)*
> > * at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:126)*
> > * at
> > org.mozilla.javascript.ScriptableObject$GetterSlot.setValue(ScriptableObject.java:270)*
> >                 
> > * at
> > org.mozilla.javascript.ScriptableObject.putImpl(ScriptableObject.java:2642)*
> > * at
> > org.mozilla.javascript.ScriptableObject.put(ScriptableObject.java:492)*
> > * at
> > org.mozilla.javascript.ScriptableObject.putProperty(ScriptableObject.java:2347)*
> > * at
> > org.mozilla.javascript.ScriptRuntime.setObjectProp(ScriptRuntime.java:1598)*
> > * at
> > org.mozilla.javascript.ScriptRuntime.setObjectProp(ScriptRuntime.java:1592)*
> > * at
> > org.jaggeryjs.rhino.mlUI.site.importData.ajax.c0._c_script_0(/mlUI/site/importData/ajax/importDataset.jag:35)**
> >  at
> > org.jaggeryjs.rhino.mlUI.site.importData.ajax.c0.call(/mlUI/site/importData/ajax/importDataset.jag)*
> > 
> 
> 
> Error is thrown from the 3rd line of follow. Please refer the attached
> file for the complete error log.
> 
> > 
> > *     response.contentType = "application/json; charset=utf-8";*
> > *     response.characterEncoding = 'UTF-8';**    response.content =
> > JSON.stringify(json);*
> 
> 
> Here 'json' is the data received from the backend service.
> 
> However, this occurs when the csv file contains some Chinese/Latin
> characters and is read as UTF-8. But if the file is read as ISO-8859-1 and
> send to Jaggery, it works.
> 
> Does Jaggery always use the ISO-8859-1 encoding?
> 
> Thanks,
> Supun
> --
> *Supun Sethunga*
> Software Engineer
> WSO2, Inc.
> lean | enterprise | middleware
> Mobile : +94 716546324
> 



-- 
*Supun Sethunga*
Software Engineer
WSO2, Inc.
lean | enterprise | middleware
Mobile : +94 716546324


[Attachment #5 (text/html)]

<div dir="ltr">Hi Ruchira,<div><br></div><div>As per the offline discussion, it seems \
response.content always takes ISO-8859-1 as the default encoding when setting the \
response content. Replacing that line by print(json); can be used as a workaround.  \
</div><div><br></div><div>Please find the JIRA created at [1] \
;</div><div><br></div><div>[1]  <a \
href="https://wso2.org/jira/browse/JAGGERY-398">https://wso2.org/jira/browse/JAGGERY-398</a></div><div><br></div><div>Thanks,</div><div>Supun</div></div><div \
class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 28, 2014 at 9:30 AM, \
Supun Sethunga <span dir="ltr">&lt;<a href="mailto:supuns@wso2.com" \
target="_blank">supuns@wso2.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>The scenario is, \
there&#39;s an backend OSGI service which reads some data from a csv file and sends \
it to the jaggery. The csv file can contain characters in different languages as \
well, hence it is read with UTF-8 character encoding. When I try to assign the data \
received from the osgi service to the Jaggery response variable, it throws out the \
following exception saying certain characters are not   ISO 8859-1 encoded.  \
</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><i>ERROR \
{org.jaggeryjs.hostobjects.web.ResponseHostObject} -   Error occurred while reading \
Servlet OutputStream<br></i><i>java.io.CharConversionException: Not an ISO 8859-1 \
character: ư<br></i><i><span style="white-space:pre-wrap">	</span>at \
javax.servlet.ServletOutputStream.print(ServletOutputStream.java:76)<br></i><i><span \
style="white-space:pre-wrap">	</span>at \
org.jaggeryjs.hostobjects.web.ResponseHostObject.jsSet_content(ResponseHostObject.java:56)<br></i><i><span \
style="white-space:pre-wrap">	</span>at \
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br></i><i><span \
style="white-space:pre-wrap">	</span>at \
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br></i><i><span \
style="white-space:pre-wrap">	</span>at \
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br></i><i><span \
style="white-space:pre-wrap">	</span>at \
java.lang.reflect.Method.invoke(Method.java:597)<br></i><i><span \
style="white-space:pre-wrap">	</span>at \
org.mozilla.javascript.MemberBox.invoke(MemberBox.java:126)<br></i><i><span \
style="white-space:pre-wrap">	</span>at \
org.mozilla.javascript.ScriptableObject$GetterSlot.setValue(ScriptableObject.java:270)<br></i><i><span \
style="white-space:pre-wrap">	</span>at \
org.mozilla.javascript.ScriptableObject.putImpl(ScriptableObject.java:2642)<br></i><i><span \
style="white-space:pre-wrap">	</span>at \
org.mozilla.javascript.ScriptableObject.put(ScriptableObject.java:492)<br></i><i><span \
style="white-space:pre-wrap">	</span>at \
org.mozilla.javascript.ScriptableObject.putProperty(ScriptableObject.java:2347)<br></i><i><span \
style="white-space:pre-wrap">	</span>at \
org.mozilla.javascript.ScriptRuntime.setObjectProp(ScriptRuntime.java:1598)<br></i><i><span \
style="white-space:pre-wrap">	</span>at \
org.mozilla.javascript.ScriptRuntime.setObjectProp(ScriptRuntime.java:1592)<br></i><i><span \
style="white-space:pre-wrap">	</span>at \
org.jaggeryjs.rhino.mlUI.site.importData.ajax.c0._c_script_0(/mlUI/site/importData/ajax/importDataset.jag:35)<br></i><i><span \
style="white-space:pre-wrap">	</span>at \
org.jaggeryjs.rhino.mlUI.site.importData.ajax.c0.call(/mlUI/site/importData/ajax/importDataset.jag)</i></blockquote></div><div><br></div><div>Error \
is thrown from the 3rd line of follow. Please refer the attached file for the \
complete error log.</div><div><blockquote class="gmail_quote" style="margin:0px 0px \
0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><i> \
response.contentType = &quot;application/json; charset=utf-8&quot;;<br></i><i>        \
response.characterEncoding = &#39;UTF-8&#39;;<br></i><i>       response.content = \
JSON.stringify(json);</i></blockquote><div><br></div><div>Here &#39;json&#39; is the \
data received from the backend service.</div><div><br></div><div>However, this occurs \
when the csv file contains some Chinese/Latin characters and is read as UTF-8. But if \
the file is read as ISO-8859-1 and send to Jaggery, it \
works.</div><div><br></div><div>Does Jaggery always use the ISO-8859-1 \
encoding?</div><div><br></div><div>Thanks,</div><div>Supun<span class="HOEnZb"><font \
color="#888888"><br>--  </font></span></div><span class="HOEnZb"><font \
color="#888888"><div><div dir="ltr"><b><font>Supun Sethunga</font></b><div>Software \
Engineer<br></div><div>WSO2, Inc.<br><font size="1">lean | enterprise | \
middleware</font><br></div><div>Mobile : <a href="tel:%2B94%20716546324" \
value="+94716546324" target="_blank">+94 716546324</a></div></div></div> \
</font></span></div></div> </blockquote></div><br><br clear="all"><div><br></div>-- \
<br><div class="gmail_signature"><div dir="ltr"><b><font>Supun \
Sethunga</font></b><div>Software Engineer<br></div><div>WSO2, Inc.<br><font \
size="1">lean | enterprise | middleware</font><br></div><div>Mobile : +94 \
716546324</div></div></div> </div>



_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic