users@jax-rpc.java.net

The complex data type and java.lang.IllegalStateException

From: zhanglin <zhanglin_at_ics.nju.edu.cn>
Date: Wed, 22 Jun 2005 17:28:42 +0800

I wrote a web service HelloWorld, and the WS had a method named sayHello(NewClass nc) where NewClass is a type I defined by myself. I defined the class according to the JavaBeans rules, and it has a private String member called value with a pair of getValue() and setValue(String s) methods.

I used the wscompile command to generated the static stub classes and wrote a Java application as the client of the HelloWorld web service. And I also newd a NewClass instance and invoked its setValue method. But when I called the web service, passed the NewClass instance as a parameter and print the result to the monitor, I do got the result I expected which accompanied with an exception. The output message is bellow:

2005-6-22 17:05:49 com.sun.xml.messaging.saaj.soap.impl.ElementImpl getValueNode Strict
严重: SAAJ0107: 无法在不具有类型文本的唯一子类型的元素中设置值
java.lang.IllegalStateException at com.sun.xml.messaging.saaj.soap.impl.ElementImpl.getValueNodeStrict(ElementImpl.java:599) at com.sun.xml.messaging.saaj.soap.impl.ElementImpl.setValue(ElementImpl.java:579) at hello.ClientHandler.handleRequest(ClientHandler.java:55)
 at com.sun.xml.rpc.client.HandlerChainImpl.handleRequest(HandlerChainImp
l.java:86)
 at com.sun.xml.rpc.client.StreamingSender._callRequestHandlers(Streaming
Sender.java:751)
at com.sun.xml.rpc.client.StreamingSender._preRequestSendingHook(Streami
ngSender.java:714)
 at com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:87)
        at hello.HelloWorldSEI_Stub.sayHello(HelloWorldSEI_Stub.java:119)
        at HelloApplication.main(HelloApplication.java:43)
client1mmix

I'm sorry there are some Chinese characters which you may not read.
The last line: client1mmix is my result. But why the above exception?

I'll paste my NewClass.java and the source of my client application at the end. Can somebody help me with the problem and is there anything to do when use a complex data type as the parameter of the web service?

Thanks for your patience and your time.

//NewClass.java

package hello;

public class NewClass implements java.io.Serializable {
    private String value;
    /** Creates a new instance of NewClass */
    public NewClass() {
    }
    
    public NewClass(String s) {
        value = s;
    }
    
    public synchronized void setValue(String a) {
        value = a;
    }
    
    public synchronized String getValue() {
        return value;
    }
}

//the client application
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.Stub;
import javax.xml.rpc.handler.*;
import java.util.*;


public class HelloApplication {
    public static void main(String[] args) {
       String url = "http://192.168.2.17:8080/HelloWorld/HelloWorld?wsdl";
       
       String namespace = "urn:HelloWorld/wsdl";
    
       String serviceName = "HelloWorld";
       QName serviceQN = new QName(namespace, serviceName);
       
       try {
       ServiceFactory serviceFactory = ServiceFactory.newInstance();
       Service service = serviceFactory.createService(new URL(url), serviceQN);
                  
       Stub stub = createProxy();
       stub._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, url);
       
       hello.HelloWorldSEI chello = (hello.HelloWorldSEI)stub;
       
       hello.NewClass nc = new hello.NewClass("aaaa");
       
       System.out.println(nc.getValue());
       
       nc.setValue("mmix");
       
       System.out.println(chello.sayHello(nc)); //throws the exception
      
       } catch(Exception e) {
       }
       
    }
    
    public static Stub createProxy() {
        return (Stub) (new hello.HelloWorld_Impl().getHelloWorldSEIPort());
    }
}