OW2 Consortium joram

Rev

Rev 4546 | Rev 4753 | 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
  }
2889 afreyssin 416
 
1873 tachker 417
  /**
861 fmaistre 418
   * Admin method setting a given value as the threshold for this user.
419
   * <p>
420
   * The request fails if the user is deleted server side.
421
   *
2746 afreyssin 422
   * @param threshold  The threshold value to be set (-1 for unsetting
423
   *                   previous value).
861 fmaistre 424
   *
425
   * @exception ConnectException  If the connection fails.
426
   * @exception AdminException  If the request fails.
427
   */
2889 afreyssin 428
  public void setThreshold(int threshold) throws ConnectException, AdminException {
4025 afreyssin 429
    doRequest(new SetThresholdRequest(proxyId, threshold));
861 fmaistre 430
  }
4025 afreyssin 431
 
432
  /**
433
   * Monitoring method returning the dead message queue of this user,
434
   * null if not set.
861 fmaistre 435
   * <p>
436
   * The request fails if the user is deleted server side.
437
   *
4025 afreyssin 438
   * @exception ConnectException  If the administration connection is closed or broken.
861 fmaistre 439
   * @exception AdminException  If the request fails.
440
   */
4025 afreyssin 441
  public Queue getDMQ() throws ConnectException, AdminException {
442
    String dmqId = getDMQId();
443
    Queue dmq = null;
444
    if (dmqId != null) {
445
      dmq = new Queue(dmqId);
446
      if (wrapper != null)
447
        dmq.setWrapper(wrapper);
448
    }
2889 afreyssin 449
    return dmq;
861 fmaistre 450
  }
451
 
4025 afreyssin 452
  /**
453
   * Monitoring method returning the dead message queue id of this user,
454
   * null if not set.
1873 tachker 455
   * <p>
4025 afreyssin 456
   * The request fails if the destination is deleted server side.
1873 tachker 457
   *
4025 afreyssin 458
   * @exception ConnectException  If the administration connection is closed or broken.
1873 tachker 459
   * @exception AdminException  If the request fails.
460
   */
461
  public String getDMQId() throws ConnectException, AdminException {
4025 afreyssin 462
    GetDMQSettingsRequest request = new GetDMQSettingsRequest(proxyId);
463
    GetDMQSettingsReply reply = (GetDMQSettingsReply) doRequest(request);
464
 
465
    return reply.getDMQName();
1873 tachker 466
  }
2889 afreyssin 467
 
1873 tachker 468
  /**
861 fmaistre 469
   * Returns the threshold for this user, -1 if not set.
470
   * <p>
471
   * The request fails if the user is deleted server side.
472
   *
473
   * @exception ConnectException  If the connection fails.
474
   * @exception AdminException  If the request fails.
475
   */
1788 afreyssin 476
  public int getThreshold() throws ConnectException, AdminException {
4025 afreyssin 477
    GetDMQSettingsRequest request = new GetDMQSettingsRequest(proxyId);
478
    GetDMQSettingsReply reply = (GetDMQSettingsReply) doRequest(request);
2889 afreyssin 479
 
4025 afreyssin 480
      return reply.getThreshold();
861 fmaistre 481
  }
482
 
1254 afreyssin 483
  /**
1331 tachker 484
   * Admin method setting nbMaxMsg for this subscription.
485
   * <p>
486
   * The request fails if the sub is deleted server side.
487
   *
488
   * @param subName the name of the subscription.
489
   * @param nbMaxMsg  nb Max of Message (-1 no limit).
490
   *
491
   * @exception ConnectException  If the admin connection is closed or broken.
492
   * @exception AdminException  If the request fails.
493
   */
2889 afreyssin 494
  public void setNbMaxMsg(String subName, int nbMaxMsg) throws ConnectException, AdminException {
495
    //  TODO: Subscription sub = getSubscription(subName);
4025 afreyssin 496
    doRequest(new SetNbMaxMsgRequest(proxyId, nbMaxMsg, subName));
1331 tachker 497
  }
498
 
499
  /**
500
   * Monitoring method returning the nbMaxMsg of this subscription, -1 if no limit.
501
   * <p>
502
   * The request fails if the sub is deleted server side.
503
   *
504
   * @param subName the name of the subscription.
505
   *
506
   * @exception ConnectException  If the admin connection is closed or broken.
507
   * @exception AdminException  If the request fails.
508
   */
2889 afreyssin 509
  public int getNbMaxMsg(String subName) throws ConnectException, AdminException {
510
    //  TODO: Subscription sub = getSubscription(subName);
4025 afreyssin 511
    GetNbMaxMsgRequest request = new GetNbMaxMsgRequest(proxyId, subName);
512
    GetNumberReply reply = (GetNumberReply) doRequest(request);
513
    return reply.getNumber();
1331 tachker 514
  }
515
 
516
  /**
1254 afreyssin 517
   * Returns the subscriptions owned by a user.
518
   *
3080 afreyssin 519
   * @return The subscriptions owned by the user.
1254 afreyssin 520
   *
3080 afreyssin 521
   * @exception AdminException If an error is raised by the administration operation.
1254 afreyssin 522
   * @exception ConnectException  If the admin connection is not established.
523
   */
2889 afreyssin 524
  public Subscription[] getSubscriptions() throws AdminException, ConnectException {
525
    GetSubscriptionsRep reply = (GetSubscriptionsRep) doRequest(new GetSubscriptions(proxyId));
526
 
1254 afreyssin 527
    String[] subNames = reply.getSubNames();
528
    String[] topicIds = reply.getTopicIds();
529
    int[] messageCounts = reply.getMessageCounts();
530
    boolean[] durable = reply.getDurable();
2889 afreyssin 531
 
1254 afreyssin 532
    Subscription[] res = new Subscription[subNames.length];
533
    for (int i = 0; i < res.length; i++) {
2889 afreyssin 534
      res[i] = new Subscription(subNames[i], topicIds[i], messageCounts[i], durable[i]);
1254 afreyssin 535
    }
536
    return res;
537
  }
538
 
1331 tachker 539
  /** used by MBean jmx */
2889 afreyssin 540
  public List getSubscriptionList() throws AdminException, ConnectException {
1331 tachker 541
    Vector list = new Vector();
542
    Subscription[] sub = getSubscriptions();
543
    for (int i = 0; i < sub.length; i++) {
544
      list.add(sub[i].toString());
545
    }
546
    return list;
547
  }
548
 
1254 afreyssin 549
  /**
550
   * Returns a subscription.
551
   *
552
   * @param subName the name of the subscription.
3080 afreyssin 553
   * @return The subscription.
1254 afreyssin 554
   *
3080 afreyssin 555
   * @exception AdminException If an error is raised by the administration operation.
1254 afreyssin 556
   * @exception ConnectException  If the admin connection is not established.
557
   */
2587 afreyssin 558
  public Subscription getSubscription(String subName) throws AdminException, ConnectException {
2889 afreyssin 559
    GetSubscriptionRep reply = (GetSubscriptionRep) doRequest(new GetSubscription(proxyId, subName));
560
    Subscription sub = new Subscription(subName, reply.getTopicId(), reply.getMessageCount(), reply.getDurable());
561
 
562
    return sub;
1254 afreyssin 563
  }
564
 
2587 afreyssin 565
  public String getSubscriptionString(String subName) throws AdminException, ConnectException {
566
    return getSubscription(subName).toString();
1331 tachker 567
  }
568
 
2587 afreyssin 569
  public String[] getMessageIds(String subName) throws AdminException, ConnectException {
2751 afreyssin 570
    GetSubscriptionMessageIdsRep reply =
2889 afreyssin 571
      (GetSubscriptionMessageIdsRep) doRequest(new GetSubscriptionMessageIds(proxyId, subName));
1254 afreyssin 572
    return reply.getMessageIds();
573
  }
574
 
2751 afreyssin 575
  public Message getMessage(String subName,
576
                            String msgId) throws AdminException, ConnectException, JMSException {
577
    GetSubscriptionMessageRep reply =
2889 afreyssin 578
      (GetSubscriptionMessageRep) doRequest(new GetSubscriptionMessage(proxyId, subName, msgId, true));
2751 afreyssin 579
    return Message.wrapMomMessage(null, reply.getMessage());
580
  }
2889 afreyssin 581
 
2751 afreyssin 582
  public String getMessageDigest(String subName,
583
                                 String msgId) throws AdminException, ConnectException, JMSException {
584
    GetSubscriptionMessageRep reply =
2889 afreyssin 585
      (GetSubscriptionMessageRep) doRequest(new GetSubscriptionMessage(proxyId, subName, msgId, true));
2751 afreyssin 586
    Message msg =  Message.wrapMomMessage(null, reply.getMessage());
2889 afreyssin 587
 
2751 afreyssin 588
    StringBuffer strbuf = new StringBuffer();
589
    strbuf.append("Message: ").append(msg.getJMSMessageID());
590
    strbuf.append("\n\tTo: ").append(msg.getJMSDestination());
591
    strbuf.append("\n\tCorrelationId: ").append(msg.getJMSCorrelationID());
592
    strbuf.append("\n\tDeliveryMode: ").append(msg.getJMSDeliveryMode());
593
    strbuf.append("\n\tExpiration: ").append(msg.getJMSExpiration());
594
    strbuf.append("\n\tPriority: ").append(msg.getJMSPriority());
595
    strbuf.append("\n\tRedelivered: ").append(msg.getJMSRedelivered());
596
    strbuf.append("\n\tReplyTo: ").append(msg.getJMSReplyTo());
597
    strbuf.append("\n\tTimestamp: ").append(msg.getJMSTimestamp());
598
    strbuf.append("\n\tType: ").append(msg.getJMSType());
599
    return strbuf.toString();
2889 afreyssin 600
  }
2751 afreyssin 601
 
602
  public Properties getMessageHeader(String subName,
603
                                     String msgId) throws AdminException, ConnectException, JMSException {
604
    GetSubscriptionMessageRep reply =
2889 afreyssin 605
      (GetSubscriptionMessageRep) doRequest(new GetSubscriptionMessage(proxyId, subName, msgId, false));
2751 afreyssin 606
    Message msg =  Message.wrapMomMessage(null, reply.getMessage());
607
 
608
    Properties prop = new Properties();
609
    prop.setProperty("JMSMessageID", msg.getJMSMessageID());
610
    prop.setProperty("JMSDestination", msg.getJMSDestination().toString());
611
    if (msg.getJMSCorrelationID() != null)
612
      prop.setProperty("JMSCorrelationID", msg.getJMSCorrelationID());
613
    prop.setProperty("JMSDeliveryMode",
614
                     new Integer(msg.getJMSDeliveryMode()).toString());
615
    prop.setProperty("JMSExpiration",
616
                     new Long(msg.getJMSExpiration()).toString());
617
    prop.setProperty("JMSPriority",
618
                     new Integer(msg.getJMSPriority()).toString());
619
    prop.setProperty("JMSRedelivered",
620
                     new Boolean(msg.getJMSRedelivered()).toString());
621
    if (msg.getJMSReplyTo() != null)
622
      prop.setProperty("JMSReplyTo", msg.getJMSReplyTo().toString());
623
    prop.setProperty("JMSTimestamp",
624
                     new Long(msg.getJMSTimestamp()).toString());
625
    if (msg.getJMSType() != null)
626
      prop.setProperty("JMSType", msg.getJMSType());
627
 
628
    return prop;
2889 afreyssin 629
  }
2751 afreyssin 630
 
2889 afreyssin 631
  public Properties getMessageProperties(String subName,
632
                                         String msgId) throws AdminException, ConnectException, JMSException {
633
    GetSubscriptionMessageRep reply =
634
      (GetSubscriptionMessageRep) doRequest(new GetSubscriptionMessage(proxyId, subName, msgId, false));
635
    Message msg =  Message.wrapMomMessage(null, reply.getMessage());
2751 afreyssin 636
 
2889 afreyssin 637
    Properties prop = new Properties();
638
    msg.getProperties(prop);
2751 afreyssin 639
 
2889 afreyssin 640
    return prop;
641
  }
2751 afreyssin 642
 
643
  /**
4557 surrel 644
   * Add interceptors
4364 tachker 645
   *
646
   * @param interceptors list of string className interceptor (separate with ",")
647
   * @throws ConnectException
648
   * @throws AdminException
649
   */
650
  public void addInterceptorsIN(String interceptors) throws ConnectException, AdminException {
651
  	Properties prop = new Properties();
4393 tachker 652
    prop.put(AdminCommandConstant.INTERCEPTORS_IN, interceptors);
4364 tachker 653
    getWrapper().processAdmin(getProxyId(), AdminCommandConstant.CMD_ADD_INTERCEPTORS, prop);
654
  }
655
 
656
  /**
4557 surrel 657
   * Get interceptors.
4364 tachker 658
   *
659
   * @return list of string className interceptor (separate with ",")
660
   * @throws ConnectException
661
   * @throws AdminException
662
   */
663
  public String getInterceptorsIN() throws ConnectException, AdminException {
4557 surrel 664
    AdminCommandReply reply = (AdminCommandReply) getWrapper().processAdmin(getProxyId(),
665
        AdminCommandConstant.CMD_GET_INTERCEPTORS, null);
4393 tachker 666
    return (String) reply.getProp().get(AdminCommandConstant.INTERCEPTORS_IN);
4364 tachker 667
  }
668
 
669
  /**
4557 surrel 670
   * Remove interceptors
4364 tachker 671
   *
672
   * @param interceptors list of string className interceptor (separate with ",")
673
   * @throws ConnectException
674
   * @throws AdminException
675
   */
676
  public void removeInterceptorsIN(String interceptors) throws ConnectException, AdminException {
677
  	Properties prop = new Properties();
4393 tachker 678
  	prop.put(AdminCommandConstant.INTERCEPTORS_IN, interceptors);
4557 surrel 679
    getWrapper().processAdmin(getProxyId(), AdminCommandConstant.CMD_REMOVE_INTERCEPTORS, prop);
4364 tachker 680
  }
681
 
682
  /**
4557 surrel 683
   * Add interceptors
4364 tachker 684
   *
685
   * @param interceptors list of string className interceptor (separate with ",")
686
   * @throws ConnectException
687
   * @throws AdminException
688
   */
689
  public void addInterceptorsOUT(String interceptors) throws ConnectException, AdminException {
690
  	Properties prop = new Properties();
4393 tachker 691
    prop.put(AdminCommandConstant.INTERCEPTORS_OUT, interceptors);
4364 tachker 692
    getWrapper().processAdmin(getProxyId(), AdminCommandConstant.CMD_ADD_INTERCEPTORS, prop);
693
  }
694
 
695
  /**
4557 surrel 696
   * Get interceptors.
4364 tachker 697
   *
698
   * @return list of string className interceptor (separate with ",")
699
   * @throws ConnectException
700
   * @throws AdminException
701
   */
702
  public String getInterceptorsOUT() throws ConnectException, AdminException {
4557 surrel 703
    AdminCommandReply reply = (AdminCommandReply) getWrapper().processAdmin(getProxyId(),
704
        AdminCommandConstant.CMD_GET_INTERCEPTORS, null);
4393 tachker 705
    return (String) reply.getProp().get(AdminCommandConstant.INTERCEPTORS_OUT);
4364 tachker 706
  }
707
 
708
  /**
4557 surrel 709
   * Remove interceptors
4364 tachker 710
   *
711
   * @param interceptors list of string className interceptor (separate with ",")
712
   * @throws ConnectException
713
   * @throws AdminException
714
   */
715
  public void removeInterceptorsOUT(String interceptors) throws ConnectException, AdminException {
716
  	Properties prop = new Properties();
4393 tachker 717
  	prop.put(AdminCommandConstant.INTERCEPTORS_OUT, interceptors);
4557 surrel 718
    getWrapper().processAdmin(getProxyId(), AdminCommandConstant.CMD_REMOVE_INTERCEPTORS, prop);
4364 tachker 719
  }
720
 
721
  /**
4557 surrel 722
   * Replace interceptor IN
4393 tachker 723
   *
724
   * @param newInterceptor the new className interceptor.
725
   * @param oldInterceptor the old className interceptor.
726
   * @throws ConnectException
727
   * @throws AdminException
728
   */
729
  public void replaceInterceptorIN(String newInterceptor, String oldInterceptor) throws ConnectException, AdminException {
730
  	Properties prop = new Properties();
731
    prop.put(AdminCommandConstant.INTERCEPTORS_IN_NEW, newInterceptor);
732
    prop.put(AdminCommandConstant.INTERCEPTORS_IN_OLD, oldInterceptor);
733
    getWrapper().processAdmin(getProxyId(), AdminCommandConstant.CMD_REPLACE_INTERCEPTORS, prop);
734
  }
735
 
736
  /**
4557 surrel 737
   * Replace interceptor OUT
4393 tachker 738
   *
739
   * @param newInterceptor the new className interceptor.
740
   * @param oldInterceptor the old className interceptor.
741
   * @throws ConnectException
742
   * @throws AdminException
743
   */
744
  public void replaceInterceptorOUT(String newInterceptor, String oldInterceptor) throws ConnectException, AdminException {
745
  	Properties prop = new Properties();
746
    prop.put(AdminCommandConstant.INTERCEPTORS_OUT_NEW, newInterceptor);
747
    prop.put(AdminCommandConstant.INTERCEPTORS_OUT_OLD, oldInterceptor);
748
    getWrapper().processAdmin(getProxyId(), AdminCommandConstant.CMD_REPLACE_INTERCEPTORS, prop);
749
  }
750
 
751
  /**
2751 afreyssin 752
   * @deprecated
753
   */
1669 afreyssin 754
  public Message readMessage(String subName,
755
                             String msgId) throws AdminException, ConnectException, JMSException {
2751 afreyssin 756
    return getMessage(subName, msgId);
1254 afreyssin 757
  }
758
 
2889 afreyssin 759
  public void deleteMessage(String subName,
760
                            String msgId)  throws AdminException, ConnectException {
761
    doRequest(new DeleteSubscriptionMessage(proxyId, subName, msgId));
1254 afreyssin 762
  }
763
 
2889 afreyssin 764
  public void clearSubscription(String subName) throws AdminException, ConnectException {
765
    doRequest(new ClearSubscription(proxyId, subName));
1254 afreyssin 766
  }
767
 
2889 afreyssin 768
 
861 fmaistre 769
  /** Returns the identifier of the user's proxy. */
1788 afreyssin 770
  public String getProxyId() {
861 fmaistre 771
    return proxyId;
772
  }
773
 
1788 afreyssin 774
  /** Sets the naming reference of a connection factory. */
775
  public void toReference(Reference ref) throws NamingException {
861 fmaistre 776
    ref.add(new StringRefAddr("user.name", name));
777
    ref.add(new StringRefAddr("user.id", proxyId));
778
  }
779
 
1788 afreyssin 780
  /** Restores the administered object from a naming reference. */
781
  public void fromReference(Reference ref) throws NamingException {
782
    name = (String) ref.get("user.name").getContent();
783
    proxyId = (String) ref.get("user.id").getContent();
784
  }
785
 
861 fmaistre 786
  /**
2795 surrel 787
   * Codes an <code>User</code> instance as a Hashtable for traveling
861 fmaistre 788
   * through the SOAP protocol.
789
   */
790
  public Hashtable code() {
1254 afreyssin 791
    Hashtable h = new Hashtable();
2889 afreyssin 792
    h.put("name", name);
793
    h.put("proxyId", proxyId);
861 fmaistre 794
    return h;
795
  }
796
 
797
  /**
2795 surrel 798
   * Decodes an <code>User</code> which traveled through the SOAP protocol.
861 fmaistre 799
   */
1254 afreyssin 800
  public void decode(Hashtable h) {
801
    name = (String) h.get("name");
802
    proxyId = (String) h.get("proxyId");
861 fmaistre 803
  }
804
}