fixed #33
This commit is contained in:
parent
22f9511f0e
commit
ff7161f513
@ -1,7 +1,7 @@
|
|||||||
weixin4j-server
|
weixin4j-server
|
||||||
===============
|
===============
|
||||||
|
|
||||||
微信回调消息服务器
|
[微信回调消息](http://mp.weixin.qq.com/wiki/1/6239b44c206cab9145b1d52c67e6c551.html)服务器
|
||||||
----------------
|
----------------
|
||||||
base on netty.
|
base on netty.
|
||||||
|
|
||||||
@ -15,13 +15,6 @@ base on netty.
|
|||||||
|
|
||||||
如何使用
|
如何使用
|
||||||
-------
|
-------
|
||||||
###maven依赖(1.1.6,2016-02-04 released)
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.foxinmy</groupId>
|
|
||||||
<artifactId>weixin4j-server</artifactId>
|
|
||||||
<version>1.1.6</version>
|
|
||||||
</dependency>
|
|
||||||
###编写服务启动类
|
###编写服务启动类
|
||||||
明文模式并总是调试输出微信请求信息的服务启动类.
|
明文模式并总是调试输出微信请求信息的服务启动类.
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
package com.foxinmy.weixin4j.exception;
|
package com.foxinmy.weixin4j.exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 调用微信接口抛出的异常
|
* 微信异常
|
||||||
*
|
*
|
||||||
* @className WeixinException
|
* @className WeixinException
|
||||||
* @author jy.hu
|
* @author jy.hu
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import java.io.ObjectOutputStream;
|
|||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.net.JarURLConnection;
|
import java.net.JarURLConnection;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@ -17,6 +18,8 @@ import java.util.List;
|
|||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对class的获取
|
* 对class的获取
|
||||||
*
|
*
|
||||||
@ -27,6 +30,8 @@ import java.util.jar.JarFile;
|
|||||||
* @see
|
* @see
|
||||||
*/
|
*/
|
||||||
public final class ClassUtil {
|
public final class ClassUtil {
|
||||||
|
private final static String POINT = ".";
|
||||||
|
private final static String CLASS = ".class";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取某个包下所有的class信息
|
* 获取某个包下所有的class信息
|
||||||
@ -36,21 +41,25 @@ public final class ClassUtil {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static List<Class<?>> getClasses(String packageName)
|
public static List<Class<?>> getClasses(String packageName)
|
||||||
throws RuntimeException {
|
throws WeixinException {
|
||||||
String packageFileName = packageName.replace(".", File.separator);
|
String packageFileName = packageName.replace(POINT, File.separator);
|
||||||
URL fullPath = getDefaultClassLoader().getResource(packageFileName);
|
URL fullPath = getDefaultClassLoader().getResource(packageFileName);
|
||||||
String protocol = fullPath.getProtocol();
|
String protocol = fullPath.getProtocol();
|
||||||
if (protocol.equals(ServerToolkits.PROTOCOL_FILE)) {
|
if (protocol.equals(ServerToolkits.PROTOCOL_FILE)) {
|
||||||
File dir = new File(fullPath.getPath());
|
try {
|
||||||
|
File dir = new File(fullPath.toURI());
|
||||||
return findClassesByFile(dir, packageName);
|
return findClassesByFile(dir, packageName);
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
throw new WeixinException(e);
|
||||||
|
}
|
||||||
} else if (protocol.equals(ServerToolkits.PROTOCOL_JAR)) {
|
} else if (protocol.equals(ServerToolkits.PROTOCOL_JAR)) {
|
||||||
try {
|
try {
|
||||||
return findClassesByJar(
|
return findClassesByJar(
|
||||||
((JarURLConnection) fullPath.openConnection())
|
((JarURLConnection) fullPath.openConnection())
|
||||||
.getJarFile(),
|
.getJarFile(),
|
||||||
packageFileName);
|
packageName);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new WeixinException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -70,18 +79,18 @@ public final class ClassUtil {
|
|||||||
File[] files = dir.listFiles(new FilenameFilter() {
|
File[] files = dir.listFiles(new FilenameFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(File file, String name) {
|
public boolean accept(File file, String name) {
|
||||||
return file.isDirectory() || file.getName().endsWith(".class");
|
return file.isDirectory() || file.getName().endsWith(CLASS);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
classes.addAll(findClassesByFile(file, packageName + "."
|
classes.addAll(findClassesByFile(file, packageName + POINT
|
||||||
+ file.getName()));
|
+ file.getName()));
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
classes.add(Class.forName(packageName + "."
|
classes.add(Class.forName(packageName + POINT
|
||||||
+ file.getName().replace(".class", "")));
|
+ file.getName().replace(CLASS, "")));
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
@ -113,12 +122,12 @@ public final class ClassUtil {
|
|||||||
if (!entryName.startsWith(packageName)) {
|
if (!entryName.startsWith(packageName)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!entryName.endsWith(".class")) {
|
if (!entryName.endsWith(CLASS)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
classes.add(Class.forName(entryName.replaceAll("/", ".")
|
classes.add(Class.forName(entryName.replace(File.separator,
|
||||||
.replace(".class", "")));
|
POINT).replace(CLASS, "")));
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
@ -126,7 +135,7 @@ public final class ClassUtil {
|
|||||||
return classes;
|
return classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object deepClone(Object obj) throws RuntimeException {
|
public static Object deepClone(Object obj) throws WeixinException {
|
||||||
ByteArrayOutputStream bos = null;
|
ByteArrayOutputStream bos = null;
|
||||||
ObjectOutputStream oos = null;
|
ObjectOutputStream oos = null;
|
||||||
ByteArrayInputStream bis = null;
|
ByteArrayInputStream bis = null;
|
||||||
@ -139,9 +148,9 @@ public final class ClassUtil {
|
|||||||
ois = new ObjectInputStream(bis);
|
ois = new ObjectInputStream(bis);
|
||||||
return ois.readObject();
|
return ois.readObject();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new WeixinException(e);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
throw new RuntimeException(e);
|
throw new WeixinException(e);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (bos != null) {
|
if (bos != null) {
|
||||||
@ -203,8 +212,7 @@ public final class ClassUtil {
|
|||||||
return cl;
|
return cl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) throws WeixinException {
|
||||||
System.err
|
System.err.println(getClasses("com.foxinmy.weixin4j.qy.event"));
|
||||||
.println(getClasses("com.foxinmy.weixin4j.qy.event"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user