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 Cp850
 at Source)
 at Source)
 at 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(
 at jcifs.ntlmssp.Type1Message.<init>(
 at jcifs.http.NtlmSsp.authenticate(
 at jcifs.http.NtlmHttpFilter.negotiate(
 at jcifs.http.NtlmHttpFilter.doFilter(
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(
 at org.apache.catalina.core.StandardWrapperValve.invoke(
 at org.apache.catalina.core.StandardContextValve.invoke(
 at org.apache.catalina.core.StandardHostValve.invoke(
 at org.apache.catalina.valves.ErrorReportValve.invoke(
 at org.apache.catalina.core.StandardEngineValve.invoke(
 at org.apache.catalina.connector.CoyoteAdapter.service(
 at org.apache.coyote.http11.Http11Processor.process(
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(
 at Source)

After some digging and reviewing the docs (  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: