ws-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Ws Wiki] Update of "XmlRpcExampleStringArray" by KenTanaka
Date Thu, 09 Jul 2009 22:27:56 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Ws Wiki" for change notification.

The following page has been changed by KenTanaka:
http://wiki.apache.org/ws/XmlRpcExampleStringArray

The comment on the change is:
Added DirList.java code

------------------------------------------------------------------------------
      </properties>
  </project>
  }}}
- The resource entry with `<directory>src/main/java</directory>` and the line
with `<include>org/apache/xmlrpc/webserver/*.properties</include>` in the resources
section tells maven to include `the Xml''''''Rpc''''''Servlet.properties` file into the warfile
WEB-INF/classes directory with the directory hierarchy that the xmlrpc library is expecting.
+ The resource entry with `<directory>src/main/java</directory>` and the line
with `<include>org/apache/xmlrpc/webserver/*.properties</include>` in the resources
section tells maven to include `the XmlRpcServlet.properties` file into the warfile WEB-INF/classes
directory with the directory hierarchy that the xmlrpc library is expecting.
+ 
+ == DirList.java Listing ==
+ Contents of '''{{{src/main/java/gov/noaa/eds/myXmlRpcServer/DirList.java}}}''' (Maven expects
the file to be nested down in this directory hierarchy unless you configure it differently).
+ 
+ {{{
+ /*
+  * FILE: DirList.java
+  */
+ package gov.noaa.eds.myXmlRpc;
+ 
+ import java.util.ArrayList;
+ import java.util.Random;
+ 
+ 
+ /**
+  * Provide directory listing functionality.
+  */
+ public class DirList {
+ 
+     static boolean listInitialized = false; // for lazy initialization
+     static int listLength = 100000;
+     static ArrayList<String> listing;
+ 
+ 
+     public int fileCount(String dirName) {
+         // fileCount for directory dirName
+         // Always returns listLength until real code is written
+         return listLength;
+     }
+ 
+ 
+     /**
+      * Return a directory listing.
+      * Currently generates made up names.
+      * @param dirName directory name for which to get a listing (currently ignored)
+      * @return a list of filenames for dirName
+      */
+     public ArrayList<String> ls(String dirName) {
+         if (!DirList.listInitialized) {
+             listing = new ArrayList<String>(listLength);
+             Random rng = new Random(); // Random Number Generator
+             for (int i = 0; i < listLength; i++) {
+                 int filenameLen = 1 + rng.nextInt(40);
+                 StringBuffer filename = new StringBuffer("sample_");
+                 for (int f = 0; f < filenameLen; f++) {
+                     filename.append("abcdefghijklmnopqrstuvwxyz".charAt(rng.nextInt(26)));
+                 }
+                 listing.add(filename.toString());
+             }
+ 
+             DirList.listInitialized = true;
+         }
+         return listing;
+     }
+ }
+ 
+ }}}
+ Rather than get a real directory listing and have to deal with filesystem specifics, this
example creates a list of randomly generated file names, all starting out with "sample_".
The list is only created once, so the same list will be returned until the web service is
restarted. The second time the client retrieves the list will be without the time needed to
generate the random file names, allowing you to judge the performance of just the data transfer
over XML-RPC.
+ 
  ----
+ 
  = myXmlRpcClient Code =
  The code provided below is for a Maven 2 project.
  

Mime
View raw message