From: Jakub Skoczen Date: Thu, 18 Feb 2010 13:21:28 +0000 (+0100) Subject: Add simple HTTP to z39.50 example X-Git-Tag: v1.1~7 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=e845ab8943d6c8ec04d9f4d43aaf2eac59b80eca;p=yaz4j-moved-to-github.git Add simple HTTP to z39.50 example --- diff --git a/examples/zgate/pom.xml b/examples/zgate/pom.xml new file mode 100644 index 0000000..190c6d7 --- /dev/null +++ b/examples/zgate/pom.xml @@ -0,0 +1,55 @@ + + 4.0.0 + com.indexdata + zgate + war + 1.0-SNAPSHOT + HTTP-to-Z3950 gateway + http://maven.apache.org + + + + org.yaz4j + yaz4j-any + 1.0-SNAPSHOT + provided + + + + javax.servlet + servlet-api + 2.5 + provided + + + + javax.servlet.jsp + jsp-api + 2.1 + provided + + + + junit + junit + 3.8.1 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.0.2 + + 1.5 + 1.5 + + + + zgate + + diff --git a/examples/zgate/src/main/java/com/indexdata/zgate/ZgateServlet.java b/examples/zgate/src/main/java/com/indexdata/zgate/ZgateServlet.java new file mode 100644 index 0000000..13b1a07 --- /dev/null +++ b/examples/zgate/src/main/java/com/indexdata/zgate/ZgateServlet.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 1995-2010, Index Data + * All rights reserved. + * See the file LICENSE for details. + */ +package com.indexdata.zgate; + +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.yaz4j.Connection; +import org.yaz4j.Record; +import org.yaz4j.ResultSet; +import org.yaz4j.exception.ZoomException; + +/** + * + * @author jakub + */ +public class ZgateServlet extends HttpServlet { + + @Override + public void init() throws ServletException { + System.out.println("Zeta: java.library.path=" + System.getProperty("java.library.path")); + System.out.println("Zeta: LD_LIBRARY_PATH=" + System.getenv("LD_LIBRARY_PATH")); + } + + @Override + /* + * For dinosaur search use: ?zurl=z3950.loc.gov:7090/voyager&query=@attr 1=7 0253333490&syntax=usmarc + **/ + 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; } + + String query = request.getParameter("query"); + 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; } + + int maxrecs=10; + if (request.getParameter("maxrecs") != null && !request.getParameter("maxrecs").isEmpty()) { + try { + maxrecs = Integer.parseInt(request.getParameter("maxrecs")); + } catch (NumberFormatException nfe) { + response.sendError(400, "Malformed parameter 'maxrecs'"); + return; + } + } + + response.getWriter().println("SEARCH PARAMETERS"); + response.getWriter().println("zurl: " + zurl); + response.getWriter().println("query: " + query); + response.getWriter().println("syntax: " + syntax); + response.getWriter().println("maxrecs: " + maxrecs); + response.getWriter().println(); + + Connection con = new Connection(zurl, 0); + con.setSyntax(syntax); + try { + con.connect(); + ResultSet set = con.search(query, Connection.QueryType.PrefixQuery); + response.getWriter().println("Showing " + maxrecs + " of " +set.getSize()); + response.getWriter().println(); + for(int i=0; i + diff --git a/examples/zgate/src/main/webapp/WEB-INF/web.xml b/examples/zgate/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..7a5a3db --- /dev/null +++ b/examples/zgate/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,21 @@ + + + zgate + + ZgateServlet + com.indexdata.zgate.ZgateServlet + + + ZgateServlet + /zgate + + + + 30 + + + + zgate + index.jsp + + diff --git a/examples/zgate/src/main/webapp/index.jsp b/examples/zgate/src/main/webapp/index.jsp new file mode 100644 index 0000000..ab292c3 --- /dev/null +++ b/examples/zgate/src/main/webapp/index.jsp @@ -0,0 +1,13 @@ +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + JSP Page + + +

Hello World!

+ +