X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=examples%2Fzgate%2Fdoc%2FARTICLE;h=caa5b842720fc6a10693b9fd7c3ab7f5aa49e924;hb=0c5af8e2d6cf47a9d048bfacb74325fb4c76f56b;hp=fd26d8d7ab96e57f5ae427d581749e9cc4dcbabb;hpb=b66a08072692115cdaa482ecef0d68b97130edc8;p=yaz4j-moved-to-github.git diff --git a/examples/zgate/doc/ARTICLE b/examples/zgate/doc/ARTICLE index fd26d8d..caa5b84 100644 --- a/examples/zgate/doc/ARTICLE +++ b/examples/zgate/doc/ARTICLE @@ -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) @@ -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