KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > userguide > clients > EchoBlockingClient


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.stream.XMLOutputFactory;
12 import javax.xml.stream.XMLStreamException;
13 import java.io.StringWriter JavaDoc;
14
15 /*
16  * Copyright 2001-2004 The Apache Software Foundation.
17  *
18  * Licensed under the Apache License, Version 2.0 (the "License");
19  * you may not use this file except in compliance with the License.
20  * You may obtain a copy of the License at
21  *
22  * http://www.apache.org/licenses/LICENSE-2.0
23  *
24  * Unless required by applicable law or agreed to in writing, software
25  * distributed under the License is distributed on an "AS IS" BASIS,
26  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27  * See the License for the specific language governing permissions and
28  * limitations under the License.
29  */

30
31 public class EchoBlockingClient {
32     private static EndpointReference targetEPR = new EndpointReference(AddressingConstants.WSA_TO,
33             "http://127.0.0.1:8080/axis2/services/MyService/echo");
34
35     public static void main(String JavaDoc[] args) {
36         try {
37             OMElement payload = ClientUtil.getEchoOMElement();
38             Call call = new Call();
39             call.setTo(targetEPR);
40             call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, false);
41
42             //Blocking invocation
43
OMElement result = (OMElement) call.invokeBlocking("echo", payload);
44
45             StringWriter JavaDoc writer = new StringWriter JavaDoc();
46             result.serializeWithCache(new OMOutput(XMLOutputFactory.newInstance().createXMLStreamWriter(writer)));
47             writer.flush();
48
49             System.out.println(writer.toString());
50
51         } catch (AxisFault axisFault) {
52             axisFault.printStackTrace();
53         } catch (XMLStreamException e) {
54             e.printStackTrace();
55         }
56     }
57 }
58
Popular Tags