Amit Aviram has uploaded a new change for review.

Change subject: image-upload: proxy for image upload
......................................................................

image-upload: proxy for image upload

Change-Id: I42a326a08217540e96cfb2c01c26b0e1106a7814
Signed-off-by: Amit Aviram <[email protected]>
---
A backend/manager/modules/ovirt-import-proxy/output/isracard.pdf
A backend/manager/modules/ovirt-import-proxy/pom.xml
A 
backend/manager/modules/ovirt-import-proxy/src/main/java/org/ovirt/import_proxy/ImportServlet.java
A backend/manager/modules/ovirt-import-proxy/src/main/webapp/WEB-INF/web.xml
A backend/manager/modules/ovirt-import-proxy/src/main/webapp/index.jsp
5 files changed, 279 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/86/41286/1

diff --git a/backend/manager/modules/ovirt-import-proxy/output/isracard.pdf 
b/backend/manager/modules/ovirt-import-proxy/output/isracard.pdf
new file mode 100644
index 0000000..4a7009c
--- /dev/null
+++ b/backend/manager/modules/ovirt-import-proxy/output/isracard.pdf
Binary files differ
diff --git a/backend/manager/modules/ovirt-import-proxy/pom.xml 
b/backend/manager/modules/ovirt-import-proxy/pom.xml
new file mode 100644
index 0000000..124cd6e
--- /dev/null
+++ b/backend/manager/modules/ovirt-import-proxy/pom.xml
@@ -0,0 +1,113 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.ovirt</groupId>
+  <artifactId>import-proxy</artifactId>
+  <packaging>war</packaging>
+  <version>3.6.0-SNAPSHOT</version>
+  <name>oVirt Import Proxy</name>
+  <description>oVirt ISO/Disk Image Import Proxy</description>
+
+  <url>http://www.ovirt.org</url>
+
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin>
+    <version.jboss.spec.javaee.7.0>1.0.0.Final</version.jboss.spec.javaee.7.0>
+    <version.compiler.plugin>3.1</version.compiler.plugin>
+    <version.war.plugin>2.5</version.war.plugin>
+    <maven.compiler.target>1.7</maven.compiler.target>
+    <maven.compiler.source>1.7</maven.compiler.source>
+  </properties>
+
+
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>org.jboss.spec</groupId>
+        <artifactId>jboss-javaee-7.0</artifactId>
+        <version>${version.jboss.spec.javaee.7.0}</version>
+        <type>pom</type>
+        <scope>import</scope>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+
+
+  <dependencies>
+    <!-- not sure if we need this -->
+<!--
+    <dependency>
+      <groupId>org.jboss.spec.javax.annotation</groupId>
+      <artifactId>jboss-annotations-api_1.2_spec</artifactId>
+      <scope>provided</scope>
+    </dependency>
+-->
+      <dependency>
+          <groupId>org.ovirt.engine.core</groupId>
+          <artifactId>bll</artifactId>
+          <version>3.6.0-SNAPSHOT</version>
+          <scope>provided</scope>
+      </dependency>
+
+    <dependency>
+      <groupId>org.jboss.spec.javax.servlet</groupId>
+      <artifactId>jboss-servlet-api_3.1_spec</artifactId>
+      <scope>provided</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+
+  <build>
+    <finalName>${project.artifactId}</finalName>
+    <plugins>
+
+      <plugin>
+        <artifactId>maven-war-plugin</artifactId>
+        <version>${version.war.plugin}</version>
+        <configuration>
+          <!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! -->
+          <failOnMissingWebXml>false</failOnMissingWebXml>
+        </configuration>
+      </plugin>
+
+      <!-- WildFly plugin to deploy war -->
+      <plugin>
+        <groupId>org.wildfly.plugins</groupId>
+        <artifactId>wildfly-maven-plugin</artifactId>
+        <version>${version.wildfly.maven.plugin}</version>
+      </plugin>
+
+      <!-- JBoss plugin to deploy war -->
+      <plugin>
+        <groupId>org.jboss.as.plugins</groupId>
+        <artifactId>jboss-as-maven-plugin</artifactId>
+        <version>7.7.Final</version>
+        <configuration>
+          <!--<port>8706</port>-->  <!-- For engine jboss-as -->
+          <!--<port>9999</port>-->  <!-- For standalone jboss-as without 
engine running -->
+          <!--<port>10000</port>--> <!-- For standalone jboss-as alongside 
engine jboss-as -->
+        </configuration>
+      </plugin>
+
+      <!-- Compiler plugin enforces Java 1.6 compatibility and activates 
annotation processors -->
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>${version.compiler.plugin}</version>
+        <configuration>
+          <source>${maven.compiler.source}</source>
+          <target>${maven.compiler.target}</target>
+        </configuration>
+      </plugin>
+
+    </plugins>
+  </build>
+</project>
diff --git 
a/backend/manager/modules/ovirt-import-proxy/src/main/java/org/ovirt/import_proxy/ImportServlet.java
 
b/backend/manager/modules/ovirt-import-proxy/src/main/java/org/ovirt/import_proxy/ImportServlet.java
new file mode 100644
index 0000000..ed3e7ac
--- /dev/null
+++ 
b/backend/manager/modules/ovirt-import-proxy/src/main/java/org/ovirt/import_proxy/ImportServlet.java
@@ -0,0 +1,138 @@
+package org.ovirt.import_proxy;
+
+import org.ovirt.engine.core.bll.AddDiskCommand;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.RandomAccessFile;
+
+/**
+ * Created by gpadgett on 3/24/15.
+ */
+//@WebServlet(name = "ImportServlet", urlPatterns = {"/hello"})
+@WebServlet("/upload")
+public class ImportServlet extends HttpServlet {
+    static final String path = 
"/home/aaviram/src/ImageUpload/ovirt-import-proxy/output/";
+    private InputStream inputStream;
+
+    @Override
+    protected void doOptions(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
+        addCORS(response);
+        super.doOptions(request, response);
+    }
+
+    private void addCORS(HttpServletResponse response) {
+        this.response = response;
+        response.addHeader("Access-Control-Allow-Origin", "*");
+        response.addHeader("Access-Control-Allow-Headers",
+                "Cache-Control, Pragma, X-Chunk-Bytes, X-Start-Offset, 
X-File-Name, X-File-Size, Content-Type");
+        response.addHeader("Access-Control-Allow-Methods", "GET, POST");
+        response.addHeader("Access-Control-Max-Age", "300");
+    }
+
+    @Override
+    protected void doPost(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
+        addCORS(response);
+
+        deb("Reached doPost. getting info.");
+
+        String name = request.getHeader("X-File-Name");
+        long offset = Long.parseLong(request.getHeader("X-Start-Offset"));
+
+        deb("Getting input stream.");
+        InputStream in = request.getInputStream();
+        byte[] buffer = new byte[4096];
+        int bytes;
+        long totalBytes = 0;
+
+        deb("Writing from stream.");
+        while ((bytes = in.read(buffer)) != -1) {
+            writeToFile(name, buffer, offset + totalBytes, bytes);
+            totalBytes += bytes;
+        }
+        in.close();
+
+        // TODO is this needed?
+        response.getWriter().println("Received " + totalBytes + " bytes");
+        response.setStatus(HttpServletResponse.SC_OK);
+    }
+
+    private void writeToFile(String name, byte[] buffer, long offset, int 
bytes) throws ServletException, IOException {
+        deb("Writing part: offset is " + Long.toString(offset));
+        File file = new File(this.path + name);
+        long size = 0;
+        if (!file.exists()) {
+            deb("File does not exist. writing a new file." + 
Long.toString(offset));
+            file.createNewFile();
+        } else {
+            size = file.length();
+        }
+
+        try (RandomAccessFile out = new RandomAccessFile(file, "rw")) {
+//            if (offset > 0) {
+            out.seek(offset);
+//                if (out.getFilePointer() != offset) {
+//                out.getChannel.position(offset);
+                // Any bytes between the former eof and current position, if 
eof < current, are unspecified
+//            }
+            out.write(buffer, 0, bytes);
+        }
+        deb("Write part done.");
+        // TODO consider apache commons' IOUtils.copy method to copy in to out
+        // TODO note the default socket buffer size is (was? need to verify) 8k
+        // TODO how can we write to the middle of a file?
+
+        // TODO we may want to create a thread pool holding open files for a 
short time;
+        // TODO if so, the below could be useful
+        /*
+        FileOutputStream rawOut = new FileOutputStream(file, true);
+        BufferedOutputStream out;
+        try {
+            out = new BufferedOutputStream(rawOut);
+        } catch (Exception e) {
+            rawOut.close();
+            return;
+        }
+        /*
+        if (out.getChannel.position() != offset) {
+            out.getChannel.position(offset);
+            // Any bytes between the former eof and current position, if eof < 
current, are unspecified
+        }
+         */
+        /*
+        out.write(buffer, 0, bytes);
+        out.flush();
+        out.close();
+        */
+    }
+
+    @Override
+    protected void doGet(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
+        addCORS(response);
+        response.getWriter().println("Hello World! getting.");
+        /*if (request.getParameter("resumeOffset") != null) {
+            String name = request.getParameter("filename");
+            File file = new File(this.path + name);
+            long size = 0;
+            if (file.exists()) {
+                size = file.length();
+            }
+            response.getWriter().print(size);
+        } else {
+            response.getWriter().println("Hello World!");
+        }*/
+    }
+
+    HttpServletResponse response;
+    private void deb(String s) throws ServletException, IOException {
+        response.getWriter().println(s);
+    }
+}
diff --git 
a/backend/manager/modules/ovirt-import-proxy/src/main/webapp/WEB-INF/web.xml 
b/backend/manager/modules/ovirt-import-proxy/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..51b6c2c
--- /dev/null
+++ b/backend/manager/modules/ovirt-import-proxy/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,23 @@
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd";
+         version="3.0">
+
+    <display-name>oVirt Image Import Proxy</display-name>
+<!-- TODO we may not need web.xml if we don't need to define 
welcome-file-list, error pages, etc -->
+    <!--
+    <welcome-file-list>
+        <welcome-file>WebAdmin.html</welcome-file>
+    </welcome-file-list>
+-->
+    <!--
+    <servlet>
+        <servlet-name>import-proxy</servlet-name>
+        <servlet-class>org.ovirt.import_proxy.ImportServlet</servlet-class>
+    </servlet>
+
+    <servlet-mapping>
+        <servlet-name>import-proxy</servlet-name>
+        <url-pattern>/import</url-pattern>
+    </servlet-mapping>
+    -->
+</web-app>
diff --git 
a/backend/manager/modules/ovirt-import-proxy/src/main/webapp/index.jsp 
b/backend/manager/modules/ovirt-import-proxy/src/main/webapp/index.jsp
new file mode 100644
index 0000000..ae48fdf
--- /dev/null
+++ b/backend/manager/modules/ovirt-import-proxy/src/main/webapp/index.jsp
@@ -0,0 +1,5 @@
+<html>
+<body>
+<h2>Hello World! index.jsp</h2>
+</body>
+</html>


-- 
To view, visit https://gerrit.ovirt.org/41286
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I42a326a08217540e96cfb2c01c26b0e1106a7814
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Amit Aviram <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to