Apache SOAP question

S

sarah chang

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!
 
P

Patrick B. Haggood

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 said:
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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top