OW2 Consortium joram

Rev

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