Using an Extra CharsetProvider in a Servlet

2003-08-14 Thread Johan Krisar
I'm messing around with character sets and character set conversions, and 
have a problem getting it to work in servlets. Installing an additional 
Charset requires entries in the file java.nio.charset.spi.CharsetProvider 
in META-INF/services. My problem is in understanding exactly WHAT META-INF 
directory I should place this file in...

So far, the only way I've been able to get things to work properly, is to 
unpack the $CATALINA_HOME/bin/bootstrap.jar, add my Charset, 
CharsetProvider, CharsetEncoder and CharsetDecoder classes to it, change 
the META-INF, and re-pack the bootstrap jar. However, this does seem a 
rather "hacky" way to get things working...

Actually, I found that James Manger had exactly the same problem about a 
year ago. I include his original posting, as it formulates the problem 
rather well:


I would like to use a non-standard character set for selected operations
within a servlet.  I have implemented a CharsetProvider, Charset,
CharsetEncoder & CharsetDecoder.
I can use my new character set from a Java application by listing the
CharsetProvider class name in the following file within the application JAR.
META-INF/services/java.nio.charset.spi.CharsetProvider
(see API for CharsetProvider)
My application (without any particular "import" statements) can make calls
such as:
String msg = "Hello, World!";
byte[] encoding = msg.getBytes("MY-CHARSET");
I cannot get these lines to work in a servlet -- the
msg.getBytes("MY-CHARSET") throws:
java.nio.charset.UnsupportedCharsetException: MY-CHARSET
QUESTION: How do I tell the system running my servlet about my character
set?
Adding a JAR with the character set (and META-INF... file) to the jre/ext/
directory makes the character set available to all Java apps - but not to
the servlet!  Adding the JAR to tomcat/common/lib/ did not seem to work
either.
My servlet can see my CharsetProvider class, but my CharsetProvider is not
"registered" with the system (and it needs to be "registered" for
String.getBytes("MY-CHARSET") to work).
[JWSDP 1.0_01, J2SE 1.4.0_01, Tomcat 4.1.2, SunOS 5.6]

James Manger


Unlike James, I'm using J2SE 1.4.1_02-b06, Tomcat 4.1.18 and RedHat 8.0.

Happy for any clue anyone may be able to provide!

Cheers,

- Johan

---
  Johan Krisár,
  johan.krisar(at)depicta.com


Tomcat: using an extra CharsetProvider in a servlet

2002-10-11 Thread Manger, James H

I would like to use a non-standard character set for selected operations
within a servlet.  I have implemented a CharsetProvider, Charset,
CharsetEncoder & CharsetDecoder.

I can use my new character set from a Java application by listing the
CharsetProvider class name in the following file within the application JAR.
META-INF/services/java.nio.charset.spi.CharsetProvider
(see API for CharsetProvider)

My application (without any particular "import" statements) can make calls
such as:
String msg = "Hello, World!";
byte[] encoding = msg.getBytes("MY-CHARSET");

I cannot get these lines to work in a servlet -- the
msg.getBytes("MY-CHARSET") throws:
java.nio.charset.UnsupportedCharsetException: MY-CHARSET

QUESTION: How do I tell the system running my servlet about my character
set?

Adding a JAR with the character set (and META-INF... file) to the jre/ext/
directory makes the character set available to all Java apps - but not to
the servlet!  Adding the JAR to tomcat/common/lib/ did not seem to work
either.

My servlet can see my CharsetProvider class, but my CharsetProvider is not
"registered" with the system (and it needs to be "registered" for
String.getBytes("MY-CHARSET") to work).

[JWSDP 1.0_01, J2SE 1.4.0_01, Tomcat 4.1.2, SunOS 5.6]

James Manger

--
To unsubscribe, e-mail:   
For additional commands, e-mail: