I have an issue while DSResponse setStatus is Failure, i don't know, how this one is behave with response to client. Client side i didn't get any repsone from server. Any one can please tel what is wrong in this.
Server Side code:-
----------------
public DSResponse execute(DSRequest dsRequest) throws Exception {
System.out.println("Kudos **** server : execute.");
String errorContent ="errorMessage";
DSResponse dsResponse = new DSResponse(this);
ISCFileItem item = null;
String fileExtension = null;
item = dsRequest.getUploadedFile("fileContent");
fileData = item.get();
strFileContent = new String(fileData);
String fileName = item.getFileName();
try{
System.out.println("File Name :- "+ fileName);
fileExtension = fileName.substring(fileName.lastIndexOf("."),fileName.length());}
catch(Exception e)
{
//dsResponse.setData(getSecurityMap(errorContent));
//dsResponse.setFailure("Incorrect File format :\""+fileExtension+"\" \nNote:- \nOnly below file formats are allow to upload :- \n-.csv\n-.txt");
dsResponse.setStatus(DSResponse.STATUS_FAILURE);
dsResponse.setData(dsRequest.getOldValues()));
}
boolean isValidFormat = isValidFileFormat(fileExtension);
System.out.println("**************File Content Info************");
System.out.println("File FileName :- "+fileName);
System.out.println("File Extension :- "+fileExtension);
System.out.println("File Size :- "+((String.format("%.2f",(float)item.getSize()/1024)))+" KB");
System.out.println("Is Valid Format:-"+isValidFormat);
System.out.println("*******************************************");
if(isValidFormat)
{
dsResponse.setData(getSecurityMap(strFileContent));
System.out.println("File content $$["+strFileContent+"]");
}
else
{
//dsResponse.setData(getSecurityMap(errorContent));
//dsResponse.setFailure("Incorrect File format :\""+fileExtension+"\" \nNote:- \nOnly below file formats allow to upload :- \n-.csv\n-.txt");
dsResponse.setStatus(DSResponse.STATUS_FAILURE);
dsResponse.setData(dsRequest.getOldValues());
}
return dsResponse;
}
private boolean isValidFileFormat(String extension)
{
if( extension.equalsIgnoreCase(".txt") || extension.equalsIgnoreCase(".csv"))
{
return true;
}
return false;
}
***********************************************
Client Side Code
----------------
DynamicForm fileUploadForm = new fileUploadForm ();
//This item is added into dynamic form.
FileItem uploadfile = new FileItem("fileContent");
//Try to execute() the server side method and get back the response.
fileUploadForm.saveData(new DSCallback() {
public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) {
System.out.println("Response received from server");
}
});
***********************************************
IDE Console
-----------
Kudos **** server : execute.
File Name :- Sample.java
**************File Content Info************
File FileName :- Sample.java
File Extension :- .java
File Size :- 45.75 KB
Is Valid Format:-false
*******************************************
=== 2014-07-30 10:20:17,592 [2-29] INFO DSResponse - [builtinApplication.fileUpload_add] DSResponse: Map with 0 keys
=== 2014-07-30 10:20:17,593 [2-29] DEBUG RPCManager - Content type for RPC transaction: text/html; charset=UTF-8
=== 2014-07-30 10:20:17,593 [2-29] DEBUG RPCManager - non-DMI response, dropExtraFields: false
=== 2014-07-30 10:20:17,775 [2-26] INFO RequestContext - URL: '/Test/sc/skins/Enterprise/images/Dialog/warn.png', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0': Moz (Gecko) with Accept-Encoding header
=== 2014-07-30 10:20:17,807 [2-26] INFO Download - done streaming: G:/Test/war/Test/sc/skins/Enterprise/images/Dialog/warn.png
******************End*****************************
Client browser while upload invalid file , if using dsResponse.setFailure("errormessage") this logic is shows custom error message i'm getting warn popup, but no response in client side. For reference see above IDE Console.
Server Side code:-
----------------
public DSResponse execute(DSRequest dsRequest) throws Exception {
System.out.println("Kudos **** server : execute.");
String errorContent ="errorMessage";
DSResponse dsResponse = new DSResponse(this);
ISCFileItem item = null;
String fileExtension = null;
item = dsRequest.getUploadedFile("fileContent");
fileData = item.get();
strFileContent = new String(fileData);
String fileName = item.getFileName();
try{
System.out.println("File Name :- "+ fileName);
fileExtension = fileName.substring(fileName.lastIndexOf("."),fileName.length());}
catch(Exception e)
{
//dsResponse.setData(getSecurityMap(errorContent));
//dsResponse.setFailure("Incorrect File format :\""+fileExtension+"\" \nNote:- \nOnly below file formats are allow to upload :- \n-.csv\n-.txt");
dsResponse.setStatus(DSResponse.STATUS_FAILURE);
dsResponse.setData(dsRequest.getOldValues()));
}
boolean isValidFormat = isValidFileFormat(fileExtension);
System.out.println("**************File Content Info************");
System.out.println("File FileName :- "+fileName);
System.out.println("File Extension :- "+fileExtension);
System.out.println("File Size :- "+((String.format("%.2f",(float)item.getSize()/1024)))+" KB");
System.out.println("Is Valid Format:-"+isValidFormat);
System.out.println("*******************************************");
if(isValidFormat)
{
dsResponse.setData(getSecurityMap(strFileContent));
System.out.println("File content $$["+strFileContent+"]");
}
else
{
//dsResponse.setData(getSecurityMap(errorContent));
//dsResponse.setFailure("Incorrect File format :\""+fileExtension+"\" \nNote:- \nOnly below file formats allow to upload :- \n-.csv\n-.txt");
dsResponse.setStatus(DSResponse.STATUS_FAILURE);
dsResponse.setData(dsRequest.getOldValues());
}
return dsResponse;
}
private boolean isValidFileFormat(String extension)
{
if( extension.equalsIgnoreCase(".txt") || extension.equalsIgnoreCase(".csv"))
{
return true;
}
return false;
}
***********************************************
Client Side Code
----------------
DynamicForm fileUploadForm = new fileUploadForm ();
//This item is added into dynamic form.
FileItem uploadfile = new FileItem("fileContent");
//Try to execute() the server side method and get back the response.
fileUploadForm.saveData(new DSCallback() {
public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) {
System.out.println("Response received from server");
}
});
***********************************************
IDE Console
-----------
Kudos **** server : execute.
File Name :- Sample.java
**************File Content Info************
File FileName :- Sample.java
File Extension :- .java
File Size :- 45.75 KB
Is Valid Format:-false
*******************************************
=== 2014-07-30 10:20:17,592 [2-29] INFO DSResponse - [builtinApplication.fileUpload_add] DSResponse: Map with 0 keys
=== 2014-07-30 10:20:17,593 [2-29] DEBUG RPCManager - Content type for RPC transaction: text/html; charset=UTF-8
=== 2014-07-30 10:20:17,593 [2-29] DEBUG RPCManager - non-DMI response, dropExtraFields: false
=== 2014-07-30 10:20:17,775 [2-26] INFO RequestContext - URL: '/Test/sc/skins/Enterprise/images/Dialog/warn.png', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0': Moz (Gecko) with Accept-Encoding header
=== 2014-07-30 10:20:17,807 [2-26] INFO Download - done streaming: G:/Test/war/Test/sc/skins/Enterprise/images/Dialog/warn.png
******************End*****************************
Client browser while upload invalid file , if using dsResponse.setFailure("errormessage") this logic is shows custom error message i'm getting warn popup, but no response in client side. For reference see above IDE Console.