首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

JOffice2中WebService的应用(CXF)

2012-07-15 
JOffice2中WebService的使用(CXF)?commons-logging-1.1.jargeronimo-activation_1.1_spec-1.0-M1.jar (or

JOffice2中WebService的使用(CXF)
?JOffice2中WebService的应用(CXF)commons-logging-1.1.jargeronimo-activation_1.1_spec-1.0-M1.jar (or Sun's Activation jar)geronimo-annotation_1.0_spec-1.1.jar (JSR 250)geronimo-javamail_1.4_spec-1.0-M1.jar (or Sun's JavaMail jar)geronimo-servlet_2.5_spec-1.1-M1.jar (or Sun's Servlet jar)geronimo-ws-metadata_2.0_spec-1.1.1.jar (JSR 181)jaxb-api-2.0.jarjaxb-impl-2.0.5.jarjaxws-api-2.0.jarneethi-2.0.jarsaaj-api-1.3.jarsaaj-impl-1.3.jarstax-api-1.0.1.jarwsdl4j-1.6.1.jarwstx-asl-3.2.1.jarXmlSchema-1.2.jarxml-resolver-1.2.jar?


参考:http://cxf.apache.org/docs/writing-a-service-with-spring.html

?

? 3.??? 发布J.Office的Service类为Service

?

? 编写RegService接口及实现类,如下所示:(注意@WebService)

? 3.1??? ??? RegService接口

?

?JOffice2中WebService的应用(CXF)package com.htsoft.oa.service.cxf;import java.util.List;import javax.jws.WebService;import com.htsoft.oa.model.admin.Regulation;@WebService(targetNamespace="http://www.jee-soft.cn")public interface RegService {public List<Regulation> getAll();}

?3. 2 RegServiceImpl

?

?

?JOffice2中WebService的应用(CXF)package com.htsoft.oa.service.cxf.impl;import java.util.List;import javax.annotation.Resource;import javax.jws.WebService;import com.htsoft.oa.model.admin.Regulation;import com.htsoft.oa.service.admin.RegulationService;import com.htsoft.oa.service.cxf.RegService;@WebServicepublic class RegServiceImpl implements RegService{@ResourceRegulationService regulationService;@Overridepublic List<Regulation> getAll() {return regulationService.getAll();}}

?4.?? ?在J.Office中加上对外的发布Service

在resources/conf下加一app-cxf.xml,内容如下:

?

?并且在app-context.xml中引入以上文件

<import resource="app-cxf.xml"/>

在web.xml中加入

?

?

?JOffice2中WebService的应用(CXF)<!-- cxf 服务器--><servlet><servlet-name>CXFServlet</servlet-name><servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>CXFServlet</servlet-name><url-pattern>/service/*</url-pattern></servlet-mapping>

?

启动后,则可以访问路径:http://localhost:8080/joffice21/ws/regService?wsdl
效果如下:

? JOffice2中WebService的应用(CXF)?JOffice2中WebService的应用(CXF)<target name="jarservice-model"><jar destfile="build/ht_cxf_client.jar"><fileset dir="web/WEB-INF/classes"><include name="com/htsoft/core/**"/><include name="com/htsoft/oa/service/**"/><include name="com/htsoft/oa/model/**"/><exclude name="com/htsoft/oa/model/**/*.hbm.xml"/></fileset></jar></target>

?5.?? ?编写测试客户端

?

?JOffice2中WebService的应用(CXF)package com.cxf;import java.util.List;import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;import com.htsoft.oa.model.admin.Regulation;import com.htsoft.oa.service.cxf.RegService;public class ClientMain {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubJaxWsProxyFactoryBean factoryBean=new JaxWsProxyFactoryBean();factoryBean.setAddress("http://localhost:8080/joffice21/ws/regService");factoryBean.setServiceClass(RegService.class);RegService regService=(RegService)factoryBean.create();List<Regulation> list=regService.getAll();if(list!=null){for(Regulation reg:list){System.out.println(" reg:" + reg.getSubject());}}}}?

?

热点排行