Fix link
[yaz4j-moved-to-github.git] / examples / zgate / doc / ARTICLE
index 213095e..caa5b84 100644 (file)
@@ -4,7 +4,7 @@ BUILDING A SIMPLE HTTP-TO-Z3950 GATEWAY USING YAZ4J AND TOMCAT
 [Yaz4J](http://www.indexdata.com/yaz4j) is a wrapper library over the 
 client-specific parts of YAZ, a C-based Z39.50 toolkit, and allows you to use 
 the ZOOM API directly from Java. Initial version of Yaz4j has been written
-by Rob Styles from [Talis][http://www.talis.com] and the project is now 
+by Rob Styles from [Talis](http://www.talis.com) and the project is now 
 developed and maintained at IndexData.
 [ZOOM](http://zoom.z3950.org/api/zoom-1.4.html) is a relatively straightforward 
 API and with a few lines of code you can write a basic application that can 
@@ -12,7 +12,7 @@ establish connection to a Z39.50 server.
 Here we will try to build a very simple HTTP-to-Z3950 gateway using yaz4j and 
 the Java Servlet technology.
 
-## COMPILING AND INSTALLING YAZ4J
+### COMPILING AND INSTALLING YAZ4J
 
 Yaz4j is still an experimental piece of software and as such is not distributed
 via Index Data's public Debian Apt repository and there is no Windows build (yet)
@@ -25,7 +25,7 @@ As a prerequisite, to complete th build process you will need JDK, Maven, Swig
 and Yaz (development package) installed on your machine. On Debian/Ubuntu you
 can get those easily via apt:
 
-    apt-get install sun-java6-jdk maven2 libyaz3-dev swig
+    apt-get install sun-java6-jdk maven2 libyaz4-dev swig
 
 
 The Yaz4j's source code can be checked-out out from our 
@@ -54,7 +54,7 @@ application is executed:
 
     java -cp /path/to/yaz4j-*.jar -Djava.library.path=/path/to/libyaz4j.so MyApp
 
-## SETTING UP THE DEVELOPMENT ENVIRONMENT
+### SETTING UP THE DEVELOPMENT ENVIRONMENT
 
 Setting up a development/runtime environment for a web (servlet) application is 
 a bit more complicated. First, you are not invoking the JVM directly, but the 
@@ -86,14 +86,17 @@ native library into the JVM you cannot simply package it along with your web
 application (inside the .war file) - it would try to load the library each time
 you deploy the webapp and all consecutive deployments would fail.
 
-## WRITING A SERVLET-BASED GATEWAY
+### WRITING A SERVLET-BASED GATEWAY
 
 With your servlet environment set up all that is left is to write the actual 
 application (peanuts :)). At IndexData we use Maven for managing builds of our 
 Java software components but Maven is also a great tool for quickly starting up 
 a project. To generate a skeleton for our webapp use the Maven archetype plugin:
 
-    mvn -DarchetypeVersion=1.0.1 -Darchetype.interactive=false -DarchetypeArtifactId=webapp-jee5 -DarchetypeGroupId=org.codehaus.mojo.archetypes -Dpackage=com.indexdata.zgate -DgroupId=com.indexdata -DartifactId=zgate archetype:generate --batch-mode
+    mvn -DarchetypeVersion=1.0.1 -Darchetype.interactive=false \
+    -DarchetypeArtifactId=webapp-jee5 -DarchetypeGroupId=org.codehaus.mojo.archetypes \ 
+    -Dpackage=com.indexdata.zgate -DgroupId=com.indexdata -DartifactId=zgate \ 
+    archetype:generate --batch-mode
 
 This will generate a basic webapp project structure:
 
@@ -146,16 +149,26 @@ solely by HTTP parameters, the servlet doGet method is shown below:
 protected void doGet(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
     String zurl = request.getParameter("zurl");
-    if (zurl == null || zurl.isEmpty()) { response.sendError(400, "Missing parameter 'zurl'"); return; }
+    if (zurl == null || zurl.isEmpty()) { 
+      response.sendError(400, "Missing parameter 'zurl'"); 
+      return; 
+    }
 
     String query = request.getParameter("query");
-    if (query == null || query.isEmpty()) { response.sendError(400, "Missing parameter 'query'"); return; }
+    if (query == null || query.isEmpty()) { 
+      response.sendError(400, "Missing parameter 'query'"); 
+      return; 
+    }
 
     String syntax = request.getParameter("syntax");
-    if (syntax == null || syntax.isEmpty()) { response.sendError(400, "Missing parameter 'syntax'"); return; }
+    if (syntax == null || syntax.isEmpty()) { 
+      response.sendError(400, "Missing parameter 'syntax'"); 
+      return; 
+    }
 
     int maxrecs=10;
-    if (request.getParameter("maxrecs") != null && !request.getParameter("maxrecs").isEmpty()) {
+    if (request.getParameter("maxrecs") != null 
+      && !request.getParameter("maxrecs").isEmpty()) {
       try {
         maxrecs = Integer.parseInt(request.getParameter("maxrecs"));
       } catch (NumberFormatException nfe) {
@@ -176,7 +189,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
     try {
       con.connect();
       ResultSet set = con.search(query, Connection.QueryType.PrefixQuery);
-      response.getWriter().println("Showing " + maxrecs + " of " +set.getSize());
+      response.getWriter().println("Showing " + maxrecs + " of "+set.getSize());
       response.getWriter().println();
       for(int i=0; i<set.getSize() && i<maxrecs; i++) {
         Record rec = set.getRecord(i);
@@ -228,8 +241,8 @@ Now we are ready to build our webapp:
     mvn package
 
 The resulting .war archive is located under `target/zgate.war`, we can deploy
-it on tomcat (e.g by using the /admin Tomcat admin  console) and test by issuing
-the follwoing request with your browser or curl 
+it on tomcat (e.g by using the `/admin` Tomcat admin  console) and test by 
+issuing the following request with your browser or curl 
 (assuming Tomcat is running on localhost:8080):
 
     http://localhost:8080/zgate/?zurl=z3950.loc.gov:7090/voyager&query=@attr%201=7%200253333490&syntax=usmarc
@@ -238,7 +251,7 @@ the follwoing request with your browser or curl
 That's it! You just build yourself a HTTP-to-Z3950 gateway! Just be careful
 with exposing it to the outside world - it's not very secure and could be 
 easily exploited. The source code and the gateway's Maven project is available 
-in the Yaz4j's Git repository under examples/zgate. In the meantime, IndexData 
+in the Yaz4j's Git repo under `examples/zgate`. In the meantime, IndexData 
 is working on a Debian/Ubuntu package to make the installation of Yaz4j and 
 Tomcat configuration greatly simplified - so stay tuned!. If you are interested 
 in Windows support - e.g. Visual Studio based build or an installer - please