KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > samples > security > Client


1 /*
2  * Copyright 2001-2004 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
17 package samples.security;
18
19 import org.apache.axis.MessageContext;
20 import org.apache.axis.client.Call;
21 import org.apache.axis.client.Service;
22 import org.apache.axis.message.SOAPBodyElement;
23 import org.apache.axis.message.SOAPEnvelope;
24 import org.apache.axis.utils.Options;
25 import org.apache.axis.utils.XMLUtils;
26
27 public class Client {
28     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
29         try {
30             Options opts = new Options(args);
31
32             Service service = new Service();
33             Call call = (Call) service.createCall();
34             call.setTargetEndpointAddress(new java.net.URL JavaDoc(opts.getURL()));
35
36             SOAPEnvelope env = new SOAPEnvelope();
37             SOAPBodyElement sbe = new SOAPBodyElement(XMLUtils.StringToElement("http://localhost:8080/LogTestService", "testMethod", ""));
38             env.addBodyElement(sbe);
39
40             env = new SignedSOAPEnvelope(env, "http://xml-security");
41
42             System.out.println("\n============= Request ==============");
43             XMLUtils.PrettyElementToStream(env.getAsDOM(), System.out);
44
45             call.invoke(env);
46
47             MessageContext mc = call.getMessageContext();
48             System.out.println("\n============= Response ==============");
49             XMLUtils.PrettyElementToStream(mc.getResponseMessage().getSOAPEnvelope().getAsDOM(), System.out);
50         }
51         catch (Exception JavaDoc e) {
52             e.printStackTrace();
53         }
54     }
55 }
56
Popular Tags