Author: keith
Date: Wed Apr  2 05:48:17 2008
New Revision: 15490

Log:

Adding support to WSRequest host object to call services giving the wsdl url



Modified:
   
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestHostImpl.java

Modified: 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestHostImpl.java
==============================================================================
--- 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestHostImpl.java
      (original)
+++ 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/wsrequest/WSRequestHostImpl.java
      Wed Apr  2 05:48:17 2008
@@ -28,6 +28,8 @@
 import org.apache.axis2.client.ServiceClient;
 import org.apache.axis2.client.async.AxisCallback;
 import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.description.WSDL2Constants;
 import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.axis2.transport.http.HttpTransportProperties;
@@ -182,13 +184,21 @@
                 break;
 
             case 4:
-                if (arguments[2] instanceof org.wso2.javascript.xmlimpl.QName) 
{
-                    org.wso2.javascript.xmlimpl.QName qName = 
(org.wso2.javascript.xmlimpl.QName) arguments[2];
+                if (arguments[1] instanceof org.wso2.javascript.xmlimpl.QName) 
{
+                    org.wso2.javascript.xmlimpl.QName qName = 
(org.wso2.javascript.xmlimpl.QName) arguments[1];
                     String uri = (String) qName.get("uri", qName);
                     String localName = (String) qName.get("localName", qName);
                     service = new QName(uri, localName);
-                    if (arguments[3] instanceof String)
-                        endpointName = (String) arguments[3];
+                    if (arguments[2] instanceof String)
+                        endpointName = (String) arguments[2];
+                    else
+                        throw 
Context.reportRuntimeError("INVALID_SYNTAX_EXCEPTION");
+                    if (arguments[3] instanceof Boolean)
+                        wsRequest.async = ((Boolean) 
arguments[3]).booleanValue();
+                    else
+                        throw 
Context.reportRuntimeError("INVALID_SYNTAX_EXCEPTION");
+                    if (arguments[0] instanceof String)
+                        url = (String) arguments[0];
                     else
                         throw 
Context.reportRuntimeError("INVALID_SYNTAX_EXCEPTION");
                     wsRequest.wsdlMode = true;
@@ -218,6 +228,18 @@
                 break;
         }
 
+        if (wsRequest.wsdlMode) {
+            try {
+                ConfigurationContext defaultConfigurationContext =
+                        
ConfigurationContextFactory.createDefaultConfigurationContext();
+                wsRequest.sender =
+                        new ServiceClient(defaultConfigurationContext, new 
URL(url), service, endpointName);
+            } catch (MalformedURLException e) {
+                throw new MashupFault(e);
+            } catch (Exception e) {
+                throw new MashupFault(e);
+            }
+        } else {
         if (arguments[0] instanceof String) {
             httpMethod = (String) arguments[0];
         } else if (arguments[0] instanceof NativeArray) {
@@ -290,28 +312,22 @@
         } else {
             throw Context.reportRuntimeError("INVALID_SYNTAX_EXCEPTION");
         }
-        Object object = 
cx.getThreadLocal(JavaScriptEngineConstants.AXIS2_MESSAGECONTEXT);
-        if (!(object instanceof MessageContext)) {
-            MessageContext messageContext = (MessageContext) object;
-            if (wsRequest.wsdlMode) {
-                try {
-                    wsRequest.sender = new 
ServiceClient(messageContext.getConfigurationContext(), new URL(url), service, 
endpointName);
-                } catch (MalformedURLException e) {
-                    throw new MashupFault(e);
-                }
-            } else {
-                wsRequest.sender = new 
ServiceClient(messageContext.getConfigurationContext(), null);
-            }
-        } else {
-            if (wsRequest.wsdlMode) {
-                try {
-                    wsRequest.sender = new ServiceClient(null, new URL(url), 
service, endpointName);
-                } catch (MalformedURLException e) {
-                    throw new MashupFault(e);
-                }
+            Object object = 
cx.getThreadLocal(JavaScriptEngineConstants.AXIS2_MESSAGECONTEXT);
+            if (!(object instanceof MessageContext)) {
+                MessageContext messageContext = (MessageContext) object;
+                wsRequest.sender =
+                        new 
ServiceClient(messageContext.getConfigurationContext(), null);
             } else {
                 wsRequest.sender = new ServiceClient();
             }
+
+            Options options = getOptionsObject(httpMethod, httpLocation, 
httpLocationIgnoreUncited,
+                                               httpQueryParameterSeparator, 
httpInputSerialization,
+                                               httpContentEncoding, url, 
username, passwd, useSOAP,
+                                               useWSA, useWSS, action, 
optionsArray, wsRequest);
+            // Setting the cookie policy here
+            options.setProperty(HTTPConstants.COOKIE_POLICY, 
CookiePolicy.IGNORE_COOKIES);
+            wsRequest.sender.setOptions(options);
         }
         // Axis2 used to support sending of multiple messages with single
         // ServiceClient. Now it seems we need to set the following explicitly
@@ -320,13 +336,6 @@
                 HTTPConstants.MUTTITHREAD_HTTP_CONNECTION_MANAGER,
                 new MultiThreadedHttpConnectionManager());
 
-        Options options = getOptionsObject(httpMethod, httpLocation, 
httpLocationIgnoreUncited,
-                                           httpQueryParameterSeparator, 
httpInputSerialization,
-                                           httpContentEncoding, url, username, 
passwd, useSOAP,
-                                           useWSA, useWSS, action, 
optionsArray, wsRequest);
-        // Setting the cookie policy here
-        options.setProperty(HTTPConstants.COOKIE_POLICY, 
CookiePolicy.IGNORE_COOKIES);
-        wsRequest.sender.setOptions(options);
         wsRequest.responseText = null;
         wsRequest.responseXML = null;
         wsRequest.error = null;
@@ -422,7 +431,7 @@
                 wsRequest.readyState = 2;
                 // TODO do we need to call onreadystatechange here too
                 if (wsRequest.wsdlMode) {
-                    wsRequest.sender.sendReceive(operationName, 
payloadElement);
+                    wsRequest.responseXML = 
wsRequest.sender.sendReceive(operationName, payloadElement);
                 } else {
                     wsRequest.responseXML = 
wsRequest.sender.sendReceive(payloadElement);
                 }

_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev

Reply via email to