broken java soap client code

(copying public archive for future reference;
 http://lists.w3.org/Archives/Public/www-archive/)

Glen,

Copied below is the would-be Java client code. It does successfully get a
message back from the (SOAP::Lite-based) Perl server. Problem is then
casting it back into Java objects (ArrayList/HashMaps). Any hints on that
front greatfully received! I'm using Axis snapshot of Sept 02 btw.

cheers,

Dan


/* 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.Debug ;
import org.apache.axis.utils.Options ;
import org.apache.axis.client.ServiceClient ;
import org.apache.axis.transport.http.HTTPTransport ;

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: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( "Response:\n" + resMsg.getAsString() );

//xxx
        System.out.println("res = " + resMsg );
// *** this doesn't work; am i casting the wrong object?
//        java.util.ArrayList rows = (java.util.ArrayList)resMsg;
// should get a java.util.ArrayList of java.util.HashMap

        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 Sunday, 2 September 2001 14:21:46 UTC