Using the Proxy in your Web Application

This section describes how to use the proxy in your web application.

Import ria.js

The first step is to import OpenLayers and the main JavaScript API library. To do this:

<script type="text/javascript" src="http://<server>:<port>/ria/openlayers/OpenLayers.js"></script>			
<script type="text/javascript" src="http://<server>:<port>/ria/ria.js"></script>

Replace localhost:8080 with the actual hostname and port number the JavaScript API is installed on.

To publicly expose JavaScript API components in your web application, all javascript resources to be downloaded need to be in a publicly accessible URL (and any URLs within those js files must also be publicly accessible.

Define the Path to your Proxy

To indicate that cross-domain calls should be routed through a proxy, the path to the proxy has to be registered like this:


Rather than calling a URL to a different domain directly, the JavaScript library code will append the encoded URL to the end of the path registered above and use the result to perform the request. The proxy takes the URL from the request parameter (by default url) , requests the resource associated with it and sends the result back to the JavaScript library code without any modifications. The exact path passed to the addProxy() method depends on which proxy is being used and how the proxy was deployed.

Note: The path above is the default for the Java Servlet proxy. For the IIS proxy, use the path /riaproxy/Proxy.aspx?url=.

Code Sample

A simple page for performing a Feature Search:

<!DOCTYPE html>
        <script src="http://<server>:<port>/ria/openlayers/OpenLayers.js"></script>
        <script src="http://<server>:<port>/ria/ria.js"></script>
        <button onclick="search();">Search</button>
            function search() {
                var fs = new
                var d = fs.searchNearest({
                    table: "/Samples/NamedTables/WorldcapTable",
                    geometry: new OpenLayers.Geometry.Point(12.875977, 47.813155),
                    srs: "epsg:4326",
                    attributes: ["Capital"],
                    withinDistance: "2000 mi",
                    distanceAttributeName: "dist",
                    maxFeatures: 10
                d.addCallback(function(result) {alert(result.features.length + " result(s)")});

Test this sample web application by viewing it in your browser and clicking Search.

A dialog appears that displays the results of the Feature Search:

In a web debugger such as Fiddler, you can see a listing of the 10 results:

:{"Capital":"San Marino","dist":267.4791030110629}},{"type":"Feature","properties"

Troubleshooting a .NET Proxy

If an exception is encountered from the remote service request or there is a problem with the authentication, the HTTP status code, description, headers, URL, and the html body (if available) are inserted into an event log. This log appears in the Microsoft Event Viewer as the "Pitney Bowes Proxy Service."