OW2 Consortium joram

Rev

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