标签:des style http java color 使用
环境:jdk1.7 grails2.4.0 ubuntu13
所需要的jar包:cxf-2.0.1
服务器端:
定义接口类:
public interface IApp{
...........//接口方法
}
定义实现类:
public class AppService implements IApp{
//定义远程调用方法使用哪种协议;rmi不可以跨防火墙;
static expose [‘cxf‘,‘rmi‘];
//剔除掉不需要被客户端调用的方法;
static excludes = [方法名];
............//方法实现
}
项目启动完成后在浏览器上输入http://项目所在IP:port/项目名/services/app?wsdl,整个页面会生成xml文件,说明cxf发布成功;
服务器发布完成后生成客户端:
eclipse:
1.先创建一个项目;
2.单击右键--> new -->other -->web Service client --> next ,输入http://项目所在IP:port/项目名/services/app?wsdl,生成客户端;
3.配置wsdl2java环境,window命令行输出:
//-p:wsdl的命名空间,也就是所谓的包名; -d:指定要生成代码所在的路径;
package com.boful.nts;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
public class BofulClassUtils {
public static void cloneObject(Object src, Object dest, String[] ignored) {
Class<?> class1 = src.getClass();
Class<?> class2 = dest.getClass();
Field[] fields1 = class1.getDeclaredFields();
Field[] fields2 = class2.getDeclaredFields();
Method[] methods1 = class1.getDeclaredMethods();
Method[] methods2 = class2.getDeclaredMethods();
System.out.println(fields1.length);
for (Field field : fields1) {
String fieldName1 = field.getName();
if (ignored != null && ignored.length > 0) {
if (Arrays.binarySearch(ignored, fieldName1) < 0) {
continue;
}
}
boolean isContain = false;
for (Field field2 : fields2) {
if (field2.getName().equals(fieldName1)) {
isContain = true;
break;
}
}
if (isContain) {
isContain = false;
String setMethodName = "set"
+ fieldName1.substring(0, 1).toUpperCase()
+ fieldName1.substring(1);
String getMethod = "get";
if((field.getType()==Boolean.class)||(field.getType()==boolean.class)){
getMethod = "is";
}
String getMethodName = getMethod + fieldName1.substring(0, 1).toUpperCase()
+ fieldName1.substring(1);
System.out.println(setMethodName);
for (Method method : methods2) {
if (method.getName().equals(setMethodName)) {
if (method.getReturnType() == void.class) {
if (method.getModifiers() == Modifier.PUBLIC) {
Class<?>[] paramTypes = method
.getParameterTypes();
System.out.println("--------------------" + field.getDeclaringClass().getName());
if ((paramTypes.length == 1)
&& (paramTypes[0] == field.getType())) {
try {
Method getMehod = class1.getMethod(getMethodName);
Object value = getMehod.invoke(src);
Method method2 = class2
.getMethod(setMethodName,
field.getType());
method2.invoke(dest, value);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
}
}
}
}
public static void cloneObject(Object src, Object dest) {
cloneObject(src, dest, null);
}
}
webservice cxf使用,布布扣,bubuko.com
标签:des style http java color 使用
原文地址:http://www.cnblogs.com/lvy6/p/3816241.html