Hi,
1. Env in Client:
Java Version: JDK 1.5
The Rightfax Version: 9.3
2. When sending out the fax as attachment, the chinese characters can come out correctly.
When putting the chinese characters into the html String, Chinese characters become '????' in the fax received.
3. The Chinese characters are Encoded as 'UTF-8'.
The Chinese character are retrieved from another system, and they are sent in UTF-8 format.
If i use the following method to save it as a txt and send the txt file as attachment, the chinese characters can come out.
Here is the code snippet i used to save the txt file:
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("C:/test.txt"),"UTF8");
4. Actually i want to send fax as html, because i need to generate the fax with dynamic data, and very complicated format. attchment can not satisfy my client's requirements.
5. Here is the code i am using to send fax.
public class Test {
public static void main(String[] args) {
Test test = new Test();
test.testBodyInHtml();
}
public void testBodyInHtml () {
// Create a outbound fax object
RFaxSubmit obFS = new RFaxSubmit();
// Set the URL of the RightFAX server
/***************************
* SG UAT
* **************************
*/
obFS.setTargetURL("http://192.168.1.1/");
// Set the information on who is sending the fax
obFS.m_FaxDocument.setSenderInfo("IVRTW");
// Add a recipient
try {
obFS.m_FaxDocument.addRecipient ("", "67858967", "", "Kiesel fx", "", "", "", "", "", "", "", "");
System.out.println("Added recipient");
}
catch (Exception nfne) {
System.out.println (nfne.toString());
}
// Set the body text
try{
String body = readInput("C:/test.txt"); //readInput() is used to read the txt file, and the read out string is encoded as UTF-8
//This is used to send fax as html STRING
obFS.m_FaxDocument.setBody("<![CDATA[" +"<html><body>" + body + "</body></html>"+ "]]>", "HTML") ; // The "test.txt" is the file that contains traditional chinese
//This is used to send fax as attachment
obFS.addAttachment("c:\\test.txt");
} catch(java.lang.IllegalArgumentException e){
e.printStackTrace();
}
Vector obRetList = null;
try {
// submit xml
obFS.setDebug(true);
obRetList = obFS.submit();
// write out result
int nSize = obRetList.size();
for (int i = 0; i < nSize; i++)
{
RFStatus obStat = (RFStatus)(obRetList.get(i));
System.out.println ((i+1) + "-");
System.out.println ("\tID: " + obStat.getID());
System.out.println ("\tStatusCode: " + obStat.getStatusCode());
System.out.println ("\tStatusMessage: " + obStat.getStatusMsg());
}
}
catch (Exception ex) {
System.out.println ("Error:" + ex.toString());
}
}
/**
* This method is used to read the txt file in UTF-8.
* @param strInFile
* @return
*/
private static String readInput(String strInFile) {
StringBuffer buffer = new StringBuffer();
try {
FileInputStream fis = new FileInputStream(strInFile);
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
Reader in = new BufferedReader(isr);
int ch;
while ((ch = in.read())>-1) {
// iCharNum +=1;
buffer.append((char)ch);
}
in.close();
return buffer.toString();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
After sending the fax, i can receive 2 faxes. The attachement is displayed correctly, and the html string was displayed as all '????'.
6. The xml generated by the 'Rightfax.zip' Java API doesnt contain Encoding.
I use "obFS.setDebug(true)" to enable the logs, and find the my fax in sent out to Rightfax server in an xml String. The xml looks like:
<?xml version="1.0" ?>
...
I think if the xml is like
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
Then the chinese characters might be decoded correctly. Anyway, that's just my suspicion.
Could you please help me to answer:
a. What is the root cause that my chinese characters cannot be displayed correctly.
b. How can i use the API to send Chinese HTML character.
c. Any work around that i could choose, if i could not send chinese in HTML.
Your help is really important to me.
Thank you very much.