W3C home > Mailing lists > Public > www-archive@w3.org > September 2001

Working RDF query client using Apache Axis

From: Dan Brickley <danbri@w3.org>
Date: Mon, 3 Sep 2001 05:04:39 -0400 (EDT)
To: <www-archive@w3.org>
cc: Glen Daniels <gdaniels@macromedia.com>, <libby.miller@bris.ac.uk>
Message-ID: <Pine.LNX.4.30.0109030500080.8261-100000@tux.w3.org>

Seems to work. The 3rd argument to the server specifies the serialization
policy (ie. whether to use the Map construct); this may turn out to be an
interop headache, dunno.

Dan


ps. still some bits in code below I could strip out; it's a recycled Axis test
---------- Forwarded message ----------
Date: Mon, 3 Sep 2001 11:06:12 +0100

/* stolen from apache Axis examples by Doug and Glen */
// http://lists.w3.org/Archives/Public/www-archive/2001Jul/0020.html
// for perl equiv i'm trying to clone

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;


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 hardcoded message to the server, and print the response.
     */
    public static String doTest (String args[], String service) throws Exception {
      Options      opts    = new Options( args );
      String       url     = opts.getURL();
      String       action  = "EchoService" ;

        if (service != null) {
            action = service;
        }

      Debug.setDebugLevel( opts.isFlagSet( 'd' ) );

      args = opts.getRemainingArgs();
      if ( args != null ) action = args[0];

      ServiceClient client = new ServiceClient(new HTTPTransport());

      url = "http://fireball.dyndns.org/cgi-bin/soap"; // danbri hack
      action = "http://rdfweb.org/RDF/RDFWeb/SOAPDemo#squish";

      client.set(HTTPTransport.URL, url);
      client.set(HTTPTransport.ACTION, action);

      Message        reqMsg      = new Message( msg );
      Message        resMsg     = null ;

      System.out.println( "Request:\n" + msg );
      System.out.println( "Url: " + url );
      System.out.println( "soap action is: " + action );
      client.setRequestMessage( reqMsg );
      client.invoke();

      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);

      System.out.println("Restoring object from xml...");
      Object result = param.getValue();

      ArrayList rows = (ArrayList)result;
      System.out.println("\n\nGot rows: "+ rows +"\n\n");

      System.out.println("result = " +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{
    doTest(args, null);
  }
  public static void mainWithService(String args[], String service) throws Exception{
    doTest(args, service);
  }
}
Received on Monday, 3 September 2001 05:04:41 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 7 November 2012 14:17:14 GMT