Author: keith
Date: Sun Jul 20 06:00:49 2008
New Revision: 19665
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=19665

Log:
Fixing Mashup-1006. Using HTTPClient to make the call


Modified:
   
trunk/mashup/java/modules/coreservices/JSStubGeneratorService/src/org/wso2/mashup/JSStubGenerator.java

Modified: 
trunk/mashup/java/modules/coreservices/JSStubGeneratorService/src/org/wso2/mashup/JSStubGenerator.java
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/coreservices/JSStubGeneratorService/src/org/wso2/mashup/JSStubGenerator.java?rev=19665&r1=19664&r2=19665&view=diff
==============================================================================
--- 
trunk/mashup/java/modules/coreservices/JSStubGeneratorService/src/org/wso2/mashup/JSStubGenerator.java
      (original)
+++ 
trunk/mashup/java/modules/coreservices/JSStubGeneratorService/src/org/wso2/mashup/JSStubGenerator.java
      Sun Jul 20 06:00:49 2008
@@ -18,19 +18,29 @@
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.description.AxisEndpoint;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.AxisServiceGroup;
+import org.apache.axis2.description.Parameter;
 import org.apache.axis2.description.WSDL11ToAllAxisServicesBuilder;
 import org.apache.axis2.description.WSDL11ToAxisServiceBuilder;
 import org.apache.axis2.description.WSDL2Constants;
 import org.apache.axis2.namespace.Constants;
+import org.apache.axis2.transport.http.ProxyConfiguration;
 import org.apache.axis2.util.XMLUtils;
 import org.apache.axis2.util.XSLTTemplateProcessor;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.URI;
+import org.apache.commons.httpclient.cookie.CookiePolicy;
+import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import sun.net.www.protocol.http.HttpURLConnection;
+import org.wso2.wsas.ServerManager;
 
 import javax.activation.DataHandler;
 import javax.xml.stream.XMLStreamException;
@@ -45,8 +55,6 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.URL;
-import java.net.URLConnection;
 import java.util.Iterator;
 import java.util.Map;
 
@@ -82,32 +90,48 @@
      * @throws MashupFault - Thrown in case an exception occurs
      */
     public String genarateStubFromURL(String type, String url) throws 
MashupFault {
-        HttpURLConnection uconn;
+
+        MultiThreadedHttpConnectionManager connectionManager =
+                new MultiThreadedHttpConnectionManager();
+        HttpClient httpClient = new HttpClient(connectionManager);
+        HttpMethod method = new GetMethod();
+
         InputStream inputStream;
         try {
-            URL wsdlURL = new URL(url);
-            URLConnection connection = wsdlURL.openConnection();
-            if (connection instanceof HttpURLConnection) {
-                uconn = (HttpURLConnection) connection;
-            } else {
-                String msg = "Unable to process given URL. " +
-                        "Only HTTP protocol is currently supported.";
-                log.error(msg);
-                throw new AxisFault(msg);
+            URI wsdlURL = new URI(url, false);
+            // We should not use method.setURI and set the complete URI here.
+            // If we do so commons-httpclient will not use our custom socket 
factory.
+            // Hence we set the path and query separatly
+            method.setURI(wsdlURL);
+            method.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
+
+            ServerManager serverManager = ServerManager.getInstance();
+            ConfigurationContext configurationContext = 
serverManager.configContext;
+            if (configurationContext != null) {
+                Parameter parameter =
+                        
configurationContext.getAxisConfiguration().getParameter("Proxy");
+                // The axis2.xml could have details of a proxy, If its present 
we should set those details
+                // on the scraper too
+                if (parameter != null) {
+                    ProxyConfiguration proxyConfiguration = new 
ProxyConfiguration();
+                    
proxyConfiguration.configure(MessageContext.getCurrentMessageContext(),
+                                                 httpClient, 
httpClient.getHostConfiguration());
+                }
+            }
+            int statusCode = httpClient.executeMethod(method);
+            if (statusCode != HttpStatus.SC_OK) {
+                throw new MashupFault(
+                        "An error occured while getting the WSDL at " + 
wsdlURL +
+                                ". Reason :" +
+                                method.getStatusLine());
             }
-            uconn.setRequestMethod("GET");
-            uconn.setAllowUserInteraction(false);
-            uconn.setDefaultUseCaches(false);
-            uconn.setDoInput(true);
-            uconn.setDoOutput(false);
-            uconn.setInstanceFollowRedirects(true);
-            uconn.setUseCaches(false);
-            uconn.connect();
-            inputStream = uconn.getInputStream();
+            inputStream = method.getResponseBodyAsStream();
+            return getStub(type, inputStream, url);            
         } catch (IOException e) {
             throw new MashupFault(e);
+        } finally {
+            method.releaseConnection();
         }
-        return getStub(type, inputStream, url);
     }
 
     private String getStub(String type, InputStream inputStream, String uri)

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

Reply via email to