`
临听岗岗
  • 浏览: 9521 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

cxf + spring 开发基于web服务的分布式异构数据同步更新应用技术研究

阅读更多

本课题主要解决不同平台和不同应用系统之间的数据转换、数据同步和多个数据源的共享集成问题。为解决该问题,采用基于Web服务的方式来进行数据的交互,主要要考虑如何保持两个系统中的数据能实时同步更新(增加、删除和修改)。

用cxf-2.6.1+spring 3.1.0+ hibernate3.6 版本开发web services

 

服务端的开发

interface IHelloService

package com.dx.service;

import javax.jws.WebMethod;
import javax.jws.WebService;

import com.dx.model.User;

@WebService
public interface IHelloService {

	@WebMethod
	public String sayHello(String username);
	
	@WebMethod
	public User getUser(int id);
	
	@WebMethod
	public void add(User user);
}

 

IHelloService 的实现 IHelloServiceImpl

package com.dx.service.impl;

import javax.jws.WebMethod;
import javax.jws.WebService;

import com.dx.dao.BaseDao;
import com.dx.model.User;
import com.dx.service.IHelloService;

@WebService
public class IHelloServiceImpl implements IHelloService{

	private BaseDao baseDao;
	
	
	@Override
	@WebMethod
	public String sayHello(String username) {
		return "Hello "+username;
	}

	@Override
	@WebMethod
	public User getUser(int id) {
		User user = new User();
		user.setName("杨钰莹");
		user.setId(id);
		
		return user;
	}

	@Override
	@WebMethod
	public void add(User user) {
		baseDao.save(user);
	}

	public BaseDao getBaseDao() {
		return baseDao;
	}

	public void setBaseDao(BaseDao baseDao) {
		this.baseDao = baseDao;
	}
	
}

 

spring applicationContext-user.xml的配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jaxws="http://cxf.apache.org/jaxws" 
	xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context-2.5.xsd
	http://cxf.apache.org/jaxws  
	http://cxf.apache.org/schemas/jaxws.xsd">

	<jaxws:endpoint id="hellos"  address="/Hellows" implementor="#helloService">
	</jaxws:endpoint>
	
	<bean id="helloService" class="com.dx.service.impl.IHelloServiceImpl">
	  <property name="baseDao" ref="baseDao"></property>
	</bean>
	
	
	
	
</beans>

 web.xml的配置

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements. See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership. The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License. You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied. See the License for the
  specific language governing permissions and limitations
  under the License.
-->
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
         http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <display-name>cxf</display-name>
    
    
    
    <context-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>
    classpath:context/applicationContext-*.xml
 </param-value>
 </context-param>

 <listener>
 <listener-class>org.springframework.web.context.ContextLoaderListener
 </listener-class>
 </listener>
    
    

    <servlet>
        <servlet-name>cxf</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>cxf</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>

    <session-config>
        <session-timeout>60</session-timeout>
    </session-config>

</web-app>

 

好了,接下来部署启动tomcat ,在浏览器输入 http://localhost:8080/cxf_web_010/services

 

在出现的页面上 点击WSDL : {http://impl.service.dx.com/}IHelloServiceImplService

出现页面

  <?xml version="1.0" encoding="UTF-8" ?> 
- <wsdl:definitions name="IHelloServiceImplService" targetNamespace="http://impl.service.dx.com/" xmlns:ns1="http://service.dx.com/" xmlns:ns2="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://impl.service.dx.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <wsdl:import location="http://localhost:8080/cxf_web_010/services/Hellows?wsdl=IHelloService.wsdl" namespace="http://service.dx.com/" /> 
- <wsdl:binding name="IHelloServiceImplServiceSoapBinding" type="ns1:IHelloService">
  <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> 
- <wsdl:operation name="sayHello">
  <soap:operation soapAction="" style="document" /> 
- <wsdl:input name="sayHello">
  <soap:body use="literal" /> 
  </wsdl:input>
- <wsdl:output name="sayHelloResponse">
  <soap:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
- <wsdl:operation name="add">
  <soap:operation soapAction="" style="document" /> 
- <wsdl:input name="add">
  <soap:body use="literal" /> 
  </wsdl:input>
- <wsdl:output name="addResponse">
  <soap:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
- <wsdl:operation name="getUser">
  <soap:operation soapAction="" style="document" /> 
- <wsdl:input name="getUser">
  <soap:body use="literal" /> 
  </wsdl:input>
- <wsdl:output name="getUserResponse">
  <soap:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
- <wsdl:service name="IHelloServiceImplService">
- <wsdl:port binding="tns:IHelloServiceImplServiceSoapBinding" name="IHelloServiceImplPort">
  <soap:address location="http://localhost:8080/cxf_web_010/services/Hellows" /> 
  </wsdl:port>
  </wsdl:service>
  </wsdl:definitions>

 

现在web services 已经发布了,下一章编写客户端

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics