#3 Connection problems

closed
nobody
None
5
2002-12-08
2002-09-01
Mick Heywood
No

Hello,

I'm trying to use the jzkit for a website I'm building.
I want to use Z39.50 to connect to online databases,
and the site is being built in Java, which led me to
the JZKit.

I've downloaded version 1.0 and attempted to get the
TestClient to run. I had to make a few changes, as it
wouldn't run as supplied. The current source is copied
below. The main changes are in the inner class, to do
with casting. Other than that there are a few
debugging prints.

import java.io.*;
import java.net.*;
import java.util.*;

import java.io.PrintStream;
import java.io.IOException;
import java.math.BigInteger;

// for OID Register
import com.k_int.codec.util.*;
import com.k_int.codec.runtime.*;

// Information Retrieval Interfaces
import com.k_int.IR.*;
import com.k_int.z3950.IRClient.*;

public class TestClient
{
public static void main(String args[]) throws
TimeoutExceededException, PresentException, SearchException
{
// OIDRegister reg = OIDRegister.getRegister();

// Properties for the search
Properties p = new Properties();
p.put("ServiceHost","z3950.loc.gov");
p.put("ServicePort","7090");
p.put("default_record_syntax","xml");

// Create an anonymous inner class to listen for
search events...
Observer fragment_count_observer = new Observer()
{
public void update(Observable o, Object arg)
{
FragmentSourceEvent e;
try {
if (arg.getClass().getName() ==
"com.k_int.IR.IREvent") {
e = new
FragmentSourceEvent(((IREvent)arg).event_type,
((IREvent)arg).event_info);
}
else {
e = (FragmentSourceEvent)arg;
}
if ( e.event_type ==
FragmentSourceEvent.SOURCE_RESET )
{
System.err.println("Fragment source reset");
}
else if ( e.event_type ==
FragmentSourceEvent.FRAGMENT_COUNT_CHANGE )
{
System.err.println("Available number of fragments
has changed to "+e.event_info);
}
}
catch (Exception ex) {
String s = arg.getClass().getName();
System.err.println("Tried to cast a " + s + "
to FragmentSourceEvent");
System.exit(1);
}
}
};

Observer[] all_observers = new Observer[] {
fragment_count_observer };

Searchable s = new Z3950Origin();
s.init(p);

IRQuery e = new IRQuery();

e.hints = new Hashtable();
e.hints.put("record_syntax", "usmarc");
e.collections = new Vector();
e.collections.add("Voyager");

e.query_syntax = "PREFIX";
e.query = new String("@attrset bib-1 @attr 1=1016
legislation");

System.err.println("Searching");
SearchTask st = (SearchTask) s.createTask(e, null,
all_observers );
System.err.println("Private task status:
"+st.lookupPrivateStatusCode(st.getPrivateTaskStatusCode()));
st.evaluate(100000);

System.err.println("Private task status:
"+st.lookupPrivateStatusCode(st.getPrivateTaskStatusCode()));

InformationFragmentSource ifs = st.getTaskResultSet();
System.err.println("Search returned " +
ifs.getFragmentCount() + " records");
for ( int i = 1; i<= ifs.getFragmentCount(); i++ )
{
InformationFragment frag = ifs.getFragment(i);
System.out.println(frag);
}

// Test fetching a batch of records
System.err.println("Test2");
InformationFragment f[] = ifs.getFragment(1,10);

// Test fetching another batch of records
System.err.println("Test3");
InformationFragment f2[] = ifs.getFragment(10,10);

// Make sure we can call getDocument
System.out.println("Test 4 : Get document");
org.w3c.dom.Document d = f2[2].getDocument();

System.exit(0);
}
}

I'm also using the Voyager database at the LoC rather
than the default test database, as I couldn't get a
reply from the test database.

Running the class gets me the following response:

C:\J2SDK1~1.0\mick\jz>java -classpath
c:\j2sdk1.4.0\jzkit\lib;. TestClient
log4j:ERROR No appenders could be found for category
(Z3950Origin).
log4j:ERROR Please initialize the log4j system properly.
Searching
Fragment source reset
Private task status: Idle
java.lang.NoSuchMethodError:
com.k_int.codec.runtime.SerializationManager.choice
(Ljava/lang/Object;[[Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;
at
com.k_int.gen.Z39_50_APDU_1995.PDU_codec.serialize(PDU_codec.java:66)

at
com.k_int.z3950.util.ZEndpoint.encodeAndSend(ZEndpoint.java:410)
at
com.k_int.z3950.util.ZEndpoint.sendInitRequest(ZEndpoint.java:265)
at
com.k_int.z3950.util.ZEndpoint.connect(ZEndpoint.java:572)
at
com.k_int.z3950.util.ZEndpoint.run(ZEndpoint.java:455)
Private task status: Idle
Search returned 0 records
Test2
Exception in thread "main"
com.k_int.IR.PresentException: Present out of range,
only 0 records available
at
com.k_int.z3950.IRClient.Z3950SearchTask.getFragment(Z3950SearchTask.
java:105)
at TestClient.main(TestClient.java:92)

C:\J2SDK1~1.0\mick\jz>

I don't know anything about the logging API but it
doesn't seem to be fatal. I don't really understand
the significance of the fragment source reset message,
because the documentation doesn't really address it. I
know by using the web interface to the LoC database
that a search for legislation does actually return
quite a few results, so something is going wrong. The
final errors are a result of the zero result, but the
NoSuchMethod error does concern me. I decompiled the
relevant classes and indeed found a call from the
PDU_codec.serialize method passing 3 arguments to the
SerializationManager.choice method which requires 4.

I'm using Java 1.4.0 to compile and run the classes,
I'm not sure if that has an impact. I'm at a bit of a
loss with these errors, I can't find any solution in
the documentation and the only solution I can really
see is to modify and re-compile the classes, which I
don't want to do. Do you have any suggestions?

Any help much appreciated,

Mick Heywood

Discussion

  • Ian Ibbotson
    Ian Ibbotson
    2002-09-01

    Logged In: YES
    user_id=88018

    Please see support request 602771 under the JZKit project.

     
  • Ian Ibbotson
    Ian Ibbotson
    2002-12-08

    • status: open --> closed