Author: keith
Date: Sun Jan 27 07:39:41 2008
New Revision: 13005

Log:

Fixing masshup downloading by adding a request processor



Added:
   
trunk/mashup/java/modules/core/src/org/wso2/mashup/requestprocessor/DownloadProcessor.java
Modified:
   trunk/mashup/java/modules/core/conf/server.xml
   
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupArchiveManupulator.java

Modified: trunk/mashup/java/modules/core/conf/server.xml
==============================================================================
--- trunk/mashup/java/modules/core/conf/server.xml      (original)
+++ trunk/mashup/java/modules/core/conf/server.xml      Sun Jan 27 07:39:41 2008
@@ -400,6 +400,10 @@
             <Item>sig</Item>
             <Class>org.wso2.mashup.requestprocessor.SigProcessor</Class>
         </Processor>
+        <Processor>
+            <Item>download</Item>
+            <Class>org.wso2.mashup.requestprocessor.DownloadProcessor</Class>
+        </Processor>
     </HttpGetRequestProcessors>
 
     <!--

Added: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/requestprocessor/DownloadProcessor.java
==============================================================================
--- (empty file)
+++ 
trunk/mashup/java/modules/core/src/org/wso2/mashup/requestprocessor/DownloadProcessor.java
  Sun Jan 27 07:39:41 2008
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2006,2007 WSO2, Inc. http://www.wso2.org
+ *
+ * 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.wso2.mashup.requestprocessor;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.mashup.MashupConstants;
+import org.wso2.mashup.utils.MashupArchiveManupulator;
+import org.wso2.mashup.utils.MashupUtils;
+import org.wso2.wsas.ServerConstants;
+import org.wso2.wsas.transport.HttpGetRequestProcessor;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.OutputStream;
+
+public class DownloadProcessor implements HttpGetRequestProcessor {
+
+    private static Log log = LogFactory.getLog(DownloadProcessor.class);
+
+    public void process(HttpServletRequest request, HttpServletResponse 
response,
+                        ConfigurationContext configurationContext) throws 
Exception {
+        String requestURI = request.getRequestURI();
+        String contextPath = configurationContext.getServiceContextPath();
+        String serviceName = MashupUtils.getServiceName(requestURI, 
contextPath);
+        AxisService axisService = configurationContext.getAxisConfiguration()
+                .getServiceForActivation(serviceName);
+
+        OutputStream outputStream = response.getOutputStream();
+        if (axisService != null) {
+
+            if (axisService.isActive()) {
+
+                String serviceType =
+                        (String) 
axisService.getParameterValue(ServerConstants.SERVICE_TYPE);
+
+                // We can show source only if this service is a javascript 
service
+                if (MashupConstants.MASHUP_JS_SERVICE.equals(serviceType)) {
+
+                    MashupArchiveManupulator mashupArchiveManupulator = new 
MashupArchiveManupulator();
+                    mashupArchiveManupulator.createMashupArchive(axisService, 
configurationContext, outputStream);
+
+                    response.setContentType("application/zip");
+                    outputStream.flush();
+                } else {
+                    response.setContentType("text/html");
+                    outputStream
+                            .write(("<h4>Source is not available for this 
service. The source view " +
+                                    "is avalable only for JavaScript services")
+                                    .getBytes());
+                    outputStream.flush();
+                }
+            } else {
+                    response.setContentType("text/html");
+                    outputStream
+                            .write(("<h4>Cannot download this service. This 
service " +
+                                    "is not active").getBytes());
+                    outputStream.flush();
+            }
+
+        } else {
+            if (log.isDebugEnabled()) {
+                log.debug("Cannot find the service" + serviceName + ". Axis 
Service is null.");
+            }
+            response.setContentType("text/html");
+            outputStream
+                    .write(("<h4>Service cannot be found. Cannot <em>download 
service</em>.</h4>")
+                            .getBytes());
+            outputStream.flush();
+        }
+    }
+}

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupArchiveManupulator.java
==============================================================================
--- 
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupArchiveManupulator.java
      (original)
+++ 
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupArchiveManupulator.java
      Sun Jan 27 07:39:41 2008
@@ -42,10 +42,7 @@
 import javax.activation.DataSource;
 import javax.activation.FileDataSource;
 import javax.xml.namespace.QName;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
+import java.io.*;
 import java.net.URL;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
@@ -70,29 +67,11 @@
     public DataHandler createMashupArchiveDataHandler(AxisService 
mashupService,
                                                       ConfigurationContext 
configCtx)
             throws MashupFault {
-        File serviceJS;
-        File serviceResourceFolder = null;
-        // Get the service js file for the given service
-        Parameter serviceJSParameter = mashupService
-                .getParameter(JavaScriptEngineConstants.SERVICE_JS);
-        if (serviceJSParameter != null && serviceJSParameter.getValue() != 
null) {
-            serviceJS = (File) serviceJSParameter.getValue();
-        } else {
-            throw new MashupFault("Service you are trying to share is not a 
Mashup Service.");
-        }
-        // Access the resources folder for the service
-        Parameter serviceResourceFolderParameter = mashupService
-                .getParameter(JavaScriptEngineConstants.RESOURCES_FOLDER);
-        if (serviceResourceFolderParameter.getValue() != null) {
-            serviceResourceFolder = (File) 
serviceResourceFolderParameter.getValue();
-        }
-
         // Use the WSAS work dir to create the temporary archive file
         Object workDirObject = configCtx.getProperty(ServerConstants.WORK_DIR);
         if (workDirObject != null) {
             DataSource dataSource;
             String workDir = (String) workDirObject;
-            if (serviceJS != null && serviceResourceFolder != null) {
                 // Directory to store the temp archive
                 File tempDir = new File(workDir);
                 tempDir.mkdirs();
@@ -100,21 +79,53 @@
                     // Creating a FileDataSource
                     dataSource =
                             new FileDataSource(File.createTempFile("mashup", 
"upload", tempDir));
-                    ZipOutputStream zos = new 
ZipOutputStream(dataSource.getOutputStream());
                     // write the service js file & the contents of the
                     // service.resources folder to the outstream of the data 
source
 
-                    createMashupArchive(zos, serviceJS, serviceResourceFolder);
+                    createMashupArchive(mashupService, configCtx, 
dataSource.getOutputStream());
                 } catch (IOException e) {
                     throw new MashupFault(e);
                 }
                 return new DataHandler(dataSource);
-            }
-            throw new MashupFault("Mashup Service Resources cannot be found.");
         }
         throw new MashupFault("Server work directory cannot be found.");
     }
 
+    public void createMashupArchive(AxisService mashupService, 
ConfigurationContext configCtx,
+                                               OutputStream outputStream) 
throws MashupFault {
+        File serviceJS;
+        File serviceResourceFolder = null;
+        // Get the service js file for the given service
+        Parameter serviceJSParameter = mashupService
+                .getParameter(JavaScriptEngineConstants.SERVICE_JS);
+        if (serviceJSParameter != null && serviceJSParameter.getValue() != 
null) {
+            serviceJS = (File) serviceJSParameter.getValue();
+        } else {
+            throw new MashupFault("Service you are trying to share is not a 
Mashup Service.");
+        }
+        // Access the resources folder for the service
+        Parameter serviceResourceFolderParameter = mashupService
+                .getParameter(JavaScriptEngineConstants.RESOURCES_FOLDER);
+        if (serviceResourceFolderParameter.getValue() != null) {
+            serviceResourceFolder = (File) 
serviceResourceFolderParameter.getValue();
+        }
+
+        if (serviceJS != null && serviceResourceFolder != null) {
+            try {
+                // Creating a FileDataSource
+                ZipOutputStream zos = new ZipOutputStream(outputStream);
+                // write the service js file & the contents of the
+                // service.resources folder to the outstream of the data source
+
+                createMashupArchive(zos, serviceJS, serviceResourceFolder);
+                return;
+            } catch (IOException e) {
+                throw new MashupFault(e);
+            }
+        }
+        throw new MashupFault("Mashup Service Resources cannot be found.");
+    }
+
     /**
      * Upload a archived mashupService included in the dataHanlder to a remote
      * Mashup Server donated by the destinationServerAddress.

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

Reply via email to