[Montag-users] how to access montag services from a java client
Status: Beta
Brought to you by:
sbtourist
|
From: Alexandra M. <al...@ya...> - 2006-01-14 11:46:20
|
Hello,
I am new to webservices and montag, and despite my efforts
reading soap and wsdl tutorials, I am not able to interact
successfully with Montag :(
I coded up a simple java client program to access one of
the montag methods (e.g., createCollection), but I keep
getting this error:
Error encountered:
montag.core.MontagSOAPFault
Here is the source code of the java program I wrote, in
case it helps.
=================================================================
package montagTest;
import java.net.URL;
import java.util.Vector;
import java.util.Iterator;
import org.apache.soap.Constants;
import org.apache.soap.Fault;
import org.apache.soap.SOAPException;
import org.apache.soap.rpc.Call;
import org.apache.soap.rpc.Parameter;
import org.apache.soap.rpc.Response;
public class CollectionAdder {
static final String MONTAG_URL =
"http://localhost:8080/montag/services/CollectionManager/";
public void add(URL url, String parent, String newCol)
throws SOAPException {
System.out.println("Adding collection '" + newCol +
"' to '" +
parent + "'");
// Build the Call object
Call call = new Call( );
call.setTargetObjectURI("CollectionManager");
call.setMethodName("createCollection");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
// Set up parameters
Vector params = new Vector( );
params.addElement(new Parameter("parent",
String.class, parent, null));
params.addElement(new Parameter("newCol",
String.class, newCol, null));
call.setParams(params);
// Invoke the call
Response response;
response = call.invoke(url, "");
if (!response.generatedFault( )) {
System.out.println("Successful collection
addition.");
} else {
Fault fault = response.getFault( );
System.out.println("Error encountered: " +
fault.getFaultString( ));
Vector entries = fault.getDetailEntries( );
for (Iterator i = entries.iterator(); i.hasNext( ); ) {
org.w3c.dom.Element entry =
(org.w3c.dom.Element)i.next( );
System.out.println(entry.getFirstChild().getNodeValue( ));
}
}
}
public static void main(String[] args) {
if (args.length != 2) {
System.out.println("Usage: java
javaxml2.CollectionAdder [Parent Collection] " +
"[New Collection]");
return;
}
try {
// URL for SOAP server to connect to
URL url = new URL(MONTAG_URL);
// Get values for new collection
String parent = args[0];
String newCol = args[1];
// Add the collection
CollectionAdder adder = new CollectionAdder(
);
adder.add(url, parent, newCol);
} catch (Exception e) {
e.printStackTrace( );
}
}
}
=================================================================
Any help or advice is greatly appreciated.
Thanks,
Alexandra
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
|