OW2 Consortium joram

Rev

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