Sunday, September 6, 2015

apache axis web service tutorial2

//ADDITION.JAVA package additionService; import java.util.Iterator; import org.apache.axiom.om.*; public class addition { public addition() { } public OMElement add(OMElement omelement) { OMFactory omfactory = OMAbstractFactory.getOMFactory(); org.apache.axiom.om.OMNamespace omnamespace = omfactory.createOMNamespace("http://www.example.org/additionService/", "additionService"); OMElement omelement1 = omfactory.createOMElement("sum", omnamespace); Iterator iterator = omelement.getChildren(); int i = Integer.parseInt(((OMElement)iterator.next()).getText()) + Integer.parseInt(((OMElement)iterator.next()).getText()); omelement1.addChild(omfactory.createOMText((new StringBuilder()).append("").append(i).toString())); return omelement1; } } //SERVICES.XML additionService.addition http://localhost:8080/axis2/services/additionService //CLIENT.JAVA import java.io.StringWriter; import javax.xml.stream.*; import org.apache.axiom.om.*; import org.apache.axis2.*; import org.apache.axis2.client.*; import org.apache.axis2.addressing.*; public class addClient { private static EndpointReference targetEPR = new EndpointReference( "http://localhost:8080/axis2/services/additionService"); public static void main(String[] args) { try { OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace omNs = fac.createOMNamespace( "http://www.example.org/additionService1/", "additionService1"); OMElement add = fac.createOMElement("add", omNs); OMElement number1 = fac.createOMElement("number", omNs); number1.addChild(fac.createOMText("1")); add.addChild(number1); OMElement number2 = fac.createOMElement("number", omNs); number2.addChild(fac.createOMText("2")); add.addChild(number2); System.out.println(add); Options options = new Options(); options.setTo(targetEPR); options.setTransportInProtocol(Constants.TRANSPORT_HTTP); options.setAction("http://localhost:8080/axis2/services/additionService"); ServiceClient sender = new ServiceClient(); sender.setOptions(options); OMElement result = sender.sendReceive(add); StringWriter writer = new StringWriter(); result.serialize(XMLOutputFactory.newInstance() .createXMLStreamWriter(writer)); writer.flush(); System.out.println(writer.toString()); } catch (AxisFault axisFault) { axisFault.printStackTrace(); } catch (XMLStreamException e) { e.printStackTrace(); } } }

No comments:

Post a Comment

உப்பு மாங்காய்

சுருக்குப்பை கிழவி. சுருக்கங்கள் சூழ் கிழவி. பார்க்கும் போதெல்லாம் கூடையுடனே குடியிருப்பாள். கூடை நிறைய குட்டி குட்டி மாங்காய்கள். வெட்டிக்க...