--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.indexdata</groupId>
+ <artifactId>zgate</artifactId>
+ <packaging>war</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>HTTP-to-Z3950 gateway</name>
+ <url>http://maven.apache.org</url>
+ <dependencies>
+
+ <dependency>
+ <groupId>org.yaz4j</groupId>
+ <artifactId>yaz4j-any</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet.jsp</groupId>
+ <artifactId>jsp-api</artifactId>
+ <version>2.1</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ <finalName>zgate</finalName>
+ </build>
+</project>
--- /dev/null
+/*
+ * 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<set.getSize() && i<maxrecs; i++) {
+ Record rec = set.getRecord(i);
+ response.getWriter().print(rec.render());
+ }
+ } catch (ZoomException ze) {
+ throw new ServletException(ze);
+ } finally {
+ con.close();
+ }
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ }
+
+ @Override
+ public String getServletInfo() {
+ return "Zeta search engine servlet";
+ }
+}