Blog信息 |
blog名称: 日志总数:1304 评论数量:2242 留言数量:5 访问次数:7595169 建立时间:2006年5月29日 |

| |
[Java Open Source]Integrate axis and appfuse part2 软件技术
lhwork 发表于 2007/1/23 9:03:14 |
Introduction
In part1, we hava a happy axis now works with appfuse.
Further more, in Integrate axis and appfuse part2, we will use ant task wsdl2java comes with axis to generate stub codes and test axis version service.
A brief description below before we start up.
Step1. Modify eclipse project setting to let us have src named webservice.
Step2. Genenate stubs from axis Version Service.
Step3. Modify Build.xml and add test-webservice ant task. Then test it.
Step1. Modify eclipse project setting
Webservice test needs a running appilication server to generate stubs code and test.
I decide to create a new package and ant tasks that would not affect appfuse too much.
1. Switch to eclipse Resource perspective view.
open .classpath file, it should be found in you appfuse project root.
2. Add classpathentry below under classpath tag.
<classpathentry output="build/webservice/classes" kind="src" path="src/webservice"/><classpathentry output="build/test/webservice/classes" kind="src" path="test/webservice"/>
You can check the screen here.
3. Create a folder named webservice under test.
Create another folder named webservice under src.
Otherwise, your eclipse will complain about no such folder at path error.
You can check the screen here.
4. Add axis related libs to you eclipse project java build path.
Right on click your appfuse project, choose properties -> Java Build path -> Libraris tab Add Jars under appfuse/lib/axis-1.2 folder.
Step2. Genenate stubs from axis Version Service.
Axis application comes with a webservice named version default,
It has one method named getVersion.
Here we consume the wsdl to generate stubs code and test our axis working fine.
1. Create folder name wsdl in your appfuse project path \metadata.
2. Start your tomcat
Point to http://localhost:8080/appfuse/services/Version?wsdl
where appfuse is the webapp of you application name deployed in tomcat.
You can check the screen here.
3. If you use IE, chosse file->save as "version.wsdl" to wsdl folder.
Refresh you eclipse appfuse project, you should see these files under metadata\wsdl path.
You can check the screen here.
4. Open build.xml and add below
<target name="axis-wsdl2java-Version" description="axis-wsdl2java-Version"> <echo message="----- Axis Running WSDL2java -------"/> <taskdef resource="axis-tasks.properties" classpathref="axis.classpath" /> <axis-wsdl2java url="metadata/wsdl/Version.wsdl" output="${basedir}/test/webservice" debug="true" helpergen="true" deployscope="session" serverSide="true" noimports="false" verbose="true" typeMappingVersion="1.1" testcase="yes"> <mapping namespace="http://${tomcat.server}:${http.port}/${webapp.name}/services/Version" package="org.appfuse.webservice.client.version"/> </axis-wsdl2java> </target>
Where classpathref="axis.classpath" is the classpath we specified in properties.xml.
Here we use axis-wsdl2java ant task
Specify output parameters to generate stub code include testcase.
Note: Since default gen package follows the wsdl declartion, It will be localhost.appfuse.services.VersionSo I use mapping tag and specify package="org.appfuse.webservice.client.version"
Another reason is default generated package follows the wsdl declartion It will causes package conflict.Especially when we have src and test the same package nameThus I add .client to avoid this.
5. Run ant axis-wsdl2java-Version, then refresh your appfuse project.
If everything is ok, you should see generated files below.
deploy.wsdd
undeploy.wsdd
Version.java
VersionService.java
VersionServiceLocator.java
VersionServiceTestCase.java
VersionSoapBindingImpl.java
VersionSoapBindingStub.java
You can check the screen here.
6. Make a simple test.
Before we go next, just make a simple test what we did. start tomcat and point to http://localhost:8080/appfuse/indexAxis.jsp Make sure you have a happy Axis Then in Appfuse project right onclick VersionServiceTestCase.java,
choose Run as -> JUnit test In the JUnit test view. you should see 2 test testVersionWSDL
and testVersionGetVersion happy.
You can check the screen here.
Step3. Modify Build.xml and add test-webservice ant task.
Axis wsdl2java ant task auto generate testcase for us.Of course we will have more tests than that.To meet this, we modify build.xml.
Add test-webservice ant task that help us batch test-webservice.
1. Add ant task named test-webservice. Open build.xml and add below.
<!-- Axis --> <target name="test-webservice" depends="copy-resources,db-load" description="Test webservice module"> <test-module module="webservice"/> </target>
You can check the screen here.
2. Add task classpath setting. Open properties.xml and add below
<!-- Axis --> <path id="webservice.test.classpath"> <path refid="axis.classpath"/> <pathelement location="${junit.jar}"/> <pathelement location="${log4j.jar}"/> </path>
Where <path refid="axis.classpath"/> is what we define path in part1.
You can check the screen here.
3. Add BaseWebServiceTestCase.java to org.appfuse.webservice Add a simple abtract class BaseWebServiceTestCase below
package org.appfuse.webservice;
import junit.framework.TestCase; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class BaseWebServiceTestCase extends TestCase { protected final Log log = LogFactory.getLog(getClass()); public BaseWebServiceTestCase() { } }
You can check the screen here.
4. Copy VersionServiceTestCase.java to package org.appfuse.webservice
Rename to VersionServiceTest. You also have to change package name,
change extands to BaseWebServiceTestCase, delete constructor.
You can check the screen here and here.
5. Run ant test-webservice You should see 2 test runs successful.
You can check the screen here. Note: Here I have problem set log level to debug works well ...
Summary
In part2, we use axis ant task help us generate and test webservice easy. Since we have test-webservice ant task, you can feel free to add tests you like. In part3 we will use xdoclet to port webservice from appfuse service layer.
22:06 | 添加评论 | 阅读评论 (3) | 引用通告 (0) | 记录它 | Java
评论500)this.width=500'>500)this.width=500'>
500)this.width=500'>
(没有名称)
Barry
I think my problem seems to be getting more complex by the moment. I am only trying to implement a client side web service but my code can't even compile inside eclipse.I can publish my build on www.dropload.com if you have a email address?2006/5/24 15:37
500)this.width=500'>
(没有名称)
RanHow
Dear Barry
Would you please paste the error stack?
It would help me identify the issue more easilly :)
I send you the original project that I use in the tutorail.
Please check if something I lost.
dowlond path
https://webftp.itri.org.tw/Retrieve?PN=0c55af10f9a41ce3a6675dbd27ea6981&ienc=cht
The project is eclipse project.
Regards Chenz2006/5/24 13:30(http://spaces.msn.com/chenztw/)
500)this.width=500'>
(没有名称)
Barry
I've intergrated Axis 1.3 as descibed in your blog ( thanks ) but when I continued on with Axis and generated some java files using WSDL2Java and put them into the src/webserivces directory, whenever I try to compile my code a get exceptions regard class in src/service not able to reconigse any of the generated classes.How can a fix this. I tried update the build.xml like so; <!-- Service --> <target name="compile-service" depends="package-dao" description="Compile service module"> <compile module="service"/> <compile module="webservice"/> </target> <target name="package-service" depends="compile-service"> <mkdir dir="${build.dir}/service/classes/META-INF"/> <copy tofile="${build.dir}/service/classes/META-INF/applicationContext-service.xml"> <fileset dir="src/service" includes="**/*-service.xml"/> </copy> <jar destfile="${dist.dir}/${webapp.name}-service.jar"> <manifest> <attribute name="Class-Path" value="${webapp.name}-dao.jar ${webapp.name}-service.jar"/> </manifest> <!-- Service --> <fileset dir="${build.dir}/service/classes" includes="**/*.class"/> <metainf dir="${build.dir}/service/classes/META-INF"/> <!-- Web Service --> <fileset dir="${build.dir}/webservice/classes" includes="**/*.class"/> </jar> </target>but it does not work. |
|
|