Making Apache as a proxy

If your application needs one of the webpages served from external sites, you can configure Apache as a proxy and filter specific URL patterns to be forwarded to external site, and the rest to the tomcat serving your web application.

My requirements were:

1. Need a uniform/transparent way to integrate external sites into my web application.
2. There should not be any URL change in the browser or should not issue a redirect but mimic forward for a specific URL pattern.
3. Ability to append additional URL parameters before forwarding to external site. [eg: my id and password that the external site expects as URL parameters which I don't want to expose]


For that I can configure my apache server as follows:


NameVirtualHost *:9090
<virtualhost *:9090="">
ServerName localhost

ProxyRequests Off
ProxyPreserveHost On

<proxy *="">
Order deny,allow
Allow from all
</proxy>

RewriteEngine On
RewriteRule ^/map-service/loadMap.do(.*)  http://192.168.111.111/some-service/load.do?%{QUERY_STRING}&amp;someparam=aaa    [P] 
RewriteRule ^/map-service/(.*)  http://192.168.111.111/some-service/$1?%{QUERY_STRING}  [P]

</virtualhost> 

Note:

The parameter [P] is important as it makes the rewrite rule as Proxy forward else it behaves like a URL rewrite, sending location header to the browser.
%{QUERY_STRING} is a placeholder for input arguments
$1 - the first regex match group (.*) in our case. which matches any part of the remaing context path after /map-service/



Extract subxml from xml

Just a method to extract Sub - XML from XML using XPath in Java


public String extractResponseData(String responseXML) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException, TransformerException {

XPathExpression expr = XPathFactory.newInstance().newXPath().compile("//responsedata/*");
InputSource inputSource = new InputSource(new ByteArrayInputStream(responseXML.getBytes()));
NodeList nodeList = (NodeList) expr.evaluate(inputSource, XPathConstants.NODESET);
StringWriter sw = new StringWriter();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(new DOMSource(nodeList.item(0)), new StreamResult(sw));
return sw.toString();
}

Install multiple Firefox versions

In windows, to install multiple firefox versions do the following steps:

0. close all the firefox windows.
1. Install various versions of firefox in your system INTO DIFFERENT DIRECTORIES.
2. run the following command and create one profile for each version.
c:\Program Files\Mozilla Firefox\firefox.exe -profilemanager
3. Run the fireforx with -p
eg:
"C:\Program Files\Mozilla Firefox 3.5\firefox.exe" -p ff3_5
"C:\Program Files\Mozilla Firefox\firefox.exe" -p ff4_0

Now, you can open both the firefox versions at once.