Hi all,
I'm using SmartGWT Pro 3.0 (SmartClient Version: v8.2p_2012-08-15/Pro Deployment (built 2012-08-15)) and I'm trying to download/view an image stored in a MSSQL database as a binary field. I have added a "_filename", "_filesize" and "_date_created" field within my table but the browser (Firefox 15) does not get the MIME type nor the filename of the image.
I have a simple DMI class (DMIRequestPrinter) which logs the requests and responses on the server side. It shows that those 3 additional field are read but not used by the smartgwt server to detect the MIME type or the filename. Firefox does always interpret the binary stream as a text file with the filename "IDACall".
I thought this would be done automatically!? Am I mistaken, do I have to do something special to set the filename and MIME type?
The content type of the HTTP response header is always "text/plain" and it doesn't make a difference if I'm downloading the file or using the URL (DataSource.getFileURL(data)).
Sample code:
My "Picture.ds.xml":
The DMIRequestPrinter class:
Log messages:
Any idea?
I'm using SmartGWT Pro 3.0 (SmartClient Version: v8.2p_2012-08-15/Pro Deployment (built 2012-08-15)) and I'm trying to download/view an image stored in a MSSQL database as a binary field. I have added a "_filename", "_filesize" and "_date_created" field within my table but the browser (Firefox 15) does not get the MIME type nor the filename of the image.
I have a simple DMI class (DMIRequestPrinter) which logs the requests and responses on the server side. It shows that those 3 additional field are read but not used by the smartgwt server to detect the MIME type or the filename. Firefox does always interpret the binary stream as a text file with the filename "IDACall".
I thought this would be done automatically!? Am I mistaken, do I have to do something special to set the filename and MIME type?
The content type of the HTTP response header is always "text/plain" and it doesn't make a difference if I'm downloading the file or using the URL (DataSource.getFileURL(data)).
Sample code:
Code:
final DataSource PictureDS = DataSource.getDataSource("Picture");
final Record data = new Record();
data.setAttribute("PictureID", 10005);
PictureDS.downloadFile(data);
Code:
<DataSource ID="Picture" serverType="sql" dataSourceVersion="1" dbName="SQLServer" schema="dbo">
<fields>
<field name="PictureID" type="integer" primaryKey="true"/>
<field name="PictureFile" type="binary" encodeInResponse="true" />
</fields>
<serverObject lookupStyle="new" className="de.infoteam.server.DMIRequestPrinter" />
<operationBindings>
<binding operationType="viewFile">
<serverObject lookupStyle="new" className="de.infoteam.server.DMIRequestPrinter" />
</binding>
<binding operationType="downloadFile">
<serverObject lookupStyle="new" className="de.infoteam.server.DMIRequestPrinter" />
</binding>
</operationBindings>
</DataSource>
Code:
package de.infoteam.server;
import org.apache.commons.logging.impl.Log4JLogger;
import com.isomorphic.datasource.DSRequest;
import com.isomorphic.datasource.DSResponse;
public class DMIRequestPrinter {
Log4JLogger log = new Log4JLogger("DMIRequestPrinter");
private void logDSRequest(final DSRequest dsRequest) {
this.log.info(dsRequest.getCriteria().size() + " criteria(s):");
for (final Object key : dsRequest.getCriteria().keySet()) {
this.log.info(key + " -> " + dsRequest.getCriteria().get(key));
}
}
private void logDSResponse(final DSResponse dsResponse) {
this.log.info(dsResponse.getRecords().size() + " record(s):");
this.log.info(dsResponse.getRecords().toString());
}
public DSResponse fetch(final DSRequest dsRequest) throws Exception {
this.log.info("fetch() called");
this.logDSRequest(dsRequest);
final DSResponse dsResponse = dsRequest.execute();
this.logDSResponse(dsResponse);
return dsResponse;
}
public DSResponse add(final DSRequest dsRequest) throws Exception {
this.log.info("add() called");
this.logDSRequest(dsRequest);
final DSResponse dsResponse = dsRequest.execute();
this.logDSResponse(dsResponse);
return dsResponse;
}
public DSResponse update(final DSRequest dsRequest) throws Exception {
this.log.info("update() called");
this.logDSRequest(dsRequest);
final DSResponse dsResponse = dsRequest.execute();
this.logDSResponse(dsResponse);
return dsResponse;
}
public DSResponse remove(final DSRequest dsRequest) throws Exception {
this.log.info("remove() called");
this.logDSRequest(dsRequest);
final DSResponse dsResponse = dsRequest.execute();
this.logDSResponse(dsResponse);
return dsResponse;
}
public DSResponse viewFile(final DSRequest dsRequest) throws Exception {
this.log.info("viewFile() called");
this.logDSRequest(dsRequest);
final DSResponse dsResponse = dsRequest.execute();
this.logDSResponse(dsResponse);
return dsResponse;
}
public DSResponse downloadFile(final DSRequest dsRequest) throws Exception {
this.log.info("downloadFile() called");
this.logDSRequest(dsRequest);
final DSResponse dsResponse = dsRequest.execute();
this.logDSResponse(dsResponse);
return dsResponse;
}
}
Code:
DEBUG 13:52:08.731 [main ] [JspRuntimeContext ] Parent class loader is: ContextLoader@null
DEBUG 13:52:08.732 [main ] [JspServlet ] Scratch dir for the JSP engine is: C:\Users\TWEISS~1.NTD\AppData\Local\Temp\Jetty_127_0_0_1_8888_war____-g0qk00\jsp
DEBUG 13:52:08.732 [main ] [JspServlet ] IMPORTANT: Do not modify the generated servlets
ISC: Configuring log4j from: file:/D:/SVN/GraphicTool/GraphicTool/war/WEB-INF/classes/log4j.isc.config.xml
=== 2012-09-12 13:52:08,795 [main] INFO ISCInit - Isomorphic SmartClient Framework - Initializing
=== 2012-09-12 13:52:08,795 [main] INFO ConfigLoader - Attempting to load framework.properties from CLASSPATH
=== 2012-09-12 13:52:08,919 [main] INFO ConfigLoader - Successfully loaded framework.properties from CLASSPATH at location: jar:file:/D:/SVN/GraphicTool/GraphicTool/war/WEB-INF/lib/isomorphic_core_rpc.jar!/framework.properties
=== 2012-09-12 13:52:08,919 [main] INFO ConfigLoader - Attempting to load project.properties from CLASSPATH
=== 2012-09-12 13:52:08,919 [main] INFO ConfigLoader - Unable to locate project.properties in CLASSPATH
=== 2012-09-12 13:52:08,919 [main] INFO ConfigLoader - Successfully loaded isc_interfaces.properties from CLASSPATH at location: jar:file:/D:/SVN/GraphicTool/GraphicTool/war/WEB-INF/lib/isomorphic_core_rpc.jar!/isc_interfaces.properties
=== 2012-09-12 13:52:08,919 [main] INFO ConfigLoader - Attempting to load server.properties from CLASSPATH
=== 2012-09-12 13:52:08,919 [main] INFO ConfigLoader - Successfully loaded server.properties from CLASSPATH at location: file:/D:/SVN/GraphicTool/GraphicTool/war/WEB-INF/classes/server.properties
=== 2012-09-12 13:52:08,935 [main] INFO Logger - Logging system started.
=== 2012-09-12 13:52:08,935 [main] INFO ISCInit - Isomorphic SmartClient Framework (v8.2p_2012-08-15/Pro Deployment 2012-08-15) - Initialization Complete
=== 2012-09-12 13:52:08,935 [main] INFO ISCInit - Auto-detected webRoot - using: D:\SVN\GraphicTool\GraphicTool\war
=== 2012-09-12 13:52:12,975 [l0-0] INFO PoolManager - SmartClient pooling disabled for 'Customer' objects
=== 2012-09-12 13:52:12,992 [l0-0] DEBUG XML - Parsed XML from D:\SVN\GraphicTool\GraphicTool\war\graphictool\sc\system\schema\builtinTypes.xml: 0ms
=== 2012-09-12 13:52:13,054 [l0-0] DEBUG XML - Parsed XML from D:\SVN\GraphicTool\GraphicTool\war\ds\Customer.ds.xml: 0ms
=== 2012-09-12 13:52:13,070 [l0-0] DEBUG XML - Parsed XML from D:\SVN\GraphicTool\GraphicTool\war\graphictool\sc\system\schema\DataSource.ds.xml: 16ms
=== 2012-09-12 13:52:13,117 [l0-0] DEBUG XML - Parsed XML from D:\SVN\GraphicTool\GraphicTool\war\graphictool\sc\system\schema\DataSourceField.ds.xml: 0ms
=== 2012-09-12 13:52:13,195 [l0-0] DEBUG XML - Parsed XML from D:\SVN\GraphicTool\GraphicTool\war\ds\Picture.ds.xml: 0ms
=== 2012-09-12 13:52:13,210 [l0-0] DEBUG XML - Parsed XML from D:\SVN\GraphicTool\GraphicTool\war\graphictool\sc\system\schema\ServerObject.ds.xml: 0ms
=== 2012-09-12 13:52:13,210 [l0-0] DEBUG XML - Parsed XML from D:\SVN\GraphicTool\GraphicTool\war\graphictool\sc\system\schema\OperationBinding.ds.xml: 0ms
=== 2012-09-12 13:52:13,226 [l0-0] DEBUG XML - Parsed XML from D:\SVN\GraphicTool\GraphicTool\war\ds\IDCounter.ds.xml: 0ms
=== 2012-09-12 13:52:22,196 [l0-4] INFO RequestContext - URL: '/graphictool/sc/IDACall', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1': Moz (Gecko) with Accept-Encoding header
=== 2012-09-12 13:52:22,228 [l0-4] DEBUG XML - Parsed XML from (in memory stream): 0ms
=== 2012-09-12 13:52:22,228 [l0-4] DEBUG XML - Parsed XML from D:\SVN\GraphicTool\GraphicTool\war\graphictool\sc\system\schema\List.ds.xml: 0ms
=== 2012-09-12 13:52:22,228 [l0-4] DEBUG RPCManager - Processing 1 requests.
=== 2012-09-12 13:52:22,244 [l0-4] DEBUG RPCManager - Request #1 (DSRequest) payload: {
criteria:{
PictureID:10005,
download_fieldname:"PictureFile"
},
operationConfig:{
dataSource:"Picture",
operationType:"downloadFile"
},
appID:"builtinApplication",
operation:"Picture_downloadFile",
oldValues:{
PictureID:10005,
download_fieldname:"PictureFile"
}
}
=== 2012-09-12 13:52:22,244 [l0-4] INFO IDACall - Performing 1 operation(s)
INFO 13:52:22.259 [btpool0-4 ] [DMIRequestPrinter ] downloadFile() called
INFO 13:52:22.259 [btpool0-4 ] [DMIRequestPrinter ] 2 criteria(s):
INFO 13:52:22.259 [btpool0-4 ] [DMIRequestPrinter ] PictureID -> 10005
INFO 13:52:22.259 [btpool0-4 ] [DMIRequestPrinter ] download_fieldname -> PictureFile
=== 2012-09-12 13:52:22,259 [l0-4] DEBUG AppBase - [builtinApplication.Picture_downloadFile] No userTypes defined, allowing anyone access to all operations for this application
=== 2012-09-12 13:52:22,259 [l0-4] DEBUG AppBase - [builtinApplication.Picture_downloadFile] No public zero-argument method named '_Picture_downloadFile' found, performing generic datasource operation
INFO 13:52:22.259 [btpool0-4 ] [DMIRequestPrinter ] fetch() called
INFO 13:52:22.259 [btpool0-4 ] [DMIRequestPrinter ] 2 criteria(s):
INFO 13:52:22.259 [btpool0-4 ] [DMIRequestPrinter ] PictureID -> 10005
INFO 13:52:22.259 [btpool0-4 ] [DMIRequestPrinter ] download_fieldname -> PictureFile
=== 2012-09-12 13:52:22,259 [l0-4] DEBUG AppBase - [builtinApplication.Picture_downloadFile, builtinApplication.null] No userTypes defined, allowing anyone access to all operations for this application
=== 2012-09-12 13:52:22,259 [l0-4] DEBUG AppBase - [builtinApplication.Picture_downloadFile, builtinApplication.null] No public zero-argument method named '_null' found, performing generic datasource operation
=== 2012-09-12 13:52:22,259 [l0-4] INFO SQLDataSource - [builtinApplication.Picture_downloadFile, builtinApplication.null] Performing fetch operation with
criteria: {PictureID:10005,download_fieldname:"PictureFile"} values: {PictureID:10005,download_fieldname:"PictureFile"}
=== 2012-09-12 13:52:22,275 [l0-4] INFO SQLDataSource - [builtinApplication.Picture_downloadFile, builtinApplication.null] derived query: SELECT $defaultSelectClause FROM $defaultTableClause WHERE $defaultWhereClause
DEBUG 13:52:22.306 [btpool0-4 ] [Velocity ] SimpleLog4JLogSystem using category 'org.apache.Velocity'
DEBUG 13:52:22.306 [btpool0-4 ] [Velocity ] *******************************************************************
DEBUG 13:52:22.306 [btpool0-4 ] [Velocity ] Starting Apache Velocity v1.6.1 (compiled: 2008-12-09 10:57:23)
DEBUG 13:52:22.306 [btpool0-4 ] [Velocity ] RuntimeInstance initializing.
DEBUG 13:52:22.306 [btpool0-4 ] [Velocity ] Default Properties File: org\apache\velocity\runtime\defaults\velocity.properties
DEBUG 13:52:22.306 [btpool0-4 ] [Velocity ] Trying to use logger class org.apache.velocity.runtime.log.SimpleLog4JLogSystem
DEBUG 13:52:22.306 [btpool0-4 ] [Velocity ] LogSystem has been deprecated. Please use a LogChute implementation.
DEBUG 13:52:22.306 [btpool0-4 ] [Velocity ] Default ResourceManager initializing. (class org.apache.velocity.runtime.resource.ResourceManagerImpl)
DEBUG 13:52:22.322 [btpool0-4 ] [Velocity ] ResourceLoader instantiated: org.apache.velocity.runtime.resource.loader.FileResourceLoader
DEBUG 13:52:22.322 [btpool0-4 ] [Velocity ] FileResourceLoader : initialization starting.
DEBUG 13:52:22.322 [btpool0-4 ] [Velocity ] Do unicode file recognition: false
DEBUG 13:52:22.322 [btpool0-4 ] [Velocity ] FileResourceLoader : adding path ''
DEBUG 13:52:22.322 [btpool0-4 ] [Velocity ] FileResourceLoader : initialization complete.
DEBUG 13:52:22.322 [btpool0-4 ] [Velocity ] ResourceCache: initialized (class org.apache.velocity.runtime.resource.ResourceCacheImpl) with class java.util.Collections$SynchronizedMap cache map.
DEBUG 13:52:22.322 [btpool0-4 ] [Velocity ] Default ResourceManager initialization complete.
DEBUG 13:52:22.322 [btpool0-4 ] [Velocity ] Loaded System Directive: org.apache.velocity.runtime.directive.Define
DEBUG 13:52:22.322 [btpool0-4 ] [Velocity ] Loaded System Directive: org.apache.velocity.runtime.directive.Break
DEBUG 13:52:22.322 [btpool0-4 ] [Velocity ] Loaded System Directive: org.apache.velocity.runtime.directive.Evaluate
DEBUG 13:52:22.322 [btpool0-4 ] [Velocity ] Loaded System Directive: org.apache.velocity.runtime.directive.Literal
DEBUG 13:52:22.337 [btpool0-4 ] [Velocity ] Loaded System Directive: org.apache.velocity.runtime.directive.Macro
DEBUG 13:52:22.337 [btpool0-4 ] [Velocity ] Loaded System Directive: org.apache.velocity.runtime.directive.Parse
DEBUG 13:52:22.337 [btpool0-4 ] [Velocity ] Loaded System Directive: org.apache.velocity.runtime.directive.Include
DEBUG 13:52:22.337 [btpool0-4 ] [Velocity ] Loaded System Directive: org.apache.velocity.runtime.directive.Foreach
DEBUG 13:52:22.353 [btpool0-4 ] [Velocity ] Created '20' parsers.
DEBUG 13:52:22.369 [btpool0-4 ] [Velocity ] Velocimacro : initialization starting.
DEBUG 13:52:22.369 [btpool0-4 ] [Velocity ] Velocimacro : "velocimacro.library" is not set. Trying default library: VM_global_library.vm
DEBUG 13:52:22.369 [btpool0-4 ] [Velocity ] Velocimacro : Default library not found.
DEBUG 13:52:22.369 [btpool0-4 ] [Velocity ] Velocimacro : allowInline = true : VMs can be defined inline in templates
DEBUG 13:52:22.369 [btpool0-4 ] [Velocity ] Velocimacro : allowInlineToOverride = false : VMs defined inline may NOT replace previous VM definitions
DEBUG 13:52:22.369 [btpool0-4 ] [Velocity ] Velocimacro : allowInlineLocal = false : VMs defined inline will be global in scope if allowed.
DEBUG 13:52:22.369 [btpool0-4 ] [Velocity ] Velocimacro : autoload off : VM system will not automatically reload global library macros
DEBUG 13:52:22.369 [btpool0-4 ] [Velocity ] Velocimacro : Velocimacro : initialization complete.
DEBUG 13:52:22.369 [btpool0-4 ] [Velocity ] RuntimeInstance successfully initialized.
=== 2012-09-12 13:52:22,369 [l0-4] INFO SQLDataSource - [builtinApplication.Picture_downloadFile, builtinApplication.null] Executing SQL query on 'SQLServer': SELECT Picture.PictureFile, Picture.PictureFile_date_created, Picture.PictureFile_filename, Picture.PictureFile_filesize, Picture.PictureID FROM dbo.Picture WHERE (Picture.PictureID='10005')
=== 2012-09-12 13:52:22,478 [l0-4] DEBUG PoolableSQLConnectionFactory - [builtinApplication.Picture_downloadFile, builtinApplication.null] Initializing SQL config for 'SQLServer' from system config - using DriverManager: com.microsoft.sqlserver.jdbc.SQLServerDriver
=== 2012-09-12 13:52:22,509 [l0-4] DEBUG PoolableSQLConnectionFactory - [builtinApplication.Picture_downloadFile, builtinApplication.null] com.microsoft.sqlserver.jdbc.SQLServerDriver lookup successful
=== 2012-09-12 13:52:22,509 [l0-4] DEBUG PoolableSQLConnectionFactory - [builtinApplication.Picture_downloadFile, builtinApplication.null] DriverManager fetching connection for SQLServer via jdbc url jdbc:sqlserver://Boschix;instanceName=Bugtracker;databaseName=GraphicToolDB;User=GraphicTool;Password=GraphicTool
=== 2012-09-12 13:52:22,509 [l0-4] DEBUG PoolableSQLConnectionFactory - [builtinApplication.Picture_downloadFile, builtinApplication.null] Passing JDBC URL only to getConnection
=== 2012-09-12 13:52:34,162 [l0-4] DEBUG PoolableSQLConnectionFactory - [builtinApplication.Picture_downloadFile, builtinApplication.null] Returning pooled Connection
=== 2012-09-12 13:52:34,178 [l0-4] INFO SQLDriver - [builtinApplication.Picture_downloadFile, builtinApplication.null] Executing SQL query on 'SQLServer': SELECT Picture.PictureFile, Picture.PictureFile_date_created, Picture.PictureFile_filename, Picture.PictureFile_filesize, Picture.PictureID FROM dbo.Picture WHERE (Picture.PictureID='10005')
=== 2012-09-12 13:52:34,226 [l0-4] INFO DSResponse - [builtinApplication.Picture_downloadFile, builtinApplication.null] DSResponse: List with 1 items
INFO 13:52:34.226 [btpool0-4 ] [DMIRequestPrinter ] 1 record(s):
INFO 13:52:34.226 [btpool0-4 ] [DMIRequestPrinter ] [{PictureFile_date_created=2012-11-09 10:00:00.0, PictureID=10005, PictureFile_filesize=4479, PictureFile=java.io.ByteArrayInputStream@5720e4e2, PictureFile_filename=Test.png}]
=== 2012-09-12 13:52:34,226 [l0-4] INFO DSResponse - [builtinApplication.Picture_downloadFile] DSResponse: Map with 5 keys
INFO 13:52:34.226 [btpool0-4 ] [DMIRequestPrinter ] 1 record(s):
INFO 13:52:34.226 [btpool0-4 ] [DMIRequestPrinter ] [{PictureFile_date_created=2012-11-09 10:00:00.0, PictureID=10005, PictureFile_filesize=4479, PictureFile=java.io.ByteArrayInputStream@5720e4e2, PictureFile_filename=Test.png}]
Comment