Wednesday, August 15, 2012

Alter Servlet parameters of a request using a Proxy Page

Alter Servlet parameters of a request using a Proxy Page

I have a request like this :

http://Server/wms/servlet/WMSServer?userid=hidden&passwd=hidden&VERSION=1.1.1&REQUEST=GetMap&SRS=EPSG:4326&BBOX=-93.0562371212999,44.2252121686514,-92.7059804612417,44.3405684382141&WIDTH=1840&HEIGHT=606&LAYERS=VIEWS&STYLES=&EXCEPTIONS=application/vnd.ogc.se_xml&FORMAT=image/png&BGCOLOR=0xFEFFFF&TRANSPARENT=TRUE

the request is passed through a proxy page, is it possible to alter the request in the proxy page so that i can add a value to the 'Styles' parameter like this:

http://Server/wms/servlet/WMSServer?userid=hidden&passwd=hidden&VERSION=1.1.1&REQUEST=GetMap&SRS=EPSG:4326&BBOX=-93.0562371212999,44.2252121686514,-92.7059804612417,44.3405684382141&WIDTH=1840&HEIGHT=606&LAYERS=VIEWS&STYLES=**TIMESTAMP**&EXCEPTIONS=application/vnd.ogc.se_xml&FORMAT=image/png&BGCOLOR=0xFEFFFF&TRANSPARENT=TRUE

Basically changing - &STYLES=&EXCEPTIONS=.... to &STYLES=TIMESTAMP&EXCEPTIONS=....

Answers & Comments...

Answer: 1

Figured it out, wasnt that hard at all.

just set the proxy to process the request and did some simple logic on the URI String.

 public void ProcessRequest(HttpContext context) {        HttpResponse response = context.Response;      // Get the URL requested by the client (take the entire querystring at once     //  to handle the case of the URL itself containing querystring parameters)     string uri = Uri.UnescapeDataString(context.Request.QueryString.ToString());       // Get token, if applicable, and append to the request     string token = getTokenFromConfigFile(uri);       // Add the 'TIMESTAMP' Value  to the Valtus Service     string styleparam = "&STYLES=";     if (uri.Contains(styleparam))     {         int position = uri.IndexOf(styleparam) + styleparam.Length;         uri = uri.Insert(position, "TIMESTAMP");     }      System.Net.WebRequest req = System.Net.WebRequest.Create(new Uri(uri)); 

}

Answer by DrStereo for Alter Servlet parameters of a request using a Proxy Page




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog