You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2013/01/07 22:09:34 UTC
svn commit: r1430009 - in /webservices/commons/trunk/modules/axiom:
modules/axiom-api/src/main/java/org/apache/axiom/om/util/
modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/
systests/ systests/jboss-tests/ systests/jboss-tests/src/ ...
Author: veithen
Date: Mon Jan 7 21:09:34 2013
New Revision: 1430009
URL: http://svn.apache.org/viewvc?rev=1430009&view=rev
Log:
AXIOM-426:
* Fixed StAX dialect detection on JBoss AS 7.1.
* Added an Arquillian based test case that validates this on JBoss AS 7.1.1.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/JBossFactoryUnwrapper.java (with props)
webservices/commons/trunk/modules/axiom/systests/jboss-tests/ (with props)
webservices/commons/trunk/modules/axiom/systests/jboss-tests/pom.xml (with props)
webservices/commons/trunk/modules/axiom/systests/jboss-tests/src/
webservices/commons/trunk/modules/axiom/systests/jboss-tests/src/test/
webservices/commons/trunk/modules/axiom/systests/jboss-tests/src/test/java/
webservices/commons/trunk/modules/axiom/systests/jboss-tests/src/test/java/org/
webservices/commons/trunk/modules/axiom/systests/jboss-tests/src/test/java/org/apache/
webservices/commons/trunk/modules/axiom/systests/jboss-tests/src/test/java/org/apache/axiom/
webservices/commons/trunk/modules/axiom/systests/jboss-tests/src/test/java/org/apache/axiom/systest/
webservices/commons/trunk/modules/axiom/systests/jboss-tests/src/test/java/org/apache/axiom/systest/jboss/
webservices/commons/trunk/modules/axiom/systests/jboss-tests/src/test/java/org/apache/axiom/systest/jboss/DialectTest.java (with props)
webservices/commons/trunk/modules/axiom/systests/jboss-tests/src/test/resources/
webservices/commons/trunk/modules/axiom/systests/jboss-tests/src/test/resources/arquillian.xml (with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXUtils.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialectDetector.java
webservices/commons/trunk/modules/axiom/systests/pom.xml
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXUtils.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXUtils.java?rev=1430009&r1=1430008&r2=1430009&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXUtils.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXUtils.java Mon Jan 7 21:09:34 2013
@@ -447,7 +447,7 @@ public class StAXUtils {
factory.setProperty((String)entry.getKey(), entry.getValue());
}
}
- StAXDialect dialect = StAXDialectDetector.getDialect(factory.getClass());
+ StAXDialect dialect = StAXDialectDetector.getDialect(factory);
if (configuration != null) {
factory = configuration.configure(factory, dialect);
}
@@ -572,7 +572,7 @@ public class StAXUtils {
factory.setProperty((String)entry.getKey(), entry.getValue());
}
}
- StAXDialect dialect = StAXDialectDetector.getDialect(factory.getClass());
+ StAXDialect dialect = StAXDialectDetector.getDialect(factory);
if (configuration != null) {
factory = configuration.configure(factory, dialect);
}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/JBossFactoryUnwrapper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/JBossFactoryUnwrapper.java?rev=1430009&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/JBossFactoryUnwrapper.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/JBossFactoryUnwrapper.java Mon Jan 7 21:09:34 2013
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.util.stax.dialect;
+
+import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Utility class to remove the {@link XMLInputFactory} or {@link XMLOutputFactory} wrapper added by
+ * JBoss 7. This class gives access the actual (implementation dependent) factory. This is important
+ * to correct detect the StAX dialect.
+ */
+final class JBossFactoryUnwrapper {
+ private static final Log log = LogFactory.getLog(JBossFactoryUnwrapper.class);
+
+ private final Class wrapperClass;
+ private final Field actual;
+
+ private JBossFactoryUnwrapper(Class factoryType) throws Exception {
+ wrapperClass = Class.forName("__redirected.__" + factoryType.getSimpleName());
+ try {
+ actual = wrapperClass.getDeclaredField("actual");
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ actual.setAccessible(true);
+ return null;
+ }
+ });
+ } catch (Exception ex) {
+ log.error("Found JBoss wrapper class for " + factoryType.getSimpleName() + ", but unwrapping is not supported", ex);
+ throw ex;
+ }
+ }
+
+ /**
+ * Get the unwrapper for the given factory type.
+ *
+ * @param factoryType
+ * the factory type ({@link XMLInputFactory} or {@link XMLOutputFactory})
+ * @return the unwrapper, or <code>null</code> if the unwrapper could not be created (which
+ * usually means that the code is not executed inside JBoss)
+ */
+ static JBossFactoryUnwrapper create(Class factoryType) {
+ try {
+ return new JBossFactoryUnwrapper(factoryType);
+ } catch (Exception ex) {
+ return null;
+ }
+ }
+
+ Object unwrap(Object factory) {
+ if (wrapperClass.isInstance(factory)) {
+ try {
+ return actual.get(factory);
+ } catch (IllegalAccessException ex) {
+ throw new IllegalAccessError(ex.getMessage());
+ }
+ } else {
+ return factory;
+ }
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/JBossFactoryUnwrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialectDetector.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialectDetector.java?rev=1430009&r1=1430008&r2=1430009&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialectDetector.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/StAXDialectDetector.java Mon Jan 7 21:09:34 2013
@@ -62,6 +62,9 @@ public class StAXDialectDetector {
private static final Attributes.Name BUNDLE_VERSION =
new Attributes.Name("Bundle-Version");
+ private static final JBossFactoryUnwrapper jbossXMLInputFactoryUnwrapper = JBossFactoryUnwrapper.create(XMLInputFactory.class);
+ private static final JBossFactoryUnwrapper jbossXMLOutputFactoryUnwrapper = JBossFactoryUnwrapper.create(XMLOutputFactory.class);
+
/**
* Map that stores detected dialects by location. The location is the URL corresponding to the
* root folder of the classpath entry from which the StAX implementation is loaded. Note that
@@ -119,7 +122,7 @@ public class StAXDialectDetector {
* @see StAXDialect#normalize(XMLInputFactory)
*/
public static XMLInputFactory normalize(XMLInputFactory factory) {
- return getDialect(factory.getClass()).normalize(factory);
+ return getDialect(factory).normalize(factory);
}
/**
@@ -131,11 +134,16 @@ public class StAXDialectDetector {
* @see StAXDialect#normalize(XMLOutputFactory)
*/
public static XMLOutputFactory normalize(XMLOutputFactory factory) {
- return getDialect(factory.getClass()).normalize(factory);
+ return getDialect(factory).normalize(factory);
}
/**
* Detect the dialect of a given StAX implementation.
+ * <p>
+ * Note that to detect the StAX dialect of a given {@link XMLInputFactory} or
+ * {@link XMLOutputFactory} instance, it is generally preferable to use
+ * {@link #getDialect(XMLInputFactory)} or {@link #getDialect(XMLOutputFactory)} instead of this
+ * method.
*
* @param implementationClass
* any class that is part of the StAX implementation; typically this should be a
@@ -154,6 +162,34 @@ public class StAXDialectDetector {
return getDialect(implementationClass.getClassLoader(), rootUrl);
}
+ /**
+ * Detect the StAX dialect of a given {@link XMLInputFactory} instance.
+ *
+ * @param factory
+ * the factory instance
+ * @return the detected dialect
+ */
+ public static StAXDialect getDialect(XMLInputFactory factory) {
+ if (jbossXMLInputFactoryUnwrapper != null) {
+ factory = (XMLInputFactory)jbossXMLInputFactoryUnwrapper.unwrap(factory);
+ }
+ return getDialect(factory.getClass());
+ }
+
+ /**
+ * Detect the StAX dialect of a given {@link XMLOutputFactory} instance.
+ *
+ * @param factory
+ * the factory instance
+ * @return the detected dialect
+ */
+ public static StAXDialect getDialect(XMLOutputFactory factory) {
+ if (jbossXMLOutputFactoryUnwrapper != null) {
+ factory = (XMLOutputFactory)jbossXMLOutputFactoryUnwrapper.unwrap(factory);
+ }
+ return getDialect(factory.getClass());
+ }
+
private static StAXDialect getDialect(ClassLoader classLoader, URL rootUrl) {
StAXDialect dialect = (StAXDialect)dialectByUrl.get(rootUrl);
if (dialect != null) {
Propchange: webservices/commons/trunk/modules/axiom/systests/jboss-tests/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Jan 7 21:09:34 2013
@@ -0,0 +1,4 @@
+.settings
+target
+.classpath
+.project
Added: webservices/commons/trunk/modules/axiom/systests/jboss-tests/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/systests/jboss-tests/pom.xml?rev=1430009&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/systests/jboss-tests/pom.xml (added)
+++ webservices/commons/trunk/modules/axiom/systests/jboss-tests/pom.xml Mon Jan 7 21:09:34 2013
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.ws.commons.axiom</groupId>
+ <artifactId>systests</artifactId>
+ <version>1.2.15-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>jboss-tests</artifactId>
+ <name>JBoss Tests</name>
+ <packaging>jar</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>axiom-impl</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.junit</groupId>
+ <artifactId>arquillian-junit-container</artifactId>
+ <version>1.0.3.Final</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.as</groupId>
+ <artifactId>jboss-as-arquillian-container-managed</artifactId>
+ <version>7.1.1.Final</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>unpack</id>
+ <phase>process-test-classes</phase>
+ <goals>
+ <goal>unpack</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.jboss.as</groupId>
+ <artifactId>jboss-as-dist</artifactId>
+ <version>7.1.1.Final</version>
+ <type>zip</type>
+ <overWrite>false</overWrite>
+ <outputDirectory>target</outputDirectory>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: webservices/commons/trunk/modules/axiom/systests/jboss-tests/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/systests/jboss-tests/src/test/java/org/apache/axiom/systest/jboss/DialectTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/systests/jboss-tests/src/test/java/org/apache/axiom/systest/jboss/DialectTest.java?rev=1430009&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/systests/jboss-tests/src/test/java/org/apache/axiom/systest/jboss/DialectTest.java (added)
+++ webservices/commons/trunk/modules/axiom/systests/jboss-tests/src/test/java/org/apache/axiom/systest/jboss/DialectTest.java Mon Jan 7 21:09:34 2013
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.systest.jboss;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import java.io.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+
+import org.apache.axiom.om.OMDocType;
+import org.apache.axiom.om.OMDocument;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.util.stax.dialect.StAXDialectDetector;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.resolver.api.DependencyResolvers;
+import org.jboss.shrinkwrap.resolver.api.maven.MavenDependencyResolver;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(Arquillian.class)
+public class DialectTest {
+ @Deployment
+ public static WebArchive createDeployment() {
+ return ShrinkWrap.create(WebArchive.class, "dialect-test.war")
+ .addAsLibraries(DependencyResolvers.use(MavenDependencyResolver.class).loadMetadataFromPom("pom.xml").goOffline()
+ .artifact("org.apache.ws.commons.axiom:axiom-impl").resolveAsFiles());
+ }
+
+ /**
+ * Directly tests {@link StAXDialectDetector}.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testStAXDialectDetector() throws Exception {
+ assertFalse(StAXDialectDetector.getDialect(XMLInputFactory.newFactory()).getName().equals("Unknown"));
+ assertFalse(StAXDialectDetector.getDialect(XMLOutputFactory.newFactory()).getName().equals("Unknown"));
+ }
+
+ /**
+ * Tests that Axiom is able to read a DOCTYPE declaration. Since accessing the information in
+ * the DOCTYPE declaration is not standardized by the StAX specification, this will fail if the
+ * StAX dialect is not detected correctly.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testDTD() throws Exception {
+ OMDocument document = OMXMLBuilderFactory.createOMBuilder(new StringReader("<!DOCTYPE root><root/>")).getDocument();
+ OMDocType dtd = (OMDocType)document.getFirstOMChild();
+ assertEquals("root", dtd.getRootName());
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/systests/jboss-tests/src/test/java/org/apache/axiom/systest/jboss/DialectTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/systests/jboss-tests/src/test/resources/arquillian.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/systests/jboss-tests/src/test/resources/arquillian.xml?rev=1430009&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/systests/jboss-tests/src/test/resources/arquillian.xml (added)
+++ webservices/commons/trunk/modules/axiom/systests/jboss-tests/src/test/resources/arquillian.xml Mon Jan 7 21:09:34 2013
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+<arquillian xmlns="http://jboss.org/schema/arquillian"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
+ <container qualifier="jbossas-managed" default="true">
+ <configuration>
+ <property name="jbossHome">target/jboss-as-7.1.1.Final</property>
+ </configuration>
+ </container>
+</arquillian>
Propchange: webservices/commons/trunk/modules/axiom/systests/jboss-tests/src/test/resources/arquillian.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/commons/trunk/modules/axiom/systests/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/systests/pom.xml?rev=1430009&r1=1430008&r2=1430009&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/systests/pom.xml (original)
+++ webservices/commons/trunk/modules/axiom/systests/pom.xml Mon Jan 7 21:09:34 2013
@@ -46,6 +46,7 @@
</plugins>
</build>
<modules>
+ <module>jboss-tests</module>
<module>osgi-tests</module>
</modules>
</project>