本站首页    管理页面    写新日志    退出


«August 2025»
12
3456789
10111213141516
17181920212223
24252627282930
31


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

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




[Java Open Source]Integrate axis and appfuse part3
软件技术

lhwork 发表于 2007/1/23 9:03:38

Introduction First congraguration you already have an env developing webservice under appfuse. In part3, we will use xdoclet help us generate servier-config.xml that axis needs. A brief description below before we start up. Add required sources. Prepare ant task. Declare model and service mapping. Generate server-config.xml and deploy. Generate stubs and test. Step1. Add required sources 1. Download files and check these articles below.     Spring JIRA SPR-371 here.     Vjekoslav Nesek's Weblog here.     You should download files below. SpringRPC.java SpringRPCProvider.java SpringAxisServlet.java SpringBeanMsgProvider.java SpringBeanProvider.java SpringBeanRPCProvider.java 2. Create package named servlet under org.appfuse.webapp.servlet     Copy files into it.     Of cource, please fix package path etc.     You can check the screen here 3. Create file named AxisServlet-servlet.xml under \web\WEB-INF path.     Add declartion below   <?xml version="1.0" encoding="UTF-8"?>  <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"      "http://www.springframework.org/dtd/spring-beans.dtd">    <beans>            <bean class="org.appfuse.webapp.servlet.SpringRPC"/>        </beans> You can check the screen here 4. Download axis-server-config.xdt.xml here.     Save it to \metadata\templates of your appfuse project.     We will use this file as xdoclet tesmplate file to generate server-config.xml. 5. Change AxisServlet.     Open servlets.xml. it should be found under metadata\web path.     Mark up below    <servlet>     <servlet-name>AxisServlet</servlet-name>     <display-name>Apache-Axis Servlet</display-name>     <servlet-class>         org.apache.axis.transport.http.AxisServlet     </servlet-class>   </servlet>     And add below    <servlet>     <servlet-name>AxisServlet</servlet-name>     <display-name>Apache-Axis Servlet</display-name>     <servlet-class>         org.appfuse.webapp.servlet.SpringAxisServlet     </servlet-class>   </servlet> You can check the screen here. 6. Yes, test your happy axis again.     Run ant clean deploy.     Start you tomcat and point to http://localhost:8080/appfuse/indexAxis.jsp     Make sure you have a happy Axis. Step2. Prepare ant task. 1. Open Build.xml and add below <target name="axis-gen-server-config" description="axis-gen-server-config">   <taskdef classpathref="xdoclet.classpath"      classname="xdoclet.DocletTask" name="xdoclet"/>   <xdoclet destDir="${webapp.target}/WEB-INF" mergedir="metadata/web">     <template destinationFile="server-config.wsdd"        templateFile="metadata/templates/axis-server-config.xdt.xml"        destDir="${webapp.target}/WEB-INF" >     <ConfigParam name="xmlEncoding"  value="utf-8" ></ConfigParam>    </template>        <fileset dir="${src}/service"  includes="**/*.java" ></fileset>        <fileset dir="${src}/dao"  includes="**/*.java" ></fileset>    </xdoclet> </target>  Here we add an ant task named axis-gen-server-config. This task will apply axis-server-config.xdt.xml xdoclet template. look for axis xdoclet deplartion and generate server-config.xml under WEB-INF  from service and dao. You can check the screen here. Note: Xdoclet 1.2 @axis tag not offers all method we need. Thus I decide to hand code one we need. Of course it would not be standard. Or maybe there is other good solutions I did not discover. Note: Here I use @Appfuse prefix instead @axis Please compare difference between them yourself Step3. Declare model and service mapping. 1. Create a model named Model under package org.appfuse.model.     With three attributes below. private Long id; private String name; private String description;     Add xdoclet delartions for them.     You can download the file here. 2. Use appgen to generate other codes we needs.     Please check appfuse tutorial here.     Here we need dao and service layers codes.     Please copy them to proper positions and test them.     Note: Here I did not describe too much.     Matt Raible has very good articles about his magic appgen. 3. Add webservice xdoclet declarions.     Here we port webservice from service layer.     Open Model.java, it should be found under package org.appfuse.model.     Add xdoclet declartion below. @appfuse.beanMapping name="model"    qname="Model"    xmlns="http://model.appfuse.org" You can download the file here.     Open ModelManagerImpl.java, it should be found under package org.appfuse.service.impl.     Add xdoclet declartion below. @appfuse.service name="ModelService" scope="Request"     enable-remote-admin="true"     namespace="http://service.appfuse.org/"    provider="java:SpringRPC"    style="rpc"    use="encoded"    class-Name="org.appfuse.service.ModelManager"    bean-Name="modelManager" and more add webservice method deplartions ont methods You can download the file here. Note: Here is little tricky. I try to delare xdoclet on interface. But it always gen duplicate webservice in server-config.xml Thus I use it on implementation. Maybe something I am wrong. Note: In theory, we should not port webservice from service layer. We should have a layer named webservice. For convenient and demo purpose, I simply use exiting architecture. If you like, you can define your layer and do some modification. Step4. Generate server-config.xml and deploy. 1. Run ant axis-gen-server-config. 2. Refresh your eclipse project. 3. Browse to build\appfuse\WEB-INF     You should find a file named server-config.wsdd.     Youcan check the screen here. 4. Run ant deploy ant start your tomcat.     Point to http://localhost:8080/appfuse/indexAxis.jsp     Click list hyperlink.     You should see ModelService is now deployed.     Congraturation!     You can check the screen here and here. Step5. Generate stubs and test. 1. Open Build.xml and add ant task below.  <target name="axis-wsdl2java-service" description="axis-wsdl2java-service">          <echo message="----- Axis Running WSDL2java -------"/>   <taskdef resource="axis-tasks.properties"    classpathref="axis.classpath" />      <axis-wsdl2java url="metadata/wsdl/ModelService.wsdl"       output="${basedir}/test/webservice"       debug="true"          helpergen="true"              deployscope="request"             serverSide="true"             noimports="false"             verbose="true"       typeMappingVersion="1.1"             testcase="yes">    <mapping namespace="http://service.appfuse.org/"      package="org.appfuse.webservice.client.modelservice"/>    <mapping namespace="http://model.appfuse.org"      package="org.appfuse.webservice.client.modelservice.model"/>     </axis-wsdl2java>    </target> You can check the screen here. 2. Start your tomcat.     Point to http://localhost:8080/appfuse/services/ModelService?wsdl 3. If you use IE, chosse file->save as "ModelService.wsdl" to metadata\wsdl path.     Refresh your eclipse appfuse project, you should see this file under metadata\wsdl path.     You can download the wsdl here. 4. Run ant axis-wsdl2java-service.     Refresh your eclipse project.     Browse to test\webservice\org\appfuse\webservice\client\modelservice     You should see files below. deploy.wsdd ModelManager.java ModelManagerService.java ModelManagerServiceLocator.java ModelManagerServiceTestCase.java ModelServiceSoapBindingImpl.java ModelServiceSoapBindingStub.java undeploy.wsdd BaseObject.java BaseObject_Helper.java Model.java Model_Helper.java You can check the screen here.  5. Start tomcat and point to http://localhost:8080/appfuse/indexAxis.jsp      Make sure you have a happy Axis.      Right on click  ModelManagerServiceTestCase.java, choose Run as -> JUnit test      In the JUnit test view. you should see 3 tests pass and 2 tests fail.      You can check the screen here. 6. Why 2 tests failed? Don't worry.     Open ModelManagerServiceTestCase.java     Check test function test2ModelServiceRemoveModel.     Change binding.removeModel(new java.lang.String());     to binding.removeModel(new java.lang.String("2"));     Check test function test3ModelServiceGetModel.     Change value = binding.getModel(new java.lang.String());     to value = binding.getModel(new java.lang.String("1"));     You can check the screen here. Note: If you still get test fails, try run ant db-load first. 7. Copy ModelManagerServiceTestCase.java to package org.appfuse.webservice     Rename to ModelManagerServiceTest     You also have to change package name,     change extands to BaseWebServiceTestCase, delete constructor.   8. Run ant test-webservice     You should see 4 test runs successful.    Summary In part3. we port webservice from appfuse service layer. With axis ant task and xdoclet template, jobs could be done more easy. In part4, we will add an one-to-many o/r map in Model Then port webservice from service layer too. Part4 is optional, I mean I did not consider it is a good way to do like me. I hope someone would offer better solution.


阅读全文(3032) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.359 second(s), page refreshed 144763714 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号