OW2 Consortium joram

Rev

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