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.stream.FactoryConfigurationError; 26 import javax.xml.stream.XMLOutputFactory; 27 import javax.xml.stream.XMLStreamException; 28 import javax.xml.stream.XMLStreamWriter; 29 30 33 public class RESTClient { 34 35 private static String toEpr = "http://localhost:8080/axis2/services/MyService"; 36 37 public static void main(String [] args) throws AxisFault { 38 39 Call call = new Call(); 40 call.setTo(new EndpointReference(AddressingConstants.WSA_TO,toEpr)); 41 call.setTransportInfo(Constants.TRANSPORT_HTTP,Constants.TRANSPORT_HTTP,false); 42 call.setDoREST(true); 43 44 OMElement result = call.invokeBlocking("echo", getPayload()); 45 46 try { 47 XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out); 48 result.serializeWithCache(new OMOutput(writer)); 49 writer.flush(); 50 } catch (XMLStreamException e) { 51 e.printStackTrace(); 52 } catch (FactoryConfigurationError e) { 53 e.printStackTrace(); 54 } 55 } 56 57 58 private static OMElement getPayload() { 59 OMFactory fac = OMAbstractFactory.getOMFactory(); 60 OMNamespace omNs = fac.createOMNamespace( 61 "http://example1.org/example1", "example1"); 62 OMElement method = fac.createOMElement("echo", omNs); 63 OMElement value = fac.createOMElement("Text", omNs); 64 value.addChild(fac.createText(value, "Axis2 Echo String ")); 65 method.addChild(value); 66 67 return method; 68 } 69 } 70 | Popular Tags |