jijo-paulose / gwtupload

Automatically exported from code.google.com/p/gwtupload
Other
0 stars 0 forks source link

server response xml message with custom file information which can be parsed in client side [in CDATA section] #92

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. coding  as in wiki::GettingStarted
2. in ServerSide.SampleUploadServlet.executeAction  compose the response 
message with file.getName (not just item.getName) so we can return the 
temporary filename.

What is the expected output? What do you see instead?

  I expect the server return the temporary filename and other item detail (size, content-type,...).
  Instead I'll get always null string, so I debug the IUploader.Utils.getXmlNodeValue and I see it use "doc.getElementsByTagName(tag)" (native in com.google.gwt.xml.client.Document).
  Well, it seems not parse in the CDATA section. In fact the additional xml information returned by server is inserted into CDATA section by the uploadAction.doPost.
  So I'll override the doPost to insert the additional field directly in the response section and this solution allow the "getXmlNodeValue" to work fine.  

What version of the product are you using? On what operating system?
gwtupload 0.6.3 - gwt 2.0.3 - Sun Glassfish 2.1.1

Please provide any additional information below.

Original issue reported on code.google.com by antonucc...@gmail.com on 15 Feb 2011 at 11:39

GoogleCodeExporter commented 9 years ago
It seems related with issue#89.
Could you test the latest snapshot?, you should not get null responses with it.

Original comment by manuel.carrasco.m on 20 Feb 2011 at 9:47

GoogleCodeExporter commented 9 years ago
I also have similar problem.

I have tested it with 0.6.4-SNAPSHOT.

The following line on the client side also returns null for me:

Utils.getXmlNodeValue(doc, "file-1-name");

I use GWT 2.1.1 and I'm running it on Tomcat 7.

Original comment by jacekza...@gmail.com on 25 Feb 2011 at 12:26

GoogleCodeExporter commented 9 years ago
Could you attach your sevlet.java and your client.java files.

Original comment by manuel.carrasco.m on 25 Feb 2011 at 1:19

GoogleCodeExporter commented 9 years ago
Same problem here. I'm using the gwtupload example. I had to change:
  String size = Utils.getXmlNodeValue(doc, "file-1-size");
  String type = Utils.getXmlNodeValue(doc, "file-1-type");
  String name = Utils.getXmlNodeValue(doc, "file-1-name");

To:
  String size = Utils.getXmlNodeValue(doc, "size");
  String type = Utils.getXmlNodeValue(doc, "type");
  String name = Utils.getXmlNodeValue(doc, "name");

This is the composed response within SampleUploadServer.java:

<response>
<file-1-field>GWTMU-022224286233171886</file-1-field>
<file-1-name>GpsiesTrack.tcx</file-1-name>
<file-1-size>43760</file-1-size>
<file-1-type>application/octet-stream</file-1type>
</response>

And this is how it gets to the client:

<?xml version="1.0" encoding="UTF-8"?>
<response><message>
<![CDATA[
<response>
<file-1-field>GWTMU-022224286233171886</file-1-field>
<file-1-name>GpsiesTrack.tcx</file-1-name>
<file-1-size>43760</file-1-size>
<file-1-type>application/octet-stream</file-1type>
</response>

]]>
</message>
<field>GWTMU-022224286233171886</field>
<name>GpsiesTrack.tcx</name>
<ctype>application/octet-stream</ctype>
<finished>ok</finished>
<size>43760</size>
</response>

The useful stuff, the one created in the servlet, like:
  response += "<file-" + cont + "-name>" + item.getName() + "</file-" + cont + "-name>\n";

seem to end up in the CDATA section only; the rest being completed by 
UploadAction I assume. I'm running Tomcat6 on Ubuntu server (and eclipse and 
firefox).

Original comment by armandof...@gmail.com on 27 Feb 2011 at 10:50

GoogleCodeExporter commented 9 years ago

Original comment by manuel.carrasco.m on 3 Mar 2011 at 3:46

GoogleCodeExporter commented 9 years ago
This is the correct behaviour now.

Server side now sends a xml which a bunch of useful fields that automatically 
are available in client side, so as your servlet is simpler.

UploadedInfo info = uploader.getServerInfo();
System.out.println("File name " + info.name);
System.out.println("File content-type " + info.ctype);
System.out.println("File size " + info.size);

Nevertheless, you can send any info from the server, even a xml message, so as 
it  can be extracted and parsed, but you have to use 
uploader.getServerInfo().message instead of uploader.getServerResponse():

Document doc = XMLParser.parse(uploader.getServerInfo().message);
String size = Utils.getXmlNodeValue(doc, "file-1-size");
String type = Utils.getXmlNodeValue(doc, "file-1-type");
System.out.println(size + " " + type);

I'll change the wiki explaining those changes.

Thanks
- Manolo

Original comment by manuel.carrasco.m on 18 Apr 2011 at 7:08

GoogleCodeExporter commented 9 years ago
Same problem here. I'm using GWT 2.2.0 + gwtupload-0.6.3-compat with 
IE8/FF4.0/Chrome10.0.
It failed on some files but not all. See attached log and my following code 
sample.
onUpload() and popupAler() are my custom methods. I found 
IUploader.Utils.getXmlNodeValue(messageDom,"message")) always throw unexpected 
exception in javascript whenever info.message == null. 
/* Code from client side*/
UploadedInfo info = uploader.getServerInfo();    
if (uploader.getStatus() == Status.SUCCESS) {          
if(info.message != null){
    onUpload(info.message, uploader.getBasename());
    popupAlert("getServerResponse="+uploader.getServerResponse()+",uploader.getServerInfo().message="+uploader.getServerInfo().message);
}
else {
    popupAlert("getServerResponse="+uploader.getServerResponse()+",uploader.getServerInfo().message="+uploader.getServerInfo().message);
    Document messageDom = XMLParser.parse(uploader.getServerResponse()); 
    popupAlert("getServerResponse="+uploader.getServerResponse()+",uploader.getServerResponse().message="+IUploader.Utils.getXmlNodeValue(messageDom,"message"));
}
/* Code from server side: executeAction() */
File file = File.createTempFile("ul-", ".tmp", tmpDir);
item.write(file); 
receivedFiles.put(item.getFieldName(), file);           
receivedContentTypes.put(item.getFieldName(), item.getContentType()); 

response += file.getName();

Original comment by supportm...@gmail.com on 28 Apr 2011 at 7:03

Attachments:

GoogleCodeExporter commented 9 years ago
I've fixed my problem by forcing tomcat's encoding to utf-8. However, it 
doesn't make sense to me that a null value should be returned in 
Uploader.getServerInfo().message if the whole server response includes 
wrong-encoding file name. Please consider to be more tolerant to encoding issue 
because the API is used for receiving server response. If server does not 
complain, so does client. 

Original comment by supportm...@gmail.com on 28 Apr 2011 at 10:23

GoogleCodeExporter commented 9 years ago
So it is an encoding problem.
- How did you fix the problem in tomcat? 
- Can you send the name of the file in utf-8 because in the attached log is 
unreadable so as I could make a test.

I do not know well how to fix it in server to force utf-8, apart of set the 
charset header.

Original comment by manuel.carrasco.m on 29 Apr 2011 at 5:36

GoogleCodeExporter commented 9 years ago
Gwtupload servlet is already setting all in the response to utf8, you have to 
configure your servlet container and your front server to handle utf8, I do not 
see a way to fix that in code, do you know a way apart of what I'm using in 
code:

http://code.google.com/p/gwtupload/source/browse/trunk/GwtUpload/core/src/main/j
ava/gwtupload/server/UploadServlet.java#324

Original comment by manuel.carrasco.m on 29 Apr 2011 at 6:40

GoogleCodeExporter commented 9 years ago
I guess it's nothing to do with your server code. The issue is that tomcat 
handles the post message's body, which carries the filename, using the default 
charset (in my case iso-8859-1) before your servlet kicks in. 
I would suggest the idea solution be
1. Configure servlet container and front server to handle utf8 (which I did and 
solved the problem some what), and
2. Find a way to parse the server response no matter what encoding is used.
The reason to have the second work is that it makes your library robust 
regardless what the server environment is.
When you look at my attached log file, the first filename includes a special 
char ( ). I don't know why my filename encoded like this, but I guess the 
GWT's DOM parser could not handle it well. That is why getServerInfo().message 
returns NULL.
I also looked at HTTP message using firebug, it shows that browser is sending 
message using utf-8. I don't know if you process filename (replace characters 
for instance) when you render the response message. 
Hope my suggestion and observation help. 

Original comment by leoj...@gmail.com on 29 Apr 2011 at 4:18