users@jax-rpc.java.net

答复: 答复: Handler problems

From: zhanglin <zhanglin_at_ics.nju.edu.cn>
Date: Tue, 7 Jun 2005 10:16:52 +0800

I haven’t tried if I could get the handlerChain with this method, what I
got is that the handler does work. When you use the wscompile –gen:client
config.xml you could notice that some additional classes are generated.

Here is my client code

 

       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);

       

       ServiceFactory serviceFactory = ServiceFactory.newInstance();

       Service service = serviceFactory.createService(new URL(url),
serviceQN);

                  

       Stub stub = createProxy();

       stub._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, url);

       

       hello.HelloWorldSEI hello = (hello.HelloWorldSEI)stub;

       

       System.out.println(hello.sayHello(args[0]));

      

    }

    

    public static Stub createProxy() {

        return (Stub) (new hello.HelloWorld_Impl().getHelloWorldSEIPort());

    }

 

I did some print job when the service was called, and it worked. But I think
that this method can only be used for the static client, I don’t know how
to add a handler when use the dynamic proxy or the DII. If you find how to
do this, please tell me, thank you!

 

-----------------------------------

Regards!

 

ZhangLin
Institute of Computer Software
Nanjing University
210093

  _____

发件人: Edoardo Causarano [mailto:curious.corn_at_katamail.com]
发送时间: 2005年6月7日 0:05
收件人: users_at_jax-rpc.dev.java.net
主题: Re: 答复: Handler problems

 

Hmm, I'm still lost. I've done like you said and used an wscompile client
mode task with a config.xml as you said (handlerChains tags inside wsdl one)

generated the static client code but still:

 

            Service_Impl f = new Service_Impl();

            HandlerRegistry r = f.getHandlerRegistry();

            Iterator ports = f.getPorts();

            while (ports.hasNext()) {

                QName e = (QName) ports.next();

                System.out.println(e.toString());

                List hc = r.getHandlerChain(e);

                System.out.println(hc.isEmpty());

            }

 

returns "true". Sigh...

 

On the other hand,

 

Service_Impl f = new Service_Impl();

HandlerRegistry registry = fact.getHandlerRegistry();

 

HandlerInfo hi = new HandlerInfo();

hi.setHandlerClass(foo.bar.Handler.class);

hi.setHandlerConfig(hashtable);

 

List hc = new ArrayList();

hc.add(hi);

 

Port_Stub stub = new ServerPort_Stub(new HandlerChainImpl(hc));

 

TypeMappingRegistry types = fact.getTypeMappingRegistry();

stub._initialize(new InternalTypeMappingRegistryImpl(types));

 

works quite fine. Can it be that my handcrafted WSDL has wrong namespaces
lying around and this breaks the code in the generated

Service_Impl() factory class that does the same things I stated explicitly
in my snippet?

 

public foo.bar.ServerPort getPort() {

   String[] roles = new String[] {};

   HandlerChainImpl handlerChain = new
HandlerChainImpl(getHandlerRegistry().getHandlerChain(ns1_ServerPort_QNAME))
;

   handlerChain.setRoles(roles);

   foo.bar..Port_Stub stub = new foo.bar.Port_Stub(handlerChain);

   try {

           stub._initialize(super.internalTypeRegistry);

        } catch (JAXRPCException e) {

           throw e;

        } catch (Exception e) {

           throw new JAXRPCException(e.getMessage(), e);

        }

   return stub;

}

 

            

 

 

Il giorno 06/giu/05, alle ore 15:16, zhanglin ha scritto:





Put your handler class in the server side, and write a config.xml:

 

<?xml version="1.0" encoding="UTF-8"?>

<configuration xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">

         <wsdl location="HelloWorld.wsdl" packageName="hello">

                   <handlerChains>

                            <chain runAt="client">

                                     <handler className="ClientHandler">

                                               <property
name="ClientHandler" value="hello client handler" />

                                     </handler>

                            </chain>

                   </handlerChains>

         </wsdl>

</configuration>

 

When you generate the stub class with the WSDL file, use wscompile with this
config.xml.

In the client side, you needn’t write the handler code, just write your
code as there is no handler, and you should get it working as you wish.

Good luck!

 

-----------------------------------

Regards!

 

ZhangLin
Institute of Computer Software
Nanjing University
210093