Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Google language translation API

 
kandarp mehta
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Google Transalation API to convert String from one language to another. I have already set Translate.setHttpHeader() value, then also it gives below exception.

java.lang.Exception: [google-api-translate-java] Error retrieving translation.
at com.google.api.GoogleAPI.retrieveJSON(GoogleAPI.java:123)
at com.google.api.translate.Translate.execute(Translate.java:69)
at com.nextenders.client.beans.ruleengine.RuleEngineTest.main(RuleEngineTest.java:27)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
null
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
at com.google.api.GoogleAPI.retrieveJSON(GoogleAPI.java:107)
... 2 more


Anybody know solution of this exception? Or anybody knows any API which convert from one language to another in java?
 
James Elsey
Ranch Hand
Posts: 228
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there anything else in the stack trace?

I did a quick google on the exception your getting, a few of them have had a "caused by" then a URL, does your stack trace have that?

Have a look here, it is a quick tutorial and several people have posted regarding the error : http://www.techiegyan.com/?p=279

Also, it would probably be worth the investment to get the google API working, since their translation service is quite good. Maybe Yahoo or BabelFish provide something similar..
 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kandarp mehta wrote:Caused by: java.net.ConnectException: Connection timed out: connect

You can't connect to the service, plain and simple. Try to find out to what host and port the service is trying to connect, then try connecting using telnet:
- open a Command Prompt
- type in "telnet HOST PORT" where HOST and PORT are the Google API host and port. For instance, "telnet www.google.com 80" to test Google's website.

If you can also not connect this way then you should check your firewall, or contact your system administrator.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15439
41
Android IntelliJ IDE Java Scala Spring
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic