Skip to content

Commit

Permalink
解决应用在servlet 3.0下出错的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Zhou committed Sep 27, 2013
1 parent 1d99662 commit f8ac04d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
5 changes: 3 additions & 2 deletions DEPLOY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ Sonatype OSS Staging 库管理: https://oss.sonatype.org/
========

cd citrus
mvn clean install // 编译和测试全部代码,在servlet 3.0环境下
mvn clean install -Dservlet2 // 编译和测试全部代码,在servlet 2.5环境下
mvn clean install // 编译和测试全部代码,在servlet 3.1环境下(默认)
mvn clean install -Dservlet30 // 编译和测试全部代码,在servlet 3.0环境下
mvn clean install -Dservlet2 // 编译和测试全部代码,在servlet 2.5环境下


发布步骤
Expand Down
9 changes: 5 additions & 4 deletions common/servlet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@
<phase>compile</phase>
<configuration>
<target>
<echo message="+-------------------------------------------------------------+" />
<echo message="! Servlet 3 Profile activated !" />
<echo message="! To test under Servlet 2, please using argument -Dservlet2 !" />
<echo message="+-------------------------------------------------------------+" />
<echo message="+----------------------------------------------------------------+" />
<echo message="! Servlet ${servlet3-version} Profile activated !" />
<echo message="! To test under Servlet 2, please using argument -Dservlet2 !" />
<echo message="! To test under Servlet 3.0, please using argument -Dservlet30 !" />
<echo message="+----------------------------------------------------------------+" />
</target>
</configuration>
<goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class Servlet3Util {
public static final Enum<?> DISPATCHER_TYPE_ASYNC = getEnum("javax.servlet.DispatcherType", "ASYNC");
public static final Enum<?> DISPATCHER_TYPE_ERROR = getEnum("javax.servlet.DispatcherType", "ERROR");

public static final Class<?> writeListenerClass = loadClass("javax.servlet.WriteListener");

private static final MethodInfo[] methods;
private static final int request_isAsyncStarted;
private static final int request_getAsyncContext;
Expand All @@ -76,7 +78,13 @@ public class Servlet3Util {
methodList.add(new MethodInfo(Boolean.class, true, ServletOutputStream.class, "isReady"));
servletOutputStream_isReady = count++;

methodList.add(new MethodInfo(null, null, ServletOutputStream.class, "setWriteListener", WriteListener.class));
// 这里不能硬编码WriteListener.class,否则在servlet 3.0环境中会失败。
if (writeListenerClass == null) {
methodList.add(new MethodInfo(null, null, null, null));
} else {
methodList.add(new MethodInfo(null, null, ServletOutputStream.class, "setWriteListener", writeListenerClass));
}

servletOutputStream_setWriteListener = count++;

methods = methodList.toArray(new MethodInfo[methodList.size()]);
Expand Down Expand Up @@ -123,6 +131,14 @@ public static boolean request_isDispatcherType(HttpServletRequest request, Enum<
}
}

private static Class<?> loadClass(String className) {
try {
return Servlet3Util.class.getClassLoader().loadClass(className);
} catch (ClassNotFoundException e) {
return null;
}
}

private static Object invoke(int methodIndex, Object target, Object... args) {
MethodInfo method = methods[methodIndex];

Expand Down
14 changes: 13 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<properties>
<java.version>1.6</java.version>
<java.encoding>UTF-8</java.encoding>
<servlet3-version>3.1.0</servlet3-version>
<webx-version>3.2.2</webx-version>
<spring-version>3.2.4.RELEASE</spring-version>
<springext-plugin-version>1.2</springext-plugin-version>
Expand All @@ -62,6 +63,17 @@
<gpg.skip>false</gpg.skip>
</properties>
</profile>
<profile>
<id>servlet30</id>
<activation>
<property>
<name>servlet30</name>
</property>
</activation>
<properties>
<servlet3-version>3.0.1</servlet3-version>
</properties>
</profile>
</profiles>
<modules>
<module>dist/springext</module>
Expand Down Expand Up @@ -580,7 +592,7 @@
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<version>${servlet3-version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down

0 comments on commit f8ac04d

Please sign in to comment.