Topic: Weblogic Web Service学习笔记(XDoclet, Ant) |
Print this page |
1.Weblogic Web Service学习笔记(XDoclet, Ant) | Copy to clipboard |
Posted by: charleszq Posted on: 2003-11-30 18:37 Wrote down some notes while learning weblogic web service. 高手们不要见笑! A question: I just can not find where the weblogic ant task 'servicegen' is defined. Weblogic webserice 学习笔记.doc (61.5k) |
2.Re:Weblogic Web Service学习笔记(XDoclet, Ant) [Re: charleszq] | Copy to clipboard |
Posted by: charleszq Posted on: 2003-11-30 18:40 Now learning how to implement Non-Built-In Data Types and 'Document/Message' based web service. Any suggestions? |
3.Continue, Implement non-built-in types [Re: charleszq] | Copy to clipboard |
Posted by: charleszq Posted on: 2003-12-01 23:44 Stateless session EJBs and Java classes do not necessarily take built-in data types as parameters and return values, but rather, might use a Java data type that you create yourself. Now let's create such a java class: ------------------------------------------------- package xdoclet; public class Address { private String name; private String address; public void setName( String name ) { this.name = name; } public String getName() { return name; } public void setAddress( String address ) { this.address = address; } public String getAddress() { return address; } } ------------------------------------------------- After this, we modify the method 'sayHello' of HelloWorldEJB as this: ------------------------------------------------- public String sayHello( Address address ) { return "Hello, " + address.getName() + ", your address is " + address.getAddress(); } ------------------------------------------------- then, we run 'ant ejbdoclet', 'ant compile-ejbs', 'ant ejb-jar', to generate the remote and home interface of the session bean, then make the 'helloworld.jar' file. |
4.Re:Weblogic Web Service学习笔记(XDoclet, Ant) [Re: charleszq] | Copy to clipboard |
Posted by: charleszq Posted on: 2003-12-01 23:58 copy 'helloworld.jar' into the folder 'staging', where we should use the 2nd build.xml to automatically generate the type, and publish the webservices. We should modify the build.xml file as this. ( This is the 2nd build.xml mentioned in the doucment) ------------------------------------------------- <path id="class.path"> <pathelement path="${java.class.path}"/> <pathelement path="."/> <fileset dir="."> <include name="**/*.jar"/> </fileset> </path> <target name="ear"> <autotype javatypes="xdoclet.Address" targetNamespace="http://www.foobar.com/autotypeer" packageName="xdoclet" destdir="." classpathref="class.path"/> <servicegen destEar="ws_basic_statelessSession.ear" contextURI="WebServices"> <classpath refid="class.path"/> <service ejbJar="HelloWorld.jar" targetNamespace="http://www.bea.com/webservices/basic/statelesSession" serviceName="HelloWorldEJB" serviceURI="/HelloWorldEJB" generateTypes="True" expandMethods="True" typeMappingFile="types.xml" style="rpc" > </service> .... ------------------------------------------------- We should add the current folder into the CLASSPATH, because the 'autotypes' task will look for the xdoclet.Address class, which is in helloworld.jar; and the 'servicegen' task will look up the Serialization class which will be generated automatically into the current folder ( it's specified in the build xml file ) we add another task 'autotype' to the target 'ear', and add a new attribute to task 'servicegen', which is typeMappingFile. the attribute 'javatypes' of 'autotype' tells ant which class is the non-built-in type, we should specify the 'classpathref' attribute to let this task know where to find the class 'xdoclet.Address'. the task 'autotype' will generate a types.xml, together with the Serialization class 'AddressCodec.class' in the current folder, which is specified by the attribute 'destdir'. the attribuet 'typeMappingFile' of 'servicegen' will merge 'types.xml' into 'web-services.xml' to show how to handle the non-built-in type, which is Address. After the task 'servicegen', you will see that in the war file generated, Address.class and AddressCodec.class is in the WEB-INF/classes folder, and the content of types.xml is there in the 'web-service.xml' Now we can deploy the generated 'ear' file into weblogic |
5.Re:Weblogic Web Service学习笔记(XDoclet, Ant) [Re: charleszq] | Copy to clipboard |
Posted by: charleszq Posted on: 2003-12-02 00:04 Now, time to test the web service. In IE, type 'http://localhost:7001/WebServices/HelloWorldEJB. If everything is right, you will see the list of the published web service. as to this practice, only one web service is there, called 'sayHello'. click this link, weblogic will generate a xml as the parameter to invoke the web service. The original xml looks like this: <address xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:n1="java:xdoclet" xsi:type="n1:Address"> <address href="#ID_2"> </address> <name href="#ID_2"> </name> <xsd:string xsi:type="xsd:string" id="ID_2">sample string</xsd:string> </address> ------------------------------------------------------------- We can modify it as this: .... <address href="#ID_1"></address> <name href="#ID_2"></name> <xsd:string xsi:type="xsd:string" id="ID_2">Charles</xsd:string> <xsd:string xsi:type="xsd:string" id="ID_1">Shanghai</xsd:string> ... then click the 'Invoke' button, you will the response like this: Return Value Hello, Charles, your address is Shanghai. |
6.Re:Weblogic Web Service学习笔记(XDoclet, Ant) [Re: charleszq] | Copy to clipboard |
Posted by: toString Posted on: 2003-12-02 04:27 我觉得这个帖子挺好,为什么没人回应?我帮忙顶一顶 |
7.Creating SOAP Message Handlers to Intercept the SOAP Message [Re: charleszq] | Copy to clipboard |
Posted by: charleszq Posted on: 2003-12-02 23:27 Thank you, toString! Let's continue with a new topic on weblogic web service: Creating SOAP Message Handlers to Intercept the SOAP Message. In weblogic edocs site, we can get very clear explanation about this: http://edocs.bea.com/wls/docs81/webserv/interceptors.html#1052635. Please go for it for detail information. Here I just did some test according to the document. First, let's write such a Handler class: package xdoclet; import java.util.Iterator; import javax.xml.rpc.handler.Handler; import javax.xml.rpc.handler.MessageContext; import javax.xml.rpc.handler.HandlerInfo; import javax.xml.rpc.handler.soap.SOAPMessageContext; import javax.xml.namespace.QName; public class TestSoapMessageHandler implements Handler { public void destroy() {} public QName[] getHeaders() { return null; } public boolean handleFault( MessageContext context ) { return true; } public boolean handleRequest( MessageContext context ) { for( Iterator it = context.getPropertyNames(); it.hasNext(); ) { String propertyName = (String)it.next(); System.out.println( "Property name: " + propertyName ); } return true; } public boolean handleResponse( MessageContext context ) { return true; } public void init( HandlerInfo config ) {} } We just do something in the method 'handleRequest', which is, just print out some useless information here. To compile this class, be sure to get weblogic.jar and jaxrpc.jar in your classpath, because in weblogic.jar, you can find QName, while in jaxrpc.jar, you can find those classes in javax.xml.rpc.handler package, such as Handler, MessageContext, etc. You can download jaxrpc.jar from sun.java.com, weblogic seems already has this file, but i don't which it is. then, we can run 'ant compile-ejbs' and 'ant ejb-jar'. Then copy the helloworld.jar into the folder 'staging' mentioned in the document. Modify the 2nd build.xml as this: <servicegen destEar="ws_basic_statelessSession.ear" contextURI="WebServices"> <classpath refid="class.path"/> <service ejbJar="HelloWorld.jar" targetNamespace="http://www.bea.com/webservices/basic/statelesSession" serviceName="HelloWorldEJB" serviceURI="/HelloWorldEJB" generateTypes="True" expandMethods="True" typeMappingFile="types.xml" style="rpc" > <handlerChain name="myChain" handlers="xdoclet.TestSoapMessageHandler" /> </service> that is, just add an element 'handlerChain' in the 1st 'service' element, then run 'ant' to generate the web service ear file. then you can examine the web-service.xml packaged in the ear file, you can see a handler chain is defined in it and the web service 'sayHello' references it. To test the handler chain, just redeploy the ear file in weblogic, then in IE, type 'http://localhost:7001/WebServices/HelloWorldEJB' to invoke the sayHello service. In weblogic console, you can just see the print-out of the handler, like this: Property name: weblogic.webservice.context Property name: __BEA_PRIVATE_BINDING_PROP Another thing, when I was trying to test this handler, I thought maybe we can let weblogic know where to find the 'jaxrpc.jar'. But finally, it turned out that weblogc does have this jar file in its classpath. So, if you're trying to find out the class load process of weblogic, please search in edocs.weblogic.com for 'classloader', there is a short-but-clear article about this. It seems that there are a lot of things to know about the handler process of weblogic web serivce. Still on this....... |
8.Have to do some other things these days, update this later. [Re: charleszq] | Copy to clipboard |
Posted by: charleszq Posted on: 2003-12-03 22:16 |
9.Re:Weblogic Web Service学习笔记(XDoclet, Ant) [Re: charleszq] | Copy to clipboard |
Posted by: find11 Posted on: 2003-12-06 11:01 bu cuo |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |