Russian text is not coming in SMS - java

I try to send a Russian text from my web application, but when the text is sent to a mobile, it is displayed as "?????????". I have tried UTF-8 and all other possible values of charset for Russian text.
Does anyone have a solution for this?

SMS text is by default a special 7bit character set, alternatively Unicode UCS2 can be used. Either way, you will need to either encode your text properly before sending or use a gateway that does the encoding for you.

you can transliterate it, i.e. "Привет" => "Privet"
also check the encoding you use. UTF8 is the most common for international characters these days.

There are several ways to send SMS, one is with Unicode text another is ASCII. Unicode has a larger space requirement so messages max length will be smaller.
Make sure you are sending the text in Unicode format. The SMS gatway API should have documentation on this.

Related

Saving Telugu text to Oracle DB with Java

I'm looking for help in saving data in Telugu to an Oracle DB with Java.
I need to generate a message to consumer in this language and save it in the DB and then send the message via SMS. The SMS triggering in done for English but for I need to add it for Telugu.
Sample text is as follows:
విద్యుత్ బకాయిలు కట్టినందుకు ధన్యవాదములు
One solution can be converting the telugu or any unicode text into hexadecimal format with UCS2 tag 81. Then save the complete data as normal english string because hexadecimal contains 0-9 and A-F characters.
Hope this will help. :-)

Convert image to textual form(compressed) and back from text to image in android

hello there i want to convert an image to compressed textual form and then i want to send it to the other android user in form of sms and then that textual form need to be converted to the Image, i tried with the base64 encoding but its of no use, because its output is very long.. so that it ll be tough to send that much of text in form of sms, so is there any other way to covert an image to text else any method to compress the text...? please help me and i am work on android emulator and really need your help. Thanks in advance
Regards Hitesh,
Base64 must be OK, because it converts 3 bytes of data to 4 characters of text. You can't decrease size of your data using textual representation. But you can try to compress data and then convert it to text. Maybe it will help.
Base64 encodes the data in base 64, i.e., using 64 different characters. According to the Wikipedia page on SMS an SMS can contain any 7-bit character (that is, you have 128 characters at your disposal!)
Here's the best way to do it:
Compress the image using a compression method of your preference. (jpg for instance)
Find out the sequence of bits that the jpg-data has.
Write this bits as 7-bit characters. (Take special care of padding the last 7 bits.)
Write this sequence of characters as an SMS.

How to encode special characters for a POST with Spring/Roo

I'm using Spring/Roo for an app server, and need to be able to post some special characters. Specifically, characters like the Yen symbol, or Euro symbol. When I receive these characters on my server, and display them in console, they appear as "?". How can they be properly encoded and received?
Try configuring src/main/resources/META-INF/spring/database.properties to this :
database.url=jdbc:mysql://[YOUR_DB_SERVER]:3306/[YOUR_DB_NAME]?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8
There are a couple of possible failure points here.
First, I'd check to see if the console supports the characters in question:
if the default encoding used by the JVM does not support the characters, they will be turned into question marks by System.out
if the console font does not support the characters, they will not be rendered properly
if the console is decoding the bytes using a different encoding to the one System.out is encoding them to, the characters will not display correctly
Instead of trying to print characters as literal, cast to int and print the hex value - then check the value against the Unicode charts.
Lossy or incorrect conversions can also happen between the browser and the server. Ideally, the server should use UTF-8 for encoding and decoding. If the encoding used by the browser when it encodes the data does not support the characters, they will be lossily encoded; the browser usually picks an encoding based on the encoding sent by the server for the GET request (or more rarely from a form attribute). Inspect the Accept-Charset header being sent with your data (you can do this with something like Firebug or Fiddler). I don't know anything about Roo, but there's bound to be some mechanism to configure encodings.

a question related to URL

Dear all,Now i have this question in my java program,I think it should be classified as URL problem,but not 100% sure.If you think I am wrong,feel free to recategorize this problem,thanks.
I would state my problem as simply as possible.
I did a search on the famouse Chinese search engine baidu.com for a Chinese key word "奥巴马" (Obama in English),and the way I do that is to pass a URL (in a Java Program)to the browser like:
http://news.baidu.com/ns?word=奥巴马
and it works perfectly just like I input the "奥巴马”keyword in the text field on baidu.com.
However,now my advisor wants another thing.Since he can not read the Chinese webpages,but he wants to make sure the webpages I got from Baidu.com is related to "Obama",he asked me to google translate it back,i.e,using google translate and translate the Chinese webpage to English one.
This sounds straightforward.However,I met my problem here.
If I simply pass the URL "http://news.baidu.com/ns?word=奥巴马" into Google Translate and tick "Chinese to English" translating option,the result looks awful.(I don't know the clue here,maybe related to Chinese character encoding).
Alternatively,if now my browser opens ""http://news.baidu.com/ns?word=奥巴马" webpage,but I click on the "百度一下" button (that simply means "search"),you will notice the URL will get changed,now if I pass this URL into the Google translate and do the same thing,the result works much better.
I hope I am not making this problem sound too complicated,and I appologize for some Chinese words invovled,but I really need your guys' help here.Becasue I did all this in a Java program,I couldn't figure out how to realize that "百度一下"(pressing search button) step then get the new URL.If I could get that new URL,things are easy,I could just call Google translate in my Java code,and pops out the new window to show my advisor.
Please share any of your idea or thougts here.Thanks a lot.
Robert
You could use
URLEncoder.encode("http://news.baidu.com/ns?word=奥巴马", "utf-8")
then pass the resulting URL to Google Translate like:
http://translate.google.com/translate?js=y&prev=_t&hl=en&ie=UTF-8&layout=1&eotf=1&sl=zh-CN&tl=en&u=YOUR_URL
Cheers
When you press the search button, the browser encodes the search term into %E5%A5%A5%E5%B7%B4%E9%A9%AC, which is the UTF-8 encoding for 奥巴马. It does this because UTF-8 is the default encoding for HTML forms.
Java uses a UTF-16 encoding internally, so it’s possible that the URL library builds a request in that encoding if you do not specify anything.
However, I could not reproduce your problem with Google translate — pasting that URL appeared to work correctly no matter how I did it.
Try calling
URLEncoder.encode("http://news.baidu.com/ns?word=奥巴马", "utf-8")
(or utf-16; I'm not quite familiar with the Chinese characters representation)
URLs can contain only ASCII characters. All other characters must be converted to bytes then %-encoded in ASCII. However there is no mandate on what charset is used to convert chars to bytes. UTF-8 is recommended, but not required. As long as a server expresses its preference on charset, the client should respect that and use the same charset for encoding.
You can see from page info that baidu uses gb2312 encoding. The characters 奥巴马 in a form on its page will be converted to bytes in gb2312: B0C2 B0CD C2ED, then %-encoded to %B0%C2%B0%CD%C2%ED. That is what actually sent to baidu server, http://www.baidu.com/s?wd=%B0%C2%B0%CD%C2%ED
Your OS happens to be configured to use gb2312 by default, therefore when you paste http://news.baidu.com/ns?word= 奥巴马 to the browser, browser does the same thing, and baidu gets the correct chars. When I paste that URL in my browser, it screws up, because my OS uses UTF-8, and the browser encodes these chinese characters in UTF-8, not something baidu expectes. (when entering a URL directly in a browser, the browser may not have communicated to the server and does not know the charset the server prefers, therefore the browser uses platform default charset)
Now, Google uses UTF-8. That's why if you paste the URL to google form, it will screw up just like on my OS. The chars are encoded in UTF-8, and baidu will try to parse it as gb2312, and gets totally wrong words.
Solution is easy. Just encode the parameter in the way that the server expects:
"http://news.baidu.com/ns?word=" + URLEncoder.encode("奥巴马", "gb2312")

Display chinese characters in AJAX and also in excel

I am currently developing a Java Struts application and i been wondering how is it possible to display chinese characters in AJAX and also when generating excel file by servlet response.
Anyone can share any pointers?
As long as you use UTF8 for your character encoding, I think you should be fine. If UTF8 is not an option, and you're going to display only Chinese, you can even try one of the Chinese specific character encodings.
I'll try and get you more details, but at the very least, to set the character encoding, you'll have to do:
response.setCharacterEncoding("UTF-8");
or
response.setContentType("text/plain; charset=UTF-8");
Refer to the Java EE Specs (http://java.sun.com/j2ee/1.4/docs/api/index.html) for what these mean exactly.

Categories