用cxf .net调用java接口公网的服务报 java.net.UnknownHostException: webservice.webxml.com.cn

srpingmvc整合mybatis mongodb cxf
时间: 02:21:17
&&&& 阅读:308
&&&& 评论:
&&&& 收藏:
标签:&&&&&&&&&&&&? ? ? ?去年搞完了oa系统,今年一开始公司就准备做大数据,公司原来数据已经有些是上亿的了,如果还是用关系型数据库又不分区分表的话,即使用了读写分离也很难保证性能了。
? ? ? 于是得搞个基础数据存储,这样过了一段时间后业务系统的数据就可以清掉了,基础系统里保留所有历史数据,以后要做统计啥的就从这边拿。
? ? ?想法分三部分,第一是原始数据,此数据不经过任何逻辑,全部入库。第二是清洗数据,经过一定的逻辑筛选出有用数据保存起来。第三是应用数据,根据业务需要生成应用数据,提供接口给业务系统调用。
? ? 前期先搭框架,以前公司系统就是用springmvc+mybatis的框架,所以这次直接就在原有框架上剥离基本的框架再来集成,第一部分的数据库最后确认是用mongodb,这部分数据特别大,如果用关系型数据库的话不好搞,性能也太差。
? ? 本来接口是想用rmi实现的,不过公司有国内(java),国际(.net)不同语言,还是用webservice好点,免得国际的以后不好调。
? ?所以最后确定系统框架需要用到的技术就是srpingmvc+mybatis+mongodb+cxf。
??srpingmvc+mybatis这里就不介绍了,主要讲mongodb。
? 本来想用spring 自己的mongodb封装的,发现配起来跟公司原来spring版本不一样,上头又催得紧。
?那就只能自己封装一层mongodb的dao层了,最终目的就是要封装成像使用hiberante一样。
? 主要难点在于如何根据类映射成表,这个当时还搞了蛮久的,以前还用了个baseService去调dao,然后其它service去调baseService,发现根据没办法在dao里取得传进去的泛型T的类型,这要就没办法取得类名也就没办法映射表了。最后去掉了baseService层,直接service就继承dao的实现类。然后把dao的实现类定义成抽象类abstract,一定要定义成abstract,不然无法获取泛型T的类型。
package base.dao.
import java.net.UnknownHostE
import com.mongodb.MongoC
import com.mongodb.MongoE
import com.mongodb.MongoO
class MongoManager extends MongoClient{
/* private String host ="127.0.0.1";
private int port =27017;*/
/*private String host ="172.16.6.40";*/
private String host ="172.16.6.16";
private int port =9901;
private int
poolSize = 100;
private int blockSize = 40;
MongoClient mongoC
private MongoManager() throws UnknownHostException{
public String getHost() {
public void setHost(String host) {
this.host =
public int getPort() {
public void setPort(int port) {
this.port =
public int getPoolSize() {
return poolS
public void setPoolSize(int poolSize) {
this.poolSize = poolS
public int getBlockSize() {
return blockS
public void setBlockSize(int blockSize) {
this.blockSize = blockS
MongoClient getMongoClient() {
mongoClient = new MongoClient(host, port);
MongoOptions opt = mongoClient.getMongoOptions();
opt.connectionsPerHost = poolS
opt.threadsAllowedToBlockForConnectionMultiplier = blockS
//opt.autoConnectRetry =
}/* catch (UnknownHostException e) {
throw new RuntimeException(e);
} */catch (MongoException e) {
throw new RuntimeException(e);
return mongoC
? dao接口类
package base.dao.
import java.util.L
import java.util.M
import org.bson.types.ObjectId;
import org.springframework.dao.DataAccessE
import base.vo.DivPageVO;
import com.mongodb.BasicDBO
import com.mongodb.DB;
import com.mongodb.DBC
import com.mongodb.DBO
import com.mongodb.WriteR
* 基础数据库操作类
* 其他DAO继承此类获取常用的数据库操作方法,基本上你能用到的方法这里都有了,不需要自己建立DAO了。
* @author miraclerz
* @param &T&
public interface MongoBaseDaoI&T& {
* 得到数据库
DB getDB(String dbName);
DBCollection getCollection(String dbName, String collName);
* 转为mongo类型数据
classType实体类类型
DBObject toDBObject(T vo);
* 转为实体数据
* @throws IllegalAccessException
* @throws InstantiationException
T toModel(DBObject dbObject) throws InstantiationException, IllegalAccessE
* 查询所有分页
* @param page
* @throws DataAccessException
* @throws InstantiationException
* @throws IllegalAccessException
findAll( DivPageVO page) throws DataAccessException, InstantiationException, IllegalAccessE
* 查询所有
* @throws DataAccessException
* @throws InstantiationException
* @throws IllegalAccessException
findAll() throws DataAccessException, InstantiationException, IllegalAccessE
* 批量删除
* @param list
* @throws DataAccessException
public WriteResult deleteList(List&ObjectId& list) throws DataAccessE
* 单条删除
* @param objectId
* @throws DataAccessException
public WriteResult deleteOne(ObjectId objectId) throws DataAccessE
* 单条插入
* @param T
* @throws DataAccessException
public WriteResult insertOne(T t) throws DataAccessE
* 批量插入
* @param list
* @throws DataAccessException
public WriteResult insertList(List&T& list) throws DataAccessE
* 清空本表数据 小心了
* @throws DataAccessException
public WriteResult clear() throws DataAccessE
* 查询一条数据 转为实体
* @param objectId
public T findOne(ObjectId objectId) throws InstantiationException,
IllegalAccessE
* 查询一条数据
* @param objectId
public DBObject findOneByDbObject(ObjectId objectId);
DBCollection getTable();
* 查询数量
* @throws DataAccessException
* @throws InstantiationException
* @throws IllegalAccessException
countAll() throws DataAccessException, InstantiationException, IllegalAccessE
* 不分页查询
* @param param
* @param map
* @param field
* @param asc
* @throws InstantiationException
* @throws IllegalAccessException
find(T param,Map&String, BasicDBObject& map,String field,boolean asc) throws InstantiationException, IllegalAccessE
* 分页查询
* @param param
* @param map
* @param page
* @param field
* @param asc
* @throws InstantiationException
* @throws IllegalAccessException
find(T param,Map&String, BasicDBObject& map, DivPageVO page,String field,boolean asc) throws InstantiationException, IllegalAccessE
* 根据条件计数
* @param param
* @param map
count(T param,Map&String, BasicDBObject& map);
* 查询条件组合,默认有实现,也可以在自己的具体类里重写自己的实现
* @param param
* @param map
abstract DBObject getCondition(T param,Map&String, BasicDBObject& map);
* 创建索引
* @param dbObject
public void createIndex(BasicDBObject dbObject);
package base.dao.mongo.
import java.lang.reflect.M
import java.lang.reflect.ParameterizedT
import java.lang.reflect.T
import java.util.ArrayL
import java.util.I
import java.util.L
import java.util.M
import java.util.Map.E
import java.util.concurrent.ConcurrentHashM
import java.util.concurrent.ConcurrentM
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.A
import org.springframework.beans.factory.annotation.Q
import org.springframework.dao.DataAccessE
import org.springframework.stereotype.R
import base.dao.mongo.MongoBaseDaoI;
import base.vo.DivPageVO;
import com.mongodb.BasicDBL
import com.mongodb.BasicDBO
import com.mongodb.DB;
import com.mongodb.DBC
import com.mongodb.DBO
import com.mongodb.MongoC
import com.mongodb.WriteR
@Repository
abstract class MongoBaseDaoImpl&T& implements MongoBaseDaoI&T& {
ConcurrentMap&String, Method& READ_METHODS = new ConcurrentHashMap&String, Method&();
ConcurrentMap&String, Method& WRITE_METHODS = new ConcurrentHashMap&String, Method&();
String GET_PREFIX = "get";
String SET_PREFIX = "set";
String IS_PREFIX = "is";
@Autowired
@Qualifier("mongoClient")
private MongoClient mongoC
final String dbName = "baseData";
private Class&T& classT
public MongoBaseDaoImpl(){
//利用反射 得到T的具体子类的类型,从而实现类到表的自动映射,这里MongoBaseDaoImpl一定要是abstract类,不然下面是获取不到类型的(搞了几天、、、)
Type genType = this.getClass().getGenericSuperclass();
Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
classType = (Class&T&) params[0];
GetMethods();//初始化泛形类的get set 属性方法
* 得到所有方法
* @param vo
public void GetMethods() {
if (READ_METHODS.size() & 0)
// 如果已经有数据就直接返回了
Method[] methods = classType.getDeclaredMethods();
for (Method method : methods) {
String name = method.getName();
method.setAccessible(true);
if (name.startsWith(SET_PREFIX)) {
WRITE_METHODS.putIfAbsent(uncapitalize(SET_PREFIX, name),
} else if (name.startsWith(IS_PREFIX)) {
READ_METHODS.putIfAbsent(uncapitalize(IS_PREFIX, name), method);
} else if (name.startsWith(GET_PREFIX)) {
READ_METHODS
.putIfAbsent(uncapitalize(GET_PREFIX, name), method);
* 得到数据库
public DB getDB(String dbName) {
DB db = mongoClient.getDB(dbName);
public DBCollection getCollection(String dbName, String collName) {
return getDB(dbName).getCollection(collName);
public static String uncapitalize(String prefix, String str) {
String _str = str.substring(prefix.length());
return Character.toLowerCase(_str.charAt(0)) + _str.substring(1);
* 转为mongo类型数据
public DBObject toDBObject(T vo) {
//GetMethods();
DBObject dbObject = new BasicDBObject();
for (Entry&String, Method& entry : READ_METHODS.entrySet()) {
dbObject.put(entry.getKey(), entry.getValue().invoke(vo));
} catch (Exception e) {
e.printStackTrace();
return dbO
* 转为实体数据
* @throws IllegalAccessException
* @throws InstantiationException
public T toModel(DBObject dbObject) throws InstantiationException,
IllegalAccessException {
T t = (T) classType.newInstance();
//GetMethods();
for (Entry&String, Method& entry : WRITE_METHODS.entrySet()) {
entry.getValue().invoke(t, dbObject.get(entry.getKey()));
} catch (Exception e) {
e.printStackTrace();
public MongoClient getMongoClient() {
return mongoC
public void setMongoClient(MongoClient mongoClient) {
this.mongoClient = mongoC
* 查询一条数据
* @param objectId
public DBObject findOneByDbObject(ObjectId objectId) {
DBObject objVO = new BasicDBObject();
objVO.put("_id", objectId);
return getTable().findOne(objVO);//
* 查询一条数据 转为实体
* @param objectId
public T findOne(ObjectId objectId) throws InstantiationException,
IllegalAccessException {
DBObject dBObject = findOneByDbObject(objectId);
if (dBObject != null) {
t = toModel(dBObject);
* 清空数据 小心了
* @throws DataAccessException
public WriteResult clear() throws DataAccessException {
return getTable().remove(new BasicDBObject());
* 批量插入
* @param list
* @throws DataAccessException
public WriteResult insertList(List&T& list) throws DataAccessException {
if (list != null&&list.size()&0) {
List&DBObject& listInsert = new ArrayList&&();
for (T t : list) {
listInsert.add(toDBObject(t));
return insertByDbObject(listInsert);
public WriteResult insertByDbObject(List&DBObject& list)
throws DataAccessException {
return getTable().insert(list);
* 单条插入
* @param T
* @throws DataAccessException
public WriteResult insertOne(T t) throws DataAccessException {
if (t != null) {
return getTable().insert(toDBObject(t));
* 单条删除
* @param list
* @throws DataAccessException
public WriteResult deleteOne(ObjectId objectId) throws DataAccessException {
DBObject objVO = new BasicDBObject();
objVO.put("_id", objectId);
return getTable().remove(objVO);
* @param list
* @throws DataAccessException
public WriteResult deleteList(List&ObjectId& list) throws DataAccessException {
DBObject obj = new BasicDBObject();
BasicDBList values = new BasicDBList();
for(int i=0;i&list.size();i++) {
values.add(new BasicDBObject("_id",list.get(i)));
obj.put("$or", values);
return getTable().remove(obj);
* 查询所有分页
* @param page
* @throws DataAccessException
* @throws InstantiationException
* @throws IllegalAccessException
findAll( DivPageVO page) throws DataAccessException, InstantiationException, IllegalAccessException{
DBObject obj = new BasicDBObject();
int pos = page.getStartPos();
int pageSize = page.getPageSize();
Iterator&DBObject&
dbList= getTable().find(obj).skip(pos).limit(pageSize);
List&T& list = new ArrayList&T&();
for (Iterator iter = dbL iter.hasNext();) {
DBObject dbo = (DBObject) iter.next();
T vo = toModel(dbo);
list.add(vo);
public List&T& findAll() throws DataAccessException,
InstantiationException, IllegalAccessException {
Iterator&DBObject&
dbList= getTable().find( new BasicDBObject());
List&T& list = new ArrayList&T&();
for (Iterator iter = dbL iter.hasNext();) {
DBObject dbo = (DBObject) iter.next();
T vo = toModel(dbo);
list.add(vo);
DBCollection getTable(){
return getDB(dbName).getCollection(classType.getName().split("\\.")[classType.getName().split("\\.").length-1].toLowerCase());
public int countAll() throws DataAccessException,
InstantiationException, IllegalAccessException {
getTable().find().count();
find(T param,Map&String, BasicDBObject& map,String field,boolean asc) throws InstantiationException, IllegalAccessException {
Iterator&DBObject&
if(field!=null)
int sort=-1;
if(asc)sort=1;
dbList= getTable().find(getCondition( param, map)).sort(new BasicDBObject(field,sort));
}else{//不排序
dbList=getTable().find(getCondition( param, map));
List&T& list = new ArrayList&T&();
for (Iterator iter = dbL iter.hasNext();) {
DBObject dbo = (DBObject) iter.next();
T vo = toModel(dbo);
list.add(vo);
find(T param,Map&String, BasicDBObject& map, DivPageVO page,String field,boolean asc) throws InstantiationException, IllegalAccessException {
int pos = page.getStartPos();
int pageSize = page.getPageSize();
Iterator&DBObject&
if(field!=null)
int sort=-1;
if(asc)sort=1;
dbList=getTable().find(getCondition( param, map)).sort(new BasicDBObject(field,sort)).skip(pos).limit(pageSize);
}else{//不排序
dbList=getTable().find(getCondition( param, map));
List&T& list = new ArrayList&T&();
for (Iterator iter = dbL iter.hasNext();) {
DBObject dbo = (DBObject) iter.next();
T vo = toModel(dbo);
list.add(vo);
count(T param,Map&String, BasicDBObject& map) {
return getTable().find(getCondition( param, map)).count();
DBObject getCondition(T param,Map&String, BasicDBObject& map){
DBObject obj = new BasicDBObject();
for (Entry&String, Method& entry : READ_METHODS.entrySet()) {
try {//利用反射,这里所有的条件都是等于的,如果有其它条件如大于小于的条件就放到下面的map里,或者在子类实现里重写这个方法
if(entry.getValue().invoke(param)!=null)
obj.put(entry.getKey(), entry.getValue().invoke(param));
} catch (Exception e) {
e.printStackTrace();
if(map!=null)
for (Map.Entry&String, BasicDBObject& entry : map.entrySet()) {
//entry.getKey() 如是 starttime 则starttime是字段
//Map&String, BasicDBObject& map=new HashMap&String, BasicDBObject&();
//map.put("updatetime", new BasicDBObject("$gte"," 10:20:00"));
//map.put("updatetime", new BasicDBObject("$gte"," 10:20:00").append("$lte"," 15:21:00"));
obj.put(entry.getKey(), entry.getValue());
public void createIndex(BasicDBObject dbObject){
getTable().createIndex(dbObject);
?mongo的配置文件
&?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"&
&bean id="mongoManage" class="base.dao.mongo.MongoManager"&
&property name="host" value="127.0.0.1" /&
&property name="port" value="27017" /&
&property name="poolSize" value="100" /&
&property name="blockSize" value="40" /&
&bean id="mongoClient" factory-bean="mongoManage" factory-method="getMongoClient" /&
这样在service层就每次基本上都是直接调方法,以类的形式来调用mongo了。
接口采用apache 的cxf
接口验证类
package base.service.
public class BaseAuthorization {
private String userN
public String getUserName() {
return userN
public void setUserName(String userName) {
this.userName = userN
public String getPassword() {
public void setPassword(String password) {
this.password =
公共返回类
package base.service.
import java.io.S
import java.util.L
* 接口调用返回统一结果
* @author miraclerz
public class RespResult&T& implements Serializable {
private static final long serialVersionUID = 1L;
private String flag="F";//正常 "T" 不正常 "F"
private List&T&//返回的数据
public String getFlag() {
public void setFlag(String flag) {
this.flag =
public String getMsg() {
public void setMsg(String msg) {
this.msg =
public List&T& getData() {
public void setData(List&T& data) {
this.data =
package base.service.cxf.gn.ttlog.
import javax.jws.WebS
import base.model.gn.dtom.GnLogO
import base.service.cxf.BaseA
import base.service.cxf.RespR
* @author miraclerz
@WebService
public interface WsGnLogOrderServiceI {
* 得到最大或最小值
* @param field
以哪个字段排序
* @param asc
true表示升序,查出最小值;false或null表示降序,查出最大值
RespResult&GnLogOrder&
getLimit(BaseAuthorization authorization,String field,boolean asc);
* 根据订单id取得日志
* @param field
以哪个字段排序
* @param asc
true表示升序,查出最小值;false或null表示降序,查出最大值
RespResult&GnLogOrder&
getLogByOrderId(BaseAuthorization authorization,Integer orderid);
* 批量插入
如果开放给外面插入就把下面的注释去掉
* @param list
RespResult&GnLogOrder&
insertList(BaseAuthorization authorization,List&GnLogOrder& list);*/
package base.service.cxf.gn.ttlog.logorder.
import java.util.L
import javax.jws.WebS
import org.springframework.beans.factory.annotation.A
import base.model.gn.dtom.GnLogO
import base.service.cxf.BaseA
import base.service.cxf.RespR
import base.service.cxf.gn.ttlog.logorder.WsGnLogOrderServiceI;
import base.service.mongo.gn.dtom.MongoGnLogOrderServiceI;
import base.vo.DivPageVO;
import com.mongodb.WriteR
* @author miraclerz
@WebService(endpointInterface = "base.service.cxf.gn.ttlog.logorder.WsGnLogOrderServiceI", serviceName = "wsGnLogOrderService")
public class WsGnLogOrderServiceImpl
implements WsGnLogOrderServiceI {
@Autowired
private MongoGnLogOrderServiceI mongoGnLogOrderServiceI;
public RespResult&GnLogOrder& getLimit(BaseAuthorization authorization,String field, boolean asc) {
RespResult&GnLogOrder& respResult =new RespResult&GnLogOrder&();
DivPageVO page =new DivPageVO();
page.setStartPos(0);
page.setPageSize(1);
List&GnLogOrder& list=mongoGnLogOrderServiceI.find(new GnLogOrder(), null, page, field, asc);
if(list!=null&&list.size()&0)
respResult.setData(list);
respResult.setFlag("T");
respResult.setMsg("正常");
} catch (InstantiationException e) {
respResult.setFlag("F");
respResult.setMsg("接口异常");
e.printStackTrace();
} catch (IllegalAccessException e) {
respResult.setFlag("F");
respResult.setMsg("接口异常");
e.printStackTrace();
return respR
//@Override
public RespResult&GnLogOrder& insertList(BaseAuthorization authorization,List&GnLogOrder& list) {
RespResult&GnLogOrder& respResult =new RespResult&GnLogOrder&();
WriteResult writeResult=mongoGnLogOrderServiceI.insertList(list);
if(writeResult!=null)
respResult.setFlag("T");
respResult.setMsg("插入成功");
return respR
public RespResult&GnLogOrder& getLogByOrderId(BaseAuthorization authorization,
Integer orderid) {
RespResult&GnLogOrder& respResult =new RespResult&GnLogOrder&();
if(orderid==null)
respResult.setFlag("F");
respResult.setMsg("订单ID不能为空!");
return respR
GnLogOrder param=new GnLogOrder();
param.setOrderid(orderid);
List&GnLogOrder& list=mongoGnLogOrderServiceI.find(param, null, "id", true);
respResult.setData(list);
respResult.setFlag("T");
respResult.setMsg("正常");
} catch (Exception e) {
respResult.setFlag("F");
respResult.setMsg("接口异常");
e.printStackTrace();
return respR
? ?cxf配置文件
&?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:aop="http://www.springframework.org/schema/aop" xmlns:c="http://www.springframework.org/schema/c" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd "&
&import resource="classpath*:META-INF/cxf/cxf.xml" /&
&import resource="classpath*:META-INF/cxf/cxf-extension-soap.xml" /&
&import resource="classpath*:META-INF/cxf/cxf-servlet.xml" /&
&!-- 对外提供的WebService接口访问地址 --&
&!-- jaxws:endpoint可以有多个,自己配置;implementor指定到你的实现类,address是webservice相对于你项目的访问路径 --&
&!-- 下面这个示例服务访问地址就是http://localhost:9999/base/ws/webServiceDemo?wsdl,为什么前面要加一个ws,请看web.xml里面的cxfService配置 --&
&!-- webService一定要有接口和实现类,否则会出错 --&
&jaxws:endpoint implementor="base.service.cxf.gn.ttlog.logorder.impl.WsGnLogOrderServiceImpl" address="/wsGnLogOrderService" /&
? cxf接口类里会调用service层,service层有mysql和mongo等业务数据调用各自数据库的实现。
用spring 的aop实现用户验证
package base.
import java.lang.reflect.M
import org.apache.cxf.interceptor.F
import org.slf4j.L
import org.slf4j.LoggerF
import org.springframework.aop.AfterReturningA
import org.springframework.aop.MethodBeforeA
import org.springframework.aop.ThrowsA
import base.exception.ServiceE
import base.service.cxf.BaseA
* AOP切面类
* @author miraclerz
public class AuthAdvice implements MethodBeforeAdvice, AfterReturningAdvice, ThrowsAdvice {
public static final Logger logger = LoggerFactory.getLogger(AuthAdvice.class);
// service方法执行之前被调用
public void before(Method method, Object[] args, Object target) throws Throwable {
// System.out.println("切入点: " + target.getClass().getName() + "类中" + method.getName() + "方法");
boolean isAuth=
for (Object object : args) {
if(object!=null&&"baseauthorization".equals(object.getClass().getName().split("\\.")[object.getClass().getName().split("\\.").length-1].toLowerCase())){
//如果有带验证参数
BaseAuthorization auth=(BaseAuthorization)
if("admin".equals(auth.getUserName())&&"123456".equals(auth.getPassword()))
if(!isAuth)
Fault fault=new
Fault(new ServiceException("用户名或密码错误"));
//fault.setStatusCode(403);
// service方法执行完之后被调用
public void afterReturning(Object arg0, Method method, Object[] args, Object target) throws Throwable {
// 抛出Exception之后被调用
public void afterThrowing(Method method, Object[] args, Object target, Exception ex) throws Throwable {
&!-- 用户权限 --&
&bean id="authAdvice" class="base.aop.AuthAdvice" /&
&aop:config&
&aop:advisor
pointcut="(execution(* base.service.cxf..*Impl.*(..)))"
advice-ref="authAdvice" /&
&/aop:config&
? 今天的记录就到这!
?标签:&&&&&&&&&&&&原文:http://520shuijing.iteye.com/blog/2278126
教程昨日排行
&&国之画&&&& &&&&&&
&& &&&&&&&&&&&&&&
鲁ICP备号-4
打开技术之扣,分享程序人生!}

我要回帖

更多关于 java调用wsdl接口 cxf 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信