LokenathHBK / google-api-translate-java

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

Error while using with Proxy #148

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I am using WindowsXp sp3 and Netbeans7.0 IDE. I am getting error while using 
proxy to connect from internet.
My program is the same as given in example code with 3-4 extra lines for proxy 
connection.

package javatranslator;
import com.google.api.translate.Language;
import com.google.api.translate.Translate;

public class translator{
    public static void main(String[] args){
        try{
            System.setProperty("http.proxyHost", "172.27.16.7");
            System.setProperty("http.proxyPort", "3128");
            System.setProperty("http.proxyUser", "username");
            System.setProperty("http.proxyPassword", "password");
            Translate.setHttpReferrer("http://localhost");
            String translatedText = Translate.execute("Good Evening.",Language.ENGLISH,Language.FRENCH);
            System.out.println(translatedText);
        }
        catch(Exception e){
            System.out.println(e.getMessage());
        }
    }
}

I am getting the following error:
[google-api-translate-java] Error retrieving translation.

Original issue reported on code.google.com by ravi2008...@gmail.com on 9 Jul 2011 at 4:18

Attachments:

GoogleCodeExporter commented 8 years ago
Hey this problem could be fixed by:

1. add a new class named ProxyAuthenticator

import java.net.Authenticator;  
import java.net.PasswordAuthentication;

class ProxyAuthenticator extends Authenticator {  

    private String user, password;  

    public ProxyAuthenticator(String user, String password) {  
        this.user = user;  
        this.password = password;  
    }  

    protected PasswordAuthentication getPasswordAuthentication() {  
        return new PasswordAuthentication(user, password.toCharArray());  
    }  
}  

2. use as 

Authenticator.setDefault(new ProxyAuthenticator("username", "password"));  
        System.setProperty("http.proxyHost", "proxy host");  
        System.setProperty("http.proxyPort", "port");  

        Translate.setHttpReferrer("htpp://localhost/");

        String translatedText = Translate.execute("how are you ?",
                Language.ENGLISH, Language.HINDI);
        System.out.println(translatedText);

Original comment by harishn...@gmail.com on 11 Aug 2011 at 5:50

Attachments:

GoogleCodeExporter commented 8 years ago
Need to see the stacktrace really to find out what the underlying cause is.

Original comment by rich.mid...@gmail.com on 5 Nov 2011 at 5:15