Author: thomas.diesler(a)jboss.com
Date: 2006-12-14 07:31:04 -0500 (Thu, 14 Dec 2006)
New Revision: 1645
Added:
trunk/src/main/java/javax/xml/soap/FactoryLoader.java
trunk/src/main/java/org/jboss/ws/core/soap/SAAJMetaFactoryImpl.java
trunk/src/main/resources/jboss-saaj.jar/
trunk/src/main/resources/jboss-saaj.jar/META-INF/
trunk/src/main/resources/jboss-saaj.jar/META-INF/services/
trunk/src/main/resources/jboss-saaj.jar/META-INF/services/javax.xml.soap.MessageFactory
trunk/src/main/resources/jboss-saaj.jar/META-INF/services/javax.xml.soap.MetaFactory
trunk/src/main/resources/jboss-saaj.jar/META-INF/services/javax.xml.soap.SOAPFactory
Modified:
trunk/build.xml
trunk/src/main/java/javax/xml/soap/MessageFactory.java
trunk/src/main/java/javax/xml/soap/SAAJMetaFactory.java
trunk/src/main/java/javax/xml/soap/SOAPConstants.java
trunk/src/main/java/javax/xml/soap/SOAPFactory.java
trunk/src/main/java/org/jboss/ws/core/soap/MessageFactoryImpl.java
trunk/src/main/java/org/jboss/ws/core/soap/SOAPFactoryImpl.java
Log:
Implement SAAJ-1.3 factory lookup
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2006-12-14 12:19:05 UTC (rev 1644)
+++ trunk/build.xml 2006-12-14 12:31:04 UTC (rev 1645)
@@ -220,6 +220,7 @@
<fileset dir="${build.classes14.dir}">
<include name="javax/xml/soap/**"/>
</fileset>
+ <metainf dir="${build.resources.dir}/jboss-saaj.jar/META-INF"/>
</jar>
<!-- Build jboss-jaxws.jar -->
Added: trunk/src/main/java/javax/xml/soap/FactoryLoader.java
===================================================================
--- trunk/src/main/java/javax/xml/soap/FactoryLoader.java 2006-12-14 12:19:05 UTC (rev
1644)
+++ trunk/src/main/java/javax/xml/soap/FactoryLoader.java 2006-12-14 12:31:04 UTC (rev
1645)
@@ -0,0 +1,197 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package javax.xml.soap;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Properties;
+
+import org.jboss.logging.Logger;
+
+// $Id$
+
+/**
+ * Load a factory using the factory lookup procedure
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 14-Dec-2006
+ */
+class FactoryLoader
+{
+ // provide logging
+ private static Logger log = Logger.getLogger(MessageFactory.class);
+
+ private FactoryLoader()
+ {
+ }
+
+ /**
+ * Load a factory using this ordered lookup procedure
+ *
+ * 1. Use the system property
+ * 2. Use the properties file "lib/jaxm.properties" in the JRE directory
+ * 3. Use the Services API (as detailed in the JAR specification), if available, to
determine the classname
+ * 4. Use the default factory implementation class
+ *
+ * @return the factory impl, or null
+ */
+ static Object loadFactory(String propertyName, String defaultFactory) throws
SOAPException
+ {
+ Object factory = null;
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
+ // Use the system property
+ PrivilegedAction action = new PropertyAccessAction(propertyName);
+ String factoryName = (String)AccessController.doPrivileged(action);
+ if (factoryName != null)
+ {
+ try
+ {
+ log.debug("Load from system property: " + factoryName);
+ Class factoryClass = loader.loadClass(factoryName);
+ factory = factoryClass.newInstance();
+ }
+ catch (Throwable t)
+ {
+ throw new SOAPException("Failed to load " + propertyName + ":
" + factoryName, t);
+ }
+ }
+
+ // Use the properties file "lib/jaxm.properties" in the JRE directory.
+ // This configuration file is in standard java.util.Properties format and contains
the fully qualified name of the implementation class with the key being the system
property defined above.
+ if (factory == null)
+ {
+ action = new PropertyAccessAction("java.home");
+ String javaHome = (String)AccessController.doPrivileged(action);
+ File jaxmFile = new File(javaHome + "/lib/jaxm.properties");
+ if (jaxmFile.exists())
+ {
+ try
+ {
+ action = new PropertyFileAccessAction(jaxmFile.getCanonicalPath());
+ Properties jaxmProperties =
(Properties)AccessController.doPrivileged(action);
+ factoryName = jaxmProperties.getProperty(propertyName);
+ if (factoryName != null)
+ {
+ log.debug("Load from " + jaxmFile + ": " +
factoryName);
+ Class factoryClass = loader.loadClass(factoryName);
+ factory = factoryClass.newInstance();
+ }
+ }
+ catch (Throwable t)
+ {
+ throw new SOAPException("Failed to load " + propertyName +
": " + factoryName, t);
+ }
+ }
+ }
+
+ // Use the Services API (as detailed in the JAR specification), if available, to
determine the classname.
+ if (factory == null)
+ {
+ String filename = "META-INF/services/" + propertyName;
+ InputStream inStream = loader.getResourceAsStream(filename);
+ if (inStream != null)
+ {
+ try
+ {
+ BufferedReader br = new BufferedReader(new InputStreamReader(inStream));
+ factoryName = br.readLine();
+ br.close();
+ if (factoryName != null)
+ {
+ log.debug("Load from Service API " + filename + ":
" + factoryName);
+ Class factoryClass = loader.loadClass(factoryName);
+ factory = factoryClass.newInstance();
+ }
+ }
+ catch (Throwable t)
+ {
+ throw new SOAPException("Failed to load " + propertyName +
": " + factoryName, t);
+ }
+ }
+ }
+
+ // Use the default factory implementation class.
+ if (factory == null && defaultFactory != null)
+ {
+ try
+ {
+ factoryName = defaultFactory;
+ log.debug("Load from default: " + factoryName);
+ Class factoryClass = loader.loadClass(factoryName);
+ factory = factoryClass.newInstance();
+ }
+ catch (Throwable t)
+ {
+ throw new SOAPException("Failed to load " + propertyName + ":
" + factoryName, t);
+ }
+ }
+
+ return factory;
+ }
+
+ private static class PropertyAccessAction implements PrivilegedAction
+ {
+ private String name;
+
+ PropertyAccessAction(String name)
+ {
+ this.name = name;
+ }
+
+ public Object run()
+ {
+ return System.getProperty(name);
+ }
+ }
+
+ private static class PropertyFileAccessAction implements PrivilegedAction
+ {
+ private String filename;
+
+ PropertyFileAccessAction(String filename)
+ {
+ this.filename = filename;
+ }
+
+ public Object run()
+ {
+ try
+ {
+ InputStream inStream = new FileInputStream(filename);
+ Properties props = new Properties();
+ props.load(inStream);
+ return props;
+ }
+ catch (IOException ex)
+ {
+ throw new SecurityException("Cannot load properties: " + filename,
ex);
+ }
+ }
+ }
+}
Property changes on: trunk/src/main/java/javax/xml/soap/FactoryLoader.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: trunk/src/main/java/javax/xml/soap/MessageFactory.java
===================================================================
--- trunk/src/main/java/javax/xml/soap/MessageFactory.java 2006-12-14 12:19:05 UTC (rev
1644)
+++ trunk/src/main/java/javax/xml/soap/MessageFactory.java 2006-12-14 12:31:04 UTC (rev
1645)
@@ -23,12 +23,7 @@
import java.io.IOException;
import java.io.InputStream;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import org.jboss.logging.Logger;
-import org.jboss.util.NotImplementedException;
-
/**
A factory for creating SOAPMessage objects.
@@ -58,37 +53,33 @@
*/
public abstract class MessageFactory
{
- // provide logging
- private static Logger log = Logger.getLogger(MessageFactory.class);
-
- private static final String DEFAULT_MESSAGE_FACTORY =
"org.jboss.ws.core.soap.MessageFactoryImpl";
-
+
/**
* Creates a new MessageFactory object that is an instance of the default
implementation (SOAP 1.1),
* This method uses the following ordered lookup procedure to determine the
MessageFactory implementation class to load:
-
+ *
* Use the javax.xml.soap.MessageFactory system property.
* Use the properties file "lib/jaxm.properties" in the JRE directory. This
configuration file is in standard java.util.Properties format and contains the fully
qualified name of the implementation class with the key being the system property defined
above.
* Use the Services API (as detailed in the JAR specification), if available, to
determine the classname. The Services API will look for a classname in the file
META-INF/services/javax.xml.soap.MessageFactory in jars available to the runtime.
- * Use the SAAJMetaFactory instance to locate the MessageFactory implementation class.
+ * Use the SAAJMetaFactory instance to locate the MessageFactory implementation
class.
+ * @throws SOAPException if there was an error in creating the default implementation
of the MessageFactory.
*/
public static MessageFactory newInstance() throws SOAPException
{
- PrivilegedAction action = new PropertyAccessAction(MessageFactory.class.getName(),
DEFAULT_MESSAGE_FACTORY);
- String factoryName = (String)AccessController.doPrivileged(action);
+ String propertyName = "javax.xml.soap.MessageFactory";
+ MessageFactory factory = (MessageFactory)FactoryLoader.loadFactory(propertyName,
null);
- //TODO: SAAJ 1.3 (implement the lookup)
-
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- try
+ // Use the SAAJMetaFactory instance to locate the MessageFactory implementation
class.
+ if (factory == null)
{
- Class factoryClass = loader.loadClass(factoryName);
- return (MessageFactory)factoryClass.newInstance();
+ SAAJMetaFactory saajFactory = SAAJMetaFactory.getInstance();
+ factory = saajFactory.newMessageFactory(SOAPConstants.DYNAMIC_SOAP_PROTOCOL);
}
- catch (Throwable t)
- {
- throw new SOAPException("Failed to create MessageFactory: " +
factoryName, t);
- }
+
+ if (factory == null)
+ throw new SOAPException("Failed to to determine the MessageFactory
implementation class");
+
+ return factory;
}
/**
@@ -104,8 +95,13 @@
*/
public static MessageFactory newInstance(String protocol) throws SOAPException
{
- //TODO: SAAJ 1.3
- throw new NotImplementedException();
+ SAAJMetaFactory saajFactory = SAAJMetaFactory.getInstance();
+ MessageFactory factory = saajFactory.newMessageFactory(protocol);
+
+ if (factory == null)
+ throw new SOAPException("Failed to to determine the MessageFactory
implementation class");
+
+ return factory;
}
/**
@@ -131,21 +127,4 @@
* @throws SOAPException if the message is invalid
*/
public abstract SOAPMessage createMessage(MimeHeaders headers, InputStream in) throws
IOException, SOAPException;
-
- private static class PropertyAccessAction implements PrivilegedAction
- {
- private String name;
- private String defaultValue;
-
- PropertyAccessAction(String name, String defaultValue)
- {
- this.name = name;
- this.defaultValue = defaultValue;
- }
-
- public Object run()
- {
- return System.getProperty(name, defaultValue);
- }
- }
}
Modified: trunk/src/main/java/javax/xml/soap/SAAJMetaFactory.java
===================================================================
--- trunk/src/main/java/javax/xml/soap/SAAJMetaFactory.java 2006-12-14 12:19:05 UTC (rev
1644)
+++ trunk/src/main/java/javax/xml/soap/SAAJMetaFactory.java 2006-12-14 12:31:04 UTC (rev
1645)
@@ -21,7 +21,7 @@
*/
package javax.xml.soap;
-import org.jboss.util.NotImplementedException;
+import java.security.PrivilegedAction;
// $Id$
@@ -57,8 +57,14 @@
*/
static SAAJMetaFactory getInstance() throws SOAPException
{
- //TODO: SAAJ 1.3
- throw new NotImplementedException();
+ String propertyName = "javax.xml.soap.MetaFactory";
+ String defaultImpl =
"com.sun.xml.messaging.saaj.soap.SAAJMetaFactoryImpl";
+ SAAJMetaFactory factory = (SAAJMetaFactory)FactoryLoader.loadFactory(propertyName,
defaultImpl);
+
+ if (factory == null)
+ throw new SOAPException("Failed to to determine the implementation class
for: " + propertyName);
+
+ return factory;
}
/**
Modified: trunk/src/main/java/javax/xml/soap/SOAPConstants.java
===================================================================
--- trunk/src/main/java/javax/xml/soap/SOAPConstants.java 2006-12-14 12:19:05 UTC (rev
1644)
+++ trunk/src/main/java/javax/xml/soap/SOAPConstants.java 2006-12-14 12:31:04 UTC (rev
1645)
@@ -53,7 +53,7 @@
/** The namespace identifier for the SOAP 1.1 encoding. */
String URI_NS_SOAP_ENCODING = "http://schemas.xmlsoap.org/soap/encoding/";
/** The namespace identifier for the SOAP 1.1 envelope, All SOAPElements in this
namespace are defined by the SOAP 1.1 specification. */
- String URI_NS_SOAP_ENVELOPE = "http://schemas.xmlsoap.org/soap/envelope/";
+ String URI_NS_SOAP_ENVELOPE = URI_NS_SOAP_1_1_ENVELOPE;
/** The URI identifying the next application processing a SOAP request as the intended
role for a SOAP 1.2 header entry (see section 2.2 of part 1 of the SOAP 1.2
specification). */
String URI_SOAP_1_2_ROLE_NEXT =
"http://www.w3.org/2003/05/soap-envelope/role/next";
/** The URI specifying the role None in SOAP 1.2. */
Modified: trunk/src/main/java/javax/xml/soap/SOAPFactory.java
===================================================================
--- trunk/src/main/java/javax/xml/soap/SOAPFactory.java 2006-12-14 12:19:05 UTC (rev
1644)
+++ trunk/src/main/java/javax/xml/soap/SOAPFactory.java 2006-12-14 12:31:04 UTC (rev
1645)
@@ -23,7 +23,6 @@
// $Id$
-import java.security.AccessController;
import java.security.PrivilegedAction;
import javax.xml.namespace.QName;
@@ -43,8 +42,6 @@
*/
public abstract class SOAPFactory
{
- private static final String DEFAULT_SOAP_FACTORY =
"org.jboss.ws.core.soap.SOAPFactoryImpl";
-
/**
* Creates a new SOAPFactory object that is an instance of the default implementation
(SOAP 1.1),
* This method uses the following ordered lookup procedure to determine the
SOAPFactory implementation class to load:
@@ -59,21 +56,20 @@
*/
public static SOAPFactory newInstance() throws SOAPException
{
- PrivilegedAction action = new PropertyAccessAction(SOAPFactory.class.getName(),
DEFAULT_SOAP_FACTORY);
- String factoryName = (String)AccessController.doPrivileged(action);
-
- //TODO: SAAJ 1.3 (implement the lookup)
+ String propertyName = "javax.xml.soap.SOAPFactory";
+ SOAPFactory factory = (SOAPFactory)FactoryLoader.loadFactory(propertyName, null);
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- try
+ // Use the SAAJMetaFactory instance to locate the MessageFactory implementation
class.
+ if (factory == null)
{
- Class factoryClass = loader.loadClass(factoryName);
- return (SOAPFactory)factoryClass.newInstance();
+ SAAJMetaFactory saajFactory = SAAJMetaFactory.getInstance();
+ factory = saajFactory.newSOAPFactory(SOAPConstants.DYNAMIC_SOAP_PROTOCOL);
}
- catch (Throwable t)
- {
- throw new SOAPException("Failed to create SOAPFactory: " +
factoryName, t);
- }
+
+ if (factory == null)
+ throw new SOAPException("Failed to to determine the SOAPFactory
implementation class");
+
+ return factory;
}
Modified: trunk/src/main/java/org/jboss/ws/core/soap/MessageFactoryImpl.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/core/soap/MessageFactoryImpl.java 2006-12-14 12:19:05
UTC (rev 1644)
+++ trunk/src/main/java/org/jboss/ws/core/soap/MessageFactoryImpl.java 2006-12-14 12:31:04
UTC (rev 1645)
@@ -36,12 +36,12 @@
import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeader;
import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPConstants;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.Service.Mode;
import org.jboss.logging.Logger;
-import org.jboss.ws.Constants;
import org.jboss.ws.core.CommonMessageContext;
import org.jboss.ws.core.jaxrpc.Style;
import org.jboss.ws.core.soap.attachment.MimeConstants;
@@ -58,13 +58,26 @@
private static Logger log = Logger.getLogger(MessageFactoryImpl.class);
// The envelope URI used by the MessageFactory
- private String envelopeURI = Constants.NS_SOAP11_ENV;
+ private String envelopeURI;
// The JAXWS ServiceMode
private Mode serviceMode;
// The style used by this MessageFactory
private Style style;
+ public MessageFactoryImpl()
+ {
+ envelopeURI = SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE;
+ }
+
+ public MessageFactoryImpl(String protocol)
+ {
+ if (SOAPConstants.SOAP_1_2_PROTOCOL.equals(protocol))
+ envelopeURI = SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE;
+ else
+ envelopeURI = SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE;
+ }
+
/**
* Get the SOAP envelope URI this factory will use when creating envelopes.
*/
Added: trunk/src/main/java/org/jboss/ws/core/soap/SAAJMetaFactoryImpl.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/core/soap/SAAJMetaFactoryImpl.java 2006-12-14
12:19:05 UTC (rev 1644)
+++ trunk/src/main/java/org/jboss/ws/core/soap/SAAJMetaFactoryImpl.java 2006-12-14
12:31:04 UTC (rev 1645)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.core.soap;
+
+// $Id$
+
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SAAJMetaFactory;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFactory;
+
+/**
+ * MessageFactory implementation
+ *
+ * @author Thomas.Diesler(a)jboss.org
+ */
+public class SAAJMetaFactoryImpl extends SAAJMetaFactory
+{
+ @Override
+ protected MessageFactory newMessageFactory(String protocol) throws SOAPException
+ {
+ return new MessageFactoryImpl(protocol);
+ }
+
+ @Override
+ protected SOAPFactory newSOAPFactory(String protocol) throws SOAPException
+ {
+ return new SOAPFactoryImpl(protocol);
+ }
+
+}
Property changes on: trunk/src/main/java/org/jboss/ws/core/soap/SAAJMetaFactoryImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: trunk/src/main/java/org/jboss/ws/core/soap/SOAPFactoryImpl.java
===================================================================
--- trunk/src/main/java/org/jboss/ws/core/soap/SOAPFactoryImpl.java 2006-12-14 12:19:05
UTC (rev 1644)
+++ trunk/src/main/java/org/jboss/ws/core/soap/SOAPFactoryImpl.java 2006-12-14 12:31:04
UTC (rev 1645)
@@ -42,6 +42,14 @@
*/
public class SOAPFactoryImpl extends SOAPFactory
{
+ public SOAPFactoryImpl()
+ {
+ }
+
+ public SOAPFactoryImpl(String protocol)
+ {
+ }
+
public SOAPElement createElement(Name name) throws SOAPException
{
return new SOAPElementImpl(name);
Added:
trunk/src/main/resources/jboss-saaj.jar/META-INF/services/javax.xml.soap.MessageFactory
===================================================================
---
trunk/src/main/resources/jboss-saaj.jar/META-INF/services/javax.xml.soap.MessageFactory 2006-12-14
12:19:05 UTC (rev 1644)
+++
trunk/src/main/resources/jboss-saaj.jar/META-INF/services/javax.xml.soap.MessageFactory 2006-12-14
12:31:04 UTC (rev 1645)
@@ -0,0 +1 @@
+org.jboss.ws.core.soap.MessageFactoryImpl
\ No newline at end of file
Added:
trunk/src/main/resources/jboss-saaj.jar/META-INF/services/javax.xml.soap.MetaFactory
===================================================================
---
trunk/src/main/resources/jboss-saaj.jar/META-INF/services/javax.xml.soap.MetaFactory 2006-12-14
12:19:05 UTC (rev 1644)
+++
trunk/src/main/resources/jboss-saaj.jar/META-INF/services/javax.xml.soap.MetaFactory 2006-12-14
12:31:04 UTC (rev 1645)
@@ -0,0 +1 @@
+org.jboss.ws.core.soap.SAAJMetaFactoryImpl
\ No newline at end of file
Added:
trunk/src/main/resources/jboss-saaj.jar/META-INF/services/javax.xml.soap.SOAPFactory
===================================================================
---
trunk/src/main/resources/jboss-saaj.jar/META-INF/services/javax.xml.soap.SOAPFactory 2006-12-14
12:19:05 UTC (rev 1644)
+++
trunk/src/main/resources/jboss-saaj.jar/META-INF/services/javax.xml.soap.SOAPFactory 2006-12-14
12:31:04 UTC (rev 1645)
@@ -0,0 +1 @@
+org.jboss.ws.core.soap.SOAPFactoryImpl
\ No newline at end of file