10

I have a listgrid in which all items are shown properly with diacritics as they are in db both locally and on jboss server.

However, on jboss server, when I try to export as csv all the diacritics characters are replaced so I get something like Școala instead of Școala, although diacritics are shown properly in the listgrid.

Locally works fine both showing in listgrid and exporting.

Here is my code for export:

private void Export() {
  String exportAs = (String) m_ExportForm.getField("exportType").getValue();  
  FormItem item = m_ExportForm.getField("showInWindow");  
  boolean showInWindow =  item.getValue() == null ? false : (Boolean) item.getValue();  

  // exportAs is either XML or CSV, which we can do with requestProperties
  Map<String,String> params= new java.util.HashMap<String, String>();
  params.put("Accept-Charset","utf-8");

  DSRequest dsRequestProperties = new DSRequest();
  dsRequestProperties.setHttpHeaders(params);
  dsRequestProperties.setExportValueFields(true);
  dsRequestProperties.setExportAs((ExportFormat)EnumUtil.getEnum(ExportFormat.values(), exportAs));  
  dsRequestProperties.setExportDisplay(showInWindow ? ExportDisplay.WINDOW : ExportDisplay.DOWNLOAD);

  // TODO: move in user-config
  dsRequestProperties.setExportTitleSeparatorChar("_");
  dsRequestProperties.setExportDelimiter(";");

  dsRequestProperties.setExportFilename("export." + extensionsValueMap.get(exportAs));
  dsRequestProperties.setContentType("text/csv; charset=UTF-8");
  m_Target.Export(dsRequestProperties);

  Close();
}

Also, in my jboss 7 property file I have this:

<system-properties>
  <property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/>
  <property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true"/>
</system-properties>

which works as the listgrids show diacritics properly.

Also, in my web.xml I have for my servlet

<init-param>
  <param-name>encoding</param-name>
  <param-value>UTF-8</param-value>
</init-param>

Maybe I'm on a wrong track and this is caused by something else.

Both the file exported locally and the file exported from jboss server have the exact file size.

Also, for my Jboss jvm I set the property for java_opts

-Dfile.encoding=UTF-8

EDIT: added the params map due to suggestion. Still nothing.

2
  • May be this might give you some insight? community.jboss.org/message/646601
    – Phani
    Apr 20, 2012 at 9:09
  • Capture the HTTP request and response headers and post them. Also, post the file sizes in bytes of the CSV you download that work and the one that has '??'.
    – Old Pro
    Apr 25, 2012 at 6:28

3 Answers 3

3

It sounds like it's a character encoding/decoding issue.

Your code generated a CSV file in the UTF-8 encoding. However, what program are you using to read the CSV? Windows notepad? If it's a Windows application, chances are it is assuming the text file is in ISO-8859-1 encoding.

Option 1:

Tell notepad or your Windows application the encoding. With notepad, there is an encoding dropdown in the File/Open dialog. Switch this to UTF-8.

Option 2:

Change the encoding in your source code from UTF-8 to ISO-8859-1, which matches Windows' default encoding. Changing the line:

dsRequestProperties.setContentType("application/csv; charset=UTF-8");

to

dsRequestProperties.setContentType("application/csv; charset=ISO-8859-1");

will hopefully do the trick. The org.apache.catalina.connector.URI_ENCODING setting does not affect the file encoding and should be left as it is.

2
  • Problem is locally where I have jvm encoding to utf-8 if I download the file, I get the file with diacritics which is ok. If I do the same thing on my jboss server the file is saved without diacritics already. This is not a matter of reading the file.
    – Fofole
    Apr 23, 2012 at 10:37
  • @Fofole, what characterset does the JBoss server declare for the downloaded file? Content-type: text/plain; charset=UTF-8? Is it the same on your local dev machine and on the JBoss server? What does fiddler/netmon or WireShark show?
    – Ben
    Apr 27, 2012 at 15:47
1

I must admit, in this constellation I have not seen a charset=.... But the charset makes more sense for text, so try first:

dsRequestProperties.setContentType("text/csv; charset=UTF-8");

Reason, application which could well indicate binary data, would make a charset byte encoding dangerous.


Added: my explanation for the error

Maybe the String asExport got UTF-8 but gives for a multi-byte char instead two characters. Those are in the non-ASCII range too, and your response somehow wants to deliver ISO-8859-1 (the default latin-1), and writes ??. That are 2 errors.

You could inspect asExport. Why writing in UTF-8 not succeeds despite charset=UTF-8...

2
1

You probably have some additional FilterServlets in your JBoss setup that are interfering with the encoding. Possibly related to authentication or compression.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.