Java Program Using MapViewer

3-18 Oracle Fusion Middleware Users Guide for Oracle MapViewer map_request

3.1.15 Java Program Using MapViewer

Example 3–18 uses the java.net package to send an XML request to MapViewer and to receive the response from MapViewer. Note, however, most programmers will find it more convenient to use the JavaBean-based API, described in Chapter 4 , or the JSP tag library, described in Chapter 5 . Example 3–18 Java Program That Interacts with MapViewer import java.net.; import java.io.; A sample program that shows how to interact with MapViewer public class MapViewerDemo { private HttpURLConnection mapViewer = null; Initializes this demo with the URL to the MapViewer server. The URL is typically http:my_corp.com:8888mapvieweromserver. public MapViewerDemoString mapViewerURLString { URL url; try { url = new URLmapViewerURLString; mapViewer = HttpURLConnection url.openConnection; mapViewer.setDoOutputtrue; mapViewer.setDoInputtrue; mapViewer.setUseCachesfalse; } catch Exception e { e.printStackTraceSystem.err; System.exit1; } } Submits an XML request to MapViewer. param xmlreq the XML document that is a MapViewer request public void submitRequestString xmlreq { try { mapViewer.setRequestMethodPOST; Use HTTP POST method. OutputStream os = mapViewer.getOutputStream; MapViewer expects to find the request as a parameter named xml_request. xmlreq = xml_request=+URLEncoder.encodexmlreq; os.writexmlreq.getBytes; os.flush; os.close; MapViewer Map Request XML API 3-19 } catch Exception e { e.printStackTraceSystem.err; System.exit1; } } Receives an XML response from MapViewer. public String getResponse { ByteArrayOutputStream content = new ByteArrayOutputStream; InputStream is = null; try { is = mapViewer.getInputStream; int c; while c = is.read = -1 content.writec; is.close; content.flush; content.close; return content.toString; } catch Exception e { e.printStackTraceSystem.err; return null; } } A simple main program that sends a list_data_sources XML request to MapViewer through HTTP POST public static void mainString[] args { ifargs.length1 { System.out.printlnUsage: java MapViewerDemo mapviewer url; System.out.printlnExample: java MapViewerDemo http:my_ corp.commapvieweromserver; System.exit1; } A sample XML request for MapViewer String listDataSources = ?xml version=\1.0\ standalone=\yes\? + non_map_request + list_data_sources + non_map_request; MapViewerDemo tester = null; tester = new MapViewerDemoargs[0]; System.out.printlnsubmitting request:\n+listDataSources; tester.submitRequestlistDataSources; String response = tester.getResponse; System.out.printlnresponse from MapViewer: \n + response; } } 3-20 Oracle Fusion Middleware Users Guide for Oracle MapViewer

3.1.16 PLSQL Program Using MapViewer