You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Peuclid <pe...@thebernsteins.com> on 2004/11/17 18:39:41 UTC
Call with different character encoding
We have a service set up which is working fine so far, but now our
client is requesting that we return our data in ISO-8859-1 instead of
UTF-8.
I've suggested that we stick with UTF-8 since it is more flexible, but
it seems that their system isn't able to handle UTF-8 for some reason.
In most cases, the encoding doesn't really matter, but when we have
some data with bullet characters and curly-quotes, they find that the
data is garbled from their end, as one would expect.
We had been using axis1.1, and I noticed that UTF-8 was hard-coded in
many places, but I see that axis1.2 does have some configurability for
the encoding.
So, just to start, I'm trying to get my test client to request the data
in ISO-8859-1 just to see what happens when I change the global
"axis.xmlEncoding" to ISO-8859-1. So far, that doesn't seem to be
changing the default anywhere. Looking at the AxisServlet code, I see
that the encoding is set by the request.
So, now I need to figure out how to set the encoding of the request.
My test jsp page just uses an html form to let the user enter the xml
expression to pass to the service. This works fine, but it always sends
it to the service in utf-8.
Here is an excerpt of the code:
String endpoint = ""; // url of the endpoint
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL( endpoint ) );
call.setOperationName( new QName( "http://soapinterop.org/",
"MyTestRequest" ) );
document = (Document) call.invoke( new Object[] { xml } );
I've tried including an encoding header on the xml which (as expected)
didn't magically change the request encoding into iso-8859-1.
Is there any way to tell Call to make it's request in iso-8859-1?
And the followup question might be: Is this going to result in the
response being sent in that same encoding as the request?
Thanks for the help.
Bernie
Re: Call with different character encoding
Posted by Bernie Bernstein <pe...@thebernsteins.com>.
I just submitted it to JIRA:
http://nagoya.apache.org/jira/browse/AXIS-1682
thanks for the help.
Bernie
On Nov 23, 2004, at 6:58 PM, Davanum Srinivas wrote:
> Looks like a useful change...can you please open a JIRA enhancement
> request?
> dims
>
> On Tue, 23 Nov 2004 13:55:32 -0500, Bernie Bernstein
> <pe...@thebernsteins.com> wrote:
>> I found a much easier way to do this by making only a minor
>> modification to org.apache.axis.client.Call.java.
>>
>> I added a new property:
>>
>> public static final String CHARACTER_SET_ENCODING =
>> SOAPMessage.CHARACTER_SET_ENCODING;
>> On Nov 17, 2004, at 4:21 PM, Bernie Bernstein wrote:
>>> I managed to do it by copy/pasting some code from
>>> org.apache.axis.client.Call.
>>>
>>> It wasn't easy, but it involved creating a new Message object,
>>> setting
>>> it's char encoding to "ISO-8859-1", and then assembling the envelope
>>> to send to Call.
>>>
>>>
>>> On Nov 17, 2004, at 12:39 PM, Peuclid wrote:
>>>> So, just to start, I'm trying to get my test client to request the
>>>> data in ISO-8859-1 just to see what happens when I change the global
>>>> "axis.xmlEncoding" to ISO-8859-1. So far, that doesn't seem to be
>>>> changing the default anywhere. Looking at the AxisServlet code, I
>>>> see
>>>> that the encoding is set by the request.
>>>>
>>>> So, now I need to figure out how to set the encoding of the request.
>>>
>>
>>
>
>
> --
> Davanum Srinivas - http://webservices.apache.org/~dims/
>
Re: Call with different character encoding
Posted by Davanum Srinivas <da...@gmail.com>.
Bernie,
Looks like a useful change...can you please open a JIRA enhancement request?
thanks,
dims
On Tue, 23 Nov 2004 13:55:32 -0500, Bernie Bernstein
<pe...@thebernsteins.com> wrote:
> I found a much easier way to do this by making only a minor
> modification to org.apache.axis.client.Call.java.
>
> I added a new property:
>
> public static final String CHARACTER_SET_ENCODING =
> SOAPMessage.CHARACTER_SET_ENCODING;
>
> and made the appropriate changes in the property checking code.
> Then in invoke(SOAPEnvelope), it sets the message
> CHARACTER_SET_ENCODING to the one set in the Call.
>
> if (getProperty(CHARACTER_SET_ENCODING) != null) {
> msg.setProperty(SOAPMessage.CHARACTER_SET_ENCODING,
> getProperty(CHARACTER_SET_ENCODING));
> }
>
> Here's the 'diff -u' for Call.java (for 1.2RC2):
>
> --- Call.java Tue Nov 16 13:04:43 2004
> +++
> /Users/bernard/src/jiveall/liveforum/WEB-INF/classes/org/apache/axis/
> client/Call.java Fri Nov 19 09:24:19 2004
> @@ -113,6 +113,8 @@
> * TIMEOUT - Timeout used by transport sender in
> milliseconds
> * TRANSPORT_NAME - Name of transport handler to use
> * ATTACHMENT_ENCAPSULATION_FORMAT- Send attachments as MIME the
> default, or DIME.
> + * CHARACTER_SET_ENCODING - Character set encoding to use for
> request
> + *
> * </pre>
> *
> * @author Doug Davis (dug@us.ibm.com)
> @@ -183,6 +185,13 @@
> public static final String TRANSPORT_NAME = "transport_name" ;
>
> /**
> + * This is the character set encoding to use for the message
> + *
> + * @see #setProperty
> + */
> + public static final String CHARACTER_SET_ENCODING =
> SOAPMessage.CHARACTER_SET_ENCODING;
> +
> + /**
> * This is not the name of a property that can be set with
> * setProperty, despite its name.
> */
> @@ -440,6 +449,9 @@
> verifyBooleanProperty(name, value);
> setStreaming(((Boolean) value).booleanValue());
> }
> + else if (name.equals(CHARACTER_SET_ENCODING)) {
> + verifyStringProperty(name, value);
> + }
> else if (name.startsWith("java.") ||
> name.startsWith("javax.")) {
> throw new JAXRPCException(
> Messages.getMessage("badProp05", name));
> @@ -544,6 +556,7 @@
> propertyNames.add(TRANSPORT_NAME);
> propertyNames.add(ATTACHMENT_ENCAPSULATION_FORMAT);
> propertyNames.add(CONNECTION_TIMEOUT_PROPERTY);
> + propertyNames.add(CHARACTER_SET_ENCODING);
> }
>
> public Iterator getPropertyNames() {
> @@ -1849,7 +1862,10 @@
> Message msg = null ;
>
> msg = new Message( env );
> - if
> (msgContext.getProperty(SOAPMessage.CHARACTER_SET_ENCODING) != null) {
> + if (getProperty(CHARACTER_SET_ENCODING) != null) {
> + msg.setProperty(SOAPMessage.CHARACTER_SET_ENCODING,
> getProperty(CHARACTER_SET_ENCODING));
> + }
> + else if
> (msgContext.getProperty(SOAPMessage.CHARACTER_SET_ENCODING) != null) {
> msg.setProperty(SOAPMessage.CHARACTER_SET_ENCODING,
> msgContext.getProperty(SOAPMessage.CHARACTER_SET_ENCODING));
> }
> setRequestMessage( msg );
>
> I'm new to the Axis project group. Is there an appropriate way to
> submit this for insertion into the project? Perhaps there is a better
> way to do this that I haven't heard of yet, but I haven't found one
> yet. This code will make it possible to set the Character encoding to
> anything when making the Call.
>
> To use it, you'd just use the setProperty() method to set the
> Call.CHARACTER_SET_ENCODING property to whatever character encoding you
> want before invoking the call.
>
> eg:
>
> call.setProperty(Call.CHARACTER_SET_ENCODING, "ISO-8859-1");
>
> Bernie
>
>
>
>
> On Nov 17, 2004, at 4:21 PM, Bernie Bernstein wrote:
> > I managed to do it by copy/pasting some code from
> > org.apache.axis.client.Call.
> >
> > It wasn't easy, but it involved creating a new Message object, setting
> > it's char encoding to "ISO-8859-1", and then assembling the envelope
> > to send to Call.
> >
> >
> > On Nov 17, 2004, at 12:39 PM, Peuclid wrote:
> >> So, just to start, I'm trying to get my test client to request the
> >> data in ISO-8859-1 just to see what happens when I change the global
> >> "axis.xmlEncoding" to ISO-8859-1. So far, that doesn't seem to be
> >> changing the default anywhere. Looking at the AxisServlet code, I see
> >> that the encoding is set by the request.
> >>
> >> So, now I need to figure out how to set the encoding of the request.
> >
>
>
--
Davanum Srinivas - http://webservices.apache.org/~dims/
Re: Call with different character encoding
Posted by Bernie Bernstein <pe...@thebernsteins.com>.
I found a much easier way to do this by making only a minor
modification to org.apache.axis.client.Call.java.
I added a new property:
public static final String CHARACTER_SET_ENCODING =
SOAPMessage.CHARACTER_SET_ENCODING;
and made the appropriate changes in the property checking code.
Then in invoke(SOAPEnvelope), it sets the message
CHARACTER_SET_ENCODING to the one set in the Call.
if (getProperty(CHARACTER_SET_ENCODING) != null) {
msg.setProperty(SOAPMessage.CHARACTER_SET_ENCODING,
getProperty(CHARACTER_SET_ENCODING));
}
Here's the 'diff -u' for Call.java (for 1.2RC2):
--- Call.java Tue Nov 16 13:04:43 2004
+++
/Users/bernard/src/jiveall/liveforum/WEB-INF/classes/org/apache/axis/
client/Call.java Fri Nov 19 09:24:19 2004
@@ -113,6 +113,8 @@
* TIMEOUT - Timeout used by transport sender in
milliseconds
* TRANSPORT_NAME - Name of transport handler to use
* ATTACHMENT_ENCAPSULATION_FORMAT- Send attachments as MIME the
default, or DIME.
+ * CHARACTER_SET_ENCODING - Character set encoding to use for
request
+ *
* </pre>
*
* @author Doug Davis (dug@us.ibm.com)
@@ -183,6 +185,13 @@
public static final String TRANSPORT_NAME = "transport_name" ;
/**
+ * This is the character set encoding to use for the message
+ *
+ * @see #setProperty
+ */
+ public static final String CHARACTER_SET_ENCODING =
SOAPMessage.CHARACTER_SET_ENCODING;
+
+ /**
* This is not the name of a property that can be set with
* setProperty, despite its name.
*/
@@ -440,6 +449,9 @@
verifyBooleanProperty(name, value);
setStreaming(((Boolean) value).booleanValue());
}
+ else if (name.equals(CHARACTER_SET_ENCODING)) {
+ verifyStringProperty(name, value);
+ }
else if (name.startsWith("java.") ||
name.startsWith("javax.")) {
throw new JAXRPCException(
Messages.getMessage("badProp05", name));
@@ -544,6 +556,7 @@
propertyNames.add(TRANSPORT_NAME);
propertyNames.add(ATTACHMENT_ENCAPSULATION_FORMAT);
propertyNames.add(CONNECTION_TIMEOUT_PROPERTY);
+ propertyNames.add(CHARACTER_SET_ENCODING);
}
public Iterator getPropertyNames() {
@@ -1849,7 +1862,10 @@
Message msg = null ;
msg = new Message( env );
- if
(msgContext.getProperty(SOAPMessage.CHARACTER_SET_ENCODING) != null) {
+ if (getProperty(CHARACTER_SET_ENCODING) != null) {
+ msg.setProperty(SOAPMessage.CHARACTER_SET_ENCODING,
getProperty(CHARACTER_SET_ENCODING));
+ }
+ else if
(msgContext.getProperty(SOAPMessage.CHARACTER_SET_ENCODING) != null) {
msg.setProperty(SOAPMessage.CHARACTER_SET_ENCODING,
msgContext.getProperty(SOAPMessage.CHARACTER_SET_ENCODING));
}
setRequestMessage( msg );
I'm new to the Axis project group. Is there an appropriate way to
submit this for insertion into the project? Perhaps there is a better
way to do this that I haven't heard of yet, but I haven't found one
yet. This code will make it possible to set the Character encoding to
anything when making the Call.
To use it, you'd just use the setProperty() method to set the
Call.CHARACTER_SET_ENCODING property to whatever character encoding you
want before invoking the call.
eg:
call.setProperty(Call.CHARACTER_SET_ENCODING, "ISO-8859-1");
Bernie
On Nov 17, 2004, at 4:21 PM, Bernie Bernstein wrote:
> I managed to do it by copy/pasting some code from
> org.apache.axis.client.Call.
>
> It wasn't easy, but it involved creating a new Message object, setting
> it's char encoding to "ISO-8859-1", and then assembling the envelope
> to send to Call.
>
>
> On Nov 17, 2004, at 12:39 PM, Peuclid wrote:
>> So, just to start, I'm trying to get my test client to request the
>> data in ISO-8859-1 just to see what happens when I change the global
>> "axis.xmlEncoding" to ISO-8859-1. So far, that doesn't seem to be
>> changing the default anywhere. Looking at the AxisServlet code, I see
>> that the encoding is set by the request.
>>
>> So, now I need to figure out how to set the encoding of the request.
>
Re: Call with different character encoding
Posted by Bernie Bernstein <pe...@thebernsteins.com>.
I managed to do it by copy/pasting some code from
org.apache.axis.client.Call.
It wasn't easy, but it involved creating a new Message object, setting
it's char encoding to "ISO-8859-1", and then assembling the envelope to
send to Call.
Then to deal with the response, the code needed to get the body
element, and extract the RPCParams from it.
As a newcomer to Axis, this was a good learning experience, and I am
getting a better feel for how all this works. No need to comment on the
details of my lack of error checking, etc, but I wouldn't mind finding
a simpler way to do this.
Here is my new much longer snippet of how I made the call in ISO-8859-1.
// before this code runs, these are set: namespace, method, xml,
endpoint, document
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL( endpoint ) );
call.setOperationName( new QName( namespace, method ) );
MessageContext msgContext = call.getMessageContext();
SOAPEnvelope env = null ;
env = new SOAPEnvelope(msgContext.getSOAPConstants(),
msgContext.getSchemaVersion());
RPCParam param = new RPCParam(namespace, method, xml);
RPCElement body = new RPCElement(namespace, method, new
Object[] { param });
env.addBodyElement((SOAPBodyElement) body);
Message msg = new Message( env );
msg.setProperty(SOAPMessage.CHARACTER_SET_ENCODING,
"ISO-8859-1");
call.setRequestMessage(msg);
call.invoke();
msg = msgContext.getResponseMessage();
if (msg == null) {
if (msgContext.isPropertyTrue(Call.FAULT_ON_NO_RESPONSE,
false)) {
System.out.println("Axis Fault");
} else {
System.out.println("Error");
}
}
env = msg.getSOAPEnvelope();
SOAPBodyElement bodyEl = env.getFirstBody();
if (bodyEl instanceof RPCElement) {
Vector resArgs = null ;
try {
resArgs = ((RPCElement) bodyEl).getParams();
} catch (Exception e) {
System.out.println("Error making resArgs: "+e);
}
if (resArgs != null && resArgs.size() > 0) {
for (int i = 0; i < resArgs.size(); i++) {
RPCParam p1 = (RPCParam) resArgs.get(i);
Object value = p1.getObjectValue();
if (value instanceof Document) {
document = (Document)value;
}
}
}
}
On Nov 17, 2004, at 12:39 PM, Peuclid wrote:
> So, just to start, I'm trying to get my test client to request the
> data in ISO-8859-1 just to see what happens when I change the global
> "axis.xmlEncoding" to ISO-8859-1. So far, that doesn't seem to be
> changing the default anywhere. Looking at the AxisServlet code, I see
> that the encoding is set by the request.
>
> So, now I need to figure out how to set the encoding of the request.