OW2 Consortium joram

Rev

Rev 2813 | Rev 2931 | 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
2634 afreyssin 3
 * Copyright (C) 2004 - 2008 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;
2663 tachker 38
import org.objectweb.joram.shared.admin.AdminReply;
2889 afreyssin 39
import org.objectweb.joram.shared.admin.AdminRequest;
2663 tachker 40
import org.objectweb.joram.shared.admin.ClearSubscription;
41
import org.objectweb.joram.shared.admin.CreateUserReply;
42
import org.objectweb.joram.shared.admin.CreateUserRequest;
43
import org.objectweb.joram.shared.admin.DeleteSubscriptionMessage;
44
import org.objectweb.joram.shared.admin.DeleteUser;
45
import org.objectweb.joram.shared.admin.GetSubscription;
46
import org.objectweb.joram.shared.admin.GetSubscriptionMessage;
47
import org.objectweb.joram.shared.admin.GetSubscriptionMessageIds;
48
import org.objectweb.joram.shared.admin.GetSubscriptionMessageIdsRep;
49
import org.objectweb.joram.shared.admin.GetSubscriptionMessageRep;
50
import org.objectweb.joram.shared.admin.GetSubscriptionRep;
51
import org.objectweb.joram.shared.admin.GetSubscriptions;
52
import org.objectweb.joram.shared.admin.GetSubscriptionsRep;
53
import org.objectweb.joram.shared.admin.Monitor_GetDMQSettings;
54
import org.objectweb.joram.shared.admin.Monitor_GetDMQSettingsRep;
55
import org.objectweb.joram.shared.admin.Monitor_GetNbMaxMsg;
56
import org.objectweb.joram.shared.admin.Monitor_GetNbMaxMsgRep;
57
import org.objectweb.joram.shared.admin.SetNbMaxMsg;
58
import org.objectweb.joram.shared.admin.SetUserDMQ;
59
import org.objectweb.joram.shared.admin.SetUserThreshold;
60
import org.objectweb.joram.shared.admin.UpdateUser;
61
import org.objectweb.joram.shared.security.Identity;
2813 afreyssin 62
import org.objectweb.joram.shared.security.SimpleIdentity;
1331 tachker 63
import org.objectweb.util.monolog.api.BasicLevel;
2889 afreyssin 64
import org.objectweb.util.monolog.api.Logger;
1331 tachker 65
 
2889 afreyssin 66
import fr.dyade.aaa.util.Debug;
2663 tachker 67
import fr.dyade.aaa.util.management.MXWrapper;
68
 
861 fmaistre 69
/**
70
 * The <code>User</code> class is a utility class needed for administering
71
 * JORAM users.
72
 */
1669 afreyssin 73
public class User extends AdministeredObject implements UserMBean {
2889 afreyssin 74
  /** define serialVersionUID for interoperability */
1977 tachker 75
  private static final long serialVersionUID = 1L;
2889 afreyssin 76
 
77
  public static Logger logger = Debug.getLogger(User.class.getName());
78
 
861 fmaistre 79
  /** The name of the user. */
904 fmaistre 80
  String name;
861 fmaistre 81
  /** Identifier of the user's proxy agent. */
904 fmaistre 82
  String proxyId;
861 fmaistre 83
 
1254 afreyssin 84
  // Used by jndi2 SoapObjectHelper
85
  public User() {}
861 fmaistre 86
 
87
  /**
88
   * Constructs an <code>User</code> instance.
89
   *
90
   * @param name  The name of the user.
91
   * @param proxyId  Identifier of the user's proxy agent.
92
   */
1254 afreyssin 93
  public User(String name, String proxyId) {
861 fmaistre 94
    this.name = name;
95
    this.proxyId = proxyId;
96
  }
97
 
2889 afreyssin 98
 
861 fmaistre 99
  /** Returns a string view of this <code>User</code> instance. */
1788 afreyssin 100
  public String toString() {
861 fmaistre 101
    return "User[" + name + "]:" + proxyId;
102
  }
103
 
883 fmaistre 104
 
105
  /** Returns the user name. */
1788 afreyssin 106
  public String getName() {
883 fmaistre 107
    return name;
108
  }
109
 
110
  /** Provides a reliable way to compare <code>User</code> instances. */
1788 afreyssin 111
  public boolean equals(Object o) {
883 fmaistre 112
    if (! (o instanceof User))
113
      return false;
114
 
115
    User other = (User) o;
116
 
117
    return other.proxyId ==proxyId;
118
  }
2889 afreyssin 119
 
861 fmaistre 120
  /**
2889 afreyssin 121
   * Administration wrapper used to perform administration stuff.
122
   * <p>
123
   * It is defined through AdminModule element, it is closed at the end of
124
   * the script. if it is not defined the wrapper set at creation is used, if
125
   * none the static AdminModule connection is used.
126
   */
127
  AdminWrapper wrapper = null;
128
 
129
  /**
130
   * Returns the administration wrapper to use.
131
   *
132
   * @return The wrapper to use.
133
   * @throws ConnectException if no wrapper is defined.
134
   */
135
  protected final AdminWrapper getWrapper() throws ConnectException {
136
    if (wrapper != null) return wrapper;
137
    return AdminModule.getWrapper();
138
  }
139
 
140
  /**
141
   * Sets the administration wrapper to use.
142
   * If not set the AdminModule static connection is used by default.
143
   *
144
   * @param wrapper The wrapper to use or null to unset.
145
   */
146
  public void setWrapper(AdminWrapper wrapper) {
147
    this.wrapper = wrapper;
148
  }
149
 
150
  /**
151
   * Method actually sending an <code>AdminRequest</code> instance to
152
   * the platform and getting an <code>AdminReply</code> instance.
153
   *
154
   * @param request the administration request to send
155
   * @return  the reply message
156
   *
157
   * @exception ConnectException  If the connection to the platform fails.
158
   * @exception AdminException  If the platform's reply is invalid, or if
159
   *              the request failed.
160
   */
161
  public final AdminReply doRequest(AdminRequest request) throws AdminException, ConnectException {
162
    return getWrapper().doRequest(request);
163
  }
164
 
165
  /**
2795 surrel 166
   * Admin method creating a user for a given server and instantiating the
861 fmaistre 167
   * corresponding <code>User</code> object.
168
   * <p>
169
   * If the user has already been set on this server, the method simply
170
   * returns the corresponding <code>User</code> object. Its fails if the
171
   * target server does not belong to the platform, or if a proxy could not
172
   * be deployed server side for a new user.
2889 afreyssin 173
   * <p>
174
   * Be careful this method use the static AdminModule connection.
861 fmaistre 175
   *
176
   * @param name  Name of the user.
177
   * @param password  Password of the user.
178
   * @param serverId  The identifier of the user's server.
179
   *
180
   * @exception ConnectException  If the connection fails.
181
   * @exception AdminException  If the request fails.
182
   */
2889 afreyssin 183
  public static User create(String name, String password,
184
                            int serverId) throws ConnectException, AdminException {
2813 afreyssin 185
    return create(name, password, serverId, SimpleIdentity.class.getName());
861 fmaistre 186
  }
2889 afreyssin 187
 
861 fmaistre 188
  /**
2795 surrel 189
   * Admin method creating a user on the local server and instantiating the
861 fmaistre 190
   * corresponding <code>User</code> object.
191
   * <p>
192
   * If the user has already been set on this server, the method simply
193
   * returns the corresponding <code>User</code> object. It fails if a
194
   * proxy could not be deployed server side for a new user.
2889 afreyssin 195
   * <p>
196
   * Be careful this method use the static AdminModule connection.
861 fmaistre 197
   *
198
   * @param name  Name of the user.
199
   * @param password  Password of the user.
200
   *
201
   * @exception ConnectException  If the connection fails.
202
   * @exception AdminException  If the request fails.
203
   */
2889 afreyssin 204
  public static User create(String name, String password) throws ConnectException, AdminException {
2813 afreyssin 205
    return create(name, password, AdminModule.getLocalServerId(), SimpleIdentity.class.getName());
861 fmaistre 206
  }
2889 afreyssin 207
 
861 fmaistre 208
  /**
2795 surrel 209
   * Admin method creating a user for a given server and instantiating the
2663 tachker 210
   * corresponding <code>User</code> object.
211
   * <p>
212
   * If the user has already been set on this server, the method simply
213
   * returns the corresponding <code>User</code> object. Its fails if the
214
   * target server does not belong to the platform, or if a proxy could not
215
   * be deployed server side for a new user.
2889 afreyssin 216
   * <p>
217
   * Be careful this method use the static AdminModule connection.
2663 tachker 218
   *
219
   * @param name  Name of the user.
220
   * @param password  Password of the user.
221
   * @param serverId  The identifier of the user's server.
2795 surrel 222
   * @param identityClassName user/password or JAAS... (default SimpleIdentity).
2663 tachker 223
   *
224
   * @exception ConnectException  If the connection fails.
225
   * @exception AdminException  If the request fails.
226
   */
2889 afreyssin 227
  public static User create(String name, String password,
228
                            int serverId,
229
                            String identityClassName) throws ConnectException, AdminException {
2663 tachker 230
    Identity identity = createIdentity(name, password, identityClassName);
2889 afreyssin 231
 
232
    AdminReply reply = AdminModule.doRequest(new CreateUserRequest(identity, serverId));
2663 tachker 233
    User user = new User(name, ((CreateUserReply) reply).getProxId());
2889 afreyssin 234
 
235
// TODO (AF): MBean (un)registration is done explicitly
236
//    user.registerMBean("joramClient");
237
 
238
    return user;
239
  }
240
 
241
  transient protected String JMXBaseName = null;
242
  transient protected String JMXBeanName = null;
243
 
244
  public void registerMBean(String base) {
245
    if (MXWrapper.mxserver == null) return;
246
 
247
    StringBuffer buf = new StringBuffer();
248
    buf.append("type=User,name=").append(getName()).append('[').append(getProxyId()).append(']');
249
    JMXBeanName = buf.toString();
250
    JMXBaseName = base;
251
 
2663 tachker 252
    try {
2889 afreyssin 253
      MXWrapper.registerMBean(this, JMXBaseName, JMXBeanName);
2663 tachker 254
    } catch (Exception e) {
2889 afreyssin 255
      if (logger.isLoggable(BasicLevel.WARN))
256
        logger.log(BasicLevel.WARN,
257
                                   "User.registerMBean: " + JMXBaseName + ", " + JMXBeanName, e);
2663 tachker 258
    }
259
  }
2889 afreyssin 260
 
261
  public void unregisterMBean() {
262
    if ((MXWrapper.mxserver == null) || (JMXBaseName == null) || (JMXBeanName == null)) return;
263
 
264
    try {
265
      MXWrapper.unregisterMBean(JMXBaseName, JMXBeanName);
266
    } catch (Exception e) {
267
      if (logger.isLoggable(BasicLevel.WARN))
268
        logger.log(BasicLevel.WARN,
269
                                   "User.unregisterMBean: " + JMXBaseName + ", " + JMXBeanName, e);
270
    }
271
  }
272
 
2663 tachker 273
  /**
274
   * Create a user Identity.
275
   *
276
   * @param user              Name of the user.
277
   * @param passwd            Password of the user.
278
   * @param identityClassName identity class name (simple, jaas).
279
   * @return identity user Identity.
280
   * @throws AdminException
281
   */
2889 afreyssin 282
  private static Identity createIdentity(String user, String passwd,
283
                                         String identityClassName) throws AdminException {
2663 tachker 284
    Identity identity = null;
285
    try {
286
      Class clazz = Class.forName(identityClassName);
287
      identity = (Identity) clazz.newInstance();
288
      if (passwd != null)
289
        identity.setIdentity(user, passwd);
290
      else
291
        identity.setUserName(user);
292
    } catch (Exception e) {
293
      throw new AdminException(e.getMessage());
294
    }
295
    return identity;
296
  }
2889 afreyssin 297
 
2663 tachker 298
  /**
861 fmaistre 299
   * Admin method updating this user identification.
300
   * <p>
301
   * The request fails if the user does not exist server side, or if the new
302
   * identification is already taken by a user on the same server.
303
   *
304
   * @param newName  The new name of the user.
305
   * @param newPassword  The new password of the user.
306
   *
307
   * @exception ConnectException  If the connection fails.
308
   * @exception AdminException  If the request fails.
309
   */
2889 afreyssin 310
  public void update(String newName, String newPassword) throws ConnectException, AdminException {
2813 afreyssin 311
    update(newName, newPassword, SimpleIdentity.class.getName());
2663 tachker 312
  }
2889 afreyssin 313
 
2663 tachker 314
  /**
315
   * Admin method updating this user identification.
316
   * <p>
317
   * The request fails if the user does not exist server side, or if the new
318
   * identification is already taken by a user on the same server.
319
   *
320
   * @param newName  The new name of the user.
321
   * @param newPassword  The new password of the user.
2795 surrel 322
   * @param identityClassName user/password or JAAS... (default SimpleIdentity).
2663 tachker 323
   *
324
   * @exception ConnectException  If the connection fails.
325
   * @exception AdminException  If the request fails.
326
   */
2889 afreyssin 327
  public void update(String newName, String newPassword,
328
                     String identityClassName) throws ConnectException, AdminException {
2663 tachker 329
    Identity newIdentity = createIdentity(newName, newPassword, identityClassName);
2889 afreyssin 330
    doRequest(new UpdateUser(name, proxyId, newIdentity));
861 fmaistre 331
    name = newName;
332
  }
333
 
334
  /**
335
   * Removes this user.
336
   *
337
   * @exception ConnectException  If the connection fails.
338
   * @exception AdminException  Never thrown.
339
   */
1331 tachker 340
  public void delete() throws ConnectException, AdminException {
2889 afreyssin 341
    doRequest(new DeleteUser(name, proxyId));
342
// TODO (AF): MBean (un)registration is done explicitly
343
//    unregisterMBean();
861 fmaistre 344
  }
345
 
346
  /**
347
   * Admin method setting a given dead message queue for this user.
348
   * <p>
349
   * The request fails if the user is deleted server side.
350
   *
351
   * @param dmq  The dead message queue to be set.
352
   *
353
   * @exception ConnectException  If the connection fails.
354
   * @exception AdminException  If the request fails.
355
   */
1788 afreyssin 356
  public void setDMQ(DeadMQueue dmq) throws ConnectException, AdminException {
1873 tachker 357
    setDMQId(dmq.getName());
861 fmaistre 358
  }
359
 
360
  /**
1873 tachker 361
   * Admin method setting a given dead message queue for this user.
362
   * <p>
363
   * The request fails if the user is deleted server side.
364
   *
365
   * @param dmqId  The dead message queue Id to be set.
366
   *
367
   * @exception ConnectException  If the connection fails.
368
   * @exception AdminException  If the request fails.
369
   */
370
  public void setDMQId(String dmqId) throws ConnectException, AdminException {
2889 afreyssin 371
    doRequest(new SetUserDMQ(proxyId, dmqId));
1873 tachker 372
  }
2889 afreyssin 373
 
1873 tachker 374
  /**
861 fmaistre 375
   * Admin method setting a given value as the threshold for this user.
376
   * <p>
377
   * The request fails if the user is deleted server side.
378
   *
2746 afreyssin 379
   * @param threshold  The threshold value to be set (-1 for unsetting
380
   *                   previous value).
861 fmaistre 381
   *
382
   * @exception ConnectException  If the connection fails.
383
   * @exception AdminException  If the request fails.
384
   */
2889 afreyssin 385
  public void setThreshold(int threshold) throws ConnectException, AdminException {
386
    doRequest(new SetUserThreshold(proxyId, threshold));
861 fmaistre 387
  }
388
 
389
  /**
390
   * Returns the dead message queue for this user, null if not set.
391
   * <p>
392
   * The request fails if the user is deleted server side.
393
   *
394
   * @exception ConnectException  If the connection fails.
395
   * @exception AdminException  If the request fails.
396
   */
1788 afreyssin 397
  public DeadMQueue getDMQ() throws ConnectException, AdminException {
861 fmaistre 398
    Monitor_GetDMQSettings request;
399
    request = new Monitor_GetDMQSettings(proxyId);
400
    Monitor_GetDMQSettingsRep reply;
2889 afreyssin 401
    reply = (Monitor_GetDMQSettingsRep) doRequest(request);
402
 
861 fmaistre 403
    if (reply.getDMQName() == null)
404
      return null;
2889 afreyssin 405
 
406
    DeadMQueue dmq = new DeadMQueue(reply.getDMQName());
407
    if (wrapper != null)
408
      dmq.setWrapper(wrapper);
409
 
410
    return dmq;
861 fmaistre 411
  }
412
 
413
  /**
1873 tachker 414
   * Returns the dead message queue Id for this user, null if not set.
415
   * <p>
416
   * The request fails if the user is deleted server side.
417
   *
418
   * @exception ConnectException  If the connection fails.
419
   * @exception AdminException  If the request fails.
420
   */
421
  public String getDMQId() throws ConnectException, AdminException {
422
    DeadMQueue dmq = getDMQ();
423
    if (dmq == null)
424
      return null;
425
    else
426
      return dmq.getName();
427
  }
2889 afreyssin 428
 
1873 tachker 429
  /**
861 fmaistre 430
   * Returns the threshold for this user, -1 if not set.
431
   * <p>
432
   * The request fails if the user is deleted server side.
433
   *
434
   * @exception ConnectException  If the connection fails.
435
   * @exception AdminException  If the request fails.
436
   */
1788 afreyssin 437
  public int getThreshold() throws ConnectException, AdminException {
2889 afreyssin 438
    Monitor_GetDMQSettings request = new Monitor_GetDMQSettings(proxyId);
439
    Monitor_GetDMQSettingsRep reply = (Monitor_GetDMQSettingsRep) doRequest(request);
440
 
861 fmaistre 441
    if (reply.getThreshold() == null)
442
      return -1;
443
    else
444
      return reply.getThreshold().intValue();
445
  }
446
 
1254 afreyssin 447
  /**
1331 tachker 448
   * Admin method setting nbMaxMsg for this subscription.
449
   * <p>
450
   * The request fails if the sub is deleted server side.
451
   *
452
   * @param subName the name of the subscription.
453
   * @param nbMaxMsg  nb Max of Message (-1 no limit).
454
   *
455
   * @exception ConnectException  If the admin connection is closed or broken.
456
   * @exception AdminException  If the request fails.
457
   */
2889 afreyssin 458
  public void setNbMaxMsg(String subName, int nbMaxMsg) throws ConnectException, AdminException {
459
    //  TODO: Subscription sub = getSubscription(subName);
460
    doRequest(new SetNbMaxMsg(proxyId, nbMaxMsg, subName));
1331 tachker 461
  }
462
 
463
  /**
464
   * Monitoring method returning the nbMaxMsg of this subscription, -1 if no limit.
465
   * <p>
466
   * The request fails if the sub is deleted server side.
467
   *
468
   * @param subName the name of the subscription.
469
   *
470
   * @exception ConnectException  If the admin connection is closed or broken.
471
   * @exception AdminException  If the request fails.
472
   */
2889 afreyssin 473
  public int getNbMaxMsg(String subName) throws ConnectException, AdminException {
474
    //  TODO: Subscription sub = getSubscription(subName);
1331 tachker 475
    Monitor_GetNbMaxMsg request = new Monitor_GetNbMaxMsg(proxyId, subName);
2889 afreyssin 476
    Monitor_GetNbMaxMsgRep reply = (Monitor_GetNbMaxMsgRep) doRequest(request);
1331 tachker 477
    return reply.getNbMaxMsg();
478
  }
479
 
480
  /**
1254 afreyssin 481
   * Returns the subscriptions owned by a user.
482
   *
483
   * @param serverId the identifier of the server where the user has been
484
   *        created.
485
   *
486
   * @param userName name of the user.
487
   *
488
   * @exception AdminException If an error is raised by the
489
   *                           administration operation.
490
   *
491
   * @exception ConnectException  If the admin connection is not established.
492
   */
2889 afreyssin 493
  public Subscription[] getSubscriptions() throws AdminException, ConnectException {
494
    GetSubscriptionsRep reply = (GetSubscriptionsRep) doRequest(new GetSubscriptions(proxyId));
495
 
1254 afreyssin 496
    String[] subNames = reply.getSubNames();
497
    String[] topicIds = reply.getTopicIds();
498
    int[] messageCounts = reply.getMessageCounts();
499
    boolean[] durable = reply.getDurable();
2889 afreyssin 500
 
1254 afreyssin 501
    Subscription[] res = new Subscription[subNames.length];
502
    for (int i = 0; i < res.length; i++) {
2889 afreyssin 503
      res[i] = new Subscription(subNames[i], topicIds[i], messageCounts[i], durable[i]);
1254 afreyssin 504
    }
505
    return res;
506
  }
507
 
1331 tachker 508
  /** used by MBean jmx */
2889 afreyssin 509
  public List getSubscriptionList() throws AdminException, ConnectException {
1331 tachker 510
    Vector list = new Vector();
511
    Subscription[] sub = getSubscriptions();
512
    for (int i = 0; i < sub.length; i++) {
513
      list.add(sub[i].toString());
514
    }
515
    return list;
516
  }
517
 
1254 afreyssin 518
  /**
519
   * Returns a subscription.
520
   *
521
   * @param serverId the identifier of the server where the user
522
   * owner of the subscription has been created.
523
   *
524
   * @param userName name of the user that owns the subscription.
525
   *
526
   * @param subName the name of the subscription.
527
   *
528
   * @exception AdminException If an error is raised by the
529
   *                           administration operation.
530
   *
531
   * @exception ConnectException  If the admin connection is not established.
532
   */
2587 afreyssin 533
  public Subscription getSubscription(String subName) throws AdminException, ConnectException {
2889 afreyssin 534
    GetSubscriptionRep reply = (GetSubscriptionRep) doRequest(new GetSubscription(proxyId, subName));
535
    Subscription sub = new Subscription(subName, reply.getTopicId(), reply.getMessageCount(), reply.getDurable());
536
 
537
    return sub;
1254 afreyssin 538
  }
539
 
2587 afreyssin 540
  public String getSubscriptionString(String subName) throws AdminException, ConnectException {
541
    return getSubscription(subName).toString();
1331 tachker 542
  }
543
 
2587 afreyssin 544
  public String[] getMessageIds(String subName) throws AdminException, ConnectException {
2751 afreyssin 545
    GetSubscriptionMessageIdsRep reply =
2889 afreyssin 546
      (GetSubscriptionMessageIdsRep) doRequest(new GetSubscriptionMessageIds(proxyId, subName));
1254 afreyssin 547
    return reply.getMessageIds();
548
  }
549
 
2751 afreyssin 550
  public Message getMessage(String subName,
551
                            String msgId) throws AdminException, ConnectException, JMSException {
552
    GetSubscriptionMessageRep reply =
2889 afreyssin 553
      (GetSubscriptionMessageRep) doRequest(new GetSubscriptionMessage(proxyId, subName, msgId, true));
2751 afreyssin 554
    return Message.wrapMomMessage(null, reply.getMessage());
555
  }
2889 afreyssin 556
 
2751 afreyssin 557
  public String getMessageDigest(String subName,
558
                                 String msgId) throws AdminException, ConnectException, JMSException {
559
    GetSubscriptionMessageRep reply =
2889 afreyssin 560
      (GetSubscriptionMessageRep) doRequest(new GetSubscriptionMessage(proxyId, subName, msgId, true));
2751 afreyssin 561
    Message msg =  Message.wrapMomMessage(null, reply.getMessage());
2889 afreyssin 562
 
2751 afreyssin 563
    StringBuffer strbuf = new StringBuffer();
564
    strbuf.append("Message: ").append(msg.getJMSMessageID());
565
    strbuf.append("\n\tTo: ").append(msg.getJMSDestination());
566
    strbuf.append("\n\tCorrelationId: ").append(msg.getJMSCorrelationID());
567
    strbuf.append("\n\tDeliveryMode: ").append(msg.getJMSDeliveryMode());
568
    strbuf.append("\n\tExpiration: ").append(msg.getJMSExpiration());
569
    strbuf.append("\n\tPriority: ").append(msg.getJMSPriority());
570
    strbuf.append("\n\tRedelivered: ").append(msg.getJMSRedelivered());
571
    strbuf.append("\n\tReplyTo: ").append(msg.getJMSReplyTo());
572
    strbuf.append("\n\tTimestamp: ").append(msg.getJMSTimestamp());
573
    strbuf.append("\n\tType: ").append(msg.getJMSType());
574
    return strbuf.toString();
2889 afreyssin 575
  }
2751 afreyssin 576
 
577
  public Properties getMessageHeader(String subName,
578
                                     String msgId) throws AdminException, ConnectException, JMSException {
579
    GetSubscriptionMessageRep reply =
2889 afreyssin 580
      (GetSubscriptionMessageRep) doRequest(new GetSubscriptionMessage(proxyId, subName, msgId, false));
2751 afreyssin 581
    Message msg =  Message.wrapMomMessage(null, reply.getMessage());
582
 
583
    Properties prop = new Properties();
584
    prop.setProperty("JMSMessageID", msg.getJMSMessageID());
585
    prop.setProperty("JMSDestination", msg.getJMSDestination().toString());
586
    if (msg.getJMSCorrelationID() != null)
587
      prop.setProperty("JMSCorrelationID", msg.getJMSCorrelationID());
588
    prop.setProperty("JMSDeliveryMode",
589
                     new Integer(msg.getJMSDeliveryMode()).toString());
590
    prop.setProperty("JMSExpiration",
591
                     new Long(msg.getJMSExpiration()).toString());
592
    prop.setProperty("JMSPriority",
593
                     new Integer(msg.getJMSPriority()).toString());
594
    prop.setProperty("JMSRedelivered",
595
                     new Boolean(msg.getJMSRedelivered()).toString());
596
    if (msg.getJMSReplyTo() != null)
597
      prop.setProperty("JMSReplyTo", msg.getJMSReplyTo().toString());
598
    prop.setProperty("JMSTimestamp",
599
                     new Long(msg.getJMSTimestamp()).toString());
600
    if (msg.getJMSType() != null)
601
      prop.setProperty("JMSType", msg.getJMSType());
602
 
603
    // Adds optional header properties
604
    msg.getOptionalHeader(prop);
605
 
606
    return prop;
2889 afreyssin 607
  }
2751 afreyssin 608
 
2889 afreyssin 609
  public Properties getMessageProperties(String subName,
610
                                         String msgId) throws AdminException, ConnectException, JMSException {
611
    GetSubscriptionMessageRep reply =
612
      (GetSubscriptionMessageRep) doRequest(new GetSubscriptionMessage(proxyId, subName, msgId, false));
613
    Message msg =  Message.wrapMomMessage(null, reply.getMessage());
2751 afreyssin 614
 
2889 afreyssin 615
    Properties prop = new Properties();
616
    msg.getProperties(prop);
2751 afreyssin 617
 
2889 afreyssin 618
    return prop;
619
  }
2751 afreyssin 620
 
621
  /**
622
   * @deprecated
623
   * @see org.objectweb.joram.client.jms.admin.UserMBean#readMessage(java.lang.String, java.lang.String)
624
   */
1669 afreyssin 625
  public Message readMessage(String subName,
626
                             String msgId) throws AdminException, ConnectException, JMSException {
2751 afreyssin 627
    return getMessage(subName, msgId);
1254 afreyssin 628
  }
629
 
2889 afreyssin 630
  public void deleteMessage(String subName,
631
                            String msgId)  throws AdminException, ConnectException {
632
    doRequest(new DeleteSubscriptionMessage(proxyId, subName, msgId));
1254 afreyssin 633
  }
634
 
2889 afreyssin 635
  public void clearSubscription(String subName) throws AdminException, ConnectException {
636
    doRequest(new ClearSubscription(proxyId, subName));
1254 afreyssin 637
  }
638
 
2889 afreyssin 639
 
861 fmaistre 640
  /** Returns the identifier of the user's proxy. */
1788 afreyssin 641
  public String getProxyId() {
861 fmaistre 642
    return proxyId;
643
  }
644
 
1788 afreyssin 645
  /** Sets the naming reference of a connection factory. */
646
  public void toReference(Reference ref) throws NamingException {
861 fmaistre 647
    ref.add(new StringRefAddr("user.name", name));
648
    ref.add(new StringRefAddr("user.id", proxyId));
649
  }
650
 
1788 afreyssin 651
  /** Restores the administered object from a naming reference. */
652
  public void fromReference(Reference ref) throws NamingException {
653
    name = (String) ref.get("user.name").getContent();
654
    proxyId = (String) ref.get("user.id").getContent();
655
  }
656
 
861 fmaistre 657
  /**
2795 surrel 658
   * Codes an <code>User</code> instance as a Hashtable for traveling
861 fmaistre 659
   * through the SOAP protocol.
660
   */
661
  public Hashtable code() {
1254 afreyssin 662
    Hashtable h = new Hashtable();
2889 afreyssin 663
    h.put("name", name);
664
    h.put("proxyId", proxyId);
861 fmaistre 665
    return h;
666
  }
667
 
668
  /**
2795 surrel 669
   * Decodes an <code>User</code> which traveled through the SOAP protocol.
861 fmaistre 670
   */
1254 afreyssin 671
  public void decode(Hashtable h) {
672
    name = (String) h.get("name");
673
    proxyId = (String) h.get("proxyId");
861 fmaistre 674
  }
675
}