OW2 Consortium joram

Rev

Rev 4393 | Rev 4557 | 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) {
289
    if (MXWrapper.mxserver == null) return null;
2889 afreyssin 290
 
3125 afreyssin 291
    int sid = Integer.parseInt(proxyId.substring(proxyId.indexOf('.') +1, proxyId.lastIndexOf('.')));
2889 afreyssin 292
    StringBuffer buf = new StringBuffer();
3060 afreyssin 293
    buf.append(base);
3125 afreyssin 294
    buf.append(":type=User,location=server#").append(sid).append(",name=").append(getName()).append('[').append(getProxyId()).append(']');
2889 afreyssin 295
    JMXBeanName = buf.toString();
2931 afreyssin 296
 
2663 tachker 297
    try {
2931 afreyssin 298
      MXWrapper.registerMBean(this, JMXBeanName);
2663 tachker 299
    } catch (Exception e) {
2971 afreyssin 300
      if (logger.isLoggable(BasicLevel.DEBUG))
301
        logger.log(BasicLevel.DEBUG, "User.registerMBean: " + JMXBeanName, e);
2663 tachker 302
    }
2931 afreyssin 303
 
304
    return JMXBeanName;
2663 tachker 305
  }
2889 afreyssin 306
 
307
  public void unregisterMBean() {
2931 afreyssin 308
    if ((MXWrapper.mxserver == null) || (JMXBeanName == null)) return;
2889 afreyssin 309
 
310
    try {
2931 afreyssin 311
      MXWrapper.unregisterMBean(JMXBeanName);
2889 afreyssin 312
    } catch (Exception e) {
2971 afreyssin 313
      if (logger.isLoggable(BasicLevel.DEBUG))
314
        logger.log(BasicLevel.DEBUG, "User.unregisterMBean: " + JMXBeanName, e);
2889 afreyssin 315
    }
316
  }
317
 
2663 tachker 318
  /**
319
   * Create a user Identity.
320
   *
321
   * @param user              Name of the user.
322
   * @param passwd            Password of the user.
323
   * @param identityClassName identity class name (simple, jaas).
324
   * @return identity user Identity.
325
   * @throws AdminException
326
   */
2889 afreyssin 327
  private static Identity createIdentity(String user, String passwd,
328
                                         String identityClassName) throws AdminException {
2663 tachker 329
    Identity identity = null;
330
    try {
331
      Class clazz = Class.forName(identityClassName);
332
      identity = (Identity) clazz.newInstance();
333
      if (passwd != null)
334
        identity.setIdentity(user, passwd);
335
      else
336
        identity.setUserName(user);
337
    } catch (Exception e) {
338
      throw new AdminException(e.getMessage());
339
    }
340
    return identity;
341
  }
2889 afreyssin 342
 
2663 tachker 343
  /**
861 fmaistre 344
   * Admin method updating this user identification.
345
   * <p>
346
   * The request fails if the user does not exist server side, or if the new
347
   * identification is already taken by a user on the same server.
348
   *
349
   * @param newName  The new name of the user.
350
   * @param newPassword  The new password of the user.
351
   *
352
   * @exception ConnectException  If the connection fails.
353
   * @exception AdminException  If the request fails.
354
   */
2889 afreyssin 355
  public void update(String newName, String newPassword) throws ConnectException, AdminException {
2813 afreyssin 356
    update(newName, newPassword, SimpleIdentity.class.getName());
2663 tachker 357
  }
2889 afreyssin 358
 
2663 tachker 359
  /**
360
   * Admin method updating this user identification.
361
   * <p>
362
   * The request fails if the user does not exist server side, or if the new
363
   * identification is already taken by a user on the same server.
364
   *
365
   * @param newName  The new name of the user.
366
   * @param newPassword  The new password of the user.
2795 surrel 367
   * @param identityClassName user/password or JAAS... (default SimpleIdentity).
2663 tachker 368
   *
369
   * @exception ConnectException  If the connection fails.
370
   * @exception AdminException  If the request fails.
371
   */
2889 afreyssin 372
  public void update(String newName, String newPassword,
373
                     String identityClassName) throws ConnectException, AdminException {
2663 tachker 374
    Identity newIdentity = createIdentity(newName, newPassword, identityClassName);
2889 afreyssin 375
    doRequest(new UpdateUser(name, proxyId, newIdentity));
861 fmaistre 376
    name = newName;
377
  }
378
 
379
  /**
380
   * Removes this user.
381
   *
382
   * @exception ConnectException  If the connection fails.
383
   * @exception AdminException  Never thrown.
384
   */
1331 tachker 385
  public void delete() throws ConnectException, AdminException {
2889 afreyssin 386
    doRequest(new DeleteUser(name, proxyId));
2931 afreyssin 387
    unregisterMBean();
861 fmaistre 388
  }
389
 
390
  /**
391
   * Admin method setting a given dead message queue for this user.
392
   * <p>
393
   * The request fails if the user is deleted server side.
394
   *
395
   * @param dmq  The dead message queue to be set.
396
   *
397
   * @exception ConnectException  If the connection fails.
398
   * @exception AdminException  If the request fails.
399
   */
3155 surrel 400
  public void setDMQ(Queue dmq) throws ConnectException, AdminException {
1873 tachker 401
    setDMQId(dmq.getName());
861 fmaistre 402
  }
403
 
404
  /**
1873 tachker 405
   * Admin method setting a given dead message queue for this user.
406
   * <p>
407
   * The request fails if the user is deleted server side.
408
   *
409
   * @param dmqId  The dead message queue Id to be set.
410
   *
411
   * @exception ConnectException  If the connection fails.
412
   * @exception AdminException  If the request fails.
413
   */
414
  public void setDMQId(String dmqId) throws ConnectException, AdminException {
4025 afreyssin 415
    doRequest(new SetDMQRequest(proxyId, dmqId));
1873 tachker 416
  }
2889 afreyssin 417
 
1873 tachker 418
  /**
861 fmaistre 419
   * Admin method setting a given value as the threshold for this user.
420
   * <p>
421
   * The request fails if the user is deleted server side.
422
   *
2746 afreyssin 423
   * @param threshold  The threshold value to be set (-1 for unsetting
424
   *                   previous value).
861 fmaistre 425
   *
426
   * @exception ConnectException  If the connection fails.
427
   * @exception AdminException  If the request fails.
428
   */
2889 afreyssin 429
  public void setThreshold(int threshold) throws ConnectException, AdminException {
4025 afreyssin 430
    doRequest(new SetThresholdRequest(proxyId, threshold));
861 fmaistre 431
  }
4025 afreyssin 432
 
433
  /**
434
   * Monitoring method returning the dead message queue of this user,
435
   * null if not set.
861 fmaistre 436
   * <p>
437
   * The request fails if the user is deleted server side.
438
   *
4025 afreyssin 439
   * @exception ConnectException  If the administration connection is closed or broken.
861 fmaistre 440
   * @exception AdminException  If the request fails.
441
   */
4025 afreyssin 442
  public Queue getDMQ() throws ConnectException, AdminException {
443
    String dmqId = getDMQId();
444
    Queue dmq = null;
445
    if (dmqId != null) {
446
      dmq = new Queue(dmqId);
447
      if (wrapper != null)
448
        dmq.setWrapper(wrapper);
449
    }
2889 afreyssin 450
    return dmq;
861 fmaistre 451
  }
452
 
4025 afreyssin 453
  /**
454
   * Monitoring method returning the dead message queue id of this user,
455
   * null if not set.
1873 tachker 456
   * <p>
4025 afreyssin 457
   * The request fails if the destination is deleted server side.
1873 tachker 458
   *
4025 afreyssin 459
   * @exception ConnectException  If the administration connection is closed or broken.
1873 tachker 460
   * @exception AdminException  If the request fails.
461
   */
462
  public String getDMQId() throws ConnectException, AdminException {
4025 afreyssin 463
    GetDMQSettingsRequest request = new GetDMQSettingsRequest(proxyId);
464
    GetDMQSettingsReply reply = (GetDMQSettingsReply) doRequest(request);
465
 
466
    return reply.getDMQName();
1873 tachker 467
  }
2889 afreyssin 468
 
1873 tachker 469
  /**
861 fmaistre 470
   * Returns the threshold for this user, -1 if not set.
471
   * <p>
472
   * The request fails if the user is deleted server side.
473
   *
474
   * @exception ConnectException  If the connection fails.
475
   * @exception AdminException  If the request fails.
476
   */
1788 afreyssin 477
  public int getThreshold() throws ConnectException, AdminException {
4025 afreyssin 478
    GetDMQSettingsRequest request = new GetDMQSettingsRequest(proxyId);
479
    GetDMQSettingsReply reply = (GetDMQSettingsReply) doRequest(request);
2889 afreyssin 480
 
4025 afreyssin 481
      return reply.getThreshold();
861 fmaistre 482
  }
483
 
1254 afreyssin 484
  /**
1331 tachker 485
   * Admin method setting nbMaxMsg for this subscription.
486
   * <p>
487
   * The request fails if the sub is deleted server side.
488
   *
489
   * @param subName the name of the subscription.
490
   * @param nbMaxMsg  nb Max of Message (-1 no limit).
491
   *
492
   * @exception ConnectException  If the admin connection is closed or broken.
493
   * @exception AdminException  If the request fails.
494
   */
2889 afreyssin 495
  public void setNbMaxMsg(String subName, int nbMaxMsg) throws ConnectException, AdminException {
496
    //  TODO: Subscription sub = getSubscription(subName);
4025 afreyssin 497
    doRequest(new SetNbMaxMsgRequest(proxyId, nbMaxMsg, subName));
1331 tachker 498
  }
499
 
500
  /**
501
   * Monitoring method returning the nbMaxMsg of this subscription, -1 if no limit.
502
   * <p>
503
   * The request fails if the sub is deleted server side.
504
   *
505
   * @param subName the name of the subscription.
506
   *
507
   * @exception ConnectException  If the admin connection is closed or broken.
508
   * @exception AdminException  If the request fails.
509
   */
2889 afreyssin 510
  public int getNbMaxMsg(String subName) throws ConnectException, AdminException {
511
    //  TODO: Subscription sub = getSubscription(subName);
4025 afreyssin 512
    GetNbMaxMsgRequest request = new GetNbMaxMsgRequest(proxyId, subName);
513
    GetNumberReply reply = (GetNumberReply) doRequest(request);
514
    return reply.getNumber();
1331 tachker 515
  }
516
 
517
  /**
1254 afreyssin 518
   * Returns the subscriptions owned by a user.
519
   *
3080 afreyssin 520
   * @return The subscriptions owned by the user.
1254 afreyssin 521
   *
3080 afreyssin 522
   * @exception AdminException If an error is raised by the administration operation.
1254 afreyssin 523
   * @exception ConnectException  If the admin connection is not established.
524
   */
2889 afreyssin 525
  public Subscription[] getSubscriptions() throws AdminException, ConnectException {
526
    GetSubscriptionsRep reply = (GetSubscriptionsRep) doRequest(new GetSubscriptions(proxyId));
527
 
1254 afreyssin 528
    String[] subNames = reply.getSubNames();
529
    String[] topicIds = reply.getTopicIds();
530
    int[] messageCounts = reply.getMessageCounts();
531
    boolean[] durable = reply.getDurable();
2889 afreyssin 532
 
1254 afreyssin 533
    Subscription[] res = new Subscription[subNames.length];
534
    for (int i = 0; i < res.length; i++) {
2889 afreyssin 535
      res[i] = new Subscription(subNames[i], topicIds[i], messageCounts[i], durable[i]);
1254 afreyssin 536
    }
537
    return res;
538
  }
539
 
1331 tachker 540
  /** used by MBean jmx */
2889 afreyssin 541
  public List getSubscriptionList() throws AdminException, ConnectException {
1331 tachker 542
    Vector list = new Vector();
543
    Subscription[] sub = getSubscriptions();
544
    for (int i = 0; i < sub.length; i++) {
545
      list.add(sub[i].toString());
546
    }
547
    return list;
548
  }
549
 
1254 afreyssin 550
  /**
551
   * Returns a subscription.
552
   *
553
   * @param subName the name of the subscription.
3080 afreyssin 554
   * @return The subscription.
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
   */
2587 afreyssin 559
  public Subscription getSubscription(String subName) throws AdminException, ConnectException {
2889 afreyssin 560
    GetSubscriptionRep reply = (GetSubscriptionRep) doRequest(new GetSubscription(proxyId, subName));
561
    Subscription sub = new Subscription(subName, reply.getTopicId(), reply.getMessageCount(), reply.getDurable());
562
 
563
    return sub;
1254 afreyssin 564
  }
565
 
2587 afreyssin 566
  public String getSubscriptionString(String subName) throws AdminException, ConnectException {
567
    return getSubscription(subName).toString();
1331 tachker 568
  }
569
 
2587 afreyssin 570
  public String[] getMessageIds(String subName) throws AdminException, ConnectException {
2751 afreyssin 571
    GetSubscriptionMessageIdsRep reply =
2889 afreyssin 572
      (GetSubscriptionMessageIdsRep) doRequest(new GetSubscriptionMessageIds(proxyId, subName));
1254 afreyssin 573
    return reply.getMessageIds();
574
  }
575
 
2751 afreyssin 576
  public Message getMessage(String subName,
577
                            String msgId) throws AdminException, ConnectException, JMSException {
578
    GetSubscriptionMessageRep reply =
2889 afreyssin 579
      (GetSubscriptionMessageRep) doRequest(new GetSubscriptionMessage(proxyId, subName, msgId, true));
2751 afreyssin 580
    return Message.wrapMomMessage(null, reply.getMessage());
581
  }
2889 afreyssin 582
 
2751 afreyssin 583
  public String getMessageDigest(String subName,
584
                                 String msgId) throws AdminException, ConnectException, JMSException {
585
    GetSubscriptionMessageRep reply =
2889 afreyssin 586
      (GetSubscriptionMessageRep) doRequest(new GetSubscriptionMessage(proxyId, subName, msgId, true));
2751 afreyssin 587
    Message msg =  Message.wrapMomMessage(null, reply.getMessage());
2889 afreyssin 588
 
2751 afreyssin 589
    StringBuffer strbuf = new StringBuffer();
590
    strbuf.append("Message: ").append(msg.getJMSMessageID());
591
    strbuf.append("\n\tTo: ").append(msg.getJMSDestination());
592
    strbuf.append("\n\tCorrelationId: ").append(msg.getJMSCorrelationID());
593
    strbuf.append("\n\tDeliveryMode: ").append(msg.getJMSDeliveryMode());
594
    strbuf.append("\n\tExpiration: ").append(msg.getJMSExpiration());
595
    strbuf.append("\n\tPriority: ").append(msg.getJMSPriority());
596
    strbuf.append("\n\tRedelivered: ").append(msg.getJMSRedelivered());
597
    strbuf.append("\n\tReplyTo: ").append(msg.getJMSReplyTo());
598
    strbuf.append("\n\tTimestamp: ").append(msg.getJMSTimestamp());
599
    strbuf.append("\n\tType: ").append(msg.getJMSType());
600
    return strbuf.toString();
2889 afreyssin 601
  }
2751 afreyssin 602
 
603
  public Properties getMessageHeader(String subName,
604
                                     String msgId) throws AdminException, ConnectException, JMSException {
605
    GetSubscriptionMessageRep reply =
2889 afreyssin 606
      (GetSubscriptionMessageRep) doRequest(new GetSubscriptionMessage(proxyId, subName, msgId, false));
2751 afreyssin 607
    Message msg =  Message.wrapMomMessage(null, reply.getMessage());
608
 
609
    Properties prop = new Properties();
610
    prop.setProperty("JMSMessageID", msg.getJMSMessageID());
611
    prop.setProperty("JMSDestination", msg.getJMSDestination().toString());
612
    if (msg.getJMSCorrelationID() != null)
613
      prop.setProperty("JMSCorrelationID", msg.getJMSCorrelationID());
614
    prop.setProperty("JMSDeliveryMode",
615
                     new Integer(msg.getJMSDeliveryMode()).toString());
616
    prop.setProperty("JMSExpiration",
617
                     new Long(msg.getJMSExpiration()).toString());
618
    prop.setProperty("JMSPriority",
619
                     new Integer(msg.getJMSPriority()).toString());
620
    prop.setProperty("JMSRedelivered",
621
                     new Boolean(msg.getJMSRedelivered()).toString());
622
    if (msg.getJMSReplyTo() != null)
623
      prop.setProperty("JMSReplyTo", msg.getJMSReplyTo().toString());
624
    prop.setProperty("JMSTimestamp",
625
                     new Long(msg.getJMSTimestamp()).toString());
626
    if (msg.getJMSType() != null)
627
      prop.setProperty("JMSType", msg.getJMSType());
628
 
629
    return prop;
2889 afreyssin 630
  }
2751 afreyssin 631
 
2889 afreyssin 632
  public Properties getMessageProperties(String subName,
633
                                         String msgId) throws AdminException, ConnectException, JMSException {
634
    GetSubscriptionMessageRep reply =
635
      (GetSubscriptionMessageRep) doRequest(new GetSubscriptionMessage(proxyId, subName, msgId, false));
636
    Message msg =  Message.wrapMomMessage(null, reply.getMessage());
2751 afreyssin 637
 
2889 afreyssin 638
    Properties prop = new Properties();
639
    msg.getProperties(prop);
2751 afreyssin 640
 
2889 afreyssin 641
    return prop;
642
  }
2751 afreyssin 643
 
644
  /**
4364 tachker 645
   * add interceptors
646
   *
647
   * @param interceptors list of string className interceptor (separate with ",")
648
   * @throws ConnectException
649
   * @throws AdminException
650
   */
651
  public void addInterceptorsIN(String interceptors) throws ConnectException, AdminException {
652
  	Properties prop = new Properties();
4393 tachker 653
    prop.put(AdminCommandConstant.INTERCEPTORS_IN, interceptors);
4364 tachker 654
    getWrapper().processAdmin(getProxyId(), AdminCommandConstant.CMD_ADD_INTERCEPTORS, prop);
655
  }
656
 
657
  /**
658
   * get interceptors.
659
   *
660
   * @return list of string className interceptor (separate with ",")
661
   * @throws ConnectException
662
   * @throws AdminException
663
   */
664
  public String getInterceptorsIN() throws ConnectException, AdminException {
665
  	AdminCommandReply reply = (AdminCommandReply) AdminModule.processAdmin(getProxyId(), AdminCommandConstant.CMD_GET_INTERCEPTORS, null);
4393 tachker 666
    return (String) reply.getProp().get(AdminCommandConstant.INTERCEPTORS_IN);
4364 tachker 667
  }
668
 
669
  /**
670
   * remove interceptors
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);
4364 tachker 679
  	AdminModule.processAdmin(getProxyId(), AdminCommandConstant.CMD_REMOVE_INTERCEPTORS, prop);
680
  }
681
 
682
  /**
683
   * add interceptors
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
  /**
696
   * get interceptors.
697
   *
698
   * @return list of string className interceptor (separate with ",")
699
   * @throws ConnectException
700
   * @throws AdminException
701
   */
702
  public String getInterceptorsOUT() throws ConnectException, AdminException {
703
  	AdminCommandReply reply = (AdminCommandReply) AdminModule.processAdmin(getProxyId(), AdminCommandConstant.CMD_GET_INTERCEPTORS, null);
4393 tachker 704
    return (String) reply.getProp().get(AdminCommandConstant.INTERCEPTORS_OUT);
4364 tachker 705
  }
706
 
707
  /**
708
   * remove interceptors
709
   *
710
   * @param interceptors list of string className interceptor (separate with ",")
711
   * @throws ConnectException
712
   * @throws AdminException
713
   */
714
  public void removeInterceptorsOUT(String interceptors) throws ConnectException, AdminException {
715
  	Properties prop = new Properties();
4393 tachker 716
  	prop.put(AdminCommandConstant.INTERCEPTORS_OUT, interceptors);
4364 tachker 717
  	AdminModule.processAdmin(getProxyId(), AdminCommandConstant.CMD_REMOVE_INTERCEPTORS, prop);
718
  }
719
 
720
  /**
4393 tachker 721
   * replace interceptor IN
722
   *
723
   * @param newInterceptor the new className interceptor.
724
   * @param oldInterceptor the old className interceptor.
725
   * @throws ConnectException
726
   * @throws AdminException
727
   */
728
  public void replaceInterceptorIN(String newInterceptor, String oldInterceptor) throws ConnectException, AdminException {
729
  	Properties prop = new Properties();
730
    prop.put(AdminCommandConstant.INTERCEPTORS_IN_NEW, newInterceptor);
731
    prop.put(AdminCommandConstant.INTERCEPTORS_IN_OLD, oldInterceptor);
732
    getWrapper().processAdmin(getProxyId(), AdminCommandConstant.CMD_REPLACE_INTERCEPTORS, prop);
733
  }
734
 
735
  /**
736
   * replace interceptor OUT
737
   *
738
   * @param newInterceptor the new className interceptor.
739
   * @param oldInterceptor the old className interceptor.
740
   * @throws ConnectException
741
   * @throws AdminException
742
   */
743
  public void replaceInterceptorOUT(String newInterceptor, String oldInterceptor) throws ConnectException, AdminException {
744
  	Properties prop = new Properties();
745
    prop.put(AdminCommandConstant.INTERCEPTORS_OUT_NEW, newInterceptor);
746
    prop.put(AdminCommandConstant.INTERCEPTORS_OUT_OLD, oldInterceptor);
747
    getWrapper().processAdmin(getProxyId(), AdminCommandConstant.CMD_REPLACE_INTERCEPTORS, prop);
748
  }
749
 
750
  /**
2751 afreyssin 751
   * @deprecated
752
   */
1669 afreyssin 753
  public Message readMessage(String subName,
754
                             String msgId) throws AdminException, ConnectException, JMSException {
2751 afreyssin 755
    return getMessage(subName, msgId);
1254 afreyssin 756
  }
757
 
2889 afreyssin 758
  public void deleteMessage(String subName,
759
                            String msgId)  throws AdminException, ConnectException {
760
    doRequest(new DeleteSubscriptionMessage(proxyId, subName, msgId));
1254 afreyssin 761
  }
762
 
2889 afreyssin 763
  public void clearSubscription(String subName) throws AdminException, ConnectException {
764
    doRequest(new ClearSubscription(proxyId, subName));
1254 afreyssin 765
  }
766
 
2889 afreyssin 767
 
861 fmaistre 768
  /** Returns the identifier of the user's proxy. */
1788 afreyssin 769
  public String getProxyId() {
861 fmaistre 770
    return proxyId;
771
  }
772
 
1788 afreyssin 773
  /** Sets the naming reference of a connection factory. */
774
  public void toReference(Reference ref) throws NamingException {
861 fmaistre 775
    ref.add(new StringRefAddr("user.name", name));
776
    ref.add(new StringRefAddr("user.id", proxyId));
777
  }
778
 
1788 afreyssin 779
  /** Restores the administered object from a naming reference. */
780
  public void fromReference(Reference ref) throws NamingException {
781
    name = (String) ref.get("user.name").getContent();
782
    proxyId = (String) ref.get("user.id").getContent();
783
  }
784
 
861 fmaistre 785
  /**
2795 surrel 786
   * Codes an <code>User</code> instance as a Hashtable for traveling
861 fmaistre 787
   * through the SOAP protocol.
788
   */
789
  public Hashtable code() {
1254 afreyssin 790
    Hashtable h = new Hashtable();
2889 afreyssin 791
    h.put("name", name);
792
    h.put("proxyId", proxyId);
861 fmaistre 793
    return h;
794
  }
795
 
796
  /**
2795 surrel 797
   * Decodes an <code>User</code> which traveled through the SOAP protocol.
861 fmaistre 798
   */
1254 afreyssin 799
  public void decode(Hashtable h) {
800
    name = (String) h.get("name");
801
    proxyId = (String) h.get("proxyId");
861 fmaistre 802
  }
803
}