RDF query SOAP client, cleaned up slightly

package org.w3c.inkling.soap;

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

import org.apache.axis.*;
import org.apache.axis.utils.*;
import org.apache.axis.client.*;
import org.apache.axis.transport.http.HTTPTransport ;
import java.lang.reflect.Array;
import org.apache.axis.message.*;
import org.apache.axis.encoding.*;
import org.apache.axis.server.AxisServer;
import org.apache.axis.utils.QName;
import org.xml.sax.InputSource;

/**
A simple RDF query client in SOAP
   Issues: the hashmap argument to the server -- can we avoid this?
   Todo:
     - wrap as a driver for Inkling, http://swordfish.rdfweb.org/rdfquery/
     - document service interface
     - look at datatyping issues (dates etc in query results)
@author Dan Brickley <danbri@w3.org>
*/

public class RDFQClient {

    public static String query = "SELECT ?x, ?l, ?c" +
	"FROM     http://xmlns.com/wordnet/1.6/Job "+
	"WHERE "+
	"  (web::type ?x rdfs::Class) "+
	"  (rdfs::label ?x ?l) "+
	"  (rdfs::description ?x ?c) "+
	"USING web FOR http://www.w3.org/1999/02/22-rdf-syntax-ns# "+
       	"rdfs FOR http://www.w3.org/2000/01/rdf-schema#";

   public static String data = "http://xmlns.com/wordnet/1.6/Job";

   public static String msg = "<SOAP-ENV:Envelope " +
        "xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
        "xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" > " +
        "<SOAP-ENV:Body>\n" +
        "<rq:squish xmlns:rq=\"http://rdfweb.org/RDF/RDFWeb/SOAPDemo\">\n" +
        "<rq:query>" + query + "</rq:query>"+
	"<rq:data>"+ data +"</rq:data>"+
        "<rq:hashmap>1</rq:hashmap>" +
        "</rq:squish>\n" +
        "</SOAP-ENV:Body></SOAP-ENV:Envelope>\n";

    /**
     * Send a query message to the server, and print the response.
     */
    public static String askWeb () throws Exception {

      Message        reqMsg      = new Message( msg );
      ServiceClient client = new ServiceClient(new HTTPTransport());
      client.set(HTTPTransport.URL,"http://fireball.dyndns.org/cgi-bin/soap" );
      client.set(HTTPTransport.ACTION, "http://rdfweb.org/RDF/RDFWeb/SOAPDemo#squish");
      client.setRequestMessage( reqMsg );
      client.invoke();

      Message resMsg = client.getMessageContext().getResponseMessage();
      // System.out.println("XML serialization: "+ resMsg.getAsString());

      SOAPEnvelope envelope = (SOAPEnvelope)resMsg.getAsSOAPEnvelope();
      RPCElement body = (RPCElement)envelope.getFirstBody();
      Vector arglist = body.getParams();
      RPCParam param = (RPCParam) arglist.get(0);
      Object result = param.getValue();

      ArrayList rows = (ArrayList)result;
      Object[] answers = (Object[])rows.toArray();
      for (int i=0; i<answers.length; i++) {
	  HashMap h = (HashMap)answers[i];
	  System.out.println("Answer "+i+" = "+ h +"\n\n");
      }
      return (String)resMsg.getAsString();
    }

  public static void main(String args[]) throws Exception{
    askWeb();
  }
}

Received on Monday, 3 September 2001 05:55:49 UTC