Author: keith
Date: Thu Jun  5 00:22:33 2008
New Revision: 17961
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=17961

Log:
Fixing Mashup-762. Need to verofy this fix though


Modified:
   trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java
   
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/feed/FeedReader.java
   
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java?rev=17961&r1=17960&r2=17961&view=diff
==============================================================================
--- trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java     
(original)
+++ trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java     
Thu Jun  5 00:22:33 2008
@@ -275,5 +275,8 @@
     // Refers to the addressing module
     public static final String HTTP_AUTH_REQUIRED = "withBasicAuth";
 
+    // Refers to username of the mashup Author
+    public static final String MASHUP_AUTHOR_NAME = "mashupAuthorName";
+
     public static final int BUFFER_SIZE = 40960;
 }

Modified: 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/feed/FeedReader.java
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/feed/FeedReader.java?rev=17961&r1=17960&r2=17961&view=diff
==============================================================================
--- 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/feed/FeedReader.java
  (original)
+++ 
trunk/mashup/java/modules/hostobjects/src/org/wso2/mashup/hostobjects/feed/FeedReader.java
  Thu Jun  5 00:22:33 2008
@@ -21,12 +21,28 @@
 import com.sun.syndication.io.SyndFeedInput;
 import com.sun.syndication.io.XmlReader;
 import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
+import org.apache.commons.httpclient.protocol.Protocol;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.params.HttpMethodParams;
 import org.mozilla.javascript.Context;
 import org.mozilla.javascript.Function;
 import org.mozilla.javascript.Scriptable;
 import org.mozilla.javascript.ScriptableObject;
+import org.wso2.mashup.utils.CustomProtocolSocketFactory;
+import org.wso2.mashup.utils.MashupUtils;
+import org.wso2.mashup.MashupConstants;
+import org.wso2.mashup.MashupFault;
 
+import javax.net.ssl.SSLHandshakeException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.URL;
 
 /**
@@ -68,20 +84,81 @@
         FeedReader feedReaderObject = (FeedReader) thisObj;
 
         if (arguments[0] instanceof String) {
+            int statusCode;
+            String feedUrl = (String) arguments[0];
+
+            HttpClient client = new HttpClient();
+
+            // Create a method instance.
+            GetMethod method = new GetMethod(feedUrl);
+
             try {
-                URL feedUrl = new URL((String) arguments[0]);
+                if (feedUrl.startsWith("https")) {
 
-                SyndFeedInput input = new SyndFeedInput();
-                SyndFeed feed = input.build(new XmlReader(feedUrl));
+                    // If the feed is on https then we have to make sure we 
set the users keystore
+                    // details into httpClient when making the call so that 
all sslHandshake stuff
+                    // will go amoothly
+                    URL targetURL = new URL(feedUrl);
+                    MessageContext currentMessageContext =
+                            MessageContext.getCurrentMessageContext();
+
+                    // In order to get the users keystore details we need his 
username. We stick the
+                    // username as a parameter into the service at deployment 
time
+                    String username =
+                            (String) 
currentMessageContext.getAxisService().getParameterValue(
+                                    MashupConstants.MASHUP_AUTHOR_NAME);
+                    ProtocolSocketFactory psf = new 
CustomProtocolSocketFactory(
+                            MashupUtils.getUserKeystoreResource(username));
+
+                    // Check weather the url has a port stated explicitly. If 
its not present
+                    // default to 443
+                    int port = targetURL.getPort();
+                    if (port == -1) {
+                        port = 443;
+                    }
+                    Protocol protocol = new Protocol("custom-https", psf, 
port);
+                    HostConfiguration config = new HostConfiguration();
+                    config.setHost(targetURL.getHost(), port, protocol);
+
+                    statusCode = client.executeMethod(config, method);
+                } else {
+                    // Execute the method.
+                    statusCode = client.executeMethod(method);
+                }
+
+                if (statusCode != HttpStatus.SC_OK) {
+                    throw new MashupFault("An error occured while getting the 
feed:" +
+                            method.getStatusLine());
+                }
+
+                // Read the response body as a stream.
+                InputStream response = method.getResponseBodyAsStream();
 
+                SyndFeedInput input = new SyndFeedInput();
+                SyndFeed feed = input.build(new XmlReader(response));
                 retFeed = (Feed) cx.newObject(feedReaderObject, "Feed", new 
Object[0]);
                 retFeed.setFeed(feed);
 
+            } catch (SSLHandshakeException e) {
+                if 
(e.getMessage().indexOf("sun.security.validator.ValidatorException: PKIX path 
building failed") > -1) {
+                    throw new MashupFault("An error occured while getting the 
feed since a " +
+                            "trusted certificate was not found for the 
destination site \"" +
+                            feedUrl + "\". You can manage your trusted 
certificates through " +
+                            "the management UI", e);
+                }
+                throw new MashupFault("An error occured while getting the 
feed.", e);
             } catch (FeedException e) {
-                throw new AxisFault("An error occured while getting the 
feed.", e);
+                throw new MashupFault("An error occured while getting the 
feed.", e);
+            } catch (HttpException e) {
+                throw new MashupFault("Fatal protocol violation: " + 
e.getMessage(), e);
+            } catch (IOException e) {
+                throw new MashupFault("Fatal transport error: " + 
e.getMessage(), e);
+            } finally {
+                // Release the connection.
+                method.releaseConnection();
             }
         } else {
-            throw new AxisFault("The parameter must be a string representing 
the Feeds URL");
+            throw new MashupFault("The parameter must be a string representing 
the Feeds URL");
         }
 
         return retFeed;

Modified: 
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java?rev=17961&r1=17960&r2=17961&view=diff
==============================================================================
--- 
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java
   (original)
+++ 
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java
   Thu Jun  5 00:22:33 2008
@@ -444,6 +444,7 @@
 
             // Infer the username (The author of this service)
             String username = MashupUtils.inferUserName(file, realm, name);
+            axisService.addParameter(MashupConstants.MASHUP_AUTHOR_NAME, 
username);
 
             // create a service group per service.
             // Axis2 has a flat space for services. But in the Mashup Server 
we need to support
@@ -588,9 +589,7 @@
                 
axisService.addParameter(MashupConstants.UNDISPATCHED_OPERATION, undispatched);
             }
 
-            ServerConfiguration serverConfig = 
ServerConfiguration.getInstance();
-            String allowHttpAccess = 
serverConfig.getFirstProperty("Management.AllowHTTPAccess");
-            if (JavaUtils.isFalseExplicitly(allowHttpAccess)) {
+            if (allowHttpAccess) {
                 axisService.setEnableAllTransports(false);
                 HashMap map = axisConfig.getTransportsIn();
                 Iterator iterator = map.values().iterator();

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

Reply via email to