Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Download a File error

    Hi isomorphic,

    I try to download a file, but I canīt get it.

    I define a DS. The code is:

    Code:
    <DataSource ID="downloadDS" 
    			serverType="generic">
    			
    	<fields>
    		<field name="file" type="binary"/>
    	</fields>
    
    	<serverObject lookupStyle="new" className="dmi.DownloadDMI" />
    
    </DataSource>
    The DownloadDMI code is:

    Code:
    public class DownloadDMI {
    
    	public DSResponse downloadFile(DSRequest dsRequest, RPCManager rpcManager) throws Exception {
    
    		System.out.println("Entro al downloadFile de DownloadDMI");
    		
    		DSResponse dsResponse = new DSResponse();
    
    		DownloadFile downloadItem= new DownloadFile();
    
    		InputStream stream = new FileInputStream( "Banner.png" );
    		
    		downloadItem.setFile(stream);
    
    		rpcManager.doCustomResponse(); 
    
    		dsResponse.setData(downloadItem);
    		
    		return dsResponse;
    		
    	}
    The value object is:

    Code:
    package model;
    
    import java.io.InputStream;
    
    public class DownloadFile {
    
    	private InputStream file;
    
    	public InputStream getFile() {
    		return file;
    	}
    
    	public void setFile(InputStream file) {
    		this.file = file;
    	} 
    
    }

    The JSP Code is:

    Code:
    
    			<isomorphic:loadDS ID="downloadDS"/>
    		
    			function openHelpContent(){
    			
    				var data = {};
    				data.param1 = "123";
    				data.param2 = "param2";
    				
    				isc.DataSource.get("downloadDS").downloadFile({data:data}); 
    
    			}		
    				
    			Button.create({
    			    title: "Download File",
    			    position: "relative",
    			    width: 150,
    			    click: function () {
    					openHelpContent();							        
    			    }
    			});
    The error that appear in the browser is:

    Code:
    com.isomorphic.servlet.IDACall top-level exception
    java.lang.ClassCastException: java.lang.String
    	at com.isomorphic.rpc.RPCManager.completeResponse(RPCManager.java:657)
    	at com.isomorphic.rpc.RPCManager.send(RPCManager.java:494)
    	at com.isomorphic.rpc.RPCManager.sendFailure(RPCManager.java:577)
    	at com.isomorphic.rpc.RPCManager.sendFailure(RPCManager.java:598)
    	at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:112)
    	at com.isomorphic.servlet.IDACall.doPost(IDACall.java:54)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    	at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    	at com.isomorphic.servlet.CompressionFilter.doFilter(CompressionFilter.java:248)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
    	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    	at java.lang.Thread.run(Unknown Source)
    The error that appear in the apache-tomcat console is:

    Code:
    === 2010-06-21 22:57:14,250 [or25] INFO  IDACall - Performing 1 operation(s)
    === 2010-06-21 22:57:14,265 [or25] WARN  RequestContext - dsRequest.execute() failed: 
    java.lang.Exception: attempt to call unknown operationType: downloadFile
    	at com.isomorphic.datasource.DataSourceDMI.execute(DataSourceDMI.java:154)
    	at com.isomorphic.datasource.DataSourceDMI.execute(DataSourceDMI.java:62)
    	at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:1172)
    	at com.isomorphic.servlet.IDACall.handleDSRequest(IDACall.java:155)
    	at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:106)
    	at com.isomorphic.servlet.IDACall.doPost(IDACall.java:54)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    	at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    	at com.isomorphic.servlet.CompressionFilter.doFilter(CompressionFilter.java:248)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
    	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    	at java.lang.Thread.run(Unknown Source)
    === 2010-06-21 22:57:14,281 [or25] ERROR IDACall - Error executing operation: downloadDS_downloadFile
    java.lang.ClassCastException: java.lang.String
    	at com.isomorphic.rpc.RPCManager.completeResponse(RPCManager.java:657)
    	at com.isomorphic.rpc.RPCManager.send(RPCManager.java:494)
    	at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:106)
    	at com.isomorphic.servlet.IDACall.doPost(IDACall.java:54)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    	at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    	at com.isomorphic.servlet.CompressionFilter.doFilter(CompressionFilter.java:248)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
    	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    	at java.lang.Thread.run(Unknown Source)
    === 2010-06-21 22:57:14,281 [or25] ERROR IDACall - Top-level servlet error: 
    java.lang.ClassCastException: java.lang.String
    	at com.isomorphic.rpc.RPCManager.completeResponse(RPCManager.java:657)
    	at com.isomorphic.rpc.RPCManager.send(RPCManager.java:494)
    	at com.isomorphic.rpc.RPCManager.sendFailure(RPCManager.java:577)
    	at com.isomorphic.rpc.RPCManager.sendFailure(RPCManager.java:598)
    	at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:112)
    	at com.isomorphic.servlet.IDACall.doPost(IDACall.java:54)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    	at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    	at com.isomorphic.servlet.CompressionFilter.doFilter(CompressionFilter.java:248)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
    	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    	at java.lang.Thread.run(Unknown Source)
    === 2010-06-21 22:57:14,281 [or25] INFO  Compression - /transporte/isomorphic/IDACall: 2234 -> 645 bytes

    I am not able to fix my problem.

    I put the RPCManager as parameter of downloadFile method on the class DownloadDMI. I call rpcManager.doCustomResponse() in that method.


    Please help me, to resolve this problem

    #2
    Create an explicit operationBinding with operationType "downloadFile" rather than having a single <serverObject> for the entire .ds.xml. Only the core DS operations (fetch, add, update, remove) are allowed with a single <serverObject> for the whole DS, otherwise, there would be a security flaw since requests could be submitted with arbitrary operationTypes as a means of discovering other methods on your <serverObject>.

    Comment


      #3
      I did your recomendation, but it does not display the dialog box. I am sure that I am reading the file.

      I do not know if the problem is in DMI class or JSP.

      I think it could be in the DMI class whenever I'm not sure if required to StartRow, EndRow, TotalRow. Besides not know if the location of rpcManager.doCustomResponse () is indicated.

      Similarly know if the JSP is to declare a panel which displays the dialog box.

      The code of DMI Class is:

      Code:
      
      public class DownloadDMI {
      
      	public DSResponse downloadFile(DSRequest dsRequest, RPCManager rpcManager) throws Exception {
      
      		System.out.println("Entro al downloadFile de DownloadDMI");
      		
      		DSResponse dsResponse = new DSResponse();
      
      		DownloadFile downloadItem= new DownloadFile();
      
      		File file = new File("mitexto.txt");
      
      		InputStream is = new FileInputStream(file);
      		
      		try {
      		    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
      		    String line = null;
      		    while ((line = reader.readLine()) != null) {
      		        System.out.println(line);
      		    }
      		} catch (IOException x) {
      		    System.err.println(x);
      		} 
      		
      		downloadItem.setFile(is);
      /*		
          	long startRow = dsRequest.getStartRow();
          	long endRow = dsRequest.getEndRow();
          	
          	long totalRows = 1;
          	     
          	// clamp endRow to available rows and slice out requested range
              endRow = Math.min(endRow, totalRows);
      		
      		dsResponse.setStartRow(0);
      		dsResponse.setEndRow(endRow);
      		dsResponse.setTotalRows(totalRows);
      */
      		rpcManager.doCustomResponse(); 
      
      		dsResponse.setData(downloadItem);
      		
      		return dsResponse;
      		
      	}	
      	
      }
      The code of JSP is:

      Code:
      			<isomorphic:loadDS ID="downloadDS"/>
      		
      			function openHelpContent(){
      			
      				var data = {};
      				data.param1 = "123";
      				data.param2 = "param2";
      				
      				isc.DataSource.get("downloadDS").downloadFile({data:data}); 
      
      			}		
      				
      			Button.create({
      			    title: "Download File",
      			    position: "relative",
      			    width: 150,
      			    click: function () {
      					openHelpContent();							        
      			    }
      			});
      I donīt have any error on the apache tomcat console and any error

      The main screen show a white screen and the firebug show one error targetWindow.isc is undefined.



      Please help me

      Comment


        #4
        I have got the same problem. Has anybody got this working?

        My Datasource:
        Code:
        <DataSource ID="DocumentCreator" serverType="generic">
        
        	<fields>
        		<field name="file" type="binary" />
        	</fields>
        	
        	<serverObject lookupStyle="spring" bean="documentCreatorDao" />
        	
        	<operationBindings>
                <binding operationType="downloadFile" serverMethod="downloadFile">
                <serverObject  lookupStyle="spring" bean="documentCreatorDao"/>
                </binding>
            </operationBindings>
        
        </DataSource>
        Client-Code:
        Code:
        		previewButton.addClickHandler(new ClickHandler()
        		{
        			@Override
        			public void onClick(final ClickEvent event)
        			{
        				final Record payload = new Record();
        				payload.setAttribute("param1", "test");
        				payload.setAttribute("param2", 17);
        				documentCreatorDataSource.downloadFile(payload, "file", new DSRequest());
        			}
        		});
        Server-Code:
        Code:
        public class DocumentCreatorDao
        {
        	public DSResponse downloadFile(final DSRequest dsRequest, final RPCManager rpcManager) throws Exception
        	{
        		final DSResponse dsResponse = new DSResponse();
        
        		final DownloadItem file = new DownloadItem();
        		final InputStream stream = new FileInputStream("D:/test.doc");
        		file.setFile(stream);
        
        		dsResponse.setData(file);
        
        		rpcManager.doCustomResponse();
        		return dsResponse;
        	}
        
        	public class DownloadItem
        	{
        		private InputStream file;
        
        		public InputStream getFile()
        		{
        			return file;
        		}
        
        		public void setFile(final InputStream file)
        		{
        			this.file = file;
        		}
        	}
        }
        Debugging shows me, that the server method is called, the input-stream is open. All I get is a white page, showing this URL:

        Code:
        http://localhost:8080/MyApp/MyApp/sc/IDACall?isc_rpc=1&isc_v=SC_SNAPSHOT-2011-02-08&isc_tnum=5
        Using SmartGWT Pro 2.5...

        No exceptions, no errors, just nothing. Has anybody got an idea?


        Your's

        Jens

        Comment


          #5
          You both need to post the complete server log for the request (we always ask for this and it's in the text you have to delete in order to post).

          jestegemann - are you getting a targetWindow.isc is undefined error as the other poster reported? Also, have you tested that you can write Java code that accesses that InputStream successfully?

          RHill - your code reads the entire input stream before providing it to the RPCManager, so your result is expected.

          Comment


            #6
            Sorry, here is the server-log:

            Code:
            === 2011-02-17 10:29:30,131 [--23] DEBUG RequestContext - Paths for request:
            Servlet path: '/MyApp/sc/IDACall'
            Request URI: '/MyApp/MyApp/sc/IDACall'
            Path Info: 'null'
            Path Translated: 'null'
            Real FileSystem Path: 'D:\java\tc-server-developer-2.0.3.RELEASE\spring-insight-instance\wtpwebapps\MyApp\MyApp\MyApp\sc\IDACall'
            === 2011-02-17 10:29:30,131 [--23] INFO  RequestContext - URL: '/MyApp/MyApp/sc/IDACall', User-Agent: 'Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13': Moz (Gecko) with Accept-Encoding header
            === 2011-02-17 10:29:30,131 [--23] DEBUG RequestContext - Paths for request:
            Servlet path: '/MyApp/sc/IDACall'
            Request URI: '/MyApp/MyApp/sc/IDACall'
            Path Info: 'null'
            Path Translated: 'null'
            Real FileSystem Path: 'D:\java\tc-server-developer-2.0.3.RELEASE\spring-insight-instance\wtpwebapps\MyApp\MyApp\MyApp\sc\IDACall'
            === 2011-02-17 10:29:30,131 [--23] DEBUG XML - Parsed XML from (in memory stream): 0ms
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - In DS.forName() for 'transaction' with DSRequest: null
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataStructCache - getInstanceFile (failure): 'transaction' instance of datasources: 0ms
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - In DS.forName() for 'Object' with DSRequest: null
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - Creating instance of DataSource 'Object'
            === 2011-02-17 10:29:30,131 [--23] DEBUG BasicDataSource - Validating a 'Object' at path ''
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - In DS.forName() for 'Object' with DSRequest: null
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - Creating instance of DataSource 'Object'
            === 2011-02-17 10:29:30,131 [--23] DEBUG Validation - Value provided for unknown field: Object.xsi: value is: http://www.w3.org/2000/10/XMLSchema-instance
            === 2011-02-17 10:29:30,131 [--23] DEBUG Validation - Validating field:
            /transaction/transactionNum as Object.transactionNum type: long
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - In DS.forName() for 'List' with DSRequest: null
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataStructCache - getInstanceFile (success): 'List' instance of datasources: 0ms
            === 2011-02-17 10:29:30,131 [--23] DEBUG BasicDataSource - Using class com.isomorphic.datasource.ListType as implementer for DataSource List
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - Creating instance of DataSource 'List'
            === 2011-02-17 10:29:30,131 [--23] DEBUG Validation - Validating field:
            /transaction/operations as Object.operations type: List
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - In DS.forName() for 'elem' with DSRequest: null
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataStructCache - getInstanceFile (failure): 'elem' instance of datasources: 0ms
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - In DS.forName() for 'Object' with DSRequest: null
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - Creating instance of DataSource 'Object'
            === 2011-02-17 10:29:30,131 [--23] DEBUG BasicDataSource - Validating a 'Object' at path '/transaction/operations'
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - In DS.forName() for 'Object' with DSRequest: null
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - Creating instance of DataSource 'Object'
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - In DS.forName() for 'Object' with DSRequest: null
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - Creating instance of DataSource 'Object'
            === 2011-02-17 10:29:30,131 [--23] DEBUG Validation - Validating field:
            /transaction/operations/elem/criteria as Object.criteria type: Object
            === 2011-02-17 10:29:30,131 [--23] DEBUG BasicDataSource - Validating a 'Object' at path '/transaction/operations/elem/criteria'
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - In DS.forName() for 'Object' with DSRequest: null
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - Creating instance of DataSource 'Object'
            === 2011-02-17 10:29:30,131 [--23] DEBUG Validation - Value provided for unknown field: Object.download_fieldname: value is: file
            === 2011-02-17 10:29:30,131 [--23] DEBUG BasicDataSource - Done validating a 'Object' at path '/transaction/operations/elem/criteria': 0ms
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - In DS.forName() for 'Object' with DSRequest: null
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - Creating instance of DataSource 'Object'
            === 2011-02-17 10:29:30,131 [--23] DEBUG Validation - Validating field:
            /transaction/operations/elem/operationConfig as Object.operationConfig type: Object
            === 2011-02-17 10:29:30,131 [--23] DEBUG BasicDataSource - Validating a 'Object' at path '/transaction/operations/elem/operationConfig'
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - In DS.forName() for 'Object' with DSRequest: null
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - Creating instance of DataSource 'Object'
            === 2011-02-17 10:29:30,131 [--23] DEBUG Validation - Value provided for unknown field: Object.dataSource: value is: DocumentCreator
            === 2011-02-17 10:29:30,131 [--23] DEBUG Validation - Value provided for unknown field: Object.operationType: value is: downloadFile
            === 2011-02-17 10:29:30,131 [--23] DEBUG BasicDataSource - Done validating a 'Object' at path '/transaction/operations/elem/operationConfig': 0ms
            === 2011-02-17 10:29:30,131 [--23] DEBUG Validation - Value provided for unknown field: Object.appID: value is: builtinApplication
            === 2011-02-17 10:29:30,131 [--23] DEBUG Validation - Value provided for unknown field: Object.operation: value is: DocumentCreator_downloadFile
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - In DS.forName() for 'Object' with DSRequest: null
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - Creating instance of DataSource 'Object'
            === 2011-02-17 10:29:30,131 [--23] DEBUG Validation - Validating field:
            /transaction/operations/elem/oldValues as Object.oldValues type: Object
            === 2011-02-17 10:29:30,131 [--23] DEBUG BasicDataSource - Validating a 'Object' at path '/transaction/operations/elem/oldValues'
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - In DS.forName() for 'Object' with DSRequest: null
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - Creating instance of DataSource 'Object'
            === 2011-02-17 10:29:30,131 [--23] DEBUG Validation - Value provided for unknown field: Object.download_fieldname: value is: file
            === 2011-02-17 10:29:30,131 [--23] DEBUG BasicDataSource - Done validating a 'Object' at path '/transaction/operations/elem/oldValues': 0ms
            === 2011-02-17 10:29:30,131 [--23] DEBUG BasicDataSource - Done validating a 'Object' at path '/transaction/operations': 0ms
            === 2011-02-17 10:29:30,131 [--23] DEBUG BasicDataSource - Done validating a 'List' at path '/transaction/operations': 0ms
            === 2011-02-17 10:29:30,131 [--23] DEBUG Validation - Value provided for unknown field: Object.jscallback: value is: parent.isc.Comm.hiddenFrameReply(5,results)
            === 2011-02-17 10:29:30,131 [--23] DEBUG BasicDataSource - Done validating a 'Object' at path '': 0ms
            === 2011-02-17 10:29:30,131 [--23] DEBUG Timing - DataSource record created from XML with document element: 'transaction': 0ms
            === 2011-02-17 10:29:30,131 [--23] DEBUG RPCManager - Processing 1 requests.
            === 2011-02-17 10:29:30,131 [--23] DEBUG DataSource - In DS.forName() for 'DocumentCreator' with DSRequest: com.isomorphic.datasource.DSRequest@5cae8c0f
            === 2011-02-17 10:29:30,141 [--23] DEBUG DataStructCache - getInstanceFile (success): 'DocumentCreator' instance of datasources: 10ms
            === 2011-02-17 10:29:30,141 [--23] DEBUG DataSource - Creating instance of DataSource 'DocumentCreator'
            === 2011-02-17 10:29:30,141 [--23] DEBUG Timing - Time to convert org.apache.commons.collections.map.LinkedMap to JS Object: 0ms
            === 2011-02-17 10:29:30,141 [--23] DEBUG RPCManager - Request #1 (DSRequest) payload: {
                criteria:{
                    download_fieldname:"file"
                },
                operationConfig:{
                    dataSource:"DocumentCreator",
                    operationType:"downloadFile"
                },
                appID:"builtinApplication",
                operation:"DocumentCreator_downloadFile",
                oldValues:{
                    download_fieldname:"file"
                }
            }
            === 2011-02-17 10:29:30,141 [--23] INFO  IDACall - Performing 1 operation(s)
            === 2011-02-17 10:29:30,141 [--23] INFO  ServerObject - DMI on Spring bean: documentCreatorDao
            === 2011-02-17 10:29:30,141 [--23] DEBUG InterfaceProvider - Instantiating com.isomorphic.spring.SpringBeanFactory to satisfy request for an ISpringBeanFactory
            === 2011-02-17 10:29:30,141 [--23] DEBUG Reflection - adaptArgsAndInvoke:
            
             public com.isomorphic.datasource.DSResponse de.test.DocumentCreatorDao.downloadFile(com.isomorphic.datasource.DSRequest,com.isomorphic.rpc.RPCManager) throws java.lang.Exception
            
            requiredArgs: [] optionalArgs: [com.isomorphic.servlet.RequestContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.servlet.ServletContext, javax.servlet.http.HttpSession, com.isomorphic.rpc.RPCManager, com.isomorphic.datasource.DSRequest, com.isomorphic.datasource.DataSource, java.sql.Connection, com.isomorphic.log.Logger, java.util.Map]
            === 2011-02-17 10:29:30,172 [--23] DEBUG Reflection - checking whether type: com.isomorphic.servlet.RequestContext fulfills type: com.isomorphic.datasource.DSRequest
            === 2011-02-17 10:29:30,172 [--23] DEBUG Reflection - checking whether type: javax.servlet.http.HttpServletRequest fulfills type: com.isomorphic.datasource.DSRequest
            === 2011-02-17 10:29:30,172 [--23] DEBUG Reflection - checking whether type: javax.servlet.http.HttpServletResponse fulfills type: com.isomorphic.datasource.DSRequest
            === 2011-02-17 10:29:30,172 [--23] DEBUG Reflection - checking whether type: javax.servlet.ServletContext fulfills type: com.isomorphic.datasource.DSRequest
            === 2011-02-17 10:29:30,173 [--23] DEBUG Reflection - checking whether type: javax.servlet.http.HttpSession fulfills type: com.isomorphic.datasource.DSRequest
            === 2011-02-17 10:29:30,173 [--23] DEBUG Reflection - checking whether type: com.isomorphic.rpc.RPCManager fulfills type: com.isomorphic.datasource.DSRequest
            === 2011-02-17 10:29:30,173 [--23] DEBUG Reflection - checking whether type: com.isomorphic.datasource.DSRequest fulfills type: com.isomorphic.datasource.DSRequest
            === 2011-02-17 10:29:30,173 [--23] DEBUG Reflection - Successfully adapted optional arg type: com.isomorphic.datasource.DSRequest to type: com.isomorphic.datasource.DSRequest
            === 2011-02-17 10:29:30,173 [--23] DEBUG Reflection - checking whether type: com.isomorphic.servlet.RequestContext fulfills type: com.isomorphic.rpc.RPCManager
            === 2011-02-17 10:29:30,173 [--23] DEBUG Reflection - checking whether type: javax.servlet.http.HttpServletRequest fulfills type: com.isomorphic.rpc.RPCManager
            === 2011-02-17 10:29:30,173 [--23] DEBUG Reflection - checking whether type: javax.servlet.http.HttpServletResponse fulfills type: com.isomorphic.rpc.RPCManager
            === 2011-02-17 10:29:30,173 [--23] DEBUG Reflection - checking whether type: javax.servlet.ServletContext fulfills type: com.isomorphic.rpc.RPCManager
            === 2011-02-17 10:29:30,173 [--23] DEBUG Reflection - checking whether type: javax.servlet.http.HttpSession fulfills type: com.isomorphic.rpc.RPCManager
            === 2011-02-17 10:29:30,173 [--23] DEBUG Reflection - checking whether type: com.isomorphic.rpc.RPCManager fulfills type: com.isomorphic.rpc.RPCManager
            === 2011-02-17 10:29:30,173 [--23] DEBUG Reflection - Successfully adapted optional arg type: com.isomorphic.rpc.RPCManager to type: com.isomorphic.rpc.RPCManager
            === 2011-02-17 10:29:30,173 [--23] DEBUG Reflection - method takes: 2 args.  I've assembled: 2 args
            === 2011-02-17 10:29:30,173 [--23] DEBUG Reflection - invoking method:
            com.isomorphic.datasource.DSResponse de.test.DocumentCreatorDao.downloadFile(com.isomorphic.datasource.DSRequest, com.isomorphic.rpc.RPCManager) throws java.lang.Exception
            
            with arg types: com.isomorphic.datasource.DSRequest, com.isomorphic.rpc.RPCManager
            === 2011-02-17 10:29:40,615 [--23] INFO  DSResponse - DSResponse: Map with 1 keys
            === 2011-02-17 10:29:40,615 [--23] DEBUG Timing - Request: /installateurs-db/InstallateursDb/sc/IDACall (start->finish): 10484ms
            I do not have any client-log. Right after the request the browser (Firefox 3.6, Chrome and IE8) show an empty page (source is empty, too) and - as I wrote in my last post - no errors-messages.

            The developer-console is displaying just:

            Code:
            The browser window that opened this log window has navigated to a new page or been closed - reopen the log window by calling 'isc.showLog()' from an Isomorphic SmartClient page.
            In my Dao I can read from the stream without any problems.

            Hope this makes things a little bit clearer...


            Your's

            Jens

            Comment


              #7
              Ok, I got it to do what I want using this code on the server (nothing changed on the client):

              Code:
              public DSResponse downloadFile(final DSRequest dsRequest, final Map data, final RPCManager rpcManager, final HttpServletResponse servletResponse)
              			throws Exception
              	{
              
              		InputStream stream = null;
              		try
              		{
              			stream = new FileInputStream("D:/test.pdf");
              
              			servletResponse.setContentType("application/PDF;charset=UTF-8");
              
              			final String PDFFilename = "testdatei";
              			servletResponse.setHeader("Content-Disposition", "attachment; filename=\"" + PDFFilename + ".pdf\"");
              			servletResponse.addHeader("Pragma", "public");
              			servletResponse.addHeader("Cache-Control", "max-age=0");
              
              			final ServletOutputStream out = servletResponse.getOutputStream();
              
              			final byte[] buffer = new byte[32 * 1024];
              			int bytesRead = 0;
              			while ((bytesRead = stream.read(buffer)) >= 0)
              			{
              				out.write(buffer, 0, bytesRead);
              			}
              			out.flush();
              
              			rpcManager.doCustomResponse();
              		}
              		catch (final Throwable t)
              		{
              			throw new Exception("error downloading: " + t.getMessage(), t);
              		}
              		finally
              		{
              			if (stream != null)
              			{
              				stream.close();
              			}
              		}
              
              		return new DSResponse();
              	}
              But is this the way that is intended? I got the impression that there is a way to deal with downloading files without writing to the ServletResponse myself.

              Is this documented in any place or by any sample (I could not find it)?

              Comment


                #8
                Ah, the problem is actually, a file download as part of a "downloadFile" operation is *not* considered a "custom response". A "custom response" means direct writing to the output stream of the HttpServletResponse, like you've shown now. Providing a file as a record attribute is not a custom response, so remove the call to doCustomResponse() in the prior version of your code.

                Comment


                  #9
                  Hi, I have gotten the download to work by folloing jstegemann's post. However, I am unable to "pass" data into the dsRequest (on client side) such that I can retrieve it on the server side. First, I tried just using various methods on the server side's dsRequest object to retrieve the values that jstegemann's code set (see payload object below)

                  Code:
                  final Record payload = new Record();
                  				payload.setAttribute("param1", "test");
                  				payload.setAttribute("param2", 17);
                  				documentCreatorDataSource.downloadFile(payload, "file", new DSRequest());
                  But, on the server side, I couldn't figure out which method would get acecss to this "paylod" object. Is there a way?

                  Second, I tried the dsRequest.setAttribute method, and then read the documentation which stated that data in the dsRequest.setAttribute would NOT make it to the server side.

                  Third, I considered using the client side dsRequest.setParams, but rejected it ultimately since the String that I need to send could be very very long (eg 10,000 bytes etc.) and from what I understand, the dsRequest.setParams method places the values in a regular HTTP url, and many browsers have limits on the lenght of that URL.

                  So, what's the "right" way of doing this? (I searched the SmartGWT forums for any "right" approaches for downloading files and then possibly sending data, but this post itself seemed the "best" one.)

                  Miscellaneous Infrastucture Details:
                  ==================================
                  OS: Windows XP Pro
                  IDE: MyEclipse 10.0 with Google Plugin for Eclipse (2.5)
                  SmartGWT Pro 3.0 (Purchased Licence)
                  Browser: Mozilla Firefox 4.0.1
                  GWT SDK: 2.4.0
                  Sun JDK 1.6.0_27

                  Comment


                    #10
                    Hey guys!
                    On server create a Servlet with this code and map it on web.xml:

                    Code:
                    @Override
                    protected void doPost(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws ServletException, IOException 
                    {		
                    	try 
                    	{
                    		RPCManager rpc = new RPCManager(httpRequest, httpResponse);
                    		Map<String, Object> params = (Map<String, Object>) rpc.getData();
                    			
                    		String fileName = (String) params.get("fileName");
                    		String fileType = getFileTypeFromName(fileName);
                    						
                    		/*  The download is only allowed if the file is a PDF and if the request is a 
                    		 *  valid RPC request. If the user try to download the file using a regular POST
                    		 */ request, it wil fail.
                    
                    		if (fileType.equals("PDF") && RPCManager.isRPC(httpRequest))
                    		{
                    			byte[] pdf = loadFile(fileName);				
                    			String fileId = (String) params.get("fileId");
                    				
                    			httpResponse.addCookie(new Cookie(fileId, "true"));
                    			httpResponse.setBufferSize(1024*1024); // 1MB
                    			httpResponse.setHeader("Content-disposition", String.format("attachment;filename=%s", fileName));
                    			httpResponse.setContentType("application/pdf");
                    			httpResponse.setContentLength(pdf.length);
                    			httpResponse.getOutputStream().write(pdf);				
                    		}			
                    			
                    		else 
                    		{
                    			throwASmartClientHandledException(new Exception("Forbidden"));
                    		}
                    	}
                    	catch (Exception ex)
                    	{
                    		ex.printStackTrace();
                    		throwASmartClientHandledException(ex);
                    	}	
                    }
                    
                    private void throwASmartClientHandledException(Exception exception, HttpServletRequest request, HttpServletResponse response) throws ServletException
                    {
                    	if (RPCManager.isRPC(request))
                    	{
                    		try
                    		{				
                    			RPCManager rpc = new RPCManager(request, response);
                    			RPCResponse rpcResponse = new RPCResponse();
                    			Map responseData = new HashMap();
                    			
                    			responseData.put("type", exception.getClass().getName());
                    			responseData.put("message", exception.getMessage());
                    			
                    			rpcResponse.setStatus(RPCResponse.STATUS_FAILURE);
                    			rpcResponse.setData(responseData);
                    			rpc.send(rpcResponse);
                    			
                    		}
                    		catch (Exception e) 
                    		{
                    			throw new ServletException(excecao);
                    		}
                    	} 
                    	else throw new ServletException(excecao);
                    }
                    On client, place this code:

                    Code:
                    function FileDownloader()
                    { 
                    	
                    }
                    
                    FileDownloader.prototype.downloadFile = function(fileName, pCallback, showPrompt)
                    {	
                    	var instance = this;
                    
                    	var params = new Object();
                    		params.fileId = fileName + new Date().getTime() + "_" + Math.floor(Math.random()*999999);
                    		
                    	if (showPrompt == null) showPrompt = true;
                    
                    	var checkDownloadCompletion = function()
                    	{
                    		if (Application.readCookie(params.fileId) != null)
                    		{	
                    			Application.deleteCookie(params.fileId);
                    			isc.clearPrompt();
                    		}
                    			
                    		else Timer.setTimeout(checkDownloadCompletion, 1000);
                    	};
                    		
                    	Timer.setTimeout(checkDownloadCompletion, 1000);
                    		
                    	if (showPrompt) isc.showPrompt("${loadingImage} Downloading file " + fileName + ", please wait...");
                    	
                    	RPCManager.sendRequest
                    	({
                    		httpMethod : "POST", actionURL : "./urlToMyServlet", data : params, willHandleError : true, downloadResult: true, /* downloadResult -> this property does the trick */		
                    		callback : function(response)
                    		{
                    			isc.clearPrompt();
                    			
                    			if (response.status == RPCResponse.STATUS_SUCCESS)
                    			{
                    				if (response.data != "Forbidden")
                    				{
                    					pCallback(response.data);
                    				}
                    				else
                    				{
                    					isc.say("You have no rights to access this file!");
                    				}		
                    			}
                    			else
                    			{
                    				instance.handleExceptions(response);
                    			}
                    		}
                    	});
                    };
                    
                    
                    FileDownloader.prototype.handleExceptions = function(response)
                    {
                    	// code for handling exceptions
                    }
                    
                    function Application()
                    {
                    
                    }
                    
                    Application.updateCookies = function()
                    {
                    	if (Application.cookies == null)
                    		Application.cookies = new Object();
                    	
                    	var cookiesList = document.cookie.split('; ');
                    		
                    	for (var i=0; i < cookiesList.length;i++) 
                    	{
                    		var cookie = cookiesList[i].split('=');
                    		var name = cookie[0];
                    		var value = cookie[1];
                    		
                    		Application.cookies[name] = value;
                    	}
                    };
                    
                    Application.writeCookie = function(name, value, expires)
                    {
                    	if (expires > 0) 
                    	{
                    		var date = new Date();
                    			date.setTime(date.getTime() + expires);
                    			
                    			document.cookie = name + "=" + value + "; expires=" + date.toGMTString() + "; path=/";
                    			Application.cookies[name] = value;		
                    	}
                    };
                    
                    Application.readCookie = function(name)
                    {
                    	Application.updateCookies();
                    	return Application.cookies[name];
                    };
                    
                    Application.deleteCookie = function(name)
                    {
                    	Application.writeCookie(name, "foo", 1);
                    	Application.updateCookies();
                    	Application.cookies[name] = undefined;
                    };
                    Finally, use this code to download a file:

                    Code:
                    	var fileDownloader = new FIleDownloader();
                    
                    	     fileDownloader.downloadFIle("test.pdf", function()
                    	     {
                    	     		isc.say("This dialog will show after download completion!");
                    	     });
                    
                    	     fileDownloader.downloadFIle("test.pdf", function()
                    	     {
                    	     		isc.say("This code do the same thing but doesn't display the downloading file message");
                    
                    	     }, false);
                    Last edited by noschang@univali.br; 28 Feb 2012, 09:02.

                    Comment


                      #11
                      Very much appreciated noschang! Thanks for sharing your working code!

                      However: does this mean that we must get lower-level and start using RPCManager.sendrequest and code the "http header infos" etc. Or is there not a simpler way of just using the pre-buit "downloadFile" method and just somehow get data into the "record" attribute? It seems like this the "downloadFile" method that's prebuilt in SmartGWT is expecting data in the record method, e.,g the "payload" field below -->

                      documentCreatorDataSource.downloadFile(payload, "file", new DSRequest());

                      but how does one "retrieve it/get data out" of the payload record object on the server side?

                      We'd like to stick to "standard" smartGWT code as much as possible before writing more low-level code (eg http posts etc.)

                      Comment


                        #12
                        OK!
                        Try this in your server code.
                        If this code don't work, try debugging and inspecting the variables 'values' and 'payload' to see what values are coming from client side:

                        Code:
                        public DSResponse downloadFile(DSRequest request, HttpSession session)
                        {
                              DSResponse response = new DSResponse();
                              response.setSuccess();
                        
                              try
                              {
                                    Map values = request.getValues();
                                    Map payload = values.get("file"); 
                        
                                    /* 
                                     *  "file" is the datasource field name passed as 
                                     *  the second parameter to the downloadFile method
                                     *  on the client side
                                     */
                        
                                    String param1 = (String) payload.get("param1");
                                    Long param2 = (Long) payload.get("param2");
                        
                                    byte[] fileData = loadFile(param1, param2);
                                    response.setData(fileData);
                              }
                              catch (Exception e)
                              {
                                    response.setFailure();
                                    response.setData(e.getMessage());
                              }
                        
                              return response;
                        }

                        Comment


                          #13
                          So I tried the suggestion from noschang. But, the 1st command of:

                          Map values = request.getValues();

                          simply returns a NULL element. Here's the code on the server side:

                          Code:
                          public DSResponse downloadFile(final DSRequest dsRequest, final Map data, final RPCManager rpcManager, final HttpServletResponse servletResponse)
                          	throws Exception
                          	{
                          ...stuff deleted
                          		try
                          		{
                          			//String allFiles = (String) data.get("allFiles");
                          			Map values = dsRequest.getValues();
                                      Map payload = (Map) values.get("file"); 
                          			
                          			String param1 = (String) payload.get("param1");
                                      Long param2 = (Long) payload.get("param2");
                          
                          			
                          			String dffieldName= dsRequest.getDownloadFieldName();
                          			String dffileName=  dsRequest.getDownloadFileName();
                          ....
                          and on the client side, it's fairly straightforward too:

                          Code:
                          	payload.setAttribute("ia_file", allFiles);
                          				payload.setAttribute("param1", "test");
                          				payload.setAttribute("param2", 17);
                          				DSRequest dsRequest = new DSRequest();
                          	//			dsRequest.setData(allFiles);
                          				DataSource documentCreatorDataSource = DataSource.get("DocumentCreator");
                          				documentCreatorDataSource.downloadFile(payload, "ia_file", dsRequest);
                          				//IAConstants.allowLeavingPage=false;

                          Comment

                          Working...
                          X