Version | Date | Author | Comments |
0.1 | 04/15/2002 | Patrick Chanezon | Created the google API proxy patch |
0.2 | 05/31/2002 | Patrick Chanezon | added GoogleAPIDemo.class to the patch so that it can be used without compiling any file |
0.3 | 09/03/2002 | Patrick Chanezon | end of life for this document: Google fixed the APIs in beta 2 to allow the use of proxy in the java API, so this document is not relevant anymore |
public void setProxyHost(java.lang.String host)
public void setProxyPort(int port)
public void setProxyUserName(java.lang.String name)
public void setProxyPassword(java.lang.String password)
I would like to congratulate Google for their handling of this very minor problem in their APIs.
Nelson Minar from Google contacted me just 4 days after I published
the patch to thank me for it, and then they fixed it in the next release.
This kind of professionalism applied a most minor problem (an easy
workaround existed: use the WSDL instead of the java API if you are behind
a firewall) demonstrates a commitment to developers from Google that is
not so common in our industry, and feels very refreshing.
This company continues to surprise me :-)
Go Google !
The problem is that com.google.soap.search.GoogleSearch performs the SOAP call using a SOAPHTTPConnection but does not let you call the following methods on this object:
setProxyHost(java.lang.String host)
Set HTTP proxy host.
void setProxyPassword(java.lang.String password)
Set the password for HTTP proxy basic authentication.
void setProxyPort(int port)
Set HTTP proxy port.
void setProxyUserName(java.lang.String userName)
Set the username for HTTP proxy basic authentication.
java -cp "patgoogle.jar;googleapi.jar" com.google.soap.search.GoogleAPIDemo <client-key> (search <query> |cached <url> | spell <phrase>) [proxy host] [proxy port] [proxy username] [proxy password]You can download it here: GoogleAPIDemo.java .
The code to add the proxy prefs is:
// Create a Google Search object, set our authorization keyIn order to be able to call these methods, download patgoogle.jar
GoogleSearch s = new GoogleSearch();
s.setKey(clientKey);//P@ added proxy support
if (withProxy) {
s.setProxyHost(proxyHost);
s.setProxyPort(proxyPort);
if (proxyUserName != null) {
s.setProxyUserName(proxyUserName);
}
if (proxyPassword != null) {
s.setProxyPassword(proxyPassword);
}
}
After 2 request (1,
2)
in the google.public.web-apis
group, I decided to include com.google.soap.search.GoogleAPIDemo.class
in the patch as well.
I did this because the original GoogleAPIDemo.class
is present in googleapi.jar, so people needed to build the new version
and put it in their classpath in order to test the API. Many people do
not want to build this class, so I included it in the patch.
With this new version of the jar, you do not
need to compile anything, just run the command line above and you're done.
Put it in front of googleapi.jar in your classpath, and presto, you're done !
In the meantime, Happy Googling !
jre -DproxySet=true -DproxyHost=myhost -DproxyPort=myport MyApp
I tried it and it did not work.
I provided an
analysis of why it doesn't work as an answer in the Google web-api
group.
I reproduce it hereunder.
victor@bit-man.com.ar (Victor Rodriguez Bit-Man) wrote in message
news:<463f91ab.0204130850.130219d4@posting.google.com>...
> Hi there !!!
>
> > The call to the Google Web APIs failed:
> > com.google.soap.search.GoogleSearchFault: [SOAPException:
> > faultCode=SOAP-ENV:Client; msg=Error opening socket: Operation
timed
> > out: connect; targetException=java.lang.IllegalArgumentException:
> > Error opening socket: Operation timed out: connect]
>
> You're having not connection to the server !!1
>
> > I suspect the problem comes from I'm working behind a proxy
>
> You're right, that's the problem, and you can find the answer in
> http://www.davidreilly.com/java/java_network_programming/#2.4
>
> Hope this helps
Ozark, Victor is right in the fact that your problem comes from being
behind a proxy.
But the solution he advocates is wrong: it does not work.
The solution using System properties to set proxies as described by
David Reilly applies to URLConnection.
It is also very well decribed in this java tip:
http://www.javaworld.com/javaworld/javatips/jw-javatip42.html
But here the Google API, more accurately the class GoogleSearch, uses
org.apache.soap.transport.http.SOAPHTTPConnection to perform the SOAP
call.
SOAPHTTPConnection inherits from object, so it has nothing to do with
URLConnection.
Moreover, if you look at SOAPHTTPConnection's implementation, the network
call is delegated to org.apache.soap.util.net.HTTPUtils.post()
method, which uses a java.net.Socket.
So setting the system properties won't work, and now you know why.
Manjul Sahay is right: if you do not use the Google Java APIs but access
the Web Service directly using Apache SOAP, you can specify a proxy.
SOAPHTTPConnection has 4 methods that allows it to set proxy settings.
GoogleSearch uses SOAPHTTPConnection but does not let you take advantage
of these methods.
I had the same problem you had, being behind a proxy at work, so I
created a patch for GoogleSearch which allows you to specify proxy settings.
You can find it at http://www.chanezon.com/pat/google_proxy_patch.html until Google adds it to the API.
I hope this helps.
P@