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 am...@apache.org on 2006/12/07 07:58:03 UTC

svn commit: r483362 - in /webservices/axis2/branches/java/WSDL_2_0/modules: codegen/src/org/apache/axis2/wsdl/template/java/ kernel/src/org/apache/axis2/addressing/ kernel/src/org/apache/axis2/client/

Author: amilas
Date: Wed Dec  6 22:58:02 2006
New Revision: 483362

URL: http://svn.apache.org/viewvc?view=rev&rev=483362
Log:
Added support to change the EPR at the operation method in codegen module. the new method added to 
Stub is called when it is necessary to change the EPR

Modified:
    webservices/axis2/branches/java/WSDL_2_0/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl
    webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/addressing/EndpointReference.java
    webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/client/Stub.java

Modified: webservices/axis2/branches/java/WSDL_2_0/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/WSDL_2_0/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl?view=diff&rev=483362&r1=483361&r2=483362
==============================================================================
--- webservices/axis2/branches/java/WSDL_2_0/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl (original)
+++ webservices/axis2/branches/java/WSDL_2_0/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl Wed Dec  6 22:58:02 2006
@@ -267,6 +267,11 @@
               _operationClient.getOptions().setAction("<xsl:value-of select="$soapAction"/>");
               _operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);
 
+              <!-- change the EPR if http location available -->
+              <xsl:if test="string-length(normalize-space(@http_location)) > 0">
+                   setAppendAddressToEPR(_operationClient,"<xsl:value-of select="@http_location"/>");
+              </xsl:if>
+
               // create a message context
               org.apache.axis2.context.MessageContext _messageContext = new org.apache.axis2.context.MessageContext();
 
@@ -501,6 +506,11 @@
              _operationClient.getOptions().setAction("<xsl:value-of select="$soapAction"/>");
              _operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);
 
+             <!-- change the EPR if http location available -->
+              <xsl:if test="string-length(normalize-space(@http_location)) > 0">
+                   setAppendAddressToEPR(_operationClient,"<xsl:value-of select="@http_location"/>");
+              </xsl:if>
+
           <!--todo if the stub was generated with unwrapping, wrap all parameters into a single element-->
 
               // create SOAP envelope with that payload
@@ -672,6 +682,11 @@
                 _operationClient.getOptions().setAction("<xsl:value-of select="$soapAction"/>");
                 _operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);
 
+                <!-- change the EPR if http location available -->
+               <xsl:if test="string-length(normalize-space(@http_location)) > 0">
+                   setAppendAddressToEPR(_operationClient,"<xsl:value-of select="@http_location"/>");
+               </xsl:if>
+
                 <xsl:for-each select="input/param[@Action!='']">_operationClient.getOptions().setAction("<xsl:value-of select="@Action"/>");</xsl:for-each>
                 org.apache.axiom.soap.SOAPEnvelope env = null;
                 org.apache.axis2.context.MessageContext _messageContext = new org.apache.axis2.context.MessageContext();
@@ -819,27 +834,7 @@
           </xsl:if>
         </xsl:for-each>
 
-        /**
-         * private method to add the http soap_headers
-         *
-         * @param messageContext
-         * @param name
-         * @param value
-         */
-        private void addHttpHeader(org.apache.axis2.context.MessageContext messageContext,
-                                   String name,
-                                   String value) {
-            java.lang.Object headersObj = messageContext.getProperty(org.apache.axis2.transport.http.HTTPConstants.HTTP_HEADERS);
-            if (headersObj == null) {
-                headersObj = new java.util.ArrayList();
-            }
-            java.util.List headers = (java.util.List) headersObj;
-            org.apache.commons.httpclient.Header header = new org.apache.commons.httpclient.Header();
-            headers.add(header);
-            messageContext.setProperty(org.apache.axis2.transport.http.HTTPConstants.HTTP_HEADERS, headers);
-        }
-
-
+        
        /**
         *  A utility method that copies the namepaces from the SOAPEnvelope
         */

Modified: webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/addressing/EndpointReference.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/addressing/EndpointReference.java?view=diff&rev=483362&r1=483361&r2=483362
==============================================================================
--- webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/addressing/EndpointReference.java (original)
+++ webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/addressing/EndpointReference.java Wed Dec  6 22:58:02 2006
@@ -365,7 +365,7 @@
      * @return
      * @throws CloneNotSupportedException
      */
-    protected EndpointReference cloneEPR() throws CloneNotSupportedException {
+    public EndpointReference cloneEPR()  {
         EndpointReference epr = new EndpointReference(this.address);
 
         if (extensibleElements != null) {

Modified: webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/client/Stub.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/client/Stub.java?view=diff&rev=483362&r1=483361&r2=483362
==============================================================================
--- webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/client/Stub.java (original)
+++ webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/client/Stub.java Wed Dec  6 22:58:02 2006
@@ -31,8 +31,12 @@
 import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axiom.soap.SOAPProcessingException;
 import org.apache.axis2.AxisFault;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.i18n.Messages;
+import org.apache.commons.httpclient.Header;
 
 /**
  * Base class for generated client stubs. This defines several client API
@@ -42,7 +46,7 @@
  * underscore character to avoid conflicts with actual implementation methods.
  */
 public abstract class Stub {
-    
+
     protected AxisService _service;
     protected ArrayList modules = new ArrayList();
 
@@ -51,7 +55,7 @@
 
     /**
      * Get service client implementation used by this stub.
-     * 
+     *
      * @return service client
      */
     public ServiceClient _getServiceClient() {
@@ -62,7 +66,7 @@
      * Set service client implementation used by this stub. Once set, the
      * service client is owned by this stub and will automatically be removed
      * from the configuration when use of the stub is done.
-     * 
+     *
      * @param _serviceClient
      */
     public void _setServiceClient(ServiceClient _serviceClient) {
@@ -73,9 +77,9 @@
      * Create a SOAP message envelope using the supplied options.
      * TODO generated stub code should use this method, or similar method taking
      * an operation client
-     * 
+     *
      * @param options
-     * @return generated 
+     * @return generated
      * @throws SOAPProcessingException
      */
     protected static SOAPEnvelope createEnvelope(Options options) throws SOAPProcessingException {
@@ -85,7 +89,7 @@
     /**
      * Read a root element from the parser.
      * TODO generated stub code should use this method
-     * 
+     *
      * @param reader
      * @return root element
      */
@@ -98,7 +102,7 @@
 
     /**
      * Get Axiom factory appropriate to selected SOAP version.
-     * 
+     *
      * @param soapVersionURI
      * @return factory
      */
@@ -117,21 +121,75 @@
     /**
      * Finalize method called by garbage collection. This is overridden to
      * support cleanup of any associated resources.
-     * 
+     *
      * @throws Throwable
      */
     protected void finalize() throws Throwable {
-         super.finalize();
-         cleanup();
+        super.finalize();
+        cleanup();
     }
 
     /**
      * Cleanup associated resources. This removes the axis service from the
      * configuration.
-     * 
+     *
      * @throws AxisFault
      */
     public void cleanup() throws AxisFault {
         _service.getAxisConfiguration().removeService(_service.getName());
     }
+
+    /**
+     * sets the EPR in operation client. First get the available EPR from the service client
+     * and then append the addressFromBinding string to available address
+     *
+     * @param _operationClient
+     * @param addressFromBinding
+     */
+
+
+    protected void setAppendAddressToEPR(OperationClient _operationClient,
+                                         String addressFromBinding) {
+        EndpointReference toEPRFromServiceClient = _serviceClient.getOptions().getTo();
+        EndpointReference endpointReference = toEPRFromServiceClient.cloneEPR();
+
+        String address = endpointReference.getAddress();
+
+        // here we assume either addressFromBinding have a '?' infront or not
+        if (addressFromBinding.charAt(0) != '?') {
+            addressFromBinding = "?" + addressFromBinding;
+        }
+
+        if (address.indexOf("?") != -1) {
+            address += addressFromBinding.replaceAll("\\?", "&");
+        } else {
+            address += addressFromBinding;
+        }
+
+        endpointReference.setAddress(address);
+        _operationClient.getOptions().setTo(endpointReference);
+    }
+
+    /**
+     * add an http header with name and value to message context
+     *
+     * @param messageContext
+     * @param name
+     * @param value
+     */
+    protected void addHttpHeader(MessageContext messageContext,
+                                 String name,
+                                 String value) {
+        java.lang.Object headersObj = messageContext.getProperty(HTTPConstants.HTTP_HEADERS);
+        if (headersObj == null) {
+            headersObj = new java.util.ArrayList();
+        }
+        java.util.List headers = (java.util.List) headersObj;
+        Header header = new Header();
+        header.setName(name);
+        header.setValue(value);
+        headers.add(header);
+        messageContext.setProperty(HTTPConstants.HTTP_HEADERS, headers);
+    }
+
 }



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