KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > userguide > clients > EchoBlockingDualClient


1 package userguide.clients;
2
3 import org.apache.axis2.Constants;
4 import org.apache.axis2.addressing.AddressingConstants;
5 import org.apache.axis2.addressing.EndpointReference;
6 import org.apache.axis2.clientapi.Call;
7 import org.apache.axis2.engine.AxisFault;
8 import org.apache.axis2.om.OMElement;
9 import org.apache.axis2.om.OMOutput;
10
11 import javax.xml.namespace.QName JavaDoc;
12 import javax.xml.stream.XMLOutputFactory;
13 import java.io.StringWriter JavaDoc;
14
15 /**
16  * Created by IntelliJ IDEA.
17  * User: Jaliya
18  * Date: Jun 4, 2005
19  * Time: 5:47:37 PM
20  */

21 public class EchoBlockingDualClient {
22     private static EndpointReference targetEPR = new EndpointReference(AddressingConstants.WSA_TO,
23             "http://127.0.0.1:8080/axis2/services/MyService/echo");
24
25     public static void main(String JavaDoc[] args) {
26         try {
27             OMElement payload = ClientUtil.getEchoOMElement();
28
29             Call call = new Call();
30             call.setTo(targetEPR);
31
32             //The boolean flag informs the axis2 engine to use two separate transport connection
33
//to retrieve the response.
34
call.engageModule(new QName JavaDoc(Constants.MODULE_ADDRESSING));
35             call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, true);
36
37             //Blocking Invocation
38
OMElement result = (OMElement) call.invokeBlocking("echo", payload);
39
40             StringWriter JavaDoc writer = new StringWriter JavaDoc();
41             result.serializeWithCache(new OMOutput(XMLOutputFactory.newInstance().createXMLStreamWriter(writer)));
42             writer.flush();
43
44             System.out.println(writer.toString());
45
46             //Need to close the Client Side Listener.
47
call.close();
48
49         } catch (AxisFault axisFault) {
50             axisFault.printStackTrace();
51         } catch (Exception JavaDoc ex) {
52             ex.printStackTrace();
53         }
54
55     }
56 }
57
Popular Tags