tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From isil...@apache.org
Subject svn commit: r561473 - in /incubator/tuscany/java/sca/distribution/webapp: ./ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/tuscany/ src/main/java/org/apache/tuscany/sca/ src/main/java/org/apache/tuscany/sca/webapp/ src/main/weba...
Date Tue, 31 Jul 2007 20:06:27 GMT
Author: isilval
Date: Tue Jul 31 13:06:26 2007
New Revision: 561473

URL: http://svn.apache.org/viewvc?view=rev&rev=561473
Log:
Adding a servlet to upload contributions

Added:
    incubator/tuscany/java/sca/distribution/webapp/src/main/java/org/
    incubator/tuscany/java/sca/distribution/webapp/src/main/java/org/apache/
    incubator/tuscany/java/sca/distribution/webapp/src/main/java/org/apache/tuscany/
    incubator/tuscany/java/sca/distribution/webapp/src/main/java/org/apache/tuscany/sca/
    incubator/tuscany/java/sca/distribution/webapp/src/main/java/org/apache/tuscany/sca/webapp/
    incubator/tuscany/java/sca/distribution/webapp/src/main/java/org/apache/tuscany/sca/webapp/ContributionUploaderServlet.java
Modified:
    incubator/tuscany/java/sca/distribution/webapp/pom.xml
    incubator/tuscany/java/sca/distribution/webapp/src/main/webapp/WEB-INF/web.xml
    incubator/tuscany/java/sca/distribution/webapp/src/main/webapp/scaDomainInfo.jsp

Modified: incubator/tuscany/java/sca/distribution/webapp/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/distribution/webapp/pom.xml?view=diff&rev=561473&r1=561472&r2=561473
==============================================================================
--- incubator/tuscany/java/sca/distribution/webapp/pom.xml (original)
+++ incubator/tuscany/java/sca/distribution/webapp/pom.xml Tue Jul 31 13:06:26 2007
@@ -240,6 +240,27 @@
             <artifactId>xbean</artifactId>
             <version>2.2.0</version>
         </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.3</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>commons-fileupload</groupId>
+            <artifactId>commons-fileupload</artifactId>
+            <version>1.2</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>1.1</version>
+        </dependency>
+        <dependency>
+            <groupId>${pom.groupId}</groupId>
+            <artifactId>tuscany-implementation-notification</artifactId>
+            <version>${pom.version}</version>
+        </dependency>
     </dependencies>
 
     <build>

Added: incubator/tuscany/java/sca/distribution/webapp/src/main/java/org/apache/tuscany/sca/webapp/ContributionUploaderServlet.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/distribution/webapp/src/main/java/org/apache/tuscany/sca/webapp/ContributionUploaderServlet.java?view=auto&rev=561473
==============================================================================
--- incubator/tuscany/java/sca/distribution/webapp/src/main/java/org/apache/tuscany/sca/webapp/ContributionUploaderServlet.java
(added)
+++ incubator/tuscany/java/sca/distribution/webapp/src/main/java/org/apache/tuscany/sca/webapp/ContributionUploaderServlet.java
Tue Jul 31 13:06:26 2007
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.tuscany.sca.webapp;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.FileItemFactory;
+import org.apache.commons.fileupload.FileUploadException;
+import org.apache.commons.fileupload.disk.DiskFileItemFactory;
+import org.apache.commons.fileupload.servlet.ServletFileUpload;
+
+/**
+ * A Servlet to upload a contribution file.
+ */
+public class ContributionUploaderServlet extends HttpServlet {
+
+    private static final long serialVersionUID = System.currentTimeMillis();
+
+    private File repository;
+    
+    @Override
+    public void init(ServletConfig config) throws ServletException {
+        ServletContext servletContext = config.getServletContext();
+        repository = new File(servletContext.getRealPath(HotUpdateContextListener.REPOSITORY_FOLDER_NAME));
+    }
+    
+    @Override
+    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException
{
+        // Check that we have a file upload request
+        boolean isMultipart = ServletFileUpload.isMultipartContent(request);
+        if (!isMultipart) {
+            throw new RuntimeException("Need multipart content");
+        }
+
+        // Create a factory for disk-based file items
+        FileItemFactory factory = new DiskFileItemFactory();
+
+        // Create a new file upload handler
+        ServletFileUpload upload = new ServletFileUpload(factory);
+
+        try {
+            // Parse the request
+            List /* FileItem */ items = upload.parseRequest(request);        
+            // Process the uploaded items
+            Iterator iter = items.iterator();
+            while (iter.hasNext()) {
+                FileItem item = (FileItem) iter.next();
+
+                if (!item.isFormField()) {
+                    String fileName = item.getName();
+                    int index = fileName.lastIndexOf("\\") + 1;
+                    String uploadedFileName = repository.getAbsolutePath() + "/" + fileName.substring(index);
+                    File uploadedFile = new File(uploadedFileName);
+                    item.write(uploadedFile);
+                }
+            }
+        }
+        catch(FileUploadException e) {
+            throw new RuntimeException(e);
+        }
+        catch(Throwable e) {
+            e.printStackTrace();
+            throw new RuntimeException(e);
+        }
+        
+        setResponse(response, request);
+    }
+    
+    private void setResponse(HttpServletResponse response, HttpServletRequest request) throws
IOException {
+        response.setContentType("text/html");
+        PrintWriter out = response.getWriter();
+        out.println("<html>");
+        out.println("<head>");
+        out.println("<title>Apache Tuscany WebApp Runtime</title>");
+        out.println("</head>");
+        out.println("<body>");
+        out.println("<h2>Composite file uploaded</h2>");
+        int port = request.getServerPort();
+        String portSubStr = ((port == -1) ? "" : (":" + request.getServerPort()));
+        String backPath = request.getScheme() + "://" + request.getServerName() + portSubStr
+ request.getContextPath();
+        out.println("Go <a href=\"" + backPath + "\">back</a>");
+        out.println("</body>");
+        out.println("</html>");
+    }
+}

Modified: incubator/tuscany/java/sca/distribution/webapp/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/distribution/webapp/src/main/webapp/WEB-INF/web.xml?view=diff&rev=561473&r1=561472&r2=561473
==============================================================================
--- incubator/tuscany/java/sca/distribution/webapp/src/main/webapp/WEB-INF/web.xml (original)
+++ incubator/tuscany/java/sca/distribution/webapp/src/main/webapp/WEB-INF/web.xml Tue Jul
31 13:06:26 2007
@@ -28,15 +28,29 @@
     <listener-class>org.apache.tuscany.sca.webapp.HotUpdateContextListener</listener-class>
   </listener>
 
+  <listener>
+    <listener-class>org.apache.commons.fileupload.servlet.FileCleanerCleanup</listener-class>
+  </listener>
+
   <servlet>
      <servlet-name>TuscanyServlet</servlet-name>
      <servlet-class>org.apache.tuscany.sca.webapp.TuscanyServlet</servlet-class>
   </servlet>
   
+  <servlet>
+     <servlet-name>ContributionUploaderServlet</servlet-name>
+     <servlet-class>org.apache.tuscany.sca.webapp.ContributionUploaderServlet</servlet-class>
+  </servlet>
+  
   <servlet-mapping>
      <servlet-name>TuscanyServlet</servlet-name>
      <url-pattern>/sca/*</url-pattern>
   </servlet-mapping>
+
+    <servlet-mapping>
+        <servlet-name>ContributionUploaderServlet</servlet-name>
+        <url-pattern>/ContributionUploader</url-pattern>
+    </servlet-mapping>
 
   <welcome-file-list id="WelcomeFileList">
     <welcome-file>scaDomainInfo.jsp</welcome-file>

Modified: incubator/tuscany/java/sca/distribution/webapp/src/main/webapp/scaDomainInfo.jsp
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/distribution/webapp/src/main/webapp/scaDomainInfo.jsp?view=diff&rev=561473&r1=561472&r2=561473
==============================================================================
--- incubator/tuscany/java/sca/distribution/webapp/src/main/webapp/scaDomainInfo.jsp (original)
+++ incubator/tuscany/java/sca/distribution/webapp/src/main/webapp/scaDomainInfo.jsp Tue Jul
31 13:06:26 2007
@@ -60,6 +60,15 @@
    %>
 <br>
 
+<hr>
+You can fill in a composite file to upload
+
+<form method='POST' enctype='multipart/form-data' action='/tuscany/ContributionUploader'>
+Composite file to upload: <input type=file name=upfile><br>
+<br>
+<input type=submit value=Press> to upload the composite file
+</form>
+
 </body>
 </html>
 



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


Mime
View raw message