1 25 package org.objectweb.jonas.jtests.appclients.timeclient; 26 27 import javax.naming.InitialContext ; 28 import javax.naming.NamingException ; 29 import javax.xml.namespace.QName ; 30 import javax.xml.rpc.Call ; 31 import javax.xml.rpc.Service ; 32 33 36 public class TimeClient { 37 38 41 private static final String SERVICE_REF_NAME = "java:comp/env/service/time"; 42 43 46 private InitialContext ic; 47 48 51 public TimeClient() throws Exception { 52 init(); 53 } 54 55 58 private void init() throws NamingException { 59 ic = new InitialContext (); 60 } 61 62 public boolean hasBindedService() throws NamingException { 63 Object o = lookupService(); 64 if (o != null) { 65 if (o instanceof Service ) { 66 return true; 67 } 68 } 69 return false; 70 } 71 72 81 82 private Object lookupService() throws NamingException { 83 return ic.lookup(SERVICE_REF_NAME); 84 } 85 86 public static void main(String [] args) throws Exception { 87 TimeClient tc = new TimeClient(); 88 89 if (!tc.hasBindedService()) { 90 throw new Exception ("TimeClient should have a Service instance binded to '" + SERVICE_REF_NAME + "'"); 91 } 92 93 tc.handlersInvoked(); 94 } 95 96 99 private boolean handlersInvoked() throws Exception { 100 Service s = (Service ) lookupService(); 101 Call call = s.createCall(new QName ("TimePort"), new QName ("jonas:Time", "getDate")); 102 call.invoke(new Object [] {}); 103 StaticPassValue spv = StaticPassValue.getInstance(); 104 String init = spv.getInit(); 105 String req = spv.getRequest(); 106 String resp = spv.getResponse(); 107 if (init == null) { 108 throw new Exception ("Handler.init not invoked"); 109 } 110 if (req == null) { 111 throw new Exception ("Handler.handleRequest not invoked"); 112 } 113 if (resp == null) { 114 throw new Exception ("Handler.handlerResponse not invoked"); 115 } 116 return true; 117 } 118 } | Popular Tags |