KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > userguide > clients > MailClient


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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.MessageSender;
22 import org.apache.axis2.engine.AxisFault;
23 import org.apache.axis2.om.OMAbstractFactory;
24 import org.apache.axis2.om.OMElement;
25 import org.apache.axis2.om.OMFactory;
26 import org.apache.axis2.om.OMNamespace;
27
28 /**
29  * This is a Client progam that accesses 'MyService' web service in Axis2 samples
30  */

31 public class MailClient {
32
33     private static String JavaDoc toEpr = "http://localhost:8080/axis2/services/MyService";
34
35     public static void main(String JavaDoc[] args) throws AxisFault {
36         MessageSender msgSender = new MessageSender();
37         msgSender.setTo(new EndpointReference(AddressingConstants.WSA_TO, toEpr));
38         msgSender.setSenderTransport(Constants.TRANSPORT_MAIL);
39         msgSender.send("echo", getPayload());
40     }
41
42     private static OMElement getPayload() {
43         OMFactory fac = OMAbstractFactory.getOMFactory();
44         OMNamespace omNs = fac.createOMNamespace("http://example1.org/example1", "example1");
45         OMElement method = fac.createOMElement("echo", omNs);
46         OMElement value = fac.createOMElement("Text", omNs);
47         value.addChild(fac.createText(value, "Axis2 Echo String "));
48         method.addChild(value);
49
50         return method;
51     }
52 }
53
Popular Tags