OW2 Consortium joram

Rev

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