This discussion is archived
2 Replies Latest reply: Oct 8, 2007 2:55 AM by 843829 RSS

wsd services

843829 Newbie
Currently Being Moderated
<?xml version="1.0" encoding="UTF-8"?>

<configuration xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">

<wsdl

location="AvalonWebService.wsdl"

packageName="com.package.stubs "/>

</configuration>

-----------------------------------------------------------------
C:\jwsdp-2.0\jaxrpc\bin\wscompile.bat -gen:client -keep -verbose -classpath build config.xml

---------------------------------------------------------------------

import javax.xml.rpc.Stub;
import com.package.stubs.AnnwynServicePortType;
import com.package.stubs.AnnwynService_Impl;
import com.package.stubs.ProcessResponseSync;

public class Ws
{
     public String getResponsePayload(String username,String password,String headerXML,String payloadXML,String path)
     {
          String p="";
          try
          {
               AnnwynServicePortType port=null;
               ProcessResponseSync res=null;
               String endpointAddress = path+"/biocap/ws/AnnwynServicePort/AnnwynServicePort";
               try
               {
                    javax.xml.rpc.Stub stub = (Stub) (new AnnwynService_Impl().getAnnwynServicePort());
                    stub._setProperty(javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY,endpointAddress);
                    port = (AnnwynServicePortType)stub;
                    stub._setProperty(Stub.USERNAME_PROPERTY,username);
                    stub._setProperty(Stub.PASSWORD_PROPERTY,password);                
               }     
               catch(Exception ex)
               {
                    System.out.println("Authentication error in Ws.java : "+ex.toString());
               }

               res=port.processSync(headerXML,payloadXML);
               p=res.getPayloadXML();
          }
          catch(Exception e)
          {
System.out.println("Error in Ws.java : "+e.toString());          
          }
          return p;
     }
}

--------------------------------------for parsing xml file------------------------------------------------

import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import java.util.Hashtable;

public class XMLParse
{
     Document dom;
     NodeList nl;
     Hashtable countries=new Hashtable();
     //int key=0;
     public Hashtable getNames(String payloadXML,String attrib,String id)
//public Hashtable getNames(byte bb[])
     {
          try
          {
               DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
               DocumentBuilder db = dbf.newDocumentBuilder();
               byte bb[]=payloadXML.getBytes();
               //java.io.ByteArrayInputStream bais=new java.io.ByteArrayInputStream(bb);               
java.io.InputStream is=new java.io.ByteArrayInputStream(bb);               
               dom = db.parse(is);                              
               Element docEle = dom.getDocumentElement();
               nl=docEle.getElementsByTagName("Messages");
               
               for ( int k = 0; k <nl.getLength(); k++ )
               { 
                    NodeList childNodeList = nl.item(k).getChildNodes();
                    for(int i=0;i<(childNodeList.getLength())-1;i++)
                    {     
                         i=i+1;
                         Node childNode = childNodeList.item(i);     
                         String CountryName=((Element)childNodeList.item(i)).getAttribute(attrib);
                         String idValue=((Element)childNodeList.item(i)).getAttribute(id);
                         countries.put(idValue,CountryName);
                         //key++;
                    }
               }
}
          catch(Exception e)
          {System.out.println("Exception in initParser:------>"+e);}
          return countries;
     }

// public static void main(String args[]) throws Exception
// {
// try
// {
// FileInputStream fis=new FileInputStream("D:/Jagadeesan/Jagadeesan_Examples/JavaApplication6/src/parser/out.xml");
// int length=fis.available();
// byte b[]=new byte[length];
// int len;
// while((len=fis.read(b)) >= 0)
// {
//
// }
// Hashtable h=new XMLParse().getNames(b);
// System.out.println("----Countries----\n");
// for(int i=0;i<h.size();i++)
// {
// System.out.println(" "+h.get(new Integer(i)));
// }
// System.out.println("\n-----------------");
// }
// catch(Exception e)
// {
// e.printStackTrace();
// }
//
// }
}


----------------------------for creating xml fie------------------------------------------------


import org.w3c.dom.*;
import org.apache.xerces.dom.DocumentImpl;
import org.apache.xerces.dom.DOMImplementationImpl;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.Serializer;
import org.apache.xml.serialize.SerializerFactory;
import org.apache.xml.serialize.XMLSerializer;
import java.io.*;
import org.w3c.dom.Attr;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Comment;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.ProcessingInstruction;
import java.util.*;


public class payloadXML
{     

     public String getpayloadXML(Hashtable request_HT) throws Exception
     {
          Document document= new DocumentImpl();

          Element root = document.createElement("Root");     

          // add child element
          Node Messages_Node = create_Messages_Node(document,request_HT);
          root.appendChild(Messages_Node);

          // create attribute
          Attr xmlns_xsd_Attribute = document.createAttribute("xmlns:xsd");
          xmlns_xsd_Attribute.setValue("http://www.w3.org/2001/XMLSchema");
          // append attribute to root element
          root.setAttributeNode(xmlns_xsd_Attribute);

          // create attribute
          Attr xmlns_xsi_Attribute = document.createAttribute("xmlns:xsi");
          xmlns_xsi_Attribute.setValue("http://www.w3.org/2001/XMLSchema-instance");
          // append attribute to root element
          root.setAttributeNode(xmlns_xsi_Attribute);

          // create attribute
          Attr localizationId_Attribute = document.createAttribute("localizationId");
          localizationId_Attribute.setValue("en-GB");
          // append attribute to root element
          root.setAttributeNode(localizationId_Attribute);

          // create attribute
          Attr xmlns_Attribute = document.createAttribute("xmlns");
          xmlns_Attribute.setValue("http://www.avalonbiometrics.com/biocap/Messages");
          // append attribute to root element
          root.setAttributeNode(xmlns_Attribute);

document.appendChild( root );
OutputFormat format = new OutputFormat( document ); //Serialize DOM
          StringWriter stringOut = new StringWriter(); //Writer will be a String
          XMLSerializer serial = new XMLSerializer( stringOut, format );
          serial.asDOMSerializer(); // As a DOM Serializer

          serial.serialize( document.getDocumentElement() );
          //System.out.println( "STRXML = " + stringOut.toString()); //Spit out DOM as a String
          return stringOut.toString();           
     }

     public Node create_Messages_Node(Document document,Hashtable request_HT)
     {
// create Msg:Messages element
Element Messages = document.createElement("Messages");
for(Enumeration key = request_HT.keys(); key.hasMoreElements();)
{
Object keyName=key.nextElement();
// create attribute
Attr Attribute_Name = document.createAttribute(keyName.toString());
Attribute_Name.setValue((request_HT.get(keyName).toString()));
// append attribute to Msg:Messages element
Messages.setAttributeNode(Attribute_Name);
}
return Messages;
     }
}


----------------------for xml parsing---------------------------------------


import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import java.util.Hashtable;

public class XMLParseSeqNo
{
     Document dom;
     NodeList nl;
     String seqNumber="";
     public String getNames(String payloadXML)
     {
          try
          {
               DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
               DocumentBuilder db = dbf.newDocumentBuilder();
               byte bb[]=payloadXML.getBytes();               
java.io.InputStream is=new java.io.ByteArrayInputStream(bb);               
               dom = db.parse(is);                              
               Element docEle = dom.getDocumentElement();
               nl=docEle.getElementsByTagName("Messages");
               for ( int k = 0; k <nl.getLength(); k++ )
               {                     
               Element el = (Element)nl.item(k);
seqNumber= el.getAttribute("seqNumber");
}
}
catch(Exception e)
{
System.out.println("Exception in initParser:------>"+e);
}
          return seqNumber;
     }

}