Tuesday, August 16, 2005

Integrating AJAX with ArcGIS Server - I

As I mentioned previously, one of the ways to implement Ajax in the ArcGIS Server Java application is by creating a custom Servlet. We can then write Javascript code to submit client request to this custom Servlet using the XMLHttpRequest object. The servlet in return will generate the response which is again processed by the custom Javascript code on the client side.

Lets talk about how to create a Magnifier tool in ArcGIS Server MapViewer template by creating a custom servlet. First, we will pass the user click point (X/Y values) to our custom servlet. The custom Servlet will then use ArcObjects to generate the magnified image for that location. That sounds easy, but how can we get the server object properties (like server connection, map properties etc.) already stored in Java ADF in our custom Servlet? They are required for us to be able generate the map image using our custom ArcObjects code. The answer is the AGSWebContext object which hosts all ArcObjects for the server object.

Getting AGSWebContext in a Servlet is pretty simple. All we need to do is first get the WebSession attribute from session and then get AGSWebContext object from WebSession. Once we get AGSWebContext object, we need to
1. call activate method to hydrate the current properties of a pooled server object. (We are using pooled server object because we want to be able to quickly generate image and release the server object back. )
2. pass the AgsWebContext to another class names AgsMap which will generate the image.
3. call passivate method to release the server object back to the pool.

I will discuss the AgsMap class next time but for now here is the complete code for the custom Servlet:


package com.esri.arcgis.sample;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.esri.arcgis.webcontrols.ags.data.*;
import com.esri.arcgis.webcontrols.data.*;

public final class AgsServlet
extends HttpServlet {

private ServletConfig servletConfig = null;

public void destroy() {
servletConfig = null;
}

public ServletConfig getServletConfig() {

return (this.servletConfig);

}

public String getServletInfo() {

return (this.getClass().getName());

}

public void init(ServletConfig servletConfig)
throws ServletException {

this.servletConfig = servletConfig;
}

public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws java.io.IOException, ServletException {
HttpSession session = request.getSession(true);
int x = Integer.parseInt(
(String)request.getParameter("x"));
int y = Integer.parseInt(
(String)request.getParameter("y"));
WebSession wsession = (WebSession)
session.getAttribute(WebSession.SESSION_ATTRIBUTE_NAME );
String url=null;
if(wsession!=null) {
AGSWebContext context = (AGSWebContext)
wsession.findWebContext(0);
context.activate();
url = AgsMap.getImageUrl(context, x, y);
context.passivate();
}
response.setContentType("text/html");
java.io.PrintWriter out=response.getWriter();
out.print(url);
out.flush();
}

public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws java.io.IOException, ServletException {
doGet(request, response);
}

}

9 Comments:

At 4:42 PM, Blogger George said...

Take a minute right now, and imagine all the cool things you will do with amazing - how your life will be so much more better - and how your famly will change for the better.
amazing

 
At 8:57 AM, Blogger Bill Cash said...

I hate you, George.

 
At 8:05 AM, Anonymous Anonymous said...

BUY CHEAP SUPER VIAGRA ONLINE AND SAVE 70 % OF MONEY...
ORDER CHEAP CIALIS ONLINE
Credit CARDS

 
At 5:21 PM, Anonymous Anonymous said...

WOMANs SUPERVIAGRA
BUY LOW-COST CIALIS.HALF-PRICE VIAGRA.CHEAP LEVITRA...
BUY LOW-COST VIAGRA ! HALF-PRICE CIALIS ! CHEAP LEVITRA !
DISCOUNT CHEAP VIAGRA.DYSFUNCTION ERECTILE NEW MEDS
ACNE MEDICINE ONLINE

order accutane
WHAT IS ANTHELMINTICS
Albenza without prescription
ANTIBACTERIAL MEDICINE & CARE
half-price amoxil
AMPICILLIN ONLINE
cheap ampicillin
BUY CHEAP BACTRIM
order bactrim
NEW DRUGS & PILLS… SUPER-VIAGRA…
CHEAP CIALIS ONLINE
BUY CIPRO ONLINE
BUY CIPRO ONLINE
BUY CHEAP DIFLUCAN ONLINE
BUY DIFLUCAN ONLINE
BUY CHEAP SUPER VIAGRA ONLINE AND SAVE 70 % OF MONEY...
BUY GENERIC CIALIS
BUSINESS CREDIT CARDS ONLINE

 
At 1:29 AM, Anonymous viagra said...

The increase in the number of erectile dysfunction patients and the easy availability of the ED drug viagra in the online pharmacies have made it easy for many to order viagra online. There are certain online pharmacies that use a number of superlative degree adjectives and try and befool the customers. Buying Viagra online without proper inspection of the online pharmacy can have serious affects on your health and there are chances that your cheap Viagra never reaches your home. Whenever you buy viagra online it’s very mandatory to bear in mind that you go through a medical consultation and that the Viagra that you are given is FDA approved. Otherwise it would be wiser to buy viagra from a local known chemist.

 
At 9:54 PM, Anonymous Health info site said...

This is an age when people are growing more and more health conscious and are becoming more aware about their bodies. The health info sites on the internet are the best guides to these kinds of people.

 
At 3:02 PM, Anonymous Anonymous said...

LIVE SEX GIRLS & WOMEN, GAY LIVE SEX, BOYS & MEN, ADULT MOVIES sex live webcam MORESOME LIVE SEX WEBCAMS girl cams amateur live cams

 
At 4:30 AM, Anonymous viagra said...

As soon as the doctor diagnoses you as a victim of male erectile dysfunction, you can start off your treatment by opting for the anti-impotency medicine Viagra. And to start with, you can choose a Viagra sample. Viagra sample indicates the viagra pills that you can procure from the doctor or from online/offline drug stores for free of cost and as soon as soon as you get hold of a Viagra sample and administer the medicine, you would soon get rid of the shackles of erectile dysfunction. For more details on Viagra sample, visit the website http://www.viagraforce.com.

 
At 9:14 PM, Blogger kevin said...

Just after its launch in the market, viagra has created a niche for itself as the most effective medication for treating male erectile dysfunction across the world but alongside, the effectives of herbal Viagra products in dealing with male sexual problems cannot be ignored. Herbs and plants are, however, extensively used as sex stimulants worldwide and details present at http://www.pill-care.com inform you that the highly utilized sex boosters collectively known as herbal Viagra are namely, gingko biloba, yohimbe, horny goat weed and muira puama.

 

Post a Comment

<< Home