jiangzhendong / google-api-translate-java

Automatically exported from code.google.com/p/google-api-translate-java
0 stars 0 forks source link

Translate hangs indefinitely after specific input #92

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Translate a specific input A.
My A here is the URL
http://ajax.googleapis.com/ajax/services/language/translate
with the parameter 
v=1.0&langpair=de%7Cen&q=159%0A&langpair=de%7Cen&q=Vaterrolle%0A&langpair=de%7Ce
n
&q=Informationen+%C3%BCber+die+Rolle+des+Vaters+bei+der+Kindererziehung%0A&langp
air
=de%7Cen&q=Alle+Dokumente%2C+die+die+spezielle+Rolle+des+Vaters+bei+der+Kinderer
zi
ehung%0A++++++++untersuchen.+Dazu+geh%C3%B6ren+auch+Dokumente%2C+die+die+Ve
r%C3%A4nderung+dieser+Rolle+%C3%BCber+die+Zeit%0A++++++++untersuchen.%0A

2. Translation of A is done.
3. Now translate B, where B is one of all inputs including A.
4. Translate hangs for several minutes.

What is the expected output? What do you see instead?
Expected: translation of B. 
See: nothing. Hangs

What version of the product are you using? On what operating system?
google-api-translate-java-0.92
Mac OS X 10.6.3, Java 1.6
Eclipse Galileo

Please provide any additional information below.
After investigating the line at which the program hangs is

final String result = inputStreamToString(uc.getInputStream());

in line 79 of GoogleAPI.java.
And specifically the uc.getInputStream() part. 
It's apparently a known issue from Sun.
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4333920

My idea / suggestion is to set a timeout to connection with 
setReadTimeout() which throws an SocketTimeoutException. 
And once this exception is caught pass it to the caller 
(Translate's retrieveJSON()) and let caller retry the translation.

Original issue reported on code.google.com by iamsy...@gmail.com on 22 May 2010 at 2:39

GoogleCodeExporter commented 8 years ago
Unit test here:
http://gist.github.com/410068

Original comment by iamsy...@gmail.com on 22 May 2010 at 2:57