[jbpm-commits] JBoss JBPM SVN: r3227 - in projects/balalaika/trunk/server/src/main: webapp and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Dec 5 09:41:31 EST 2008
Author: heiko.braun at jboss.com
Date: 2008-12-05 09:41:31 -0500 (Fri, 05 Dec 2008)
New Revision: 3227
Added:
projects/balalaika/trunk/server/src/main/java/org/jboss/balalaika/FileWriter.java
Modified:
projects/balalaika/trunk/server/src/main/java/org/jboss/balalaika/ReportFacade.java
projects/balalaika/trunk/server/src/main/webapp/WEB-INF/web.xml
projects/balalaika/trunk/server/src/main/webapp/index.html
Log:
Avoid double buffering of report contents
Added: projects/balalaika/trunk/server/src/main/java/org/jboss/balalaika/FileWriter.java
===================================================================
--- projects/balalaika/trunk/server/src/main/java/org/jboss/balalaika/FileWriter.java (rev 0)
+++ projects/balalaika/trunk/server/src/main/java/org/jboss/balalaika/FileWriter.java 2008-12-05 14:41:31 UTC (rev 3227)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.balalaika;
+
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import java.lang.reflect.Type;
+import java.lang.annotation.Annotation;
+import java.io.OutputStream;
+import java.io.IOException;
+import java.io.FileInputStream;
+import java.io.File;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+ at Provider
+ at Produces({"text/html", "image/*"})
+public class FileWriter implements MessageBodyWriter
+{
+
+ public boolean isWriteable(Class aClass, Type type, Annotation[] annotations, MediaType mediaType)
+ {
+ return aClass.equals(java.io.File.class);
+ }
+
+ public long getSize(Object o, Class aClass, Type type, Annotation[] annotations, MediaType mediaType)
+ {
+ return ((File)o).length();
+ }
+
+ public void writeTo(Object o, Class aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap multivaluedMap, OutputStream outputStream) throws IOException, WebApplicationException
+ {
+ FileInputStream fin = new FileInputStream((File)o);
+ int c;
+ while ((c = fin.read()) != -1)
+ {
+ outputStream.write(c);
+ }
+
+ fin.close();
+
+ }
+}
Modified: projects/balalaika/trunk/server/src/main/java/org/jboss/balalaika/ReportFacade.java
===================================================================
--- projects/balalaika/trunk/server/src/main/java/org/jboss/balalaika/ReportFacade.java 2008-12-05 14:20:19 UTC (rev 3226)
+++ projects/balalaika/trunk/server/src/main/java/org/jboss/balalaika/ReportFacade.java 2008-12-05 14:41:31 UTC (rev 3227)
@@ -25,16 +25,10 @@
import org.apache.commons.logging.LogFactory;
import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
+import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
/**
* BIRT integration facade.<p>
@@ -130,8 +124,8 @@
String absoluteFile = birtService.getIConfig().getOutputDir() + outputFileName;
log.info("Render " + absoluteFile);
- File f = new File(absoluteFile);
- return Response.ok(bytesFromFile(f)).type("text/html").build();
+ File reportFile = new File(absoluteFile);
+ return Response.ok(reportFile).type("text/html").build();
}
@GET
@@ -150,33 +144,6 @@
File imageFile = new File(absName);
if(!imageFile.exists())
throw new IllegalArgumentException("Image " +absName+" doesn't exist");
- return Response.ok(bytesFromFile(imageFile)).build();
+ return Response.ok(imageFile).build();
}
-
- public static byte[] bytesFromFile(File file)
- {
- try
- {
- InputStream is = new FileInputStream(file);
- long length = file.length();
-
- byte[] bytes = new byte[(int)length];
- int offset = 0;
- int numRead = 0;
- while (offset < bytes.length && (numRead=is.read(bytes,
- offset, bytes.length-offset)) >= 0) {
- offset += numRead;
- }
- if (offset < bytes.length) {
- throw new IOException("Could not completely read file "
- + file.getName());
- }
- is.close();
- return bytes;
- }
- catch (IOException e)
- {
- throw new RuntimeException("Failed to read file " + file);
- }
- }
}
Modified: projects/balalaika/trunk/server/src/main/webapp/WEB-INF/web.xml
===================================================================
--- projects/balalaika/trunk/server/src/main/webapp/WEB-INF/web.xml 2008-12-05 14:20:19 UTC (rev 3226)
+++ projects/balalaika/trunk/server/src/main/webapp/WEB-INF/web.xml 2008-12-05 14:41:31 UTC (rev 3227)
@@ -15,6 +15,11 @@
<param-value>/rs</param-value>
</context-param>
+ <context-param>
+ <param-name>resteasy.providers</param-name>
+ <param-value>org.jboss.balalaika.FileWriter</param-value>
+ </context-param>
+
<!--context-param>
<param-name>org.jboss.bpm.console.server.dao.ManagementFactory</param-name>
<param-value>org.jboss.bpm.console.server.dao.internal.JBPM3ManagementFactory</param-value>
Modified: projects/balalaika/trunk/server/src/main/webapp/index.html
===================================================================
--- projects/balalaika/trunk/server/src/main/webapp/index.html 2008-12-05 14:20:19 UTC (rev 3226)
+++ projects/balalaika/trunk/server/src/main/webapp/index.html 2008-12-05 14:41:31 UTC (rev 3227)
@@ -20,15 +20,16 @@
<tr>
<td>GET</td>
<td>/rs/report/view/{reportName}</td>
- <td>Get an HTML report from file 'reportName' </td>
+ <td>View a HTML report from template 'reportName' </td>
<td>text/html</td>
</tr>
<tr>
<td>GET</td>
<td>/rs/report/view/image/{image}</td>
- <td>Get images associated with an HTML report (usally a private call)</td>
- <td>image/jpg, image/gif, image/png</td>
+ <td>Get images associated with an HTML report
+ (The exported reports refer to tzhis URL)</td>
+ <td>image/*</td>
</tr>
</table>
</body>
More information about the jbpm-commits
mailing list