Skip to content

Commit f3ec0b1

Browse files
committed
issue binarywang#71 替换掉JAXB,避免因OpenJDK造成无法deserialize xml的错误
1 parent eaa77bc commit f3ec0b1

File tree

73 files changed

+834
-986
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+834
-986
lines changed

pom.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,6 @@
5555
<artifactId>httpmime</artifactId>
5656
<version>${httpclient.version}</version>
5757
</dependency>
58-
<dependency>
59-
<groupId>javax.xml.bind</groupId>
60-
<artifactId>jaxb-api</artifactId>
61-
<version>2.2.7</version>
62-
</dependency>
63-
<dependency>
64-
<groupId>com.sun.xml.bind</groupId>
65-
<artifactId>jaxb-impl</artifactId>
66-
<version>2.2.7</version>
67-
</dependency>
6858
<dependency>
6959
<groupId>com.google.code.gson</groupId>
7060
<artifactId>gson</artifactId>

weixin-java-common/pom.xml

Lines changed: 66 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,73 @@
11
<?xml version="1.0"?>
22
<project
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4-
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5-
<modelVersion>4.0.0</modelVersion>
6-
<parent>
7-
<groupId>me.chanjar</groupId>
8-
<artifactId>weixin-java-parent</artifactId>
9-
<version>1.0.7-SNAPSHOT</version>
10-
</parent>
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>me.chanjar</groupId>
8+
<artifactId>weixin-java-parent</artifactId>
9+
<version>1.0.7-SNAPSHOT</version>
10+
</parent>
1111

12-
<artifactId>weixin-java-common</artifactId>
13-
<name>WeiXin Java Tools - Common</name>
14-
<description>微信公众号、企业号Java SDK Common</description>
12+
<artifactId>weixin-java-common</artifactId>
13+
<name>WeiXin Java Tools - Common</name>
14+
<description>微信公众号、企业号Java SDK Common</description>
1515

16-
<dependencies>
17-
<dependency>
18-
<groupId>junit</groupId>
19-
<artifactId>junit</artifactId>
20-
<scope>test</scope>
21-
</dependency>
22-
<dependency>
23-
<groupId>org.testng</groupId>
24-
<artifactId>testng</artifactId>
25-
<version>6.8.7</version>
26-
<scope>test</scope>
27-
</dependency>
28-
<dependency>
29-
<groupId>org.mockito</groupId>
30-
<artifactId>mockito-all</artifactId>
31-
<version>1.9.5</version>
32-
<scope>test</scope>
33-
</dependency>
34-
<dependency>
35-
<groupId>com.google.inject</groupId>
36-
<artifactId>guice</artifactId>
37-
<version>3.0</version>
38-
<scope>test</scope>
39-
</dependency>
40-
<dependency>
41-
<groupId>org.eclipse.jetty</groupId>
42-
<artifactId>jetty-server</artifactId>
43-
<version>9.3.0.M0</version>
44-
<scope>test</scope>
45-
</dependency>
46-
<dependency>
47-
<groupId>org.eclipse.jetty</groupId>
48-
<artifactId>jetty-servlet</artifactId>
49-
<version>9.3.0.M0</version>
50-
<scope>test</scope>
51-
</dependency>
52-
</dependencies>
16+
<dependencies>
17+
<dependency>
18+
<groupId>com.thoughtworks.xstream</groupId>
19+
<artifactId>xstream</artifactId>
20+
<version>1.4.7</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>junit</groupId>
24+
<artifactId>junit</artifactId>
25+
<scope>test</scope>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.testng</groupId>
29+
<artifactId>testng</artifactId>
30+
<version>6.8.7</version>
31+
<scope>test</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.mockito</groupId>
35+
<artifactId>mockito-all</artifactId>
36+
<version>1.9.5</version>
37+
<scope>test</scope>
38+
</dependency>
39+
<dependency>
40+
<groupId>com.google.inject</groupId>
41+
<artifactId>guice</artifactId>
42+
<version>3.0</version>
43+
<scope>test</scope>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.eclipse.jetty</groupId>
47+
<artifactId>jetty-server</artifactId>
48+
<version>9.3.0.M0</version>
49+
<scope>test</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.eclipse.jetty</groupId>
53+
<artifactId>jetty-servlet</artifactId>
54+
<version>9.3.0.M0</version>
55+
<scope>test</scope>
56+
</dependency>
57+
</dependencies>
5358

54-
<build>
55-
<plugins>
56-
<plugin>
57-
<groupId>org.apache.maven.plugins</groupId>
58-
<artifactId>maven-surefire-plugin</artifactId>
59-
<configuration>
60-
<suiteXmlFiles>
61-
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
62-
</suiteXmlFiles>
63-
</configuration>
64-
</plugin>
65-
</plugins>
66-
</build>
59+
<build>
60+
<plugins>
61+
<plugin>
62+
<groupId>org.apache.maven.plugins</groupId>
63+
<artifactId>maven-surefire-plugin</artifactId>
64+
<configuration>
65+
<suiteXmlFiles>
66+
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
67+
</suiteXmlFiles>
68+
</configuration>
69+
</plugin>
70+
</plugins>
71+
</build>
6772

6873
</project>

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/AdapterCDATA.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/xml/MediaIdMarshaller.java

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package me.chanjar.weixin.common.util.xml;
2+
3+
import com.thoughtworks.xstream.converters.basic.StringConverter;
4+
5+
/**
6+
* Created by qianjia on 15/1/19.
7+
*/
8+
public class XStreamCDataConverter extends StringConverter {
9+
10+
@Override
11+
public String toString(Object obj) {
12+
return "<![CDATA[" + super.toString(obj) + "]]>";
13+
}
14+
15+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package me.chanjar.weixin.common.util.xml;
2+
3+
import com.thoughtworks.xstream.XStream;
4+
import com.thoughtworks.xstream.converters.basic.DoubleConverter;
5+
import com.thoughtworks.xstream.converters.basic.FloatConverter;
6+
import com.thoughtworks.xstream.converters.basic.IntConverter;
7+
import com.thoughtworks.xstream.core.util.QuickWriter;
8+
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
9+
import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
10+
import com.thoughtworks.xstream.io.xml.XppDriver;
11+
12+
import java.io.Writer;
13+
14+
/**
15+
* Created by qianjia on 15/1/19.
16+
*/
17+
public class XStreamInitializer {
18+
19+
public static XStream getInstance() {
20+
XStream xstream = new XStream(new XppDriver() {
21+
@Override
22+
public HierarchicalStreamWriter createWriter(Writer out) {
23+
return new PrettyPrintWriter(out, getNameCoder()) {
24+
protected String PREFIX_CDATA = "<![CDATA[";
25+
protected String SUFFIX_CDATA = "]]>";
26+
protected String PREFIX_MEDIA_ID = "<MediaId>";
27+
protected String SUFFIX_MEDIA_ID = "</MediaId>";
28+
@Override
29+
protected void writeText(QuickWriter writer, String text) {
30+
if (text.startsWith(PREFIX_CDATA) && text.endsWith(SUFFIX_CDATA)) {
31+
writer.write(text);
32+
} else if (text.startsWith(PREFIX_MEDIA_ID) && text.endsWith(SUFFIX_MEDIA_ID)) {
33+
writer.write(text);
34+
} else {
35+
super.writeText(writer, text);
36+
}
37+
38+
}
39+
};
40+
}
41+
});
42+
xstream.setMode(XStream.NO_REFERENCES);
43+
return xstream;
44+
}
45+
46+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package me.chanjar.weixin.common.util.xml;
2+
3+
/**
4+
* Created by qianjia on 15/1/19.
5+
*/
6+
public class XStreamMediaIdConverter extends XStreamCDataConverter {
7+
@Override
8+
public String toString(Object obj) {
9+
return "<MediaId>" + super.toString(obj) + "</MediaId>";
10+
}
11+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package me.chanjar.weixin.cp.api;
22

3-
import java.util.Map;
4-
53
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
64
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
75

6+
import java.util.Map;
7+
88
/**
99
* 处理微信推送消息的处理器接口
1010
* @author Daniel Qian

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageInterceptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package me.chanjar.weixin.cp.api;
22

3-
import java.util.Map;
4-
53
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
64

5+
import java.util.Map;
6+
77
/**
88
* 微信消息拦截器,可以用来做验证
99
* @author Daniel Qian

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageRouter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package me.chanjar.weixin.cp.api;
22

3+
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
4+
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
5+
36
import java.util.ArrayList;
47
import java.util.HashMap;
58
import java.util.List;
@@ -8,9 +11,6 @@
811
import java.util.concurrent.Executors;
912
import java.util.regex.Pattern;
1013

11-
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
12-
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
13-
1414
/**
1515
* <pre>
1616
* 微信消息路由器,通过代码化的配置,把来自微信的消息交给handler处理

0 commit comments

Comments
 (0)