001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: TimeClient.java 5079 2004-07-06 13:04:06Z sauthieg $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.jtests.appclients.timeclient;
025:
026: import javax.naming.InitialContext;
027: import javax.naming.NamingException;
028: import javax.xml.namespace.QName;
029: import javax.xml.rpc.Call;
030: import javax.xml.rpc.Service;
031:
032: /**
033: * @author Guillaume Sauthier
034: */
035: public class TimeClient {
036:
037: /**
038: * Service Ref Name
039: */
040: private static final String SERVICE_REF_NAME = "java:comp/env/service/time";
041:
042: /**
043: * InitialContext
044: */
045: private InitialContext ic;
046:
047: /**
048: *
049: */
050: public TimeClient() throws Exception {
051: init();
052: }
053:
054: /**
055: *
056: */
057: private void init() throws NamingException {
058: ic = new InitialContext();
059: }
060:
061: public boolean hasBindedService() throws NamingException {
062: Object o = lookupService();
063: if (o != null) {
064: if (o instanceof Service) {
065: return true;
066: }
067: }
068: return false;
069: }
070:
071: /*
072: public boolean isServiceWellConfigured() throws NamingException {
073: Service s = (Service) lookupService();
074: if (s instanceof XXX) {
075: return true;
076: }
077: return false;
078: }
079: */
080:
081: private Object lookupService() throws NamingException {
082: return ic.lookup(SERVICE_REF_NAME);
083: }
084:
085: public static void main(String[] args) throws Exception {
086: TimeClient tc = new TimeClient();
087:
088: if (!tc.hasBindedService()) {
089: throw new Exception(
090: "TimeClient should have a Service instance binded to '"
091: + SERVICE_REF_NAME + "'");
092: }
093:
094: tc.handlersInvoked();
095: }
096:
097: /**
098: * @return
099: */
100: private boolean handlersInvoked() throws Exception {
101: Service s = (Service) lookupService();
102: Call call = s.createCall(new QName("TimePort"), new QName(
103: "jonas:Time", "getDate"));
104: call.invoke(new Object[] {});
105: StaticPassValue spv = StaticPassValue.getInstance();
106: String init = spv.getInit();
107: String req = spv.getRequest();
108: String resp = spv.getResponse();
109: if (init == null) {
110: throw new Exception("Handler.init not invoked");
111: }
112: if (req == null) {
113: throw new Exception("Handler.handleRequest not invoked");
114: }
115: if (resp == null) {
116: throw new Exception("Handler.handlerResponse not invoked");
117: }
118: return true;
119: }
120: }
|