You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by ve...@apache.org on 2012/11/17 18:33:06 UTC
svn commit: r1410754 - in /axis/axis1/java/trunk:
axis-rt-core/src/main/java/org/apache/axis/configuration/
axis-rt-core/src/main/java/org/apache/axis/utils/
axis-rt-transport-http-javanet/src/main/resources/META-INF/
axis-rt-transport-http-javanet/src...
Author: veithen
Date: Sat Nov 17 17:33:04 2012
New Revision: 1410754
URL: http://svn.apache.org/viewvc?rev=1410754&view=rev
Log:
Added a mechanism that allows individual JARs to contribute items to the default client or server configuration. This is essential for splitting up the Axis JAR into smaller modules.
Added:
axis/axis1/java/trunk/axis-rt-core/src/main/java/org/apache/axis/configuration/DefaultConfiguration.java (with props)
axis/axis1/java/trunk/axis-rt-transport-http-javanet/src/main/resources/META-INF/
axis/axis1/java/trunk/axis-rt-transport-http-javanet/src/main/resources/META-INF/axis/
axis/axis1/java/trunk/axis-rt-transport-http-javanet/src/main/resources/META-INF/axis/default-client-config.wsdd
axis/axis1/java/trunk/axis-rt-transport-http-javanet/src/test/java/org/apache/axis/transport/http/javanet/TestDefaultConfiguration.java (with props)
Removed:
axis/axis1/java/trunk/axis-rt-transport-http-javanet/src/test/resources/
axis/axis1/java/trunk/interop/src/test/resources/
Modified:
axis/axis1/java/trunk/axis-rt-core/src/main/java/org/apache/axis/configuration/FileProvider.java
axis/axis1/java/trunk/axis-rt-core/src/main/java/org/apache/axis/utils/ClassUtils.java
axis/axis1/java/trunk/axis-rt-transport-http-javanet/src/site/apt/index.apt.vm
Added: axis/axis1/java/trunk/axis-rt-core/src/main/java/org/apache/axis/configuration/DefaultConfiguration.java
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-rt-core/src/main/java/org/apache/axis/configuration/DefaultConfiguration.java?rev=1410754&view=auto
==============================================================================
--- axis/axis1/java/trunk/axis-rt-core/src/main/java/org/apache/axis/configuration/DefaultConfiguration.java (added)
+++ axis/axis1/java/trunk/axis-rt-core/src/main/java/org/apache/axis/configuration/DefaultConfiguration.java Sat Nov 17 17:33:04 2012
@@ -0,0 +1,158 @@
+/*
+ * 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.axis.configuration;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Enumeration;
+
+import org.apache.axis.AxisEngine;
+import org.apache.axis.ConfigurationException;
+import org.apache.axis.components.logger.LogFactory;
+import org.apache.axis.deployment.wsdd.WSDDDeployment;
+import org.apache.axis.deployment.wsdd.WSDDDocument;
+import org.apache.axis.utils.XMLUtils;
+import org.apache.commons.logging.Log;
+
+/**
+ * Configuration provider that loads the default Axis configuration. It first loads the
+ * <tt>org/apache/axis/<type>/<type>-config.wsdd</tt> resource and then searches for resources
+ * with name <tt>META-INF/axis/default-<type>-config.wsdd</tt>. All the discovered WSDD documents
+ * are merged into a single configuration. <tt><type></tt> identifies the engine type for which
+ * the configuration is to be built; it is either <tt>client</tt> or <tt>server</tt>.
+ * <p>
+ * This class looks up the resources using the thread context class loader, except if it determines
+ * that the context class loader is not set correctly, in which case it falls back to the class
+ * loader that loaded the {@link DefaultConfiguration} class. To determine if the context class
+ * loader is set correctly, the code checks that the {@link DefaultConfiguration} class is visible
+ * to the context class loader.
+ * <p>
+ * The algorithm implemented by this class is designed to support the modularized artifacts
+ * introduced in Axis 1.4.1. It allows individual JARs to contribute items (transports, handlers,
+ * etc.) to the default configuration. The naming convention for the base configuration file
+ * (<tt>org/apache/axis/<type>/<type>-config.wsdd</tt>) was chosen for consistency with Axis
+ * 1.4, while <tt>META-INF/axis/default-<type>-config.wsdd</tt> is new in Axis 1.4.1.
+ * <p>
+ * {@link DefaultConfiguration} is also used by {@link FileProvider} to build the configuration if
+ * no existing configuration file is found.
+ *
+ * @author Andreas Veithen
+ */
+public class DefaultConfiguration extends DelegatingWSDDEngineConfiguration {
+ private static final Log log = LogFactory.getLog(DefaultConfiguration.class.getName());
+
+ private final String type;
+ private WSDDDeployment deployment;
+
+ /**
+ * Constructor.
+ *
+ * @param type
+ * the engine type to load the default configuration for; this should be
+ * <code>client</code> or <code>server</code> (although any value is supported)
+ */
+ public DefaultConfiguration(String type) {
+ this.type = type;
+ }
+
+ public void configureEngine(AxisEngine engine) throws ConfigurationException {
+ ClassLoader classLoader;
+ try {
+ classLoader = Thread.currentThread().getContextClassLoader();
+ } catch (SecurityException ex) {
+ // We can only get a SecurityException if "the caller's class loader is not the same as
+ // or an ancestor of the context class loader". In this case we are not interested in
+ // the class loader anyway.
+ classLoader = null;
+ }
+ if (classLoader != null) {
+ // Check if we are visible to the thread context class loader. If this is not the case,
+ // then the context class loader is likely not set correctly and we ignore it.
+ try {
+ classLoader.loadClass(DefaultConfiguration.class.getName());
+ } catch (ClassNotFoundException ex) {
+ log.debug(DefaultConfiguration.class.getName() + " not visible to thread context class loader");
+ classLoader = null;
+ }
+ }
+ if (classLoader == null) {
+ log.debug("Not using thread context class loader");
+ classLoader = DefaultConfiguration.class.getClassLoader();
+ } else {
+ log.debug("Using thread context class loader");
+ }
+
+ // Load the base configuration
+ String resourceName = "org/apache/axis/" + type + "/" + type + "-config.wsdd";
+ if (log.isDebugEnabled()) {
+ log.debug("Loading resource " + resourceName);
+ }
+ InputStream in = classLoader.getResourceAsStream(resourceName);
+ if (in == null) {
+ throw new ConfigurationException("Resource " + resourceName + " not found");
+ }
+ try {
+ try {
+ deployment = new WSDDDocument(XMLUtils.newDocument(in)).getDeployment();
+ } finally {
+ in.close();
+ }
+ } catch (Exception ex) {
+ // TODO: refactor ConfigurationException to support exception chaining
+ throw new ConfigurationException(/*"Failed to process resource " + baseConfigResource,*/ ex);
+ }
+
+ // Discover and load additional default configuration fragments
+ resourceName = "META-INF/axis/default-" + type + "-config.wsdd";
+ Enumeration resources;
+ try {
+ resources = classLoader.getResources(resourceName);
+ } catch (IOException ex) {
+ // TODO: refactor ConfigurationException to support exception chaining
+ throw new ConfigurationException(/*"Failed to discover resources with name " + resourceName,*/ ex);
+ }
+ while (resources.hasMoreElements()) {
+ URL url = (URL)resources.nextElement();
+ if (log.isDebugEnabled()) {
+ log.debug("Loading " + url);
+ }
+ try {
+ in = url.openStream();
+ try {
+ new WSDDDocument(XMLUtils.newDocument(in)).deploy(deployment);
+ } finally {
+ in.close();
+ }
+ } catch (Exception ex) {
+ // TODO: refactor ConfigurationException to support exception chaining
+ throw new ConfigurationException(/*"Failed to process " + url,*/ ex);
+ }
+ }
+ deployment.configureEngine(engine);
+ }
+
+ public WSDDDeployment getDeployment() {
+ return deployment;
+ }
+
+ public void writeEngineConfig(AxisEngine engine) throws ConfigurationException {
+ // Default configuration is read-only
+ }
+}
Propchange: axis/axis1/java/trunk/axis-rt-core/src/main/java/org/apache/axis/configuration/DefaultConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: axis/axis1/java/trunk/axis-rt-core/src/main/java/org/apache/axis/configuration/FileProvider.java
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-rt-core/src/main/java/org/apache/axis/configuration/FileProvider.java?rev=1410754&r1=1410753&r2=1410754&view=diff
==============================================================================
--- axis/axis1/java/trunk/axis-rt-core/src/main/java/org/apache/axis/configuration/FileProvider.java (original)
+++ axis/axis1/java/trunk/axis-rt-core/src/main/java/org/apache/axis/configuration/FileProvider.java Sat Nov 17 17:33:04 2012
@@ -156,21 +156,39 @@ public class FileProvider extends Delega
try {
setInputStream(new FileInputStream(configFile));
} catch (Exception e) {
- if (searchClasspath)
- setInputStream(ClassUtils.getResourceAsStream(engine.getClass(), filename, true));
+ // Ignore and continue
}
}
+ if (getInputStream() == null && searchClasspath) {
+ // Attempt to load the file from the classpath
+ setInputStream(ClassUtils.getResourceAsStream(filename, engine.getClass().getClassLoader()));
+ }
if (getInputStream() == null) {
- throw new ConfigurationException(
- Messages.getMessage("noConfigFile"));
+ // Load the default configuration. This piece of code provides compatibility with Axis 1.4,
+ // which ends up loading org/apache/axis/(client|server)/(client|server)-config.wsdd if
+ // (1) filename is (client|server)-config.wsdd;
+ // (2) the runtime type of the engine is AxisClient or AxisServer;
+ // (3) the file is not found on the file system or in the classpath.
+ String type;
+ if (filename.equals(EngineConfigurationFactoryDefault.CLIENT_CONFIG_FILE)) {
+ type = "client";
+ } else if (filename.equals(EngineConfigurationFactoryDefault.SERVER_CONFIG_FILE)) {
+ type = "server";
+ } else {
+ throw new ConfigurationException(
+ Messages.getMessage("noConfigFile"));
+ }
+ DefaultConfiguration defaultConfig = new DefaultConfiguration(type);
+ defaultConfig.configureEngine(engine);
+ deployment = defaultConfig.getDeployment();
+ } else {
+ WSDDDocument doc = new WSDDDocument(XMLUtils.
+ newDocument(getInputStream()));
+ deployment = doc.getDeployment();
+
+ deployment.configureEngine(engine);
}
-
- WSDDDocument doc = new WSDDDocument(XMLUtils.
- newDocument(getInputStream()));
- deployment = doc.getDeployment();
-
- deployment.configureEngine(engine);
engine.refreshGlobalOptions();
setInputStream(null);
Modified: axis/axis1/java/trunk/axis-rt-core/src/main/java/org/apache/axis/utils/ClassUtils.java
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-rt-core/src/main/java/org/apache/axis/utils/ClassUtils.java?rev=1410754&r1=1410753&r2=1410754&view=diff
==============================================================================
--- axis/axis1/java/trunk/axis-rt-core/src/main/java/org/apache/axis/utils/ClassUtils.java (original)
+++ axis/axis1/java/trunk/axis-rt-core/src/main/java/org/apache/axis/utils/ClassUtils.java Sat Nov 17 17:33:04 2012
@@ -161,30 +161,33 @@ public final class ClassUtils {
* Get an input stream from a named resource.
* Tries
* <ol>
- * <li>the classloader that loaded "clazz" first,
+ * <li>the thread context class loader
+ * <li>the given fallback classloader
* <li>the system classloader
- * <li>the class "clazz" itself
* </ol>
- * @param clazz class to use in the lookups
* @param resource resource string to look for
- * @param checkThreadContextFirst check the thread context first?
+ * @param fallbackClassLoader the class loader to use if the resource could not be loaded from
+ * the thread context class loader
* @return input stream if found, or null
*/
- public static InputStream getResourceAsStream(Class clazz, String resource, boolean checkThreadContextFirst) {
- InputStream myInputStream = null;
+ public static InputStream getResourceAsStream(String resource, ClassLoader fallbackClassLoader) {
+ InputStream is = null;
- if (checkThreadContextFirst &&
- Thread.currentThread().getContextClassLoader() != null) {
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ if (tccl != null) {
// try the context class loader.
- myInputStream =
- Thread.currentThread().getContextClassLoader()
- .getResourceAsStream(resource);
+ is = tccl.getResourceAsStream(resource);
}
- if (myInputStream == null) {
+ if (is == null) {
// if not found in context class loader fall back to default
- myInputStream = getResourceAsStream(clazz, resource);
+ if (fallbackClassLoader != null) {
+ is = fallbackClassLoader.getResourceAsStream(resource);
+ } else {
+ // Try the system class loader.
+ is = ClassLoader.getSystemClassLoader().getResourceAsStream(resource);
+ }
}
- return myInputStream;
+ return is;
}
/**
Added: axis/axis1/java/trunk/axis-rt-transport-http-javanet/src/main/resources/META-INF/axis/default-client-config.wsdd
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-rt-transport-http-javanet/src/main/resources/META-INF/axis/default-client-config.wsdd?rev=1410754&view=auto
==============================================================================
--- axis/axis1/java/trunk/axis-rt-transport-http-javanet/src/main/resources/META-INF/axis/default-client-config.wsdd (added)
+++ axis/axis1/java/trunk/axis-rt-transport-http-javanet/src/main/resources/META-INF/axis/default-client-config.wsdd Sat Nov 17 17:33:04 2012
@@ -0,0 +1,24 @@
+<?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.
+ -->
+<deployment name="axis-rt-transport-http-javanet"
+ xmlns="http://xml.apache.org/axis/wsdd/"
+ xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
+ <transport name="http" pivot="java:org.apache.axis.transport.http.javanet.JavaNetHTTPSender"/>
+</deployment>
Modified: axis/axis1/java/trunk/axis-rt-transport-http-javanet/src/site/apt/index.apt.vm
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-rt-transport-http-javanet/src/site/apt/index.apt.vm?rev=1410754&r1=1410753&r2=1410754&view=diff
==============================================================================
--- axis/axis1/java/trunk/axis-rt-transport-http-javanet/src/site/apt/index.apt.vm (original)
+++ axis/axis1/java/trunk/axis-rt-transport-http-javanet/src/site/apt/index.apt.vm Sat Nov 17 17:33:04 2012
@@ -36,9 +36,20 @@
<<<HTTPSender>>>. However, it only works with Java 1.5 or higher because it relies on features of
the <<<java.net.HttpURLConnection>>> API that were not available in earlier Java versions.
- To use the java.net based HTTP transport, add <<<${project.artifactId}-${project.version}.jar>>> to the class path and set up
- <<<client-config.wsdd>>> with the right pivot handler for the <<<http>>> transport, as shown in the following
+ To use the java.net based HTTP transport, add <<<${project.artifactId}-${project.version}.jar>>> to the class path.
+ If you are using the default client configuration, it will be configured automatically. If you provide your own
+ custom client configuration WSDD file, then configure the pivot handler for the <<<http>>> transport as shown in the following
sample:
-%{snippet|id=deployment|file=${project.basedir}/src/test/resources/client-config.wsdd}
+-------------------------------------------------------------------------------------------------
+<deployment name="testClientConfig"
+ xmlns="http://xml.apache.org/axis/wsdd/"
+ xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
+ <globalConfiguration>
+ <parameter name="disablePrettyXML" value="true"/>
+ <parameter name="enableNamespacePrefixOptimization" value="false"/>
+ </globalConfiguration>
+ <transport name="http" pivot="java:org.apache.axis.transport.http.javanet.JavaNetHTTPSender"/>
+</deployment>
+-------------------------------------------------------------------------------------------------
\ No newline at end of file
Added: axis/axis1/java/trunk/axis-rt-transport-http-javanet/src/test/java/org/apache/axis/transport/http/javanet/TestDefaultConfiguration.java
URL: http://svn.apache.org/viewvc/axis/axis1/java/trunk/axis-rt-transport-http-javanet/src/test/java/org/apache/axis/transport/http/javanet/TestDefaultConfiguration.java?rev=1410754&view=auto
==============================================================================
--- axis/axis1/java/trunk/axis-rt-transport-http-javanet/src/test/java/org/apache/axis/transport/http/javanet/TestDefaultConfiguration.java (added)
+++ axis/axis1/java/trunk/axis-rt-transport-http-javanet/src/test/java/org/apache/axis/transport/http/javanet/TestDefaultConfiguration.java Sat Nov 17 17:33:04 2012
@@ -0,0 +1,40 @@
+/*
+ * 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.axis.transport.http.javanet;
+
+import junit.framework.TestCase;
+
+import org.apache.axis.Handler;
+import org.apache.axis.SimpleTargetedChain;
+import org.apache.axis.client.AxisClient;
+import org.apache.axis.configuration.DefaultConfiguration;
+
+/**
+ * Tests that {@link DefaultConfiguration} (with type <tt>client</tt>) configures the java.net
+ * transport as default HTTP transport if it is in the classpath.
+ *
+ * @author Andreas Veithen
+ */
+public class TestDefaultConfiguration extends TestCase {
+ public void test() throws Exception {
+ AxisClient client = new AxisClient(new DefaultConfiguration("client"));
+ Handler[] handlers = ((SimpleTargetedChain)client.getTransport("http")).getHandlers();
+ assertTrue(handlers[0] instanceof JavaNetHTTPSender);
+ }
+}
Propchange: axis/axis1/java/trunk/axis-rt-transport-http-javanet/src/test/java/org/apache/axis/transport/http/javanet/TestDefaultConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native