OW2 Consortium joram

Rev

Rev 4557 | Rev 5044 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
861 fmaistre 1
/*
2
 * JORAM: Java(TM) Open Reliable Asynchronous Messaging
4364 tachker 3
 * Copyright (C) 2004 - 2011 ScalAgent Distributed Technologies
1669 afreyssin 4
 * Copyright (C) 2004 Bull SA
861 fmaistre 5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
19
 * USA.
20
 *
1669 afreyssin 21
 * Initial developer(s): Frederic Maistre (Bull SA)
22
 * Contributor(s): ScalAgent Distributed Technologies
861 fmaistre 23
 */
24
package org.objectweb.joram.client.jms.admin;
25
 
2663 tachker 26
import java.net.ConnectException;
861 fmaistre 27
import java.util.Hashtable;
1331 tachker 28
import java.util.List;
2751 afreyssin 29
import java.util.Properties;
2663 tachker 30
import java.util.Vector;
861 fmaistre 31
 
1254 afreyssin 32
import javax.jms.JMSException;
2663 tachker 33
import javax.naming.NamingException;
34
import javax.naming.Reference;
35
import javax.naming.StringRefAddr;
861 fmaistre 36
 
1254 afreyssin 37
import org.objectweb.joram.client.jms.Message;
3155 surrel 38
import org.objectweb.joram.client.jms.Queue;
4364 tachker 39
import org.objectweb.joram.shared.admin.AdminCommandConstant;
40
import org.objectweb.joram.shared.admin.AdminCommandReply;
2663 tachker 41
import org.objectweb.joram.shared.admin.AdminReply;
2889 afreyssin 42
import org.objectweb.joram.shared.admin.AdminRequest;
2663 tachker 43
import org.objectweb.joram.shared.admin.ClearSubscription;
44
import org.objectweb.joram.shared.admin.CreateUserReply;
45
import org.objectweb.joram.shared.admin.CreateUserRequest;
46
import org.objectweb.joram.shared.admin.DeleteSubscriptionMessage;
47
import org.objectweb.joram.shared.admin.DeleteUser;
4546 surrel 48
import org.objectweb.joram.shared.admin.GetDMQSettingsReply;
49
import org.objectweb.joram.shared.admin.GetDMQSettingsRequest;
50
import org.objectweb.joram.shared.admin.GetNbMaxMsgRequest;
4025 afreyssin 51
import org.objectweb.joram.shared.admin.GetNumberReply;
2663 tachker 52
import org.objectweb.joram.shared.admin.GetSubscription;
53
import org.objectweb.joram.shared.admin.GetSubscriptionMessage;
54
import org.objectweb.joram.shared.admin.GetSubscriptionMessageIds;
55
import org.objectweb.joram.shared.admin.GetSubscriptionMessageIdsRep;
56
import org.objectweb.joram.shared.admin.GetSubscriptionMessageRep;
57
import org.objectweb.joram.shared.admin.GetSubscriptionRep;
58
import org.objectweb.joram.shared.admin.GetSubscriptions;
59
import org.objectweb.joram.shared.admin.GetSubscriptionsRep;
4025 afreyssin 60
import org.objectweb.joram.shared.admin.SetDMQRequest;
61
import org.objectweb.joram.shared.admin.SetNbMaxMsgRequest;
62
import org.objectweb.joram.shared.admin.SetThresholdRequest;
2663 tachker 63
import org.objectweb.joram.shared.admin.UpdateUser;
64
import org.objectweb.joram.shared.security.Identity;
2813 afreyssin 65
import org.objectweb.joram.shared.security.SimpleIdentity;
1331 tachker 66
import org.objectweb.util.monolog.api.BasicLevel;
2889 afreyssin 67
import org.objectweb.util.monolog.api.Logger;
1331 tachker 68
 
3161 surrel 69
import fr.dyade.aaa.common.Debug;
2663 tachker 70
import fr.dyade.aaa.util.management.MXWrapper;
71
 
861 fmaistre 72
/**
73
 * The <code>User</code> class is a utility class needed for administering
74
 * JORAM users.
75
 */
1669 afreyssin 76
public class User extends AdministeredObject implements UserMBean {
2889 afreyssin 77
  /** define serialVersionUID for interoperability */
1977 tachker 78
  private static final long serialVersionUID = 1L;
2889 afreyssin 79
 
80
  public static Logger logger = Debug.getLogger(User.class.getName());
81
 
861 fmaistre 82
  /** The name of the user. */
904 fmaistre 83
  String name;
861 fmaistre 84
  /** Identifier of the user's proxy agent. */
904 fmaistre 85
  String proxyId;
861 fmaistre 86
 
1254 afreyssin 87
  // Used by jndi2 SoapObjectHelper
88
  public User() {}
861 fmaistre 89
 
90
  /**
91
   * Constructs an <code>User</code> instance.
92
   *
93
   * @param name  The name of the user.
4203 afreyssin 94
   */
95
  public User(String name) {
96
    this.name = name;
97
  }
98
 
99
  /**
100
   * Constructs an <code>User</code> instance.
101
   *
102
   * @param name  The name of the user.
861 fmaistre 103
   * @param proxyId  Identifier of the user's proxy agent.
104
   */
1254 afreyssin 105
  public User(String name, String proxyId) {
861 fmaistre 106
    this.name = name;
107
    this.proxyId = proxyId;
108
  }
109
 
2889 afreyssin 110
 
861 fmaistre 111
  /** Returns a string view of this <code>User</code> instance. */
1788 afreyssin 112
  public String toString() {
861 fmaistre 113
    return "User[" + name + "]:" + proxyId;
114
  }
115
 
883 fmaistre 116
 
117
  /** Returns the user name. */
1788 afreyssin 118
  public String getName() {
883 fmaistre 119
    return name;
120
  }
121
 
122
  /** Provides a reliable way to compare <code>User</code> instances. */
1788 afreyssin 123
  public boolean equals(Object o) {
883 fmaistre 124
    if (! (o instanceof User))
125
      return false;
126
 
127
    User other = (User) o;
128
 
4025 afreyssin 129
    return other.proxyId.equals(proxyId);
883 fmaistre 130
  }
2889 afreyssin 131
 
4025 afreyssin 132
  public int hashCode() {
133
    return getName().hashCode();
134
  }
135
 
861 fmaistre 136
  /**
2889 afreyssin 137
   * Administration wrapper used to perform administration stuff.
138
   * <p>
139
   * It is defined through AdminModule element, it is closed at the end of
140
   * the script. if it is not defined the wrapper set at creation is used, if
141
   * none the static AdminModule connection is used.
142
   */
143
  AdminWrapper wrapper = null;
144
 
145
  /**
146
   * Returns the administration wrapper to use.
147
   *
148
   * @return The wrapper to use.
149
   * @throws ConnectException if no wrapper is defined.
150
   */
151
  protected final AdminWrapper getWrapper() throws ConnectException {
2988 afreyssin 152
    if ((wrapper != null) && (! wrapper.isClosed()))
153
      return wrapper;
2889 afreyssin 154
    return AdminModule.getWrapper();
155
  }
156
 
157
  /**
158
   * Sets the administration wrapper to use.
159
   * If not set the AdminModule static connection is used by default.
160
   *
161
   * @param wrapper The wrapper to use or null to unset.
162
   */
163
  public void setWrapper(AdminWrapper wrapper) {
164
    this.wrapper = wrapper;
165
  }
166
 
167
  /**
168
   * Method actually sending an <code>AdminRequest</code> instance to
169
   * the platform and getting an <code>AdminReply</code> instance.
170
   *
171
   * @param request the administration request to send
172
   * @return  the reply message
173
   *
174
   * @exception ConnectException  If the connection to the platform fails.
175
   * @exception AdminException  If the platform's reply is invalid, or if
176
   *              the request failed.
177
   */
178
  public final AdminReply doRequest(AdminRequest request) throws AdminException, ConnectException {
179
    return getWrapper().doRequest(request);
180
  }
181
 
182
  /**
2795 surrel 183
   * Admin method creating a user for a given server and instantiating the
861 fmaistre 184
   * corresponding <code>User</code> object.
185
   * <p>
186
   * If the user has already been set on this server, the method simply
187
   * returns the corresponding <code>User</code> object. Its fails if the
188
   * target server does not belong to the platform, or if a proxy could not
189
   * be deployed server side for a new user.
2889 afreyssin 190
   * <p>
191
   * Be careful this method use the static AdminModule connection.
861 fmaistre 192
   *
193
   * @param name  Name of the user.
194
   * @param password  Password of the user.
195
   * @param serverId  The identifier of the user's server.
196
   *
197
   * @exception ConnectException  If the connection fails.
198
   * @exception AdminException  If the request fails.
199
   */
2889 afreyssin 200
  public static User create(String name, String password,
201
                            int serverId) throws ConnectException, AdminException {
2813 afreyssin 202
    return create(name, password, serverId, SimpleIdentity.class.getName());
861 fmaistre 203
  }
2889 afreyssin 204
 
861 fmaistre 205
  /**
2795 surrel 206
   * Admin method creating a user on the local server and instantiating the
861 fmaistre 207
   * corresponding <code>User</code> object.
208
   * <p>
209
   * If the user has already been set on this server, the method simply
210
   * returns the corresponding <code>User</code> object. It fails if a
211
   * proxy could not be deployed server side for a new user.
2889 afreyssin 212
   * <p>
213
   * Be careful this method use the static AdminModule connection.
861 fmaistre 214
   *
215
   * @param name  Name of the user.
216
   * @param password  Password of the user.
217
   *
218
   * @exception ConnectException  If the connection fails.
219
   * @exception AdminException  If the request fails.
220
   */
2889 afreyssin 221
  public static User create(String name, String password) throws ConnectException, AdminException {
2813 afreyssin 222
    return create(name, password, AdminModule.getLocalServerId(), SimpleIdentity.class.getName());
861 fmaistre 223
  }
2889 afreyssin 224
 
861 fmaistre 225
  /**
2795 surrel 226
   * Admin method creating a user for a given server and instantiating the
2663 tachker 227
   * corresponding <code>User</code> object.
228
   * <p>
229
   * If the user has already been set on this server, the method simply
230
   * returns the corresponding <code>User</code> object. Its fails if the
231
   * target server does not belong to the platform, or if a proxy could not
232
   * be deployed server side for a new user.
2889 afreyssin 233
   * <p>
234
   * Be careful this method use the static AdminModule connection.
2663 tachker 235
   *
236
   * @param name  Name of the user.
237
   * @param password  Password of the user.
238
   * @param serverId  The identifier of the user's server.
2795 surrel 239
   * @param identityClassName user/password or JAAS... (default SimpleIdentity).
2663 tachker 240
   *
241
   * @exception ConnectException  If the connection fails.
242
   * @exception AdminException  If the request fails.
243
   */
2889 afreyssin 244
  public static User create(String name, String password,
245
                            int serverId,
246
                            String identityClassName) throws ConnectException, AdminException {
4393 tachker 247
  	return create(name, password, serverId, identityClassName, null);
248
  }
249
 
250
  /**
251
   * Admin method creating a user for a given server and instantiating the
252
   * corresponding <code>User</code> object.
253
   * <p>
254
   * If the user has already been set on this server, the method simply
255
   * returns the corresponding <code>User</code> object. Its fails if the
256
   * target server does not belong to the platform, or if a proxy could not
257
   * be deployed server side for a new user.
258
   * <p>
259
   * Be careful this method use the static AdminModule connection.
260
   *
261
   * @param name  Name of the user.
262
   * @param password  Password of the user.
263
   * @param serverId  The identifier of the user's server.
264
   * @param identityClassName user/password or JAAS... (default SimpleIdentity).
265
   * @param prop properties
266
   *
267
   * @exception ConnectException  If the connection fails.
268
   * @exception AdminException  If the request fails.
269
   */
270
  public static User create(String name, String password,
271
                            int serverId,
272
                            String identityClassName,
273
                            Properties prop) throws ConnectException, AdminException {
2663 tachker 274
    Identity identity = createIdentity(name, password, identityClassName);
2889 afreyssin 275
 
4203 afreyssin 276
    User user = new User(name);
4393 tachker 277
    AdminReply reply = user.getWrapper().doRequest(new CreateUserRequest(identity, serverId, prop));
4203 afreyssin 278
    user.proxyId = ((CreateUserReply) reply).getProxId();
279
 
2931 afreyssin 280
    // Be careful, MBean registration is now done explicitly
2889 afreyssin 281
 
282
    return user;
283
  }
284
 
2931 afreyssin 285
  // Object name of the MBean if it is registered.
2889 afreyssin 286
  transient protected String JMXBeanName = null;
287
 
2931 afreyssin 288
  public String registerMBean(String base) {
3125 afreyssin 289
    int sid = Integer.parseInt(proxyId.substring(proxyId.indexOf('.') +1, proxyId.lastIndexOf('.')));
2889 afreyssin 290
    StringBuffer buf = new StringBuffer();
3060 afreyssin 291
    buf.append(base);
3125 afreyssin 292
    buf.append(":type=User,location=server#").append(sid).append(",name=").append(getName()).append('[').append(getProxyId()).append(']');
2889 afreyssin 293
    JMXBeanName = buf.toString();
2931 afreyssin 294
 
2663 tachker 295
    try {
2931 afreyssin 296
      MXWrapper.registerMBean(this, JMXBeanName);
2663 tachker 297
    } catch (Exception e) {
2971 afreyssin 298
      if (logger.isLoggable(BasicLevel.DEBUG))
299
        logger.log(BasicLevel.DEBUG, "User.registerMBean: " + JMXBeanName, e);
2663 tachker 300
    }
2931 afreyssin 301
 
302
    return JMXBeanName;
2663 tachker 303
  }
2889 afreyssin 304
 
305
  public void unregisterMBean() {
4557 surrel 306
    if (JMXBeanName == null)
307
      return;
2889 afreyssin 308
 
309
    try {
2931 afreyssin 310
      MXWrapper.unregisterMBean(JMXBeanName);
2889 afreyssin 311
    } catch (Exception e) {
2971 afreyssin 312
      if (logger.isLoggable(BasicLevel.DEBUG))
313
        logger.log(BasicLevel.DEBUG, "User.unregisterMBean: " + JMXBeanName, e);
2889 afreyssin 314
    }
315
  }
316
 
2663 tachker 317
  /**
318
   * Create a user Identity.
319
   *
320
   * @param user              Name of the user.
321
   * @param passwd            Password of the user.
322
   * @param identityClassName identity class name (simple, jaas).
323
   * @return identity user Identity.
324
   * @throws AdminException
325
   */
2889 afreyssin 326
  private static Identity createIdentity(String user, String passwd,
327
                                         String identityClassName) throws AdminException {
2663 tachker 328
    Identity identity = null;
329
    try {
330
      Class clazz = Class.forName(identityClassName);
331
      identity = (Identity) clazz.newInstance();
332
      if (passwd != null)
333
        identity.setIdentity(user, passwd);
334
      else
335
        identity.setUserName(user);
336
    } catch (Exception e) {
337
      throw new AdminException(e.getMessage());
338
    }
339
    return identity;
340
  }
2889 afreyssin 341
 
2663 tachker 342
  /**
861 fmaistre 343
   * Admin method updating this user identification.
344
   * <p>
345
   * The request fails if the user does not exist server side, or if the new
346
   * identification is already taken by a user on the same server.
347
   *
348
   * @param newName  The new name of the user.
349
   * @param newPassword  The new password of the user.
350
   *
351
   * @exception ConnectException  If the connection fails.
352
   * @exception AdminException  If the request fails.
353
   */
2889 afreyssin 354
  public void update(String newName, String newPassword) throws ConnectException, AdminException {
2813 afreyssin 355
    update(newName, newPassword, SimpleIdentity.class.getName());
2663 tachker 356
  }
2889 afreyssin 357
 
2663 tachker 358
  /**
359
   * Admin method updating this user identification.
360
   * <p>
361
   * The request fails if the user does not exist server side, or if the new
362
   * identification is already taken by a user on the same server.
363
   *
364
   * @param newName  The new name of the user.
365
   * @param newPassword  The new password of the user.
2795 surrel 366
   * @param identityClassName user/password or JAAS... (default SimpleIdentity).
2663 tachker 367
   *
368
   * @exception ConnectException  If the connection fails.
369
   * @exception AdminException  If the request fails.
370
   */
2889 afreyssin 371
  public void update(String newName, String newPassword,
372
                     String identityClassName) throws ConnectException, AdminException {
2663 tachker 373
    Identity newIdentity = createIdentity(newName, newPassword, identityClassName);
2889 afreyssin 374
    doRequest(new UpdateUser(name, proxyId, newIdentity));
861 fmaistre 375
    name = newName;
376
  }
377
 
378
  /**
379
   * Removes this user.
380
   *
381
   * @exception ConnectException  If the connection fails.
382
   * @exception AdminException  Never thrown.
383
   */
1331 tachker 384
  public void delete() throws ConnectException, AdminException {
2889 afreyssin 385
    doRequest(new DeleteUser(name, proxyId));
2931 afreyssin 386
    unregisterMBean();
861 fmaistre 387
  }
388
 
389
  /**
390
   * Admin method setting a given dead message queue for this user.
391
   * <p>
392
   * The request fails if the user is deleted server side.
393
   *
394
   * @param dmq  The dead message queue to be set.
395
   *
396
   * @exception ConnectException  If the connection fails.
397
   * @exception AdminException  If the request fails.
398
   */
3155 surrel 399
  public void setDMQ(Queue dmq) throws ConnectException, AdminException {
1873 tachker 400
    setDMQId(dmq.getName());
861 fmaistre 401
  }
402
 
403
  /**
1873 tachker 404
   * Admin method setting a given dead message queue for this user.
405
   * <p>
406
   * The request fails if the user is deleted server side.
407
   *
408
   * @param dmqId  The dead message queue Id to be set.
409
   *
410
   * @exception ConnectException  If the connection fails.
411
   * @exception AdminException  If the request fails.
412
   */
413
  public void setDMQId(String dmqId) throws ConnectException, AdminException {
4025 afreyssin 414
    doRequest(new SetDMQRequest(proxyId, dmqId));
1873 tachker 415
  }
4025 afreyssin 416
 
417
  /**
418
   * Monitoring method returning the dead message queue of this user,
419
   * null if not set.
861 fmaistre 420
   * <p>
421
   * The request fails if the user is deleted server side.
422
   *
4025 afreyssin 423
   * @exception ConnectException  If the administration connection is closed or broken.
861 fmaistre 424
   * @exception AdminException  If the request fails.
425
   */
4025 afreyssin 426
  public Queue getDMQ() throws ConnectException, AdminException {
427
    String dmqId = getDMQId();
428
    Queue dmq = null;
429
    if (dmqId != null) {
430
      dmq = new Queue(dmqId);
431
      if (wrapper != null)
432
        dmq.setWrapper(wrapper);
433
    }
2889 afreyssin 434
    return dmq;
861 fmaistre 435
  }
436
 
4025 afreyssin 437
  /**
438
   * Monitoring method returning the dead message queue id of this user,
439
   * null if not set.
1873 tachker 440
   * <p>
4025 afreyssin 441
   * The request fails if the destination is deleted server side.
1873 tachker 442
   *
4025 afreyssin 443
   * @exception ConnectException  If the administration connection is closed or broken.
1873 tachker 444
   * @exception AdminException  If the request fails.
445
   */
446
  public String getDMQId() throws ConnectException, AdminException {
4025 afreyssin 447
    GetDMQSettingsRequest request = new GetDMQSettingsRequest(proxyId);
448
    GetDMQSettingsReply reply = (GetDMQSettingsReply) doRequest(request);
449
 
450
    return reply.getDMQName();
1873 tachker 451
  }
2889 afreyssin 452
 
4753 afreyssin 453
  /**
454
   * Admin method setting a given value as the threshold for this user.
455
   * <p>
456
   * The request fails if the user is deleted server side.
457
   *
458
   * @param threshold  The threshold value to be set (-1 for unsetting
459
   *                   previous value).
460
   *
461
   * @exception ConnectException  If the connection fails.
462
   * @exception AdminException  If the request fails.
463
   */
464
  public void setThreshold(int threshold) throws ConnectException, AdminException {
465
    doRequest(new SetThresholdRequest(proxyId, threshold));
466
  }
467
 
468
  /**
469
   * Admin method setting a given value as the threshold for a particular
470
   * subscription of this user.
471
   * <p>
472
   * The request fails if the user is deleted server side.
473
   *
474
   * @param subname    The subscription name.
475
   * @param threshold  The threshold value to be set (-1 for unsetting
476
   *                   previous value).
477
   *
478
   * @exception ConnectException  If the connection fails.
479
   * @exception AdminException  If the request fails.
480
   */
481
  public void setThreshold(String subname, int threshold) throws ConnectException, AdminException {
482
    doRequest(new SetThresholdRequest(proxyId, subname, threshold));
483
  }
484
 
1873 tachker 485
  /**
861 fmaistre 486
   * Returns the threshold for this user, -1 if not set.
487
   * <p>
488
   * The request fails if the user is deleted server side.
489
   *
490
   * @exception ConnectException  If the connection fails.
491
   * @exception AdminException  If the request fails.
492
   */
1788 afreyssin 493
  public int getThreshold() throws ConnectException, AdminException {
4025 afreyssin 494
    GetDMQSettingsRequest request = new GetDMQSettingsRequest(proxyId);
495
    GetDMQSettingsReply reply = (GetDMQSettingsReply) doRequest(request);
2889 afreyssin 496
 
4753 afreyssin 497
    return reply.getThreshold();
861 fmaistre 498
  }
499
 
4753 afreyssin 500
  /**
501
   * Returns the threshold for a particular subscription of this user,
502
   * -1 if not set.
503
   * <p>
504
   * The request fails if the user is deleted server side.
505
   *
506
   * @param subname The subscription name.
507
   *
508
   * @exception ConnectException  If the connection fails.
509
   * @exception AdminException  If the request fails.
510
   */
511
  public int getThreshold(String subname) throws ConnectException, AdminException {
512
    GetDMQSettingsRequest request = new GetDMQSettingsRequest(proxyId, subname);
513
    GetDMQSettingsReply reply = (GetDMQSettingsReply) doRequest(request);
514
 
515
    return reply.getThreshold();
516
  }
517
 
1254 afreyssin 518
  /**
1331 tachker 519
   * Admin method setting nbMaxMsg for this subscription.
520
   * <p>
521
   * The request fails if the sub is deleted server side.
522
   *
523
   * @param subName the name of the subscription.
524
   * @param nbMaxMsg  nb Max of Message (-1 no limit).
525
   *
526
   * @exception ConnectException  If the admin connection is closed or broken.
527
   * @exception AdminException  If the request fails.
528
   */
2889 afreyssin 529
  public void setNbMaxMsg(String subName, int nbMaxMsg) throws ConnectException, AdminException {
530
    //  TODO: Subscription sub = getSubscription(subName);
4025 afreyssin 531
    doRequest(new SetNbMaxMsgRequest(proxyId, nbMaxMsg, subName));
1331 tachker 532
  }
533
 
534
  /**
535
   * Monitoring method returning the nbMaxMsg of this subscription, -1 if no limit.
536
   * <p>
537
   * The request fails if the sub is deleted server side.
538
   *
539
   * @param subName the name of the subscription.
540
   *
541
   * @exception ConnectException  If the admin connection is closed or broken.
542
   * @exception AdminException  If the request fails.
543
   */
2889 afreyssin 544
  public int getNbMaxMsg(String subName) throws ConnectException, AdminException {
545
    //  TODO: Subscription sub = getSubscription(subName);
4025 afreyssin 546
    GetNbMaxMsgRequest request = new GetNbMaxMsgRequest(proxyId, subName);
547
    GetNumberReply reply = (GetNumberReply) doRequest(request);
548
    return reply.getNumber();
1331 tachker 549
  }
550
 
551
  /**
1254 afreyssin 552
   * Returns the subscriptions owned by a user.
553
   *
3080 afreyssin 554
   * @return The subscriptions owned by the user.
1254 afreyssin 555
   *
3080 afreyssin 556
   * @exception AdminException If an error is raised by the administration operation.
1254 afreyssin 557
   * @exception ConnectException  If the admin connection is not established.
558
   */
2889 afreyssin 559
  public Subscription[] getSubscriptions() throws AdminException, ConnectException {
560
    GetSubscriptionsRep reply = (GetSubscriptionsRep) doRequest(new GetSubscriptions(proxyId));
561
 
1254 afreyssin 562
    String[] subNames = reply.getSubNames();
563
    String[] topicIds = reply.getTopicIds();
564
    int[] messageCounts = reply.getMessageCounts();
565
    boolean[] durable = reply.getDurable();
2889 afreyssin 566
 
1254 afreyssin 567
    Subscription[] res = new Subscription[subNames.length];
568
    for (int i = 0; i < res.length; i++) {
2889 afreyssin 569
      res[i] = new Subscription(subNames[i], topicIds[i], messageCounts[i], durable[i]);
1254 afreyssin 570
    }
571
    return res;
572
  }
573
 
1331 tachker 574
  /** used by MBean jmx */
2889 afreyssin 575
  public List getSubscriptionList() throws AdminException, ConnectException {
1331 tachker 576
    Vector list = new Vector();
577
    Subscription[] sub = getSubscriptions();
578
    for (int i = 0; i < sub.length; i++) {
579
      list.add(sub[i].toString());
580
    }
581
    return list;
582
  }
583
 
1254 afreyssin 584
  /**
585
   * Returns a subscription.
586
   *
587
   * @param subName the name of the subscription.
3080 afreyssin 588
   * @return The subscription.
1254 afreyssin 589
   *
3080 afreyssin 590
   * @exception AdminException If an error is raised by the administration operation.
1254 afreyssin 591
   * @exception ConnectException  If the admin connection is not established.
592
   */
2587 afreyssin 593
  public Subscription getSubscription(String subName) throws AdminException, ConnectException {
2889 afreyssin 594
    GetSubscriptionRep reply = (GetSubscriptionRep) doRequest(new GetSubscription(proxyId, subName));
595
    Subscription sub = new Subscription(subName, reply.getTopicId(), reply.getMessageCount(), reply.getDurable());
596
 
597
    return sub;
1254 afreyssin 598
  }
599
 
2587 afreyssin 600
  public String getSubscriptionString(String subName) throws AdminException, ConnectException {
601
    return getSubscription(subName).toString();
1331 tachker 602
  }
603
 
2587 afreyssin 604
  public String[] getMessageIds(String subName) throws AdminException, ConnectException {
2751 afreyssin 605
    GetSubscriptionMessageIdsRep reply =
2889 afreyssin 606
      (GetSubscriptionMessageIdsRep) doRequest(new GetSubscriptionMessageIds(proxyId, subName));
1254 afreyssin 607
    return reply.getMessageIds();
608
  }
609
 
2751 afreyssin 610
  public Message getMessage(String subName,
611
                            String msgId) throws AdminException, ConnectException, JMSException {
612
    GetSubscriptionMessageRep reply =
2889 afreyssin 613
      (GetSubscriptionMessageRep) doRequest(new GetSubscriptionMessage(proxyId, subName, msgId, true));
2751 afreyssin 614
    return Message.wrapMomMessage(null, reply.getMessage());
615
  }
2889 afreyssin 616
 
2751 afreyssin 617
  public String getMessageDigest(String subName,
618
                                 String msgId) throws AdminException, ConnectException, JMSException {
619
    GetSubscriptionMessageRep reply =
2889 afreyssin 620
      (GetSubscriptionMessageRep) doRequest(new GetSubscriptionMessage(proxyId, subName, msgId, true));
2751 afreyssin 621
    Message msg =  Message.wrapMomMessage(null, reply.getMessage());
2889 afreyssin 622
 
2751 afreyssin 623
    StringBuffer strbuf = new StringBuffer();
624
    strbuf.append("Message: ").append(msg.getJMSMessageID());
625
    strbuf.append("\n\tTo: ").append(msg.getJMSDestination());
626
    strbuf.append("\n\tCorrelationId: ").append(msg.getJMSCorrelationID());
627
    strbuf.append("\n\tDeliveryMode: ").append(msg.getJMSDeliveryMode());
628
    strbuf.append("\n\tExpiration: ").append(msg.getJMSExpiration());
629
    strbuf.append("\n\tPriority: ").append(msg.getJMSPriority());
630
    strbuf.append("\n\tRedelivered: ").append(msg.getJMSRedelivered());
631
    strbuf.append("\n\tReplyTo: ").append(msg.getJMSReplyTo());
632
    strbuf.append("\n\tTimestamp: ").append(msg.getJMSTimestamp());
633
    strbuf.append("\n\tType: ").append(msg.getJMSType());
634
    return strbuf.toString();
2889 afreyssin 635
  }
2751 afreyssin 636
 
637
  public Properties getMessageHeader(String subName,
638
                                     String msgId) throws AdminException, ConnectException, JMSException {
639
    GetSubscriptionMessageRep reply =
2889 afreyssin 640
      (GetSubscriptionMessageRep) doRequest(new GetSubscriptionMessage(proxyId, subName, msgId, false));
2751 afreyssin 641
    Message msg =  Message.wrapMomMessage(null, reply.getMessage());
642
 
643
    Properties prop = new Properties();
644
    prop.setProperty("JMSMessageID", msg.getJMSMessageID());
645
    prop.setProperty("JMSDestination", msg.getJMSDestination().toString());
646
    if (msg.getJMSCorrelationID() != null)
647
      prop.setProperty("JMSCorrelationID", msg.getJMSCorrelationID());
648
    prop.setProperty("JMSDeliveryMode",
649
                     new Integer(msg.getJMSDeliveryMode()).toString());
650
    prop.setProperty("JMSExpiration",
651
                     new Long(msg.getJMSExpiration()).toString());
652
    prop.setProperty("JMSPriority",
653
                     new Integer(msg.getJMSPriority()).toString());
654
    prop.setProperty("JMSRedelivered",
655
                     new Boolean(msg.getJMSRedelivered()).toString());
656
    if (msg.getJMSReplyTo() != null)
657
      prop.setProperty("JMSReplyTo", msg.getJMSReplyTo().toString());
658
    prop.setProperty("JMSTimestamp",
659
                     new Long(msg.getJMSTimestamp()).toString());
660
    if (msg.getJMSType() != null)
661
      prop.setProperty("JMSType", msg.getJMSType());
662
 
663
    return prop;
2889 afreyssin 664
  }
2751 afreyssin 665
 
2889 afreyssin 666
  public Properties getMessageProperties(String subName,
667
                                         String msgId) throws AdminException, ConnectException, JMSException {
668
    GetSubscriptionMessageRep reply =
669
      (GetSubscriptionMessageRep) doRequest(new GetSubscriptionMessage(proxyId, subName, msgId, false));
670
    Message msg =  Message.wrapMomMessage(null, reply.getMessage());
2751 afreyssin 671
 
2889 afreyssin 672
    Properties prop = new Properties();
673
    msg.getProperties(prop);
2751 afreyssin 674
 
2889 afreyssin 675
    return prop;
676
  }
2751 afreyssin 677
 
678
  /**
4557 surrel 679
   * Add interceptors
4364 tachker 680
   *
681
   * @param interceptors list of string className interceptor (separate with ",")
682
   * @throws ConnectException
683
   * @throws AdminException
684
   */
685
  public void addInterceptorsIN(String interceptors) throws ConnectException, AdminException {
686
  	Properties prop = new Properties();
4393 tachker 687
    prop.put(AdminCommandConstant.INTERCEPTORS_IN, interceptors);
4364 tachker 688
    getWrapper().processAdmin(getProxyId(), AdminCommandConstant.CMD_ADD_INTERCEPTORS, prop);
689
  }
690
 
691
  /**
4557 surrel 692
   * Get interceptors.
4364 tachker 693
   *
694
   * @return list of string className interceptor (separate with ",")
695
   * @throws ConnectException
696
   * @throws AdminException
697
   */
698
  public String getInterceptorsIN() throws ConnectException, AdminException {
4557 surrel 699
    AdminCommandReply reply = (AdminCommandReply) getWrapper().processAdmin(getProxyId(),
700
        AdminCommandConstant.CMD_GET_INTERCEPTORS, null);
4393 tachker 701
    return (String) reply.getProp().get(AdminCommandConstant.INTERCEPTORS_IN);
4364 tachker 702
  }
703
 
704
  /**
4557 surrel 705
   * Remove interceptors
4364 tachker 706
   *
707
   * @param interceptors list of string className interceptor (separate with ",")
708
   * @throws ConnectException
709
   * @throws AdminException
710
   */
711
  public void removeInterceptorsIN(String interceptors) throws ConnectException, AdminException {
712
  	Properties prop = new Properties();
4393 tachker 713
  	prop.put(AdminCommandConstant.INTERCEPTORS_IN, interceptors);
4557 surrel 714
    getWrapper().processAdmin(getProxyId(), AdminCommandConstant.CMD_REMOVE_INTERCEPTORS, prop);
4364 tachker 715
  }
716
 
717
  /**
4557 surrel 718
   * Add interceptors
4364 tachker 719
   *
720
   * @param interceptors list of string className interceptor (separate with ",")
721
   * @throws ConnectException
722
   * @throws AdminException
723
   */
724
  public void addInterceptorsOUT(String interceptors) throws ConnectException, AdminException {
725
  	Properties prop = new Properties();
4393 tachker 726
    prop.put(AdminCommandConstant.INTERCEPTORS_OUT, interceptors);
4364 tachker 727
    getWrapper().processAdmin(getProxyId(), AdminCommandConstant.CMD_ADD_INTERCEPTORS, prop);
728
  }
729
 
730
  /**
4557 surrel 731
   * Get interceptors.
4364 tachker 732
   *
733
   * @return list of string className interceptor (separate with ",")
734
   * @throws ConnectException
735
   * @throws AdminException
736
   */
737
  public String getInterceptorsOUT() throws ConnectException, AdminException {
4557 surrel 738
    AdminCommandReply reply = (AdminCommandReply) getWrapper().processAdmin(getProxyId(),
739
        AdminCommandConstant.CMD_GET_INTERCEPTORS, null);
4393 tachker 740
    return (String) reply.getProp().get(AdminCommandConstant.INTERCEPTORS_OUT);
4364 tachker 741
  }
742
 
743
  /**
4557 surrel 744
   * Remove interceptors
4364 tachker 745
   *
746
   * @param interceptors list of string className interceptor (separate with ",")
747
   * @throws ConnectException
748
   * @throws AdminException
749
   */
750
  public void removeInterceptorsOUT(String interceptors) throws ConnectException, AdminException {
751
  	Properties prop = new Properties();
4393 tachker 752
  	prop.put(AdminCommandConstant.INTERCEPTORS_OUT, interceptors);
4557 surrel 753
    getWrapper().processAdmin(getProxyId(), AdminCommandConstant.CMD_REMOVE_INTERCEPTORS, prop);
4364 tachker 754
  }
755
 
756
  /**
4557 surrel 757
   * Replace interceptor IN
4393 tachker 758
   *
759
   * @param newInterceptor the new className interceptor.
760
   * @param oldInterceptor the old className interceptor.
761
   * @throws ConnectException
762
   * @throws AdminException
763
   */
764
  public void replaceInterceptorIN(String newInterceptor, String oldInterceptor) throws ConnectException, AdminException {
765
  	Properties prop = new Properties();
766
    prop.put(AdminCommandConstant.INTERCEPTORS_IN_NEW, newInterceptor);
767
    prop.put(AdminCommandConstant.INTERCEPTORS_IN_OLD, oldInterceptor);
768
    getWrapper().processAdmin(getProxyId(), AdminCommandConstant.CMD_REPLACE_INTERCEPTORS, prop);
769
  }
770
 
771
  /**
4557 surrel 772
   * Replace interceptor OUT
4393 tachker 773
   *
774
   * @param newInterceptor the new className interceptor.
775
   * @param oldInterceptor the old className interceptor.
776
   * @throws ConnectException
777
   * @throws AdminException
778
   */
779
  public void replaceInterceptorOUT(String newInterceptor, String oldInterceptor) throws ConnectException, AdminException {
780
  	Properties prop = new Properties();
781
    prop.put(AdminCommandConstant.INTERCEPTORS_OUT_NEW, newInterceptor);
782
    prop.put(AdminCommandConstant.INTERCEPTORS_OUT_OLD, oldInterceptor);
783
    getWrapper().processAdmin(getProxyId(), AdminCommandConstant.CMD_REPLACE_INTERCEPTORS, prop);
784
  }
785
 
786
  /**
2751 afreyssin 787
   * @deprecated
788
   */
1669 afreyssin 789
  public Message readMessage(String subName,
790
                             String msgId) throws AdminException, ConnectException, JMSException {
2751 afreyssin 791
    return getMessage(subName, msgId);
1254 afreyssin 792
  }
793
 
2889 afreyssin 794
  public void deleteMessage(String subName,
795
                            String msgId)  throws AdminException, ConnectException {
796
    doRequest(new DeleteSubscriptionMessage(proxyId, subName, msgId));
1254 afreyssin 797
  }
798
 
2889 afreyssin 799
  public void clearSubscription(String subName) throws AdminException, ConnectException {
800
    doRequest(new ClearSubscription(proxyId, subName));
1254 afreyssin 801
  }
802
 
2889 afreyssin 803
 
861 fmaistre 804
  /** Returns the identifier of the user's proxy. */
1788 afreyssin 805
  public String getProxyId() {
861 fmaistre 806
    return proxyId;
807
  }
808
 
1788 afreyssin 809
  /** Sets the naming reference of a connection factory. */
810
  public void toReference(Reference ref) throws NamingException {
861 fmaistre 811
    ref.add(new StringRefAddr("user.name", name));
812
    ref.add(new StringRefAddr("user.id", proxyId));
813
  }
814
 
1788 afreyssin 815
  /** Restores the administered object from a naming reference. */
816
  public void fromReference(Reference ref) throws NamingException {
817
    name = (String) ref.get("user.name").getContent();
818
    proxyId = (String) ref.get("user.id").getContent();
819
  }
820
 
861 fmaistre 821
  /**
2795 surrel 822
   * Codes an <code>User</code> instance as a Hashtable for traveling
861 fmaistre 823
   * through the SOAP protocol.
824
   */
825
  public Hashtable code() {
1254 afreyssin 826
    Hashtable h = new Hashtable();
2889 afreyssin 827
    h.put("name", name);
828
    h.put("proxyId", proxyId);
861 fmaistre 829
    return h;
830
  }
831
 
832
  /**
2795 surrel 833
   * Decodes an <code>User</code> which traveled through the SOAP protocol.
861 fmaistre 834
   */
1254 afreyssin 835
  public void decode(Hashtable h) {
836
    name = (String) h.get("name");
837
    proxyId = (String) h.get("proxyId");
861 fmaistre 838
  }
839
}