1 16 package userguide.clients; 17 18 import org.apache.axis2.Constants; 19 import org.apache.axis2.addressing.AddressingConstants; 20 import org.apache.axis2.addressing.EndpointReference; 21 import org.apache.axis2.clientapi.Call; 22 import org.apache.axis2.engine.AxisFault; 23 import org.apache.axis2.om.*; 24 25 import javax.xml.namespace.QName ; 26 import javax.xml.stream.FactoryConfigurationError; 27 import javax.xml.stream.XMLOutputFactory; 28 import javax.xml.stream.XMLStreamException; 29 import javax.xml.stream.XMLStreamWriter; 30 31 34 public class TCPClient { 35 36 private static String toEpr = "tcp://localhost:8080/axis2/services/MyService"; 37 38 public static void main(String [] args) throws AxisFault { 39 40 Call call = new Call(); 41 call.setTo(new EndpointReference(AddressingConstants.WSA_TO,toEpr)); 42 call.setTransportInfo(Constants.TRANSPORT_TCP,Constants.TRANSPORT_TCP,false); 43 45 OMElement result = call.invokeBlocking("echo", getPayload()); 46 47 try { 48 XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out); 49 result.serializeWithCache(new OMOutput(writer)); 50 writer.flush(); 51 } catch (XMLStreamException e) { 52 e.printStackTrace(); 53 } catch (FactoryConfigurationError e) { 54 e.printStackTrace(); 55 } 56 } 57 58 59 private static OMElement getPayload() { 60 OMFactory fac = OMAbstractFactory.getOMFactory(); 61 OMNamespace omNs = fac.createOMNamespace( 62 "tcp://localhost:8080/axis2/services/MyService", "example1"); 63 OMElement method = fac.createOMElement("echo", omNs); 64 OMElement value = fac.createOMElement("Text", omNs); 65 value.addChild(fac.createText(value, "Axis2 Echo String ")); 66 method.addChild(value); 67 68 return method; 69 } 70 } 71 | Popular Tags |