OW2 Consortium joram

Rev

Rev 2971 | Rev 3060 | 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 {
2988 afreyssin 136
    if ((wrapper != null) && (! wrapper.isClosed()))
137
      return wrapper;
2889 afreyssin 138
    return AdminModule.getWrapper();
139
  }
140
 
141
  /**
142
   * Sets the administration wrapper to use.
143
   * If not set the AdminModule static connection is used by default.
144
   *
145
   * @param wrapper The wrapper to use or null to unset.
146
   */
147
  public void setWrapper(AdminWrapper wrapper) {
148
    this.wrapper = wrapper;
149
  }
150
 
151
  /**
152
   * Method actually sending an <code>AdminRequest</code> instance to
153
   * the platform and getting an <code>AdminReply</code> instance.
154
   *
155
   * @param request the administration request to send
156
   * @return  the reply message
157
   *
158
   * @exception ConnectException  If the connection to the platform fails.
159
   * @exception AdminException  If the platform's reply is invalid, or if
160
   *              the request failed.
161
   */
162
  public final AdminReply doRequest(AdminRequest request) throws AdminException, ConnectException {
163
    return getWrapper().doRequest(request);
164
  }
165
 
166
  /**
2795 surrel 167
   * Admin method creating a user for a given server and instantiating the
861 fmaistre 168
   * corresponding <code>User</code> object.
169
   * <p>
170
   * If the user has already been set on this server, the method simply
171
   * returns the corresponding <code>User</code> object. Its fails if the
172
   * target server does not belong to the platform, or if a proxy could not
173
   * be deployed server side for a new user.
2889 afreyssin 174
   * <p>
175
   * Be careful this method use the static AdminModule connection.
861 fmaistre 176
   *
177
   * @param name  Name of the user.
178
   * @param password  Password of the user.
179
   * @param serverId  The identifier of the user's server.
180
   *
181
   * @exception ConnectException  If the connection fails.
182
   * @exception AdminException  If the request fails.
183
   */
2889 afreyssin 184
  public static User create(String name, String password,
185
                            int serverId) throws ConnectException, AdminException {
2813 afreyssin 186
    return create(name, password, serverId, SimpleIdentity.class.getName());
861 fmaistre 187
  }
2889 afreyssin 188
 
861 fmaistre 189
  /**
2795 surrel 190
   * Admin method creating a user on the local server and instantiating the
861 fmaistre 191
   * corresponding <code>User</code> object.
192
   * <p>
193
   * If the user has already been set on this server, the method simply
194
   * returns the corresponding <code>User</code> object. It fails if a
195
   * proxy could not be deployed server side for a new user.
2889 afreyssin 196
   * <p>
197
   * Be careful this method use the static AdminModule connection.
861 fmaistre 198
   *
199
   * @param name  Name of the user.
200
   * @param password  Password of the user.
201
   *
202
   * @exception ConnectException  If the connection fails.
203
   * @exception AdminException  If the request fails.
204
   */
2889 afreyssin 205
  public static User create(String name, String password) throws ConnectException, AdminException {
2813 afreyssin 206
    return create(name, password, AdminModule.getLocalServerId(), SimpleIdentity.class.getName());
861 fmaistre 207
  }
2889 afreyssin 208
 
861 fmaistre 209
  /**
2795 surrel 210
   * Admin method creating a user for a given server and instantiating the
2663 tachker 211
   * corresponding <code>User</code> object.
212
   * <p>
213
   * If the user has already been set on this server, the method simply
214
   * returns the corresponding <code>User</code> object. Its fails if the
215
   * target server does not belong to the platform, or if a proxy could not
216
   * be deployed server side for a new user.
2889 afreyssin 217
   * <p>
218
   * Be careful this method use the static AdminModule connection.
2663 tachker 219
   *
220
   * @param name  Name of the user.
221
   * @param password  Password of the user.
222
   * @param serverId  The identifier of the user's server.
2795 surrel 223
   * @param identityClassName user/password or JAAS... (default SimpleIdentity).
2663 tachker 224
   *
225
   * @exception ConnectException  If the connection fails.
226
   * @exception AdminException  If the request fails.
227
   */
2889 afreyssin 228
  public static User create(String name, String password,
229
                            int serverId,
230
                            String identityClassName) throws ConnectException, AdminException {
2663 tachker 231
    Identity identity = createIdentity(name, password, identityClassName);
2889 afreyssin 232
 
233
    AdminReply reply = AdminModule.doRequest(new CreateUserRequest(identity, serverId));
2663 tachker 234
    User user = new User(name, ((CreateUserReply) reply).getProxId());
2889 afreyssin 235
 
2931 afreyssin 236
    // Be careful, MBean registration is now done explicitly
2889 afreyssin 237
 
238
    return user;
239
  }
240
 
2931 afreyssin 241
  // Object name of the MBean if it is registered.
2889 afreyssin 242
  transient protected String JMXBeanName = null;
243
 
2931 afreyssin 244
  public String registerMBean(String base) {
245
    if (MXWrapper.mxserver == null) return null;
2889 afreyssin 246
 
247
    StringBuffer buf = new StringBuffer();
2931 afreyssin 248
    buf.append(base).append(':');
2889 afreyssin 249
    buf.append("type=User,name=").append(getName()).append('[').append(getProxyId()).append(']');
250
    JMXBeanName = buf.toString();
2931 afreyssin 251
 
2663 tachker 252
    try {
2931 afreyssin 253
      MXWrapper.registerMBean(this, JMXBeanName);
2663 tachker 254
    } catch (Exception e) {
2971 afreyssin 255
      if (logger.isLoggable(BasicLevel.DEBUG))
256
        logger.log(BasicLevel.DEBUG, "User.registerMBean: " + JMXBeanName, e);
2663 tachker 257
    }
2931 afreyssin 258
 
259
    return JMXBeanName;
2663 tachker 260
  }
2889 afreyssin 261
 
262
  public void unregisterMBean() {
2931 afreyssin 263
    if ((MXWrapper.mxserver == null) || (JMXBeanName == null)) return;
2889 afreyssin 264
 
265
    try {
2931 afreyssin 266
      MXWrapper.unregisterMBean(JMXBeanName);
2889 afreyssin 267
    } catch (Exception e) {
2971 afreyssin 268
      if (logger.isLoggable(BasicLevel.DEBUG))
269
        logger.log(BasicLevel.DEBUG, "User.unregisterMBean: " + JMXBeanName, e);
2889 afreyssin 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));
2931 afreyssin 342
    unregisterMBean();
861 fmaistre 343
  }
344
 
345
  /**
346
   * Admin method setting a given dead message queue for this user.
347
   * <p>
348
   * The request fails if the user is deleted server side.
349
   *
350
   * @param dmq  The dead message queue to be set.
351
   *
352
   * @exception ConnectException  If the connection fails.
353
   * @exception AdminException  If the request fails.
354
   */
1788 afreyssin 355
  public void setDMQ(DeadMQueue dmq) throws ConnectException, AdminException {
1873 tachker 356
    setDMQId(dmq.getName());
861 fmaistre 357
  }
358
 
359
  /**
1873 tachker 360
   * Admin method setting a given dead message queue for this user.
361
   * <p>
362
   * The request fails if the user is deleted server side.
363
   *
364
   * @param dmqId  The dead message queue Id to be set.
365
   *
366
   * @exception ConnectException  If the connection fails.
367
   * @exception AdminException  If the request fails.
368
   */
369
  public void setDMQId(String dmqId) throws ConnectException, AdminException {
2889 afreyssin 370
    doRequest(new SetUserDMQ(proxyId, dmqId));
1873 tachker 371
  }
2889 afreyssin 372
 
1873 tachker 373
  /**
861 fmaistre 374
   * Admin method setting a given value as the threshold for this user.
375
   * <p>
376
   * The request fails if the user is deleted server side.
377
   *
2746 afreyssin 378
   * @param threshold  The threshold value to be set (-1 for unsetting
379
   *                   previous value).
861 fmaistre 380
   *
381
   * @exception ConnectException  If the connection fails.
382
   * @exception AdminException  If the request fails.
383
   */
2889 afreyssin 384
  public void setThreshold(int threshold) throws ConnectException, AdminException {
385
    doRequest(new SetUserThreshold(proxyId, threshold));
861 fmaistre 386
  }
387
 
388
  /**
389
   * Returns the dead message queue for this user, null if not set.
390
   * <p>
391
   * The request fails if the user is deleted server side.
392
   *
393
   * @exception ConnectException  If the connection fails.
394
   * @exception AdminException  If the request fails.
395
   */
1788 afreyssin 396
  public DeadMQueue getDMQ() throws ConnectException, AdminException {
861 fmaistre 397
    Monitor_GetDMQSettings request;
398
    request = new Monitor_GetDMQSettings(proxyId);
399
    Monitor_GetDMQSettingsRep reply;
2889 afreyssin 400
    reply = (Monitor_GetDMQSettingsRep) doRequest(request);
401
 
861 fmaistre 402
    if (reply.getDMQName() == null)
403
      return null;
2889 afreyssin 404
 
405
    DeadMQueue dmq = new DeadMQueue(reply.getDMQName());
406
    if (wrapper != null)
407
      dmq.setWrapper(wrapper);
408
 
409
    return dmq;
861 fmaistre 410
  }
411
 
412
  /**
1873 tachker 413
   * Returns the dead message queue Id for this user, null if not set.
414
   * <p>
415
   * The request fails if the user is deleted server side.
416
   *
417
   * @exception ConnectException  If the connection fails.
418
   * @exception AdminException  If the request fails.
419
   */
420
  public String getDMQId() throws ConnectException, AdminException {
421
    DeadMQueue dmq = getDMQ();
422
    if (dmq == null)
423
      return null;
424
    else
425
      return dmq.getName();
426
  }
2889 afreyssin 427
 
1873 tachker 428
  /**
861 fmaistre 429
   * Returns the threshold for this user, -1 if not set.
430
   * <p>
431
   * The request fails if the user is deleted server side.
432
   *
433
   * @exception ConnectException  If the connection fails.
434
   * @exception AdminException  If the request fails.
435
   */
1788 afreyssin 436
  public int getThreshold() throws ConnectException, AdminException {
2889 afreyssin 437
    Monitor_GetDMQSettings request = new Monitor_GetDMQSettings(proxyId);
438
    Monitor_GetDMQSettingsRep reply = (Monitor_GetDMQSettingsRep) doRequest(request);
439
 
861 fmaistre 440
    if (reply.getThreshold() == null)
441
      return -1;
442
    else
443
      return reply.getThreshold().intValue();
444
  }
445
 
1254 afreyssin 446
  /**
1331 tachker 447
   * Admin method setting nbMaxMsg for this subscription.
448
   * <p>
449
   * The request fails if the sub is deleted server side.
450
   *
451
   * @param subName the name of the subscription.
452
   * @param nbMaxMsg  nb Max of Message (-1 no limit).
453
   *
454
   * @exception ConnectException  If the admin connection is closed or broken.
455
   * @exception AdminException  If the request fails.
456
   */
2889 afreyssin 457
  public void setNbMaxMsg(String subName, int nbMaxMsg) throws ConnectException, AdminException {
458
    //  TODO: Subscription sub = getSubscription(subName);
459
    doRequest(new SetNbMaxMsg(proxyId, nbMaxMsg, subName));
1331 tachker 460
  }
461
 
462
  /**
463
   * Monitoring method returning the nbMaxMsg of this subscription, -1 if no limit.
464
   * <p>
465
   * The request fails if the sub is deleted server side.
466
   *
467
   * @param subName the name of the subscription.
468
   *
469
   * @exception ConnectException  If the admin connection is closed or broken.
470
   * @exception AdminException  If the request fails.
471
   */
2889 afreyssin 472
  public int getNbMaxMsg(String subName) throws ConnectException, AdminException {
473
    //  TODO: Subscription sub = getSubscription(subName);
1331 tachker 474
    Monitor_GetNbMaxMsg request = new Monitor_GetNbMaxMsg(proxyId, subName);
2889 afreyssin 475
    Monitor_GetNbMaxMsgRep reply = (Monitor_GetNbMaxMsgRep) doRequest(request);
1331 tachker 476
    return reply.getNbMaxMsg();
477
  }
478
 
479
  /**
1254 afreyssin 480
   * Returns the subscriptions owned by a user.
481
   *
482
   * @param serverId the identifier of the server where the user has been
483
   *        created.
484
   *
485
   * @param userName name of the user.
486
   *
487
   * @exception AdminException If an error is raised by the
488
   *                           administration operation.
489
   *
490
   * @exception ConnectException  If the admin connection is not established.
491
   */
2889 afreyssin 492
  public Subscription[] getSubscriptions() throws AdminException, ConnectException {
493
    GetSubscriptionsRep reply = (GetSubscriptionsRep) doRequest(new GetSubscriptions(proxyId));
494
 
1254 afreyssin 495
    String[] subNames = reply.getSubNames();
496
    String[] topicIds = reply.getTopicIds();
497
    int[] messageCounts = reply.getMessageCounts();
498
    boolean[] durable = reply.getDurable();
2889 afreyssin 499
 
1254 afreyssin 500
    Subscription[] res = new Subscription[subNames.length];
501
    for (int i = 0; i < res.length; i++) {
2889 afreyssin 502
      res[i] = new Subscription(subNames[i], topicIds[i], messageCounts[i], durable[i]);
1254 afreyssin 503
    }
504
    return res;
505
  }
506
 
1331 tachker 507
  /** used by MBean jmx */
2889 afreyssin 508
  public List getSubscriptionList() throws AdminException, ConnectException {
1331 tachker 509
    Vector list = new Vector();
510
    Subscription[] sub = getSubscriptions();
511
    for (int i = 0; i < sub.length; i++) {
512
      list.add(sub[i].toString());
513
    }
514
    return list;
515
  }
516
 
1254 afreyssin 517
  /**
518
   * Returns a subscription.
519
   *
520
   * @param serverId the identifier of the server where the user
521
   * owner of the subscription has been created.
522
   *
523
   * @param userName name of the user that owns the subscription.
524
   *
525
   * @param subName the name of the subscription.
526
   *
527
   * @exception AdminException If an error is raised by the
528
   *                           administration operation.
529
   *
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
  /**
621
   * @deprecated
622
   * @see org.objectweb.joram.client.jms.admin.UserMBean#readMessage(java.lang.String, java.lang.String)
623
   */
1669 afreyssin 624
  public Message readMessage(String subName,
625
                             String msgId) throws AdminException, ConnectException, JMSException {
2751 afreyssin 626
    return getMessage(subName, msgId);
1254 afreyssin 627
  }
628
 
2889 afreyssin 629
  public void deleteMessage(String subName,
630
                            String msgId)  throws AdminException, ConnectException {
631
    doRequest(new DeleteSubscriptionMessage(proxyId, subName, msgId));
1254 afreyssin 632
  }
633
 
2889 afreyssin 634
  public void clearSubscription(String subName) throws AdminException, ConnectException {
635
    doRequest(new ClearSubscription(proxyId, subName));
1254 afreyssin 636
  }
637
 
2889 afreyssin 638
 
861 fmaistre 639
  /** Returns the identifier of the user's proxy. */
1788 afreyssin 640
  public String getProxyId() {
861 fmaistre 641
    return proxyId;
642
  }
643
 
1788 afreyssin 644
  /** Sets the naming reference of a connection factory. */
645
  public void toReference(Reference ref) throws NamingException {
861 fmaistre 646
    ref.add(new StringRefAddr("user.name", name));
647
    ref.add(new StringRefAddr("user.id", proxyId));
648
  }
649
 
1788 afreyssin 650
  /** Restores the administered object from a naming reference. */
651
  public void fromReference(Reference ref) throws NamingException {
652
    name = (String) ref.get("user.name").getContent();
653
    proxyId = (String) ref.get("user.id").getContent();
654
  }
655
 
861 fmaistre 656
  /**
2795 surrel 657
   * Codes an <code>User</code> instance as a Hashtable for traveling
861 fmaistre 658
   * through the SOAP protocol.
659
   */
660
  public Hashtable code() {
1254 afreyssin 661
    Hashtable h = new Hashtable();
2889 afreyssin 662
    h.put("name", name);
663
    h.put("proxyId", proxyId);
861 fmaistre 664
    return h;
665
  }
666
 
667
  /**
2795 surrel 668
   * Decodes an <code>User</code> which traveled through the SOAP protocol.
861 fmaistre 669
   */
1254 afreyssin 670
  public void decode(Hashtable h) {
671
    name = (String) h.get("name");
672
    proxyId = (String) h.get("proxyId");
861 fmaistre 673
  }
674
}