package sample_consumers;
import javax.xml.rpc.Stub;
import javax.naming.InitialContext;
import org.w3c.dom.*;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import java.util.Iterator;
public class DomClient {
private static int iden;
private static String idenChars = " ";
public static void main(String[] args) throws Exception
{
if (args.length != 4){
System.out.println("Usage: Client dsmlFile [URL to service - "+
"defaults to http://localhost/novell-dsml/jbroker] loginDN password");
System.exit(0);
}
String dsmlFile = args[0];
String dsmlUrl = args[1];
String loginDN = args[2];
String password = args[3];
InitialContext ctx = new InitialContext();
DsmlClientService svc = (DsmlClientService)
ctx.lookup("xmlrpc:soap:sample_consumers.DsmlClientService");
DsmlClient dsml = (DsmlClient) svc.getDsmlClientPort();
((Stub)dsml)._setProperty("javax.xml.rpc.service.endpoint.address",
args.length > 1 ? dsmlUrl :"http://localhost/novell-dsml/jbroker");
((Stub)dsml)._setProperty("javax.xml.rpc.security.auth.username", loginDN);
((Stub)dsml)._setProperty("javax.xml.rpc.security.auth.password", password);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(dsmlFile);
Element request = doc.getDocumentElement();
Element response = dsml.batchRequest(request);
displayElement(response);
}
public static void displayElement(Element element) {
String eText = new String("<" + element.getNodeName());
NamedNodeMap nodeMap = element.getAttributes();
int attrNum = nodeMap.getLength();
for (int i=0; i<attrNum; i++) {
Attr attr = (Attr)nodeMap.item(i);
eText += " "+attr.getNodeName()+"=\"" + attr.getNodeValue() + "\"";
}
System.out.println(eText + ">");
for ( Node cNode = element.getFirstChild();
cNode != null;
cNode = cNode.getNextSibling()) {
int nodeType = cNode.getNodeType();
if (nodeType != Node.TEXT_NODE)
iden++;
for(int i=0;i<iden;i++)
System.out.print(idenChars);
if (nodeType == Node.ELEMENT_NODE) {
displayElement((Element)cNode);
}
else if (nodeType == Node.TEXT_NODE) {
String nText = cNode.getNodeValue().trim();
if(nText.length() > 0) {
System.out.println(" " + nText);
}
}
}
for(int i=0;i<iden;i++)
System.out.print(idenChars);
System.out.println("</" + element.getNodeName() + ">");
iden--;
}
}