-
Notifications
You must be signed in to change notification settings - Fork 555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support for variables in 'param-value' from properties file without depending on any 3rd party libs #106
Open
MadhbhavikaR
wants to merge
9
commits into
mitre:master
Choose a base branch
from
MadhbhavikaR:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+146
−15
Open
support for variables in 'param-value' from properties file without depending on any 3rd party libs #106
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9219348
Support for injecting properties files into web.xml param-value
198c8d7
Changed the version in the doc
d9f627f
Fix for - Headers were not getting read properly
bfba817
CONN_MANAGER_TIMEOUT issue
19b8c1f
Merge pull request #1 from madhbhavikar/propertiesSupport
MadhbhavikaR 459da71
Changes to the Readme to point to proper status
fc16d30
Reverted the change meant for my company
f597ee5
changes as per Discussion with dsmily
ab711f8
Changes to the doc
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
<groupId>org.mitre.dsmiley.httpproxy</groupId> | ||
<artifactId>smiley-http-proxy-servlet</artifactId> | ||
<version>1.9-SNAPSHOT</version> | ||
<version>1.9.1</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>Smiley's HTTP Proxy Servlet</name> | ||
|
@@ -35,7 +35,7 @@ | |
<url>https://github.com/dsmiley/HTTP-Proxy-Servlet</url> | ||
<connection>scm:git:https://[email protected]/dsmiley/HTTP-Proxy-Servlet.git</connection> | ||
<developerConnection>scm:git:[email protected]:dsmiley/HTTP-Proxy-Servlet.git</developerConnection> | ||
<tag>HEAD</tag> | ||
<tag>smiley-http-proxy-servlet-1.9</tag> | ||
</scm> | ||
|
||
<properties> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,16 +36,13 @@ | |
import org.apache.http.message.BasicHttpRequest; | ||
import org.apache.http.message.HeaderGroup; | ||
import org.apache.http.params.BasicHttpParams; | ||
import org.apache.http.params.CoreConnectionPNames; | ||
import org.apache.http.params.HttpParams; | ||
import org.apache.http.util.EntityUtils; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.Cookie; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.lang.reflect.Constructor; | ||
import java.net.HttpCookie; | ||
|
@@ -54,6 +51,13 @@ | |
import java.util.Enumeration; | ||
import java.util.Formatter; | ||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.Cookie; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
/** | ||
* An HTTP reverse proxy/gateway servlet. It is designed to be extended for customization | ||
|
@@ -112,6 +116,8 @@ public class ProxyServlet extends HttpServlet { | |
|
||
private HttpClient proxyClient; | ||
|
||
private Properties configurationProperties = null; | ||
|
||
@Override | ||
public String getServletInfo() { | ||
return "A proxy servlet by David Smiley, [email protected]"; | ||
|
@@ -129,9 +135,80 @@ protected HttpHost getTargetHost(HttpServletRequest servletRequest) { | |
/** | ||
* Reads a configuration parameter. By default it reads servlet init parameters but | ||
* it can be overridden. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these javadocs are now missing info about the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Java docs added to the method |
||
* In case if you are using an externalized properties file http-proxy.properties and / or | ||
* http-proxy-override.properties which would be plugged into the web.xml if it is available in the classpath: | ||
* | ||
* ... | ||
* <servlet> | ||
* <servlet-name>solr</servlet-name> | ||
* <servlet-class>org.mitre.dsmiley.httpproxy.ProxyServlet</servlet-class> | ||
* <init-param> | ||
* <param-name>targetUri</param-name> | ||
* <param-value>${some-url}</param-value> | ||
* </init-param> | ||
* <init-param> | ||
* <param-name>log</param-name> | ||
* <param-value>true</param-value> | ||
* </init-param> | ||
* </servlet> | ||
* ... | ||
* | ||
* make sure you put ${some-url} is used if you want to pickup values from the properties file. | ||
* | ||
* The properties file could be: | ||
* | ||
* http-proxy.properties: | ||
* | ||
* some-url=http://www.cisco.com/{x-some-parameter}/someEndpoint | ||
* | ||
* Assuming x-some-parameter is a custom header parameter. | ||
* | ||
* If this property needs to be overridden for some reason for a different environment for example, then the override properties file could be: | ||
* | ||
* http-proxy-override.properties | ||
* | ||
* some-url=http://www.cisco.com/someContext/someEndpoint | ||
*/ | ||
|
||
protected String getConfigParam(String key) { | ||
return getServletConfig().getInitParameter(key); | ||
if(configurationProperties == null) { | ||
configurationProperties = getConfigurationProperties(); | ||
} | ||
return getValue(configurationProperties, getServletConfig().getInitParameter(key)); | ||
} | ||
|
||
protected String getValue(Properties configurationProperties, String value){ | ||
if(value == null){ | ||
return value; | ||
} | ||
if(value.startsWith("${") && value.endsWith("}")){ | ||
String key = value.replaceAll("\\$\\{(.*)\\}", "$1"); | ||
return (String) configurationProperties.get(key); | ||
} | ||
return value; | ||
} | ||
protected Properties getConfigurationProperties() | ||
{ | ||
Properties configurationProperties = new Properties(); | ||
try | ||
{ | ||
InputStream proxyPropertiesResource = Thread.currentThread().getContextClassLoader().getResourceAsStream("http-proxy.properties"); | ||
if (proxyPropertiesResource != null) { | ||
configurationProperties.load(proxyPropertiesResource); | ||
} | ||
} | ||
catch (IOException e) {} | ||
Properties proxyOverrideProperties = new Properties(); | ||
try | ||
{ | ||
InputStream proxyOverridePropertiesResource = Thread.currentThread().getContextClassLoader().getResourceAsStream("http-proxy-override.properties"); | ||
if (proxyOverridePropertiesResource != null) { | ||
proxyOverrideProperties.load(proxyOverridePropertiesResource); | ||
} | ||
} | ||
catch (IOException e) {} | ||
configurationProperties.putAll(proxyOverrideProperties); | ||
return configurationProperties; | ||
} | ||
|
||
@Override | ||
|
@@ -161,6 +238,12 @@ public void init() throws ServletException { | |
hcParams.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES); | ||
hcParams.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false); // See #70 | ||
readConfigParam(hcParams, ClientPNames.HANDLE_REDIRECTS, Boolean.class); | ||
readConfigParam(hcParams, ClientPNames.ALLOW_CIRCULAR_REDIRECTS, Boolean.class); | ||
readConfigParam(hcParams, "http.conn-manager.timeout", Integer.class); | ||
readConfigParam(hcParams, ClientPNames.MAX_REDIRECTS, Integer.class); | ||
readConfigParam(hcParams, CoreConnectionPNames.CONNECTION_TIMEOUT, Integer.class); | ||
readConfigParam(hcParams, CoreConnectionPNames.SO_TIMEOUT, Integer.class); | ||
readConfigParam(hcParams, CoreConnectionPNames.STALE_CONNECTION_CHECK, Boolean.class); | ||
proxyClient = createHttpClient(hcParams); | ||
} | ||
|
||
|
@@ -650,6 +733,10 @@ protected static CharSequence encodeUriQuery(CharSequence in) { | |
formatter.format("%%%02X",(int)c);//TODO | ||
} | ||
} | ||
|
||
if(formatter!= null){ | ||
formatter.close(); | ||
} | ||
return outBuf != null ? outBuf : in; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm; I'm not sure what the implication of this change is... but I see it's something to maintain between versions :-/