You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sc...@apache.org on 2009/11/23 16:09:50 UTC
svn commit: r883361 - in /webservices/axis2/trunk/java/modules:
jaxws-integration/test/org/apache/axis2/jaxws/misc/JAXBContextTest.java
jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
Author: scheu
Date: Mon Nov 23 15:09:49 2009
New Revision: 883361
URL: http://svn.apache.org/viewvc?rev=883361&view=rev
Log:
AXIs2-4562
Contributor:Rich Scheuerle
To improve the performance of the initialization of a JAXBContext, exclude SessionBean objects from the calculation.
Also provided a test.
Modified:
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/misc/JAXBContextTest.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/misc/JAXBContextTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/misc/JAXBContextTest.java?rev=883361&r1=883360&r2=883361&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/misc/JAXBContextTest.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/misc/JAXBContextTest.java Mon Nov 23 15:09:49 2009
@@ -57,6 +57,9 @@
assertTrue(jaxbContext1 != null);
assertTrue(context1.contains("org.test.addnumbers"));
assertTrue(context1.contains("org.test.anytype"));
+ String context1String = jaxbContext1.toString();
+ assertTrue(context1String.contains("org.test.addnumbers"));
+ assertTrue(context1String.contains("org.test.anytype"));
// Repeat with the same packages
TreeSet<String> context2 = new TreeSet<String>();
@@ -71,6 +74,10 @@
assertTrue(jaxbContext2.toString().equals(jaxbContext1.toString()));
assertTrue(context2.contains("org.test.addnumbers"));
assertTrue(context2.contains("org.test.anytype"));
+ String context2String = jaxbContext2.toString();
+ assertTrue(context2String.contains("org.test.addnumbers"));
+ assertTrue(context2String.contains("org.test.anytype"));
+
// Repeat with the same packages + an invalid package
TreeSet<String> context3 = new TreeSet<String>();
@@ -83,12 +90,14 @@
// The following assertion is probably true,but GC may have wiped out the weak reference
//assertTrue(jaxbContext3 == jaxbContext1);
assertTrue(jaxbContext3 != null);
- assertTrue(jaxbContext1.toString().equals(jaxbContext1.toString()));
+
assertTrue(context3.contains("org.test.addnumbers"));
assertTrue(context3.contains("org.test.anytype"));
- // The invalid package should now be retained...this is due
- // a minor semantic change to avoid this side effect.
- assertTrue(context3.contains("my.grandma.loves.jaxws"));
+ assertTrue(context3.contains("my.grandma.loves.jaxws"));
+ String context3String = jaxbContext3.toString();
+ assertTrue(context3String.contains("org.test.addnumbers"));
+ assertTrue(context3String.contains("org.test.anytype"));
+ assertTrue(!context3String.contains("my.grandma.loves.jaxws"));
// Repeat with a subset of packages
TreeSet<String> context4 = new TreeSet<String>();
@@ -101,4 +110,80 @@
assertTrue(jaxbContext4 != jaxbContext3);
assertTrue(context4.contains("org.test.addnumbers"));
}
+
+ /**
+ * Test basic functionality of JAXBUtils pooling
+ * @throws Exception
+ */
+ public void test02() throws JAXBException {
+ // Get a JAXBContext
+ TreeSet<String> context1 = new TreeSet<String>();
+ context1.add("org.test.addnumbers");
+ context1.add("org.test.anytype");
+ context1.add("org.apache.axis2.jaxws.misc.jaxbexclude");
+
+ JAXBContext jaxbContext1 = JAXBUtils.getJAXBContext(context1);
+
+ // Assert that the JAXBContext was found and the context contains the two valid packages
+ assertTrue(jaxbContext1 != null);
+ assertTrue(context1.contains("org.test.addnumbers"));
+ assertTrue(context1.contains("org.test.anytype"));
+ assertTrue(context1.contains("org.apache.axis2.jaxws.misc.jaxbexclude"));
+ String context1String = jaxbContext1.toString();
+ assertTrue(context1String.contains("org.test.addnumbers"));
+ assertTrue(context1String.contains("org.test.anytype"));
+ assertTrue(!context1String.contains("org.apache.axis2.jaxws.misc.jaxbexclude"));
+
+ // Repeat with the same packages
+ TreeSet<String> context2 = new TreeSet<String>();
+ context2.add("org.test.addnumbers");
+ context2.add("org.test.anytype");
+ context2.add("org.apache.axis2.jaxws.misc.jaxbexclude");
+
+ JAXBContext jaxbContext2 = JAXBUtils.getJAXBContext(context2);
+
+ // The following assertion is probably true,but GC may have wiped out the weak reference
+ //assertTrue(jaxbContext2 == jaxbContext1);
+ assertTrue(jaxbContext2 != null);
+ assertTrue(jaxbContext2.toString().equals(jaxbContext1.toString()));
+ assertTrue(context2.contains("org.test.addnumbers"));
+ assertTrue(context2.contains("org.test.anytype"));
+ String context2String = jaxbContext2.toString();
+ assertTrue(context2String.contains("org.test.addnumbers"));
+ assertTrue(context2String.contains("org.test.anytype"));
+ assertTrue(!context2String.contains("org.apache.axis2.jaxws.misc.jaxbexclude"));
+
+ // Repeat with the same packages + an invalid package
+ TreeSet<String> context3 = new TreeSet<String>();
+ context3.add("org.test.addnumbers");
+ context3.add("org.test.anytype");
+ context3.add("my.grandma.loves.jaxws");
+ context3.add("org.apache.axis2.jaxws.misc.jaxbexclude");
+
+ JAXBContext jaxbContext3 = JAXBUtils.getJAXBContext(context3);
+
+ // The following assertion is probably true,but GC may have wiped out the weak reference
+ //assertTrue(jaxbContext3 == jaxbContext1);
+ assertTrue(jaxbContext3 != null);
+ assertTrue(jaxbContext3.toString().equals(jaxbContext3.toString()));
+ assertTrue(context3.contains("org.test.addnumbers"));
+ assertTrue(context3.contains("org.test.anytype"));
+ assertTrue(context3.contains("my.grandma.loves.jaxws"));
+ String context3String = jaxbContext3.toString();
+ assertTrue(context3String.contains("org.test.addnumbers"));
+ assertTrue(context3String.contains("org.test.anytype"));
+ assertTrue(!context3String.contains("my.grandma.loves.jaxws"));
+ assertTrue(!context3String.contains("org.apache.axis2.jaxws.misc.jaxbexclude"));
+
+ // Repeat with a subset of packages
+ TreeSet<String> context4 = new TreeSet<String>();
+ context4.add("org.test.addnumbers");
+
+
+ JAXBContext jaxbContext4 = JAXBUtils.getJAXBContext(context4);
+
+ assertTrue(jaxbContext4 != null);
+ assertTrue(jaxbContext4 != jaxbContext3);
+ assertTrue(context4.contains("org.test.addnumbers"));
+ }
}
\ No newline at end of file
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java?rev=883361&r1=883360&r2=883361&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java Mon Nov 23 15:09:49 2009
@@ -879,6 +879,7 @@
getAnnotation(cls, XmlType.class) != null ||
ClassUtils.getDefaultPublicConstructor(cls) != null) &&
!ClassUtils.isJAXWSClass(cls) &&
+ !isSkipClass(cls) &&
cls.getPackage().getName().equals(pkg)) {
i++; // Acceptable class
} else {
@@ -945,6 +946,7 @@
getAnnotation(clazz, XmlType.class) != null ||
ClassUtils.getDefaultPublicConstructor(clazz) != null)
&& !ClassUtils.isJAXWSClass(clazz)
+ && !isSkipClass(clazz)
&& !java.lang.Exception.class.isAssignableFrom(clazz)) {
// Ensure that all the referenced classes are loadable too
@@ -1055,6 +1057,73 @@
return cl;
}
+
+
+ /**
+ * @return true if clazz is a class that should be skipped (should not
+ * be a considered for JAXB)
+ */
+ private static boolean isSkipClass(Class clazz) {
+
+ Class cls = clazz;
+ while (cls != null) {
+ // Check the name of the class to see if it should be excluded.
+ String clsName = cls.getCanonicalName();
+ if (clsName != null &&
+ (clsName.equals("javax.ejb.SessionBean") ||
+ clsName.equals("org.apache.axis2.jaxws.spi.JAXBExclude"))) {
+ if (log.isDebugEnabled()) {
+ log.debug("isSkipClass returns true for : " + clazz);
+ log.debug(" (It is skipped because the class extends " + clsName);
+ }
+ return true;
+ }
+
+ // Check the interfaces of the class to see if it should be excluded
+ Class[] intferfaces = getInterfaces_priv(cls);
+ if (intferfaces != null) {
+ for (int i=0; i<intferfaces.length; i++) {
+ clsName = intferfaces[i].getCanonicalName();
+ if (clsName != null &&
+ (clsName.equals("javax.ejb.SessionBean") ||
+ clsName.equals("org.apache.axis2.jaxws.spi.JAXBExclude"))) {
+ if (log.isDebugEnabled()) {
+ log.debug("isSkipClass returns true for : " + clazz);
+ log.debug(" (It is skipped because the class implements " + clsName);
+ }
+ return true;
+ }
+ }
+ }
+ cls = cls.getSuperclass(); // Proceed up the hierarchy
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("isSkipClass returns false for : " + clazz);
+ }
+ return false;
+ }
+
+ private static Class[] getInterfaces_priv(final Class cls) {
+ Class[] intferfaces = null;
+ if (cls == null) {
+ return null;
+ }
+ try {
+ intferfaces = (Class[]) AccessController.doPrivileged(
+ new PrivilegedExceptionAction() {
+ public Object run() throws ClassNotFoundException {
+ return cls.getInterfaces();
+ }
+ }
+ );
+ } catch (PrivilegedActionException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("Exception thrown from AccessController: " + e);
+ log.debug("Exception is ignored.");
+ }
+ }
+ return intferfaces;
+ }
/**
* Return the class for this name