Friday, January 30, 2009

UnsupportedEncodingException: Cp850

I am using JCIFS so that I can use Windows Authentication for my Java web application running under Apache. The authentication prompts me for a username and password as expected when I use FireFox. However, when I access the exact same page using Internet Explorer I get a 500 error, and then I check the apache log and see the following message:

Jan 30, 2009 8:06:52 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
java.io.UnsupportedEncodingException: Cp850
 at sun.io.Converters.getConverterClass(Unknown Source)
 at sun.io.Converters.newConverter(Unknown Source)
 at sun.io.ByteToCharConverter.getConverter(Unknown Source)
 at java.lang.StringCoding.decode(Unknown Source)
 at java.lang.String.<init>(Unknown Source)
 at java.lang.String.<init>(Unknown Source)
 at jcifs.ntlmssp.Type1Message.parse(Type1Message.java:236)
 at jcifs.ntlmssp.Type1Message.<init>(Type1Message.java:86)
 at jcifs.http.NtlmSsp.authenticate(NtlmSsp.java:88)
 at jcifs.http.NtlmHttpFilter.negotiate(NtlmHttpFilter.java:160)
 at jcifs.http.NtlmHttpFilter.doFilter(NtlmHttpFilter.java:114)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
 at java.lang.Thread.run(Unknown Source)


After some digging and reviewing the docs (
https://thea.openintegra.com/project/sauron/browser/vendor/jcifs/current/docs/overview.html?rev=149&format=txt)  for JCIFS, I see that there is a jcifs.encoding property that can be set. The default is Cp850. It appears that Cp850 refers to an encoding. I set the jcifs.encoding to ASCII then Internet Explorer works without prompting for a password and renders the page as expected.

You can set the jcifs.encoding property as described in the JCIFS docs (see above link). I put mine in the Initialization Parameters for the Servlet Filter called NtlmHttpFilter.

I read that you can use Cp1252 instead of ASCII and that should work also, but I have not verified. I also read that Cp850 is in the jre-lib/charsets.jar and that the Cp1252 is in the rt.jar. I tried adding charsets.jar to my class path and it didn't seem to help. 

I read the other way to fix the issue is to install the Enterprise version or at least a version that has the internationalized JVM. I didn't want to change the version of java running on my app server due to change management, etc, but I expect that would have worked. I did not try this solution, but I believe it would work because I didn't have the issue when running locally or on another server. I expect may also have to due with the character set that the target server is set up with. I don't really know where to find that to verify though. Any info on this is appreciated.

No comments: