Hi people,

I'm trying to develop a little wms server for my new project in order to
publish .shp files. A complete gis product is overkilling for this specific
task and we have some experience on this topic, so I'm implementing the
features we need. Unfortunately looks like I'm missing something (maybe
related to some thread unsafe operation) and after a few *concurrent*
request to the server tomcat becomes absolutely freeze. Maybe you can give
me some hint about what's wrong. Here's a (a bit simplified) version of the
code I've developed. As far as I can see the only shared resource is the
DataStore. Any tip will be very well received :-)

jv

public class WMSGetMap extends HttpServlet  {

 private FileDataStoreFinder store;

public void init()  {
 String file = "shape.shp";
 this.store = FileDataStoreFinder.getDataStore(file);
 }

protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {

WMSRequest wmsRequest = WMSRequest.getInstance(request); // <-- parses
request
 if (wmsRequest instanceof WMSGetMapRequest) {
 WMSGetMapRequest wmsGetMapRequest = (WMSGetMapRequest) wmsRequest;
 FeatureSource featureSource = store.getFeatureSource();
 // imageWidth, minx, etc are obtained from the wmsRequest.
 BufferedImage image =
 new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_ARGB);
 Graphics2D g = image.createGraphics();
 CoordinateReferenceSystem crs = featureSource.getInfo().getCRS();
 if (crs == null) {
 crs = DefaultGeographicCRS.WGS84;
 }
 ReferencedEnvelope activeArea = new ReferencedEnvelope(minx, maxx, miny,
maxy, crs);
 MapContext mapContext = new DefaultMapContext();
 mapContext.setTitle(featureSource.getName().getLocalPart());
 mapContext.addLayer(featureSource, null);

HashMap hints = new HashMap();
 GTRenderer renderer = new StreamingRenderer();
 renderer.setContext(mapContext);
 mapContext.setAreaOfInterest(activeArea);
 renderer.paint(g, new Rectangle(imageWidth, imageHeight), activeArea);
 mapContext.dispose();

ImageWriter iw = (ImageWriter) writers.next();
 ImageOutputStream ios =
ImageIO.createImageOutputStream(response.getOutputStream());
 iw.setOutput(ios);
 iw.write(new IIOImage(image, null, null));
 ios.flush();
 iw.dispose();
 out.flush();
 image.flush();
 }

}
}
------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to