[JBossWS] - Web Service Response encoding problem
by AndersM
Hi,
I'm having problem with the encoding of java.lang.String in my Web Service response.
Seems like a String in a complex data structure will be returned as ISO-8859-1 instead of UTF-8.
If the WebMethod only returns a String it will be interpreted correctly as UTF-8. Very odd.
I've written a small example made up of one interface:
package se.test.webservice.bean;
|
| @javax.jws.WebService
| @javax.jws.soap.SOAPBinding(style = javax.jws.soap.SOAPBinding.Style.RPC)
| public interface Text extends java.rmi.Remote {
| @javax.jws.WebMethod(operationName = "TEST1")
| String test1((a)javax.jws.WebParam(name = "Text1")
| String x);
|
| @javax.jws.WebMethod(operationName = "TEST2")
| String[] test2((a)javax.jws.WebParam(name = "Text2")
| String x);
| }
and a stateless session bean:
package se.test.webservice.bean;
|
| @javax.ejb.Stateless
| @javax.jws.WebService(endpointInterface = "se.test.webservice.bean.Text")
| public class TextBean {
| public String test1(String x) {
| return ">" + x + "<";
| }
|
| public String[] test2(String x) {
| String[] returnValue = {">" + x + "<", ">" + x + "<"};
| return returnValue;
| }
| }
The jar is deployed on JBoss AS 4.2.1.GA.
Calling method TEST1, I'm using the Web Service Explorer from within Eclipse, with a character string containing Swedish special characters "üåäöÜÅÄÖÂ" (I hope these will come out OK when I submit this post) the response looks fine. But calling method TEST2 with the same string will produce a response that looks like it is UTF-8 characters interpreted as ISO-8859-1: "üÃ¥äöÃÅÃâ¦ÃâÃâÂ". Strange.
This is the produced wsdl:
<definitions name='TextBeanService'
| targetNamespace='http://bean.webservice.test.se/'
| xmlns='http://schemas.xmlsoap.org/wsdl/'
| xmlns:ns1='http://jaxb.dev.java.net/array'
| xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
| xmlns:tns='http://bean.webservice.test.se/'
| xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
| <types>
| <xs:schema targetNamespace='http://jaxb.dev.java.net/array'
| version='1.0' xmlns:xs='http://www.w3.org/2001/XMLSchema'>
| <xs:complexType final='#all' name='stringArray'>
| <xs:sequence>
| <xs:element maxOccurs='unbounded' minOccurs='0'
| name='item' nillable='true' type='xs:string' />
| </xs:sequence>
| </xs:complexType>
| </xs:schema>
|
| </types>
| <message name='Text_TEST2'>
| <part name='Text2' type='xsd:string'></part>
| </message>
| <message name='Text_TEST1'>
| <part name='Text1' type='xsd:string'></part>
| </message>
| <message name='Text_TEST2Response'>
| <part name='return' type='ns1:stringArray'></part>
|
| </message>
| <message name='Text_TEST1Response'>
| <part name='return' type='xsd:string'></part>
| </message>
| <portType name='Text'>
| <operation name='TEST1' parameterOrder='Text1'>
| <input message='tns:Text_TEST1'></input>
| <output message='tns:Text_TEST1Response'></output>
| </operation>
|
| <operation name='TEST2' parameterOrder='Text2'>
| <input message='tns:Text_TEST2'></input>
| <output message='tns:Text_TEST2Response'></output>
| </operation>
| </portType>
| <binding name='TextBinding' type='tns:Text'>
| <soap:binding style='rpc'
| transport='http://schemas.xmlsoap.org/soap/http' />
| <operation name='TEST1'>
| <soap:operation soapAction='' />
|
| <input>
| <soap:body namespace='http://bean.webservice.test.se/'
| use='literal' />
| </input>
| <output>
| <soap:body namespace='http://bean.webservice.test.se/'
| use='literal' />
| </output>
| </operation>
| <operation name='TEST2'>
| <soap:operation soapAction='' />
|
| <input>
| <soap:body namespace='http://bean.webservice.test.se/'
| use='literal' />
| </input>
| <output>
| <soap:body namespace='http://bean.webservice.test.se/'
| use='literal' />
| </output>
| </operation>
| </binding>
| <service name='TextBeanService'>
|
| <port binding='tns:TextBinding' name='TextBeanPort'>
| <soap:address
| location='http://127.0.0.1:8080/TextBeanService/TextBean' />
| </port>
| </service>
| </definitions>
This is the response from TEST1:
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
| <env:Header />
| <env:Body>
| <ns0:TEST1Response
| xmlns:ns0="http://bean.webservice.test.se/">
| <return>>üåäöÜÅÄÖ<</return>
| </ns0:TEST1Response>
| </env:Body>
| </env:Envelope>
And the response from TEST2:
| <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
| <env:Header />
| <env:Body>
| <ns0:TEST2Response
| xmlns:ns0="http://bean.webservice.test.se/">
| <return>
| <item>>üÃ¥äöÃÅÃâ¦ÃâÃâÂ<</item>
| <item>>üÃ¥äöÃÅÃâ¦ÃâÃâÂ<</item>
| </return>
| </ns0:TEST2Response>
| </env:Body>
| </env:Envelope>
I hope someone can shed some light on the problem.
I looked at the preview and of course all the characters looked like crap.
I'll try to restore them above but if I fail the correct version of the characters should look like "üåäöÃÃ
ÃÃ" or "üåäöÜÅÄÖ" whatever version looks best.
I wont even try to fix the TEST2-response.
Regards,
Anders
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4114381#4114381
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4114381
17 years
[JBossWS] - Re: JBoss Hanging on start up during Web Service ServletCont
by hopkinst
Here is the web.xml that contains the listener.
<?xml version="1.0" encoding="UTF-8"?>
| <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
| <display-name>SSDIWeb</display-name>
|
| <listener>
| <listener-class>com.ctc.ssdi.SSDIWebInitialization</listener-class>
| </listener>
|
| <servlet>
| <servlet-name>ASIA</servlet-name>
| <servlet-class>com.ctc.ssdi.asia.ASIA</servlet-class>
| <load-on-startup>1</load-on-startup>
| </servlet>
| <servlet>
| <servlet-name>COMEXIA</servlet-name>
| <servlet-class>com.ctc.ssdi.comexia.COMEXIA</servlet-class>
| <load-on-startup>1</load-on-startup>
| </servlet>
| <servlet>
| <servlet-name>DESSIA</servlet-name>
| <servlet-class>com.ctc.ssdi.dessia.DESSIA</servlet-class>
| <load-on-startup>1</load-on-startup>
| </servlet>
| <servlet-mapping>
| <servlet-name>ASIA</servlet-name>
| <url-pattern>/ASIA</url-pattern>
| </servlet-mapping>
| <servlet-mapping>
| <servlet-name>COMEXIA</servlet-name>
| <url-pattern>/COMEXIA</url-pattern>
| </servlet-mapping>
| <servlet-mapping>
| <servlet-name>DESSIA</servlet-name>
| <url-pattern>/DESSIA</url-pattern>
| </servlet-mapping>
| <session-config>
| <session-timeout>30</session-timeout>
| </session-config>
| </web-app>
This is the contex tinitialized code that is called from the listener.
package com.ctc.ssdi;
|
| import javax.servlet.ServletContext;
| import javax.servlet.ServletContextEvent;
| import javax.servlet.ServletContextListener;
|
| import com.ctc.ssdi.asia.ASIA;
|
| /**
| * This is the SSDIWebInitialization that will be called when the WAR is deployed.
| */
| public final class SSDIWebInitialization
| implements ServletContextListener
| {
| public void contextInitialized (ServletContextEvent servletContextEvent)
| {
| ServletContext servletContext = servletContextEvent.getServletContext ();
| try
| {
| System.out.println("Inside of the contextInitialized in ContextListener.");
| ASIA asia = new ASIA();
| asia.RegisterService();
| }
| catch (Exception e)
| {
| servletContext.log ("Couldn't create addressesDB attribute: " + e.getMessage ());
| }
|
| //TODO: Create a waiting state to generate some sample data 1 and 5 minutes after it starts.
| //This may need to be a thread.
| }
|
| public void contextDestroyed (ServletContextEvent servletContextEvent)
| {
| System.out.println("Destroying the context.");
| }
| }
Here is the registerAgent code that is called in the context initialized section.
| public void RegisterService() {
| System.out.println("Beginning the registration of the ASIA Web Service.");
|
| try{
| System.out.println("In the try block before the connection to the SSDR Registry Web Service.");
|
| com.ctc.ssdi.ssdr.generated.SsdrRegistryService service = new com.ctc.ssdi.ssdr.generated.SsdrRegistryService();
| com.ctc.ssdi.ssdr.generated.SsdrRegistry port = service.getSsdrRegistryPort();
|
| System.out.println("Connected to the SsdrRegistry. Now creating the agentASIA Agent");
|
| // Creating a new instance of the Agent Class for the ASIA Web Service
| Agent agentASIA = new Agent();
| agentASIA.setName("ASIA");
| agentASIA.setCommunity("Fake Plane Alpha");
| agentASIA.setFunction("ELINT");
| agentASIA.setHost("http://127.0.0.1:8080/ssdi-web/ASIA?wsdl");
| agentASIA.setIpAddress("127.0.0.1");
| agentASIA.setLowFreq((float)0);
| agentASIA.setHighFreq((float)1000);
| // Note you need to space before and after the first and last words or the letters are cut off (not sure why)
| agentASIA.setProvidedServices("subscribe,generalSearch");
| System.out.println("[...agentASIA created]");
|
| // Running the subscribe function
| java.lang.Boolean result = port.registerAgent(agentASIA);
| System.out.println("The results of the agent registration are:" + result);
| } catch (Exception ex){
| ex.printStackTrace();
| }
| }
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4114363#4114363
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4114363
17 years