webservice配置

服务端配置:
第一步:引用jar包
commons-httpclient.jar
commons-logging.jar
jdom-10.jar
wsdl4j-1.6.1.jar
xbean-spring-2.8.jar
xfire-all-1.2.6.jar

第二步:添加配置文件
路径:WEB-INF/config/xfire-servlet.xml
内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- START SNIPPET: xfire -->
<import resource="classpath:org/codehaus/xfire/spring/xfire.xml"/>
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<entry key="/userWeb">
<ref bean="sso"/>
</entry>
</map>
</property>
</bean>

<!-- Declare a parent bean with all properties common to both services -->
<bean id="sso" class="org.codehaus.xfire.spring.remoting.XFireExporter">
<property name="serviceFactory">
<ref bean="xfire.serviceFactory"/>
</property>
<property name="xfire">
<ref bean="xfire"/>
</property>
<property name="serviceBean">
<ref bean="cmsUserWebMng"/>
</property>
<property name="serviceClass">
<value>com.jeecms.cms.manager.main.CmsUserWebMng</value>
</property>
</bean>
<!-- END SNIPPET: xfire -->
</beans>


第三步:修改web。xml
添加配置:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/application-context.xml
/WEB-INF/config/cache-context.xml
/WEB-INF/config/captcha-context.xml
/WEB-INF/config/jeecore-context.xml
/WEB-INF/config/jeecms-context.xml
/WEB-INF/config/xfire-servlet.xml//添加配置
</param-value>
</context-param>

增加:

<servlet>
<servlet-name>XFireServlet</servlet-name>
<servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>XFireServlet</servlet-name>
<url-pattern>/portal/door/services/*</url-pattern>
</servlet-mapping>

第四步:添加接口和实现方法CmsUserWebMng和CmsUserWebMngImpl
CmsUserWebMng:
package com.jeecms.cms.manager.main;

public interface CmsUserWebMng {
public void save(String username, String password, String email, String ip, String realname);

public void update(String oldUsername, String username, String password, String email);

public void delete(String username);
}

CmsUserWebMngImpl

package com.jeecms.cms.manager.main.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeecms.cms.dao.main.CmsUserDao;
import com.jeecms.cms.entity.main.CmsGroup;
import com.jeecms.cms.entity.main.CmsSite;
import com.jeecms.cms.entity.main.CmsUser;
import com.jeecms.cms.entity.main.CmsUserExt;
import com.jeecms.cms.manager.main.CmsGroupMng;
import com.jeecms.cms.manager.main.CmsSiteMng;
import com.jeecms.cms.manager.main.CmsUserExtMng;
import com.jeecms.cms.manager.main.CmsUserSiteMng;
import com.jeecms.cms.manager.main.CmsUserWebMng;
import com.jeecms.common.hibernate3.Updater;
import com.jeecms.core.entity.UnifiedUser;
import com.jeecms.core.manager.UnifiedUserMng;

@Service
@Transactional
public class CmsUserWebMngImpl implements CmsUserWebMng {

public void save(String username, String password, String email, String ip, String realname) {
// TODO Auto-generated method stub
UnifiedUser unifiedUser = unifiedUserMng.save(username, email,
password, ip);
CmsUser user = new CmsUser();
user.forAdmin(unifiedUser, false, false, 8);
CmsGroup group = null;
CmsSite site = cmsSiteMng.findById(1);
group = cmsGroupMng.getRegDef();

if (group == null) {
throw new RuntimeException(
"register default member group not setted!");
}
user.setGroup(group);

user.init();
dao.save(user);
CmsUserExt userExt = new CmsUserExt();
userExt.setRealname(realname);
cmsUserExtMng.save(userExt, user);
cmsUserSiteMng.save(site, user, Byte.parseByte("1"), true);
System.out.println("管理员添加成功");
}

public void update(String oldUsername, String username, String password, String email) {
// TODO Auto-generated method stub
CmsUser bean = dao.findByUsername(oldUsername);
if (bean != null) {
bean.setUsername(username);
bean.setEmail(email);
Updater<CmsUser> updater = new Updater<CmsUser>(bean);
updater.include("email");
CmsUser user = dao.updateByUpdater(updater);
if (!password.equals("")){
unifiedUserMng.update(user.getId(), password, user.getEmail());
}
System.out.println("更新成功");
}
}

public void delete(String username) {
// TODO Auto-generated method stub
CmsUser bean = dao.findByUsername(username);
unifiedUserMng.deleteById(bean.getId());
CmsUser user = dao.deleteById(bean.getId());
if (user != null) {
System.out.println("删除成功");
}
}

public CmsUserDao dao;
private CmsUserExtMng cmsUserExtMng;
private UnifiedUserMng unifiedUserMng;
private CmsGroupMng cmsGroupMng;
private CmsSiteMng cmsSiteMng;
private CmsUserSiteMng cmsUserSiteMng;

@Autowired
public void setDao(CmsUserDao dao) {
this.dao = dao;
}

@Autowired
public void setCmsUserExtMng(CmsUserExtMng cmsUserExtMng) {
this.cmsUserExtMng = cmsUserExtMng;
}

@Autowired
public void setUnifiedUserMng(UnifiedUserMng unifiedUserMng) {
this.unifiedUserMng = unifiedUserMng;
}

@Autowired
public void setCmsGroupMng(CmsGroupMng cmsGroupMng) {
this.cmsGroupMng = cmsGroupMng;
}

@Autowired
public void setCmsSiteMng(CmsSiteMng cmsSiteMng) {
this.cmsSiteMng = cmsSiteMng;
}

@Autowired
public void setCmsUserSiteMng(CmsUserSiteMng cmsUserSiteMng) {
this.cmsUserSiteMng = cmsUserSiteMng;
}
}


第五步:配置接口及实现类
在config/jeecms-context.xml中添加
<bean id="cmsUserWebMng" class="com.jeecms.cms.manager.main.impl.CmsUserWebMngImpl" />
服务端配置成功

 


客户端:

public void websave(CmsUser bean, String password, String ip){
org.codehaus.xfire.service.Service srModel = new ObjectServiceFactory().create(CmsUserWebMng.class);
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
.newInstance().getXFire());// 创建工厂实例
String url = Constants.EMSP_URL;

try{
CmsUserWebMng manager = (CmsUserWebMng)factory.create(srModel, url);
manager.save(bean.getUsername(), password, bean.getEmail(), ip, bean.getRealname());

} catch (Exception e) {
e.printStackTrace();
}

String url2 = Constants.DSPTECH_URL;

try{
CmsUserWebMng manager = (CmsUserWebMng)factory.create(srModel, url2);
manager.save(bean.getUsername(), password, bean.getEmail(), ip, bean.getRealname());

} catch (Exception e) {
e.printStackTrace();
}

String url3 = Constants.DSPTALENT_URL;

try{
CmsUserWebMng manager = (CmsUserWebMng)factory.create(srModel, url3);
manager.save(bean.getUsername(), password, bean.getEmail(), ip, bean.getRealname());

} catch (Exception e) {
e.printStackTrace();
}
}

public void webupdate(String oldUsername, String username, String password, String email){
org.codehaus.xfire.service.Service srModel = new ObjectServiceFactory().create(CmsUserWebMng.class);
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
.newInstance().getXFire());// 创建工厂实例
String url = Constants.EMSP_URL;

try{
CmsUserWebMng manager = (CmsUserWebMng)factory.create(srModel, url);
manager.update(oldUsername, username, password, email);

} catch (Exception e) {
e.printStackTrace();
}

String url2 = Constants.DSPTECH_URL;

try{
CmsUserWebMng manager = (CmsUserWebMng)factory.create(srModel, url2);
manager.update(oldUsername, username, password, email);

} catch (Exception e) {
e.printStackTrace();
}

String url3 = Constants.DSPTALENT_URL;

try{
CmsUserWebMng manager = (CmsUserWebMng)factory.create(srModel, url3);
manager.update(oldUsername, username, password, email);

} catch (Exception e) {
e.printStackTrace();
}
}

public void webdelete(String username){
org.codehaus.xfire.service.Service srModel = new ObjectServiceFactory().create(CmsUserWebMng.class);
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
.newInstance().getXFire());// 创建工厂实例
String url = Constants.EMSP_URL;

try{
CmsUserWebMng manager = (CmsUserWebMng)factory.create(srModel, url);
manager.delete(username);

} catch (Exception e) {
e.printStackTrace();
}

String url2 = Constants.DSPTECH_URL;

try{
CmsUserWebMng manager = (CmsUserWebMng)factory.create(srModel, url2);
manager.delete(username);

} catch (Exception e) {
e.printStackTrace();
}

String url3 = Constants.DSPTALENT_URL;

try{
CmsUserWebMng manager = (CmsUserWebMng)factory.create(srModel, url3);
manager.delete(username);

} catch (Exception e) {
e.printStackTrace();
}
}

posted @ 2016-04-13 17:05  李清欣  阅读(373)  评论(0编辑  收藏  举报