Apache SOAP question

Discussion in 'Java' started by sarah chang, Jan 12, 2004.

  1. sarah chang

    sarah chang Guest

    I want to implement a variety of SOAP methods (with Apache SOAP) using
    just one method of one Java class, with the SOAP method name passed as
    a
    parameter to the Java method and the SOAP parameters passed in as an
    array of Strings.

    For example, the method could look like this:

    public static void executeSoapMethod (String soapMethodName, String[]
    soapParams) {
    ////
    }

    The reason for this is that I am writing an application that will
    allow users to define their own SOAP operations interactively in a
    proprietary scripting language.

    Is anyone aware of a way I can do this?

    Thanks!
     
    sarah chang, Jan 12, 2004
    #1
    1. Advertising

  2. This is still a work in progress for me; but the direction I'm going is
    adapted from examples out of chaper 14 in 'Professional Java Web Services'
    from Wrox Press. Maybe you can use it as a starting point on your own.
    I'm depending on JDOM for assembling/disassembling my commands and params
    into XML docs.

    **************************************************

    package codezilla.client.soap;


    /**
    * Write a description of class TrinitySOAPCall here.
    *
    * @author (your name)
    * @version (a version number or a date)
    */
    public class TrinitySOAPCall
    {
    // instance variables - replace the example below with your own
    private static String endpointURL =
    "http://localhost:8080/axis/Trinity";
    Call call;
    Service service;
    Element root = new Element("params");
    Document doc = new Document(root);

    /**
    * Constructor for objects of class TrinitySOAPCall
    * Include and assign all variables that aren't call specific
    */
    public TrinitySOAPCall(String methodname)
    {
    service = new Service();
    call = (Call) service.createCall();
    call.setTargetEndpointAddress(new java.net.URL(endpointURL));
    call.setOperationName(methodName);
    call.setProperty(Call.NAMESPACE,"urn:Trinity"); // greetingSpace
    call.addParameter("xml", XMLType.XSD_STRING, Call.PARAM_MODE_IN); //
    vector? array?
    }

    // execute the call and get back an XML doc in response
    public Document callMethod()
    {
    try {
    String response = (String) call.invoke( xmldoc.toString() );
    return StringToJDOM(response);
    } catch(Exception e){
    System.out.println(e);
    }
    }

    // create new elements in XML tree of call params
    public void addParam( String name, String val) {
    Element newcommand = new Element("param");
    newcommand.setAttribute("name", name);
    newcommand.setText("val", val);
    doc.getroot().addContent(newcommand);
    }

    // xml converter
    private Document StringToJDOM( String str) {
    SAXBuilder builder = new SAXBuilder();

    // command line should offer URIs or file names
    try {
    StringReader srdr = new StringReader(str); // create string
    input stream
    Document responsedoc = builder.build(srdr); // build DOM from
    that stream
    // If there are no well-formedness errors,
    // then no exception is thrown
    }
    // indicates a well-formedness error
    catch (JDOMException e) {
    System.out.println(args[0] + " is not well-formed.");
    System.out.println(e.getMessage());
    }
    catch (IOException e) {
    System.out.println("Could not check " + args[0]);
    System.out.println(" because " + e.getMessage());
    }
    return responsedoc;
    }
    }

    **************************************************************************
    sarah chang wrote:
    > I want to implement a variety of SOAP methods (with Apache SOAP) using
    > just one method of one Java class, with the SOAP method name passed as
    > a
    > parameter to the Java method and the SOAP parameters passed in as an
    > array of Strings.
    >
    > For example, the method could look like this:
    >
    > public static void executeSoapMethod (String soapMethodName, String[]
    > soapParams) {
    > ////
    > }
    >
    > The reason for this is that I am writing an application that will
    > allow users to define their own SOAP operations interactively in a
    > proprietary scripting language.
    >
    > Is anyone aware of a way I can do this?
    >
    > Thanks!
     
    Patrick B. Haggood, Jan 14, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page