You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sc...@apache.org on 2006/11/29 22:21:58 UTC

svn commit: r480715 - in /webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws: BindingProvider.java binding/BindingImpl.java binding/SOAPBinding.java client/BaseDispatch.java message/util/impl/SAAJConverterImpl.java util/SAAJFactory.java

Author: scheu
Date: Wed Nov 29 13:21:54 2006
New Revision: 480715

URL: http://svn.apache.org/viewvc?view=rev&rev=480715
Log:
AXIS2-1782
Contributor: Mike Rheinheimer
Additional SOAPBinding Apis

Added:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/SAAJFactory.java
Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/BindingProvider.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/binding/BindingImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/binding/SOAPBinding.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/BindingProvider.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/BindingProvider.java?view=diff&rev=480715&r1=480714&r2=480715
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/BindingProvider.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/BindingProvider.java Wed Nov 29 13:21:54 2006
@@ -21,9 +21,9 @@
 import java.util.Hashtable;
 import java.util.Map;
 
+import javax.xml.soap.SOAPFactory;
 import javax.xml.ws.Binding;
 
-
 import org.apache.axis2.jaxws.binding.SOAPBinding;
 import org.apache.axis2.jaxws.description.EndpointDescription;
 import org.apache.axis2.jaxws.i18n.Messages;
@@ -34,7 +34,7 @@
 
 	protected Map<String, Object> requestContext;
     protected Map<String, Object> responseContext;
-    protected Binding binding;
+    private Binding binding;  // force subclasses to use the lazy getter
     protected EndpointDescription endpointDesc;
     protected ServiceDelegate serviceDelegate;
     
@@ -47,8 +47,6 @@
         requestContext.put(BindingProvider.SOAPACTION_USE_PROPERTY, new Boolean(false));
         requestContext.put(BindingProvider.SOAPACTION_URI_PROPERTY, "");
         
-        //The default Binding is the SOAPBinding
-        binding = new SOAPBinding();
     }
     
     public BindingProvider(ServiceDelegate svcDelegate, EndpointDescription epDesc) {
@@ -65,6 +63,17 @@
     }
     
     public Binding getBinding() {
+        
+        // TODO support HTTP binding when available
+        
+        // The default Binding is the SOAPBinding
+        if (binding == null) {
+            String bindingType = endpointDesc.getBindingType();
+            if (bindingType == null) { // we must be on the client
+                bindingType = endpointDesc.getClientBindingID();
+            }
+            binding = new SOAPBinding(bindingType);
+        }
         return binding;
     }
 

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/binding/BindingImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/binding/BindingImpl.java?view=diff&rev=480715&r1=480714&r2=480715
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/binding/BindingImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/binding/BindingImpl.java Wed Nov 29 13:21:54 2006
@@ -17,8 +17,10 @@
 
 package org.apache.axis2.jaxws.binding;
 
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
 
 import javax.xml.ws.Binding;
 import javax.xml.ws.handler.Handler;
@@ -33,7 +35,17 @@
 
 	// an unsorted list of handlers
 	private List<Handler> handlers;
+    
+    protected String bindingId = null;
+    protected Set<URI> roles = null;
 
+    protected static final String SOAP11_ENV_NS = "http://schemas.xmlsoap.org/soap/envelope/";
+    protected static final String SOAP12_ENV_NS = "http://www.w3.org/2003/05/soap-envelope";
+    
+    public BindingImpl(String bindingId) {
+        this.bindingId = bindingId;
+    }
+    
 	public List<Handler> getHandlerChain() {
 		return handlers;
 	}

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/binding/SOAPBinding.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/binding/SOAPBinding.java?view=diff&rev=480715&r1=480714&r2=480715
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/binding/SOAPBinding.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/binding/SOAPBinding.java Wed Nov 29 13:21:54 2006
@@ -20,8 +20,14 @@
 import java.util.Set;
 
 import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPFactory;
 
+import org.apache.axis2.jaxws.message.MessageException;
+import org.apache.axis2.jaxws.util.SAAJFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 /**
  * An implementation of the <link>javax.xml.ws.soap.SOAPBinding</link>
  * interface.  This is the default binding for JAX-WS, and will exist
@@ -32,12 +38,47 @@
     implements javax.xml.ws.soap.SOAPBinding {
 
     private boolean mtomEnabled = false;
+    private static Log log = LogFactory.getLog(SOAPBinding.class);
+    
+    public SOAPBinding(String bindingId) {
+        super(bindingId);
+    }
     
     /*
      * (non-Javadoc)
      * @see javax.xml.ws.soap.SOAPBinding#getMessageFactory()
      */
     public MessageFactory getMessageFactory() {
+        String bindingNamespace = null;
+        try {
+            /*
+             * SAAJFactory.createMessageFactory takes a namespace String as a param:
+             *     "http://schemas.xmlsoap.org/soap/envelope/"  (SOAP1.1)
+             *     "http://www.w3.org/2003/05/soap-envelope"    (SOAP1.2)
+             *     
+             * The bindingId will be in one of the following forms:
+             *     "http://schemas.xmlsoap.org/wsdl/soap/http"      (SOAP1.1)
+             *     "http://www.w3.org/2003/05/soap/bindings/HTTP/"  (SOAP1.2)
+             */
+            if (bindingId.equalsIgnoreCase(SOAPBinding.SOAP12HTTP_BINDING)
+                    || bindingId.equalsIgnoreCase(SOAPBinding.SOAP12HTTP_MTOM_BINDING)) {
+                bindingNamespace = SOAP12_ENV_NS;
+            } else {
+                // TODO currently defaults to SOAP11.  Should we be more stricct about checking?
+                bindingNamespace = SOAP11_ENV_NS;
+            }
+            return SAAJFactory.createMessageFactory(bindingNamespace);
+        } catch (MessageException e) {
+            // TODO log it and then what?
+            if(log.isDebugEnabled()){
+                log.debug("MessageException calling SAAJFactory.createMessageFactory(\""+bindingNamespace+"\")");
+            }
+        } catch (SOAPException e) {
+            // TODO log it and then what?
+            if(log.isDebugEnabled()){
+                log.debug("SOAPException calling SAAJFactory.createMessageFactory(\""+bindingNamespace+"\")");
+            }
+        }
         return null;
     }
 
@@ -46,7 +87,7 @@
      * @see javax.xml.ws.soap.SOAPBinding#getRoles()
      */
     public Set<URI> getRoles() {
-        return null;
+        return roles;
     }
 
     /*
@@ -54,6 +95,36 @@
      * @see javax.xml.ws.soap.SOAPBinding#getSOAPFactory()
      */
     public SOAPFactory getSOAPFactory() {
+        String bindingNamespace = null;
+        try {
+            /*
+             * SAAJFactory.createMessageFactory takes a namespace String as a param:
+             *     "http://schemas.xmlsoap.org/soap/envelope/"  (SOAP1.1)
+             *     "http://www.w3.org/2003/05/soap-envelope"    (SOAP1.2)
+             *     
+             * The bindingId will be in one of the following forms:
+             *     "http://schemas.xmlsoap.org/wsdl/soap/http"      (SOAP1.1)
+             *     "http://www.w3.org/2003/05/soap/bindings/HTTP/"  (SOAP1.2)
+             */
+            if (bindingId.equalsIgnoreCase(SOAPBinding.SOAP12HTTP_BINDING)
+                    || bindingId.equalsIgnoreCase(SOAPBinding.SOAP12HTTP_MTOM_BINDING)) {
+                bindingNamespace = SOAP12_ENV_NS;
+            } else {
+                // TODO currently defaults to SOAP11.  Should we be more stricct about checking?
+                bindingNamespace = SOAP11_ENV_NS;
+            }
+            return SAAJFactory.createSOAPFactory(bindingNamespace);
+        } catch (MessageException e) {
+            // TODO log it and then what?
+            if(log.isDebugEnabled()){
+                log.debug("MessageException calling SAAJFactory.createSOAPFactory(\""+bindingNamespace+"\")");
+            }
+        } catch (SOAPException e) {
+            // TODO log it and then what?
+            if(log.isDebugEnabled()){
+                log.debug("SOAPException calling SAAJFactory.createSOAPFactory(\""+bindingNamespace+"\")");
+            }
+        }
         return null;
     }
 
@@ -78,7 +149,7 @@
      * @see javax.xml.ws.soap.SOAPBinding#setRoles(java.util.Set)
      */
     public void setRoles(Set<URI> set) {
-        
+        roles = set;
     }
 
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java?view=diff&rev=480715&r1=480714&r2=480715
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java Wed Nov 29 13:21:54 2006
@@ -20,6 +20,7 @@
 import java.util.concurrent.Future;
 
 import javax.xml.ws.AsyncHandler;
+import javax.xml.ws.Binding;
 import javax.xml.ws.Response;
 import javax.xml.ws.WebServiceException;
 import javax.xml.ws.Service.Mode;
@@ -342,6 +343,7 @@
     private void setupMessageProperties(Message msg) {
         // If the user has enabled MTOM on the SOAPBinding, we need
         // to make sure that gets pushed to the Message object.
+        Binding binding = getBinding();
         if (binding != null && binding instanceof SOAPBinding) {
             SOAPBinding soapBinding = (SOAPBinding) binding;
             if (soapBinding.isMTOMEnabled())

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java?view=diff&rev=480715&r1=480714&r2=480715
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java Wed Nov 29 13:21:54 2006
@@ -44,19 +44,13 @@
 import org.apache.axis2.jaxws.message.MessageException;
 import org.apache.axis2.jaxws.message.util.SAAJConverter;
 import org.apache.axis2.jaxws.message.util.SOAPElementReader;
+import org.apache.axis2.jaxws.util.SAAJFactory;
 
 /**
  * SAAJConverterImpl
  * Provides an conversion methods between OM<->SAAJ
  */
 public class SAAJConverterImpl implements SAAJConverter {
-
-	private static final String SOAP11_ENV_NS = "http://schemas.xmlsoap.org/soap/envelope/";
-	private static final String SOAP12_ENV_NS = "http://www.w3.org/2003/05/soap-envelope";
-	
-	public static final String SOAP_1_1_PROTOCOL = "SOAP 1.1 Protocol"; 
-	public static final String SOAP_1_2_PROTOCOL = "SOAP 1.2 Protocol";
-	public static final String DYNAMIC_PROTOCOL  = "Dynamic Protocol"; 
 	
 	/**
 	 * Constructed via SAAJConverterFactory
@@ -181,49 +175,6 @@
 		return buildSOAPTree(nc, null, parent, reader, false);
 	}
 
-	/**
-	 * Create MessageFactory using information from the envelope namespace 
-	 * @param namespace
-	 * @return
-	 */
-	public MessageFactory createMessageFactory(String namespace) throws MessageException, SOAPException {
-		Method m = getNewInstanceProtocolMethod();
-		MessageFactory mf = null;
-		if (m == null) {
-			if (namespace.equals(SOAP11_ENV_NS)) {
-				mf = MessageFactory.newInstance();
-			} else {
-				throw ExceptionFactory.makeMessageException(Messages.getMessage("SOAP12WithSAAJ12Err"));
-			}
-		} else {
-			String protocol = DYNAMIC_PROTOCOL;
-			if (namespace.equals(SOAP11_ENV_NS)) {
-				protocol = SOAP_1_1_PROTOCOL;
-			} else if (namespace.equals(SOAP12_ENV_NS)) {
-				protocol = SOAP_1_2_PROTOCOL;
-			} 
-			try {
-				mf = (MessageFactory) m.invoke(null, new Object[] {protocol});
-			} catch (Exception e) {
-				throw ExceptionFactory.makeMessageException(e);
-			}
-		}
-		return mf;
-	}
-	
-	private Method newInstanceProtocolMethod = null;
-	private Method getNewInstanceProtocolMethod() {
-		if (newInstanceProtocolMethod == null) {
-			try {
-				newInstanceProtocolMethod = MessageFactory.class.getMethod("newInstance", new Class[] {String.class});
-			} catch (Exception e) {
-				// TODO Might want to log this.
-				// Flow to here indicates that the installed SAAJ model does not support version 1.3
-				newInstanceProtocolMethod = null;
-			}
-		}
-		return newInstanceProtocolMethod;
-	}
 	
 	/**
 	 * Build SOAPTree
@@ -496,4 +447,8 @@
 		}
 		
 	}
+
+    public MessageFactory createMessageFactory(String namespace) throws SOAPException, MessageException {
+        return SAAJFactory.createMessageFactory(namespace);
+    }
 }

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/SAAJFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/SAAJFactory.java?view=auto&rev=480715
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/SAAJFactory.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/util/SAAJFactory.java Wed Nov 29 13:21:54 2006
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed 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.axis2.jaxws.util;
+
+import java.lang.reflect.Method;
+
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFactory;
+
+import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.i18n.Messages;
+import org.apache.axis2.jaxws.message.MessageException;
+
+/**
+ * Provides convenience methods to construct a SOAP 1.1 or SOAP 1.2 SAAJ MessageFactory or SOAPFactory.
+ * The code uses reflection; thus, when Axis2 upgrades to SAAJ 1.3, no changes will be neded to this class.
+ *
+ */
+public class SAAJFactory {
+
+    private static final String SOAP11_ENV_NS = "http://schemas.xmlsoap.org/soap/envelope/";
+    private static final String SOAP12_ENV_NS = "http://www.w3.org/2003/05/soap-envelope";
+    
+    // Protocol Names per the SAAJ 1.3 specification.
+    public static final String SOAP_1_1_PROTOCOL = "SOAP 1.1 Protocol"; 
+    public static final String SOAP_1_2_PROTOCOL = "SOAP 1.2 Protocol";
+    public static final String DYNAMIC_PROTOCOL  = "Dynamic Protocol"; 
+    
+    /**
+     * Create SOAPFactory using information from the envelope namespace 
+     * @param namespace
+     * @return
+     */
+    public static SOAPFactory createSOAPFactory(String namespace) throws MessageException, SOAPException {
+        Method m = getSOAPFactoryNewInstanceProtocolMethod();
+        SOAPFactory sf = null;
+        if (m == null) {
+            if (namespace.equals(SOAP11_ENV_NS)) {
+                sf = SOAPFactory.newInstance();
+            } else {
+                throw ExceptionFactory.makeMessageException(Messages.getMessage("SOAP12WithSAAJ12Err"));
+            }
+        } else {
+            String protocol = DYNAMIC_PROTOCOL;
+            if (namespace.equals(SOAP11_ENV_NS)) {
+                protocol = SOAP_1_1_PROTOCOL;
+            } else if (namespace.equals(SOAP12_ENV_NS)) {
+                protocol = SOAP_1_2_PROTOCOL;
+            } 
+            try {
+                sf = (SOAPFactory) m.invoke(null, new Object[] {protocol});
+            } catch (Exception e) {
+                throw ExceptionFactory.makeMessageException(e);
+            }
+        }
+        return sf;
+    }
+    
+    /**
+     * Create MessageFactory using information from the envelope namespace 
+     * @param namespace
+     * @return
+     */
+    public static MessageFactory createMessageFactory(String namespace) throws MessageException, SOAPException {
+        Method m = getMessageFactoryNewInstanceProtocolMethod();
+        MessageFactory mf = null;
+        if (m == null) {
+            if (namespace.equals(SOAP11_ENV_NS)) {
+                mf = MessageFactory.newInstance();
+            } else {
+                throw ExceptionFactory.makeMessageException(Messages.getMessage("SOAP12WithSAAJ12Err"));
+            }
+        } else {
+            String protocol = DYNAMIC_PROTOCOL;
+            if (namespace.equals(SOAP11_ENV_NS)) {
+                protocol = SOAP_1_1_PROTOCOL;
+            } else if (namespace.equals(SOAP12_ENV_NS)) {
+                protocol = SOAP_1_2_PROTOCOL;
+            } 
+            try {
+                mf = (MessageFactory) m.invoke(null, new Object[] {protocol});
+            } catch (Exception e) {
+                throw ExceptionFactory.makeMessageException(e);
+            }
+        }
+        return mf;
+    }
+    
+    private static Method messageFactoryNewInstanceProtocolMethod = null;
+    
+    /**
+     * SAAJ 1.3 has a newInstance method that has a protocol parameter.
+     * @return newInstance(String) method if available
+     */
+    private static Method getMessageFactoryNewInstanceProtocolMethod() {
+        if (messageFactoryNewInstanceProtocolMethod == null) {
+            try {
+                messageFactoryNewInstanceProtocolMethod = MessageFactory.class.getMethod("newInstance", new Class[] {String.class});
+            } catch (Exception e) {
+                // TODO Might want to log this.
+                // Flow to here indicates that the installed SAAJ model does not support version 1.3
+                messageFactoryNewInstanceProtocolMethod = null;
+            }
+        }
+        return messageFactoryNewInstanceProtocolMethod;
+    }
+    
+    private static Method soapFactoryNewInstanceProtocolMethod = null;
+    
+    /**
+     * SAAJ 1.3 has a newInstance method that has a protocol parameter.
+     * @return newInstance(String) method if available
+     */
+    private static Method getSOAPFactoryNewInstanceProtocolMethod() {
+        if (soapFactoryNewInstanceProtocolMethod == null) {
+            try {
+                soapFactoryNewInstanceProtocolMethod = MessageFactory.class.getMethod("newInstance", new Class[] {String.class});
+            } catch (Exception e) {
+                // TODO Might want to log this.
+                // Flow to here indicates that the installed SAAJ model does not support version 1.3
+                soapFactoryNewInstanceProtocolMethod = null;
+            }
+        }
+        return soapFactoryNewInstanceProtocolMethod;
+    }
+
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org