Added support for various HTTP Proxy configuration context parameters.

This commit is contained in:
Erik C. Thauvin 2003-10-01 20:30:22 +00:00
parent 82c56e0fd0
commit ca045bc110
8 changed files with 274 additions and 69 deletions

View file

@ -25,10 +25,10 @@
<window_info id="BeanShell" active="false" anchor="bottom" auto_hide="true" internal_type="sliding" type="sliding" visible="false" weight="0.32972136" order="8" />
<window_info id="JavaSig" active="false" anchor="bottom" auto_hide="false" internal_type="docked" type="docked" visible="false" weight="0.33" order="11" />
<window_info id="CVS" active="false" anchor="bottom" auto_hide="false" internal_type="docked" type="docked" visible="false" weight="0.32972136" order="11" />
<window_info id="Web" active="false" anchor="left" auto_hide="false" internal_type="docked" type="docked" visible="false" weight="0.24948665" order="2" />
<window_info id="Web" active="false" anchor="left" auto_hide="false" internal_type="docked" type="docked" visible="true" weight="0.31519508" order="2" />
<window_info id="Javadoc" active="false" anchor="right" auto_hide="true" internal_type="sliding" type="sliding" visible="false" weight="0.33028457" order="3" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="docked" type="docked" visible="false" weight="0.33126935" order="6" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="docked" type="docked" visible="false" weight="0.3059548" order="0" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="docked" type="docked" visible="false" weight="0.2412731" order="0" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="docked" type="docked" visible="false" weight="0.32972136" order="1" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="docked" type="docked" visible="false" weight="0.28131416" order="1" />
<window_info id="Aspects" active="false" anchor="right" auto_hide="false" internal_type="docked" type="docked" visible="false" weight="0.33" order="4" />
@ -62,15 +62,19 @@
<option name="HIDE_NOT_PUBLIC" value="false" />
</component>
<component name="ProjectViewSettings">
<navigator currentView="SourcepathPane" flattenPackages="false" showMembers="false" showStructure="false" autoscrollToSource="false" splitterProportion="0.5" />
<navigator currentView="ClasspathPane" flattenPackages="false" showMembers="false" showStructure="false" autoscrollToSource="false" splitterProportion="0.5" />
<view id="ProjectPane">
<expanded_node type="directory" url="file://$PROJECT_DIR$/src/net/thauvin" />
<expanded_node type="directory" url="file://$PROJECT_DIR$/src/net" />
<expanded_node type="directory" url="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs" />
<expanded_node type="directory" url="file://$PROJECT_DIR$" />
<expanded_node type="directory" url="file://$PROJECT_DIR$/src" />
<expanded_node type="directory" url="file://$PROJECT_DIR$/src/net/thauvin/google" />
</view>
<view id="SourcepathPane">
<expanded_node type="directory" url="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs" />
<expanded_node type="directory" url="file://$PROJECT_DIR$/src/net/thauvin/google" />
<expanded_node type="directory" url="file://$PROJECT_DIR$/src/net" />
<expanded_node type="directory" url="file://$PROJECT_DIR$/src" />
<expanded_node type="directory" url="file://$PROJECT_DIR$/src/net" />
<expanded_node type="directory" url="file://$PROJECT_DIR$/src/net/thauvin" />
</view>
<view id="ClasspathPane" />
@ -99,23 +103,60 @@
<is-autoscroll-to-source value="true" />
</todo-panel>
</component>
<component name="FileEditorManager" selected-file="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs/Search.java">
<component name="FileEditorManager" selected-file="file://$PROJECT_DIR$/src/net/thauvin/google/GoogleSearchBean.java">
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/GoogleSearchBean.java">
<provider selected="true" editor-type-id="text-editor">
<state line="689" column="43" selection-start="18946" selection-end="18946" vertical-scroll-proportion="19.258741">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs/Search.java">
<provider selected="true" editor-type-id="text-editor">
<state line="53" column="13" selection-start="2004" selection-end="2004" vertical-scroll-proportion="0.40202704">
<state line="273" column="50" selection-start="6458" selection-end="6458" vertical-scroll-proportion="0.48776224">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs/Spelling.java">
<provider selected="true" editor-type-id="text-editor">
<state line="75" column="63" selection-start="2652" selection-end="2652" vertical-scroll-proportion="0.49125874">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs/CachedPage.java">
<provider selected="true" editor-type-id="text-editor">
<state line="69" column="71" selection-start="2375" selection-end="2375" vertical-scroll-proportion="0.50874126">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs/QuerySupport.java">
<provider selected="true" editor-type-id="text-editor">
<state line="55" column="22" selection-start="2203" selection-end="2203" vertical-scroll-proportion="0.3444056">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs/KeySupport.java">
<provider selected="true" editor-type-id="text-editor">
<state line="87" column="18" selection-start="2865" selection-end="2865" vertical-scroll-proportion="0.9423077">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/TagUtility.java">
<provider selected="true" editor-type-id="text-editor">
<state line="211" column="13" selection-start="5455" selection-end="5455" vertical-scroll-proportion="4.43007">
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs/SearchQuery.java">
<provider selected="true" editor-type-id="text-editor">
<state line="47" column="13" selection-start="1930" selection-end="1930" vertical-scroll-proportion="0.2394636">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/build.properties">
<provider selected="true" editor-type-id="text-editor">
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
@ -144,34 +185,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs/CachedPage.java">
<provider selected="true" editor-type-id="text-editor">
<state line="100" column="19" selection-start="2710" selection-end="2710" vertical-scroll-proportion="0.6612319">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs/QuerySupport.java">
<provider selected="true" editor-type-id="text-editor">
<state line="60" column="16" selection-start="2207" selection-end="2207" vertical-scroll-proportion="-0.38586956">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs/SearchResultSupport.java">
<provider selected="true" editor-type-id="text-editor">
<state line="183" column="19" selection-start="4595" selection-end="4595" vertical-scroll-proportion="0.6612319">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs/Spelling.java">
<provider selected="true" editor-type-id="text-editor">
<state line="107" column="19" selection-start="2855" selection-end="2855" vertical-scroll-proportion="0.6612319">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs/Element.java">
<provider selected="true" editor-type-id="text-editor">
<state line="61" column="22" selection-start="2144" selection-end="2144" vertical-scroll-proportion="0.17391305">
@ -179,13 +192,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs/KeySupport.java">
<provider selected="true" editor-type-id="text-editor">
<state line="76" column="22" selection-start="2632" selection-end="2632" vertical-scroll-proportion="0.17391305">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs/StyleSupport.java">
<provider selected="true" editor-type-id="text-editor">
<state line="91" column="22" selection-start="2572" selection-end="2572" vertical-scroll-proportion="0.17391305">
@ -193,29 +199,71 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/TagUtility.java">
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs/SearchResultSupport.java">
<provider selected="true" editor-type-id="text-editor">
<state line="62" column="31" selection-start="2215" selection-end="2215" vertical-scroll-proportion="-10.371622">
<folding>
<element signature="imports" expanded="true" />
</folding>
<state line="56" column="7" selection-start="2221" selection-end="2221" vertical-scroll-proportion="0.45945945">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/GoogleSearchBean.java">
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs/QuerySupport.java">
<provider selected="true" editor-type-id="text-editor">
<state line="634" column="22" selection-start="17548" selection-end="17548" vertical-scroll-proportion="17.028717">
<state line="55" column="22" selection-start="2203" selection-end="2203" vertical-scroll-proportion="0.3444056">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs/Spelling.java">
<provider selected="true" editor-type-id="text-editor">
<state line="75" column="63" selection-start="2652" selection-end="2652" vertical-scroll-proportion="0.49125874">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs/Search.java">
<provider selected="true" editor-type-id="text-editor">
<state line="53" column="13" selection-start="2004" selection-end="2004" vertical-scroll-proportion="0.40202704">
<state line="273" column="50" selection-start="6458" selection-end="6458" vertical-scroll-proportion="0.48776224">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/google-examples/WEB-INF/web.xml">
<provider selected="true" editor-type-id="text-editor">
<state line="8" column="70" selection-start="405" selection-end="405" vertical-scroll-proportion="0.23776224">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/GoogleSearchBean.java">
<provider selected="true" editor-type-id="text-editor">
<state line="689" column="43" selection-start="18946" selection-end="18946" vertical-scroll-proportion="19.258741">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs/KeySupport.java">
<provider selected="true" editor-type-id="text-editor">
<state line="87" column="18" selection-start="2865" selection-end="2865" vertical-scroll-proportion="0.9423077">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/taglibs/CachedPage.java">
<provider selected="true" editor-type-id="text-editor">
<state line="69" column="71" selection-start="2375" selection-end="2375" vertical-scroll-proportion="0.50874126">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/net/thauvin/google/TagUtility.java">
<provider selected="true" editor-type-id="text-editor">
<state line="211" column="13" selection-start="5455" selection-end="5455" vertical-scroll-proportion="4.43007">
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component>
<component name="DaemonCodeAnalyzer">
<disable_hints />
@ -452,6 +500,11 @@
<option name="name" value="C/jdk1.3.1_08/docs/api/" />
<option name="indexed" value="false" />
</JavadocEntry>
<JavadocEntry>
<option name="path" value="$PROJECT_DIR$/../../../jdk1.3.1_09/docs/api/" />
<option name="name" value="C/jdk1.3.1_09/docs/api/" />
<option name="indexed" value="false" />
</JavadocEntry>
</JavadocEntries>
</component>
<component name="JavaSig" />

View file

@ -8,6 +8,26 @@
<param-value/>
<description>The Google Web APIs client authorization key.</description>
</context-param>
<context-param>
<param-name>google_proxy_host</param-name>
<param-value/>
<description>The host to use as an HTTP proxy.</description>
</context-param>
<context-param>
<param-name>google_proxy_port</param-name>
<param-value/>
<description>The port to use as an HTTP proxy.</description>
</context-param>
<context-param>
<param-name>google_proxy_username</param-name>
<param-value/>
<description>The username required for the HTTP proxy.</description>
</context-param>
<context-param>
<param-name>google_proxy_password</param-name>
<param-value/>
<description>The password required for the HTTP proxy.</description>
</context-param>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

View file

@ -75,7 +75,8 @@ code {font-size:10pt}
<blockquote>
<font size="-1">1.1 <a href="#1_1">Installation</a><br>
1.2 <a href="#1_2">Google API Library</a><br>
1.3 <a href="#1_3">TagLib Directive </a></font>
1.3 <a href="#1_3">TagLib Directive </a><br>
1.4 <a href="#1_4">HTTP Proxy</a></font>
</blockquote>
<p>
<font size="-1"><b>&nbsp; &nbsp; 2. <a href="#search">Search Tags </a></b></font>
@ -206,6 +207,31 @@ code {font-size:10pt}
<blockquote>
<pre>&lt;%@taglib uri=&quot;/google-taglib&quot; prefix=&quot;google&quot;%&gt;</pre>
</blockquote>
<p>
<a name="1_4"></a>
<table bgcolor="#fff9e4" cellpadding="2" width="100%" border="0">
<tr>
<td style="background-color: #fff9e4" width="80%"><b>1.4 HTTP Proxy</b></td>
<td style="background-color: #fff9e4" width="20%" nowrap><font size="-1"><a href="#top">Back
to top</a> &nbsp; &nbsp; </font></td>
</tr>
</table>
<p>
<font size="-1">An HTTP Proxy server can be specified using context parameters in your
web application deployment descriptor (<code>web.xml</code>) as follows:</font>
<blockquote>
<pre>&lt;context-param&gt;<br> &lt;param-name&gt;google_proxy_host&lt;/param-name&gt;<br> &lt;param-value&gt;proxy.example.com&lt;/param-value&gt;<br>&lt;/context-param&gt;</pre>
<pre>&lt;context-param&gt;<br> &lt;param-name&gt;google_proxy_port&lt;/param-name&gt;<br> &lt;param-value&gt;3128&lt;/param-value&gt;<br>&lt;/context-param&gt;</pre>
</blockquote>
<p>
<font size="-1">Similarly, the HTTP Proxy user name and password (if any) may be specified using:</font>
<blockquote>
<pre>&lt;context-param&gt;<br> &lt;param-name&gt;google_proxy_username&lt;/param-name&gt;<br> &lt;param-value&gt;john&lt;/param-value&gt;<br>&lt;/context-param&gt;</pre>
<pre>&lt;context-param&gt;<br> &lt;param-name&gt;google_proxy_password&lt;/param-name&gt;<br> &lt;param-value&gt;opensesame&lt;/param-value&gt;<br>&lt;/context-param&gt;</pre>
</blockquote>
<p>
<font size="-1">Please note that the Google Web APIs automatically check the standard <code>http.proxyHost</code>
and <code>http.proxyPort</code> Java system properties.</font>
</blockquote>
<p>
<a name="search" id="search"></a>

View file

@ -138,7 +138,7 @@ public class GoogleSearchBean
{
service.setKey(key);
if ((key != null) && (key.trim().length() > 0))
if (isValidString(key))
{
keySet = true;
}
@ -158,6 +158,34 @@ public class GoogleSearchBean
return keySet;
}
/**
* Sets the HTTP proxy host, port, user name and password.
*
* @param proxyHost The host to use for the HTTP proxy.
* @param proxyPort The port to use for the HTTP proxy.
* @param proxyUserName The user name to use for the HTTP proxy.
* @param proxyPassword The password to use for the HTTP proxy.
*/
public void setProxyServer(String proxyHost, String proxyPort,
String proxyUserName, String proxyPassword)
{
int port = -1;
if (isValidString(proxyPort))
{
try
{
port = Integer.valueOf(proxyPort).intValue();
}
catch (NumberFormatException e)
{
; // Do nothing.
}
}
setProxyServer(proxyHost, port, proxyUserName, proxyPassword);
}
/**
* Sets the HTTP proxy host, port, user name and password.
*
@ -169,10 +197,25 @@ public class GoogleSearchBean
public void setProxyServer(String proxyHost, int proxyPort,
String proxyUserName, String proxyPassword)
{
service.setProxyHost(proxyHost);
service.setProxyPort(proxyPort);
service.setProxyUserName(proxyUserName);
service.setProxyPassword(proxyPassword);
if (isValidString(proxyHost))
{
service.setProxyHost(proxyHost);
if (proxyPort > 0)
{
service.setProxyPort(proxyPort);
}
if (isValidString(proxyUserName))
{
service.setProxyUserName(proxyUserName);
}
if (isValidString(proxyPassword))
{
service.setProxyPassword(proxyPassword);
}
}
}
/**
@ -641,6 +684,22 @@ public class GoogleSearchBean
elements = null;
}
/**
* Validates a string value by insuring it is not null or empty.
*
* @param stringValue The String value.
* @return true if valid, false if not.
*/
private boolean isValidString(String stringValue)
{
if ((stringValue != null) && (stringValue.trim().length() > 0))
{
return true;
}
return false;
}
/**
* Prints the usage and exits.
*/

View file

@ -67,6 +67,26 @@ public class TagUtility
*/
public static final String FILTER_PARAM = "filter";
/**
* The HTTP proxy host.
*/
public static final String GOOGLE_PROXY_HOST = "google_proxy_host";
/**
* The HTTP proxy password.
*/
public static final String GOOGLE_PROXY_PASSWORD = "google_proxy_password";
/**
* The HTTP proxy port.
*/
public static final String GOOGLE_PROXY_PORT = "google_proxy_port";
/**
* The HTTP proxy username.
*/
public static final String GOOGLE_PROXY_USERNAME = "google_proxy_username";
/**
* The name of the Google Search bean attribute.
*/

View file

@ -4,14 +4,14 @@
* Copyright (c) 2002-2003, Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
@ -20,7 +20,7 @@
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
@ -69,6 +69,15 @@ public class CachedPage extends QuerySupport
{
final GoogleSearchBean bean = new GoogleSearchBean(getKey());
bean.setProxyServer(pageContext.getServletContext()
.getInitParameter(TagUtility.GOOGLE_PROXY_HOST),
pageContext.getServletContext()
.getInitParameter(TagUtility.GOOGLE_PROXY_PORT),
pageContext.getServletContext()
.getInitParameter(TagUtility.GOOGLE_PROXY_USERNAME),
pageContext.getServletContext()
.getInitParameter(TagUtility.GOOGLE_PROXY_PASSWORD));
// Output the body
pageContext.getOut().write(bean.getCachedPage(query));
}

View file

@ -275,6 +275,15 @@ public class Search extends QuerySupport
{
try
{
bean.setProxyServer(pageContext.getServletContext()
.getInitParameter(TagUtility.GOOGLE_PROXY_HOST),
pageContext.getServletContext()
.getInitParameter(TagUtility.GOOGLE_PROXY_PORT),
pageContext.getServletContext()
.getInitParameter(TagUtility.GOOGLE_PROXY_USERNAME),
pageContext.getServletContext()
.getInitParameter(TagUtility.GOOGLE_PROXY_PASSWORD));
bean.getGoogleSearch(getKey(), getSite() + getQuery(),
getStart(), getMaxResults(), getFilter(),
getRestrict(), getSafeSearch(), getLr());

View file

@ -4,14 +4,14 @@
* Copyright (c) 2002-2003, Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
@ -20,7 +20,7 @@
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
@ -69,6 +69,15 @@ public class Spelling extends QuerySupport
{
final GoogleSearchBean bean = new GoogleSearchBean(getKey());
bean.setProxyServer(pageContext.getServletContext()
.getInitParameter(TagUtility.GOOGLE_PROXY_HOST),
pageContext.getServletContext()
.getInitParameter(TagUtility.GOOGLE_PROXY_PORT),
pageContext.getServletContext()
.getInitParameter(TagUtility.GOOGLE_PROXY_USERNAME),
pageContext.getServletContext()
.getInitParameter(TagUtility.GOOGLE_PROXY_PASSWORD));
String result = bean.getSpellingSuggestion(query);
if (!TagUtility.isValidString(result, true))