Ajax Proxy file configuration

The Ajax proxy configuration is specified using an XML file called proxy-config.xml.

This is how a sample Ajax Proxy Configuration file looks like

<?xml version="1.0" encoding="UTF-8"?>
<proxy-rules xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:proxy="http://www.ibm.com/xmlns/prod/sw/ajax/proxy-config/1.0">
<proxy:mapping contextpath="/ibm" url="http://www.ibm.com" />
<proxy:policy url="http://www.ibm.com/*" acf="none">
<proxy:actions>
<proxy:method>GET</proxy:method>
<proxy:method>POST</proxy:method>
</proxy:actions>
</proxy:policy>
<proxy:meta-data>
<proxy:name>max-connections-per-host</proxy:name>
<proxy:value>5</proxy:value>
</proxy:meta-data>
<proxy:meta-data>
<proxy:name>max-total-connections</proxy:name>
<proxy:value>100</proxy:value>
</proxy:meta-data>
</proxy-rules>


The proxy-config.xml file has three main elements

  • policy: The policy element defines an access policy for specific URL pattern. Value of the url attribute of proxy element defines what URL pattern this policy is addressing. . In our sample configuration you can make GET and POST request to ibm.com, if you try to make either PUT or DELETE that it will deny access

    • actions:Required subelement defines defines the list of HTTP methods that can be used to access resource in the target domain

    • headers: Optional element that defines the list of header names that you want the proxy to forward to the target domain. By default it will forward Cache-Control, Pragma, User-Agent, Accept*, and Content*

    • cookies: Optional element that defines the list of cookies that you want to forward in the target request. If no cookie names are specified then proxy wont forward any cookies

    • mime-types:This element is optional. Use it to specify the list of accepted mime types.If no mime type is specified, the proxy accepts all responses

    • user: Optional element that defines the user roles that are allowed to make the request. If you set AllAuthenticatedUsers here then proxy will only allow requests from authenticated users.


    In our sample configuration file we are saying that Proxy will only accept GET and POST requests to http://www.ibm.com and both authenticated and non-authenticated users are allowed to make request and it will forward the default headers from incoming request to the request that it makes to http://www.ibm.com and it wont forward any cookies.

  • mapping: The mapping element is used to map incoming request to a target URL, based on their context path.The proxy resolves context path mappings prior to applying the matching access policy. The mapping element has two attributes

    • contextpath: The context path is short name for the actual URL that developer will use for making the request

    • url:Actual URL where the proxy will forward the request


    In our sample case whenever proxy servlet gets a request for /ibm it will forward that request to http://www.ibm.com. Request to /ibm/en/us would be forwarded to http://www.ibm.com/en/us

  • meta-data: Use the meta-data to specify general configuration properties of the proxy.The following HTTP related parameters are defined:

    • socket-timeout:This defines the default socket timeout in milliseconds. The socket timeout defines the timeout the proxy server waits for data after successfully establishing a connection with the target server. The default value is 20 seconds. A timeout value of zero is interpreted as an infinite timeout.

    • retries:TThis defines the number of retries that should be performed if the proxy could not establish a connection with the target server. The default value is 2 retries.

    • max-total-connections:This defines the maximum number of HTTP connections that the proxy can open to connect to arbitrary target hosts. The default value is 100 connections.

    • max-connections-per-host:This defines the number of HTTP connections the proxy can open to connect to a specific host. The default value is 5 connections per host.





Once your proxy is configured use appropriate URL for making request. For example in our case you can use this code to get response from http://www.ibm.com/en/us

function getYahooData(){
console.log("getYahooData.xhrGet()");
try{
dojo.xhrGet({
url: "/ibm",
load: function(data,error){
alert(data)
},
error: function(data, error){
alert("Error occured in accessing http://www.yahoo.com")
}
});
}catch(e){
alert(e);
}
}


DOwnload the AJaxSamplePortlet to see how it works

4 comments:

alon24 said...

Tried this on portal 6151 and it does not work, it does not get data not from google nor ibm.

Can you post it again (working) please?

Albert said...

Where is the proxy-config.xml file located?

Anonymous said...

I know Albert's question is almost 3 years old now, but for anybody else viewing this article, the proxy-config.xml is located at:
/AppServer/profiles//config/cells//LotusConnections-config

Anonymous said...

The comment box stripped my angled brackets. The above comment should read:
{WAS_HOME}/AppServer/profiles/{DEPLOYMENT_MANAGER}/config/cells/{CELL_NAME}/LotusConnections-config.