KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > samples > faults > EmployeeClient


1 package samples.faults;
2
3 import org.apache.axis.encoding.ser.BeanSerializerFactory;
4 import org.apache.axis.encoding.ser.BeanDeserializerFactory;
5 import org.apache.axis.AxisFault;
6 import org.apache.axis.utils.Options;
7 import org.apache.axis.transport.http.SimpleAxisWorker;
8 import org.apache.axis.description.OperationDesc;
9
10 import javax.xml.rpc.ServiceFactory JavaDoc;
11 import javax.xml.rpc.Service JavaDoc;
12 import javax.xml.rpc.Call JavaDoc;
13 import javax.xml.rpc.encoding.TypeMappingRegistry JavaDoc;
14 import javax.xml.rpc.encoding.TypeMapping JavaDoc;
15 import javax.xml.namespace.QName JavaDoc;
16 import java.net.URL JavaDoc;
17 import java.util.Map JavaDoc;
18 import java.util.Iterator JavaDoc;
19
20 import samples.faults.Employee;
21
22 public class EmployeeClient {
23     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
24         Options opts = new Options(args);
25         String JavaDoc uri = "http://faults.samples";
26         String JavaDoc serviceName = "EmployeeInfoService";
27         ServiceFactory JavaDoc serviceFactory = ServiceFactory.newInstance();
28         Service JavaDoc service = serviceFactory.createService(new QName JavaDoc(uri, serviceName));
29         
30         TypeMappingRegistry JavaDoc registry = service.getTypeMappingRegistry();
31         TypeMapping JavaDoc map = registry.getDefaultTypeMapping();
32         
33         QName JavaDoc employeeQName = new QName JavaDoc("http://faults.samples", "Employee");
34         map.register(Employee.class, employeeQName, new BeanSerializerFactory(Employee.class, employeeQName), new BeanDeserializerFactory(Employee.class, employeeQName));
35
36         QName JavaDoc faultQName = new QName JavaDoc("http://faults.samples", "NoSuchEmployeeFault");
37         map.register(NoSuchEmployeeFault.class, faultQName, new BeanSerializerFactory(NoSuchEmployeeFault.class, faultQName), new BeanDeserializerFactory(NoSuchEmployeeFault.class, faultQName));
38         
39         Call JavaDoc call = service.createCall();
40         call.setTargetEndpointAddress(new URL JavaDoc(opts.getURL()).toString());
41         call.setProperty(Call.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
42         call.setProperty(Call.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
43         call.setProperty(Call.SOAPACTION_URI_PROPERTY, "http://faults.samples");
44         call.setOperationName( new QName JavaDoc(uri, "getEmployee") );
45
46         String JavaDoc[] args2 = opts.getRemainingArgs();
47         System.out.println("Trying :" + args2[0]);
48         Employee emp = (Employee) call.invoke(new Object JavaDoc[]{ args2[0] });
49         System.out.println("Got :" + emp.getEmployeeID());
50     }
51 }
52
Popular Tags