-
Notifications
You must be signed in to change notification settings - Fork 33
/
DirectPacket.java
1885 lines (1734 loc) · 74.7 KB
/
DirectPacket.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2000, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2022 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.messaging.jms.ra;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.logging.Logger;
import jakarta.jms.DeliveryMode;
import jakarta.jms.Destination;
import jakarta.jms.JMSException;
import jakarta.jms.Message;
import jakarta.jms.MessageFormatException;
import jakarta.jms.MessageNotReadableException;
import jakarta.jms.MessageNotWriteableException;
import com.sun.messaging.DestinationConfiguration;
import com.sun.messaging.jmq.ClientConstants;
import com.sun.messaging.jmq.io.JMQByteArrayOutputStream;
import com.sun.messaging.jmq.io.JMSPacket;
import com.sun.messaging.jmq.io.Packet;
import com.sun.messaging.jmq.io.PacketFlag;
import com.sun.messaging.jmq.io.PacketType;
import com.sun.messaging.jmq.io.SysMessageID;
import com.sun.messaging.jmq.jmsclient.MessageImpl;
import com.sun.messaging.jmq.jmsclient.zip.Compressor;
import com.sun.messaging.jmq.jmsclient.zip.Decompressor;
import com.sun.messaging.jmq.jmsservice.JMSService;
import com.sun.messaging.jmq.util.net.IPAddress;
/**
* DirectPacket encapsulates the JMS Message and Sun MQ Packet for DIRECT Mode.
* <p>
*/
public class DirectPacket implements JMSPacket, jakarta.jms.Message, com.sun.messaging.jms.Message {
/** The Sun MQ Packet that is associated with this DirectPacket */
protected Packet pkt = null;
/** The SysMessageID of this DirectPacket when it is received */
private SysMessageID receivedSysMessageID = null;
/** The Properties of the JMS Message */
private Hashtable<String, Object> properties = null;
/** The consumerId sent by the broker if this is a delivered JMS Message */
private long consumerId = 0L;
/** The JMS Destination of the JMS Message - usable via JMS API */
private jakarta.jms.Destination jmsDestination = null;
/** The JMS ReplyTo Destination of the JMS Message - usable via JMS API */
private jakarta.jms.Destination jmsReplyTo = null;
/** The JMS MessageID of the JMS Message - usable via JMS API */
private String jmsMessageID = null;
/**
* Indicates whether the client application has programatically set the JMS MessageID
*/
private boolean jmsMessageIDSet = false;
/** The flags controlling read-only mode for this JMS Message */
private boolean readOnlyBody = false;
private boolean readOnlyProperties = false;
/**
* The DirectSession that is associated with this JMS Message This is only used with messages which have been received,
* not for messages which are being sent
*/
private DirectSession ds = null;
/** Flags whether this JMS Message is a QueueBrowser message or not */
private boolean browserMessage = false;
/**
* Logging
*/
private static final String _className = "com.sun.messaging.jms.ra.DirectPacket";
private static final String _lgrNameOutboundConnection = "javax.resourceadapter.mqjmsra.outbound.connection";
private static final String _lgrNameJMSMessage = "jakarta.jms.Message.mqjmsra";
protected static final Logger _loggerOC = Logger.getLogger(_lgrNameOutboundConnection);
protected static final Logger _loggerJM = Logger.getLogger(_lgrNameJMSMessage);
private static final String _lgrMIDPrefix = "MQJMSRA_DM";
protected static final String _lgrMID_EET = _lgrMIDPrefix + "1001: ";
protected static final String _lgrMID_INF = _lgrMIDPrefix + "1101: ";
protected static final String _lgrMID_WRN = _lgrMIDPrefix + "2001: ";
protected static final String _lgrMID_ERR = _lgrMIDPrefix + "3001: ";
protected static final String _lgrMID_EXC = _lgrMIDPrefix + "4001: ";
/** For optimized logging while messaging */
protected static final int _logLevel;
protected static final boolean _logFINE;
protected static final String UTF8 = "UTF8";
protected static final int DIRECT_PACKET_LOCAL_PORT = 1;
private static final byte[] pktIPAddress;
private static final byte[] pktMacAddress;
protected boolean shouldCompress = false;
protected int clientRetries = 0;
public static final String JMS_SUN_COMPRESS = "JMS_SUN_COMPRESS";
public static final String JMS_SUN_UNCOMPRESSED_SIZE = "JMS_SUN_UNCOMPRESSED_SIZE";
public static final String JMS_SUN_COMPRESSED_SIZE = "JMS_SUN_COMPRESSED_SIZE";
private boolean enableZip = Boolean.getBoolean("imq.zip.enable");
static {
// _loggerOC = Logger.getLogger(_lgrNameOutboundConnection);
// _loggerJM = Logger.getLogger(_lgrNameJMSMessage);
pktMacAddress = ((System.getProperty("imq.useMac", "true")).equalsIgnoreCase("true") ? IPAddress.getRandomMac() : null);
InetAddress addr = null;
try {
addr = InetAddress.getLocalHost();
} catch (UnknownHostException ex) {
}
pktIPAddress = (addr == null ? null : addr.getAddress());
java.util.logging.Level _level = _loggerJM.getLevel();
int tmplevel = java.util.logging.Level.INFO.intValue();
boolean tmplogfine = false;
if (_level != null) {
tmplevel = _level.intValue();
if (tmplevel <= java.util.logging.Level.FINE.intValue()) {
tmplogfine = true;
}
}
_logLevel = tmplevel;
_logFINE = tmplogfine;
}
/** Create a new instance of DirectPacket - used by createMessage APIs */
public DirectPacket(DirectSession ds) throws JMSException {
if (_logFINE) {
Object params[] = new Object[2];
params[0] = ds;
_loggerOC.entering(_className, "constructor()", params);
}
// Use the default (i.e. using Direct ByteBuffer)
this.ds = ds;
this.pkt = new Packet();
this._setDefaultValues();
}
public DirectPacket(JMSPacket jmsPacket, long consumerId, DirectSession ds) throws JMSException {
if (jmsPacket != null) {
this.pkt = jmsPacket.getPacket();
this.consumerId = consumerId;
this.ds = ds;
try {
this.properties = this.pkt.getProperties();
} catch (Exception ex) {
this.properties = null;
ex.printStackTrace();
String exerrmsg = _lgrMID_EXC + "DirectPacket:Constructor on deliver:Unable to get properties from JMSPacket.";
JMSException jmse = new JMSException(exerrmsg);
throw jmse;
}
this.setIntProperty(JMSService.JMSXProperties.JMSXDeliveryCount.toString(), jmsPacket.getPacket().getDeliveryCount());
this.readOnlyProperties = true;
this.readOnlyBody = true;
} else {
String exerrmsg = _lgrMID_EXC + "DirectPacket:Construct on deliver:Failed due to invalid JMSPacket.";
JMSException jmse = new JMSException(exerrmsg);
throw jmse;
}
}
/**
* Factory to construct the right type of JMS Message from a received JMSPacket
*
* If browserMessage is set to false, this is a message that is received by a consumer and receivedSysMessageIDwill be
* initialized from the Packet for use when acknowledging the message.
*
* If browserMessage is set to true, them receivedSysMessageID is left as null
*/
protected static jakarta.jms.Message constructMessage(JMSPacket jmsPacket, long consumerId, DirectSession ds, JMSService jmsservice,
boolean browserMessage) throws JMSException {
jakarta.jms.Message jmsMsg = null;
boolean valid = true;
Throwable t = null;
int pType = 0;
try {
pType = jmsPacket.getPacket().getPacketType();
switch (pType) {
case PacketType.MESSAGE:
jmsMsg = new DirectPacket(jmsPacket, consumerId, ds);
break;
case PacketType.BYTES_MESSAGE:
jmsMsg = new DirectBytesPacket(jmsPacket, consumerId, ds);
break;
case PacketType.MAP_MESSAGE:
jmsMsg = new DirectMapPacket(jmsPacket, consumerId, ds);
break;
case PacketType.OBJECT_MESSAGE:
jmsMsg = new DirectObjectPacket(jmsPacket, consumerId, ds);
break;
case PacketType.STREAM_MESSAGE:
jmsMsg = new DirectStreamPacket(jmsPacket, consumerId, ds);
break;
case PacketType.TEXT_MESSAGE:
jmsMsg = new DirectTextPacket(jmsPacket, consumerId, ds);
break;
default:
valid = false;
}
} catch (Exception e) {
valid = false;
t = e;
}
if (!valid) {
String exerrmsg = _lgrMID_EXC + "DirectPacket:constructMessage():" + "Failed on invalid " + "PacketType=" + pType
+ ((t != null) ? " due to Exception=" + t.getMessage() : "") + ".";
JMSException jmse = new JMSException(exerrmsg);
if (t != null) {
jmse.initCause(t);
}
throw jmse;
}
// Finally set whether this is a Browser Message or not
((DirectPacket) jmsMsg).browserMessage = browserMessage;
if (browserMessage != true) {
((DirectPacket) jmsMsg).setReceivedSysMessageID((SysMessageID) jmsPacket.getPacket().getSysMessageID().clone());
}
return jmsMsg;
}
/** Factory to construct our JMS Message from a foreign JMS Message */
protected static DirectPacket constructFromForeignMessage(JMSService jmsservice, DirectSession ds, jakarta.jms.Message foreignMessage)
throws JMSException {
DirectPacket jmsMsg = null;
if (foreignMessage instanceof jakarta.jms.TextMessage) {
DirectTextPacket dtp = new DirectTextPacket(ds, ((jakarta.jms.TextMessage) foreignMessage).getText());
jmsMsg = dtp;
} else if (foreignMessage instanceof jakarta.jms.MapMessage) {
DirectMapPacket dmp = new DirectMapPacket(ds);
String tkey = null;
Enumeration keys = ((jakarta.jms.MapMessage) foreignMessage).getMapNames();
while (keys.hasMoreElements()) {
tkey = (String) keys.nextElement();
dmp.setObject(tkey, ((jakarta.jms.MapMessage) foreignMessage).getObject(tkey));
}
jmsMsg = dmp;
} else if (foreignMessage instanceof jakarta.jms.ObjectMessage) {
DirectObjectPacket dop = new DirectObjectPacket(ds, ((jakarta.jms.ObjectMessage) foreignMessage).getObject());
jmsMsg = dop;
} else if (foreignMessage instanceof jakarta.jms.BytesMessage) {
DirectBytesPacket dbp = new DirectBytesPacket(ds);
((jakarta.jms.BytesMessage) foreignMessage).reset();
try {
byte b;
while (true) {
b = ((jakarta.jms.BytesMessage) foreignMessage).readByte();
dbp.writeByte(b);
}
} catch (jakarta.jms.MessageEOFException meofe) {
// ok - since the read to eof will end here
} catch (Exception e) {
String exerrmsg = _lgrMID_EXC + "DirectPacket:+" + "constructFromForeignMessage():" + "Failed on converting foreign BytesMessage"
+ " due to Exception=" + e.getMessage();
JMSException jmse = new JMSException(exerrmsg);
jmse.initCause(e);
throw jmse;
}
jmsMsg = dbp;
} else if (foreignMessage instanceof jakarta.jms.StreamMessage) {
DirectStreamPacket dsp = new DirectStreamPacket(ds);
((jakarta.jms.StreamMessage) foreignMessage).reset();
Object obj = null;
try {
while (true) {
obj = ((jakarta.jms.StreamMessage) foreignMessage).readObject();
dsp.writeObject(obj);
}
} catch (jakarta.jms.MessageEOFException meofe) {
// ok - since the read to eof will end here
} catch (Exception e) {
String exerrmsg = _lgrMID_EXC + "DirectPacket:+" + "constructFromForeignMessage():" + "Failed on converting foreign StreamMessage"
+ " due to Exception=" + e.getMessage();
JMSException jmse = new JMSException(exerrmsg);
jmse.initCause(e);
throw jmse;
}
jmsMsg = dsp;
} else {
DirectPacket dp = new DirectPacket(ds);
jmsMsg = dp;
}
// Assign JMS Headers from the foreignMessage to our JMS Message
// that need to be the same as what was set by the application
jmsMsg.setJMSCorrelationID(foreignMessage.getJMSCorrelationID());
jmsMsg.setJMSType(foreignMessage.getJMSType());
// JMS Headers that ned to be set after the send operation
// are
// JMSDeliveryMode
// JMSExpiration
// JMSDeliveryTime
// JMSPriority
// JMSTimestamp
// JMSMessageID
// JMSDestination
//
// The JMSReplyTo JMS Header is specifically excluded from having
// to be handled for a foreign JMS Message
//
// Finally, assign JMS Message Properties from the foreignMessage
// to our JMS Message
Enumeration keys = foreignMessage.getPropertyNames();
String tkey = null;
Object tvalue = null;
while (keys.hasMoreElements()) {
tkey = (String) keys.nextElement();
tvalue = foreignMessage.getObjectProperty(tkey);
jmsMsg.setObjectProperty(tkey, tvalue);
}
return jmsMsg;
}
/** Method to update the foreign JMS Message after it is used in a send */
protected static void updateForeignMessageAfterSend(DirectPacket jmsPacket, jakarta.jms.Message foreignMessage) throws JMSException {
foreignMessage.setJMSDeliveryMode(jmsPacket.getJMSDeliveryMode());
foreignMessage.setJMSExpiration(jmsPacket.getJMSExpiration());
Method m = null;
try {
Class c = foreignMessage.getClass();
m = c.getMethod("getJMSDeliveryTime", (Class[]) null);
if (Modifier.isAbstract(m.getModifiers())) {
m = null;
}
} catch (NoSuchMethodException e) {
}
if (m != null && jmsPacket.getJMSDeliveryTime() != 0L) {
foreignMessage.setJMSDeliveryTime(jmsPacket.getJMSDeliveryTime());
}
foreignMessage.setJMSPriority(jmsPacket.getJMSPriority());
foreignMessage.setJMSTimestamp(jmsPacket.getJMSTimestamp());
foreignMessage.setJMSMessageID(jmsPacket.getJMSMessageID());
// The JMS Destination will be set to be that which has a name
// in our JMS provider and it may not make any sense in the
// foreign JMS provider
foreignMessage.setJMSDestination(jmsPacket.getJMSDestination());
// The JMSReplyTo JMS Header is excluded from having to be handled
// when a foreign JMS Message is used.
}
/////////////////////////////////////////////////////////////////////////
// methods that implement com.sun.messaging.jmq.jmsservice.JMSPacket
/////////////////////////////////////////////////////////////////////////
@Override
public Packet getPacket() {
return this.pkt;
}
public Message getMessage() {
return this;
}
protected SysMessageID getReceivedSysMessageID() {
return receivedSysMessageID;
}
protected void setReceivedSysMessageID(SysMessageID sysMsgId) {
this.receivedSysMessageID = sysMsgId;
}
/////////////////////////////////////////////////////////////////////////
// end com.sun.messaging.jmq.jmsservice.JMSPacket
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
// methods that implement jakarta.jms.Message
/////////////////////////////////////////////////////////////////////////
/**
* Acknowledge this and all previous messages received.
*
* <P>
* All JMS messages support the acknowledge() method for use when a client has specified that a JMS consumers messages
* are to be explicitly acknowledged.
*
* <P>
* JMS defaults to implicit message acknowledgement. In this mode, calls to acknowledge() are ignored.
*
* <P>
* Acknowledgment of a message automatically acknowledges all messages previously received by the session. Clients may
* individually acknowledge messages or they may choose to acknowledge messages in application defined groups (which is
* done by acknowledging the last received message in the group).
*
* <P>
* Messages that have been received but not acknowledged may be redelivered to the consumer.
*
* @throws JMSException if JMS fails to acknowledge due to some internal JMS error.
* @throws IllegalStateException if this method is called on a closed session.
*/
@Override
public void acknowledge() throws JMSException {
if (_logFINE) {
_loggerJM.fine(_lgrMID_INF + /* "messageId="+messageId+":"+ */"acknowledge()");
}
if (this.browserMessage) {
return;
}
}
/**
* Clear out the message body. Clearing a message's body does not clear its header values or property entries.
*
* <P>
* If this message body was read-only, calling this method leaves the message body is in the same state as an empty body
* in a newly created message.
*
*
* @throws JMSException if JMS fails to due to some internal JMS error.
*/
@Override
public void clearBody() throws JMSException {
if (_logFINE) {
_loggerJM.fine(_lgrMID_INF + /* "messageId="+messageId+":"+ */"clearBody()");
}
// clear out the body of the underlying packet
// sub classes must call this as well as clear out message level data
this.pkt.clearMessageBody();
this._setReadOnlyBody(false);
}
/**
* Clear a message's properties.
*
* <P>
* The message's header fields and body are not cleared.
*
* @throws JMSException if the JMS provider fails to clear the message properties due to some internal error.
*/
@Override
public void clearProperties() throws JMSException {
if (_logFINE) {
_loggerJM.fine(_lgrMID_INF + /* "messageId="+messageId+":"+ */"clearProperties()");
}
this._setReadOnlyProperties(false);
if (this.properties != null) {
this.properties.clear();
}
// set shouldCompress compress flag to false.
shouldCompress = false;
}
/**
* Return the value of the <CODE>boolean</CODE> property with the specified name.
*
* @param name the name of the <CODE>boolean</CODE> property
*
* @return the <CODE>boolean</CODE> property value for the specified name
*
* @throws JMSException if the JMS provider fails to get the property value due to some internal error.
* @throws MessageFormatException if this type conversion is invalid.
*/
@Override
public boolean getBooleanProperty(String name) throws JMSException {
if (_logFINE) {
String methodName = "getBooleanProperty()";
_loggerJM.fine(_lgrMID_INF + /* "messageId="+messageId+":"+ */
methodName + name);
}
Object obj = null;
if (this.properties != null) {
obj = this.properties.get(name);
}
return ConvertValue.toBoolean(obj);
}
/**
* Return the value of the <CODE>byte</CODE> property with the specified name.
*
* @param name the name of the <CODE>byte</CODE> property
*
* @return the <CODE>byte</CODE> property value for the specified name
*
* @throws JMSException if the JMS provider fails to get the property value due to some internal error.
* @throws MessageFormatException if this type conversion is invalid.
*/
@Override
public byte getByteProperty(String name) throws JMSException {
if (_logFINE) {
String methodName = "getByteProperty()";
_loggerJM.fine(_lgrMID_INF + /* "messageId="+messageId+":"+ */
methodName + name);
}
Object obj = null;
if (this.properties != null) {
obj = this.properties.get(name);
}
return ConvertValue.toByte(obj);
}
/**
* Return the value of the <CODE>double</CODE> property with the specified name.
*
* @param name the name of the <CODE>double</CODE> property
*
* @return the <CODE>double</CODE> property value for the specified name
*
* @throws JMSException if the JMS provider fails to get the property value due to some internal error.
* @throws MessageFormatException if this type conversion is invalid.
*/
@Override
public double getDoubleProperty(String name) throws JMSException {
if (_logFINE) {
String methodName = "getDoubleProperty()";
_loggerJM.fine(_lgrMID_INF + /* "messageId="+messageId+":"+ */
methodName + name);
}
Object obj = null;
if (this.properties != null) {
obj = this.properties.get(name);
}
return ConvertValue.toDouble(obj);
}
/**
* Return the value of the <CODE>float</CODE> property with the specified name.
*
* @param name the name of the <CODE>float</CODE> property
*
* @return the <CODE>float</CODE> property value for the specified name
*
* @throws JMSException if the JMS provider fails to get the property value due to some internal error.
* @throws MessageFormatException if this type conversion is invalid.
*/
@Override
public float getFloatProperty(String name) throws JMSException {
if (_logFINE) {
String methodName = "getFloatProperty()";
_loggerJM.fine(_lgrMID_INF + /* "messageId="+messageId+":"+ */
methodName + name);
}
Object obj = null;
if (this.properties != null) {
obj = this.properties.get(name);
}
return ConvertValue.toFloat(obj);
}
/**
* Return the value of the <CODE>int</CODE> property with the specified name.
*
* @param name the name of the <CODE>int</CODE> property
*
* @return the <CODE>int</CODE> property value for the specified name
*
* @throws JMSException if the JMS provider fails to get the property value due to some internal error.
* @throws MessageFormatException if this type conversion is invalid.
*/
@Override
public int getIntProperty(String name) throws JMSException {
if (_logFINE) {
String methodName = "getIntProperty()";
_loggerJM.fine(_lgrMID_INF + /* "messageId="+messageId+":"+ */
methodName + name);
}
Object obj = null;
if (this.properties != null) {
obj = this.properties.get(name);
}
return ConvertValue.toInt(obj);
}
/**
* Get the correlation ID for the message.
*
* <P>
* This method is used to return correlation ID values that are either provider-specific message IDs or
* application-specific <CODE>String</CODE> values.
*
* @return The correlation ID of a message as a <CODE>String</CODE>
*
* @throws JMSException if the JMS provider fails to get the correlation ID due to some internal error.
*
* @see jakarta.jms.Message#setJMSCorrelationID(String)
* @see jakarta.jms.Message#getJMSCorrelationIDAsBytes()
* @see jakarta.jms.Message#setJMSCorrelationIDAsBytes(byte[])
*/
@Override
public String getJMSCorrelationID() throws JMSException {
if (_logFINE) {
_loggerJM.fine(_lgrMID_INF + /* "messageId="+messageId+":"+ */"getJMSCorrelationID()");
}
return pkt.getCorrelationID();
}
/**
* Gets the correlation ID as an array of bytes for the message.
*
* <P>
* The use of a <CODE>byte[]</CODE> value for <CODE>JMSCorrelationID</CODE> is non-portable.
*
* @return the correlation ID of a message as an array of bytes
*
* @throws JMSException if the JMS provider fails to get the correlation ID due to some internal error.
*
* @see jakarta.jms.Message#setJMSCorrelationID(String)
* @see jakarta.jms.Message#getJMSCorrelationID()
* @see jakarta.jms.Message#setJMSCorrelationIDAsBytes(byte[])
*/
@Override
public byte[] getJMSCorrelationIDAsBytes() throws JMSException {
if (_logFINE) {
_loggerJM.fine(_lgrMID_INF + /* "messageId="+messageId+":"+ */"getJMSCorrelationIDAsBytes()");
}
byte[] bytes = null;
try {
bytes = pkt.getCorrelationID().getBytes(UTF8);
} catch (Exception e) {
String exerrmsg = _lgrMID_EXC + "getJMSCorrelationIDAsBytes()" + " failed "/* for connectionId:"+ connectionId */ + ":due to " + e.getMessage();
JMSException jmse = new JMSException(exerrmsg);
_loggerJM.severe(exerrmsg);
jmse.initCause(e);
throw jmse;
}
return bytes;
}
/**
* Get the <CODE>DeliveryMode</CODE> value specified for this message.
*
* @return the delivery mode for this message
*
* @throws JMSException if the JMS provider fails to get the delivery mode due to some internal error.
*
* @see jakarta.jms.Message#setJMSDeliveryMode(int)
* @see jakarta.jms.DeliveryMode
*/
@Override
public int getJMSDeliveryMode() throws JMSException {
if (_logFINE) {
_loggerJM.fine(_lgrMID_INF +
/* "messageId="+messageId+":"+ */"getJMSDeliveryMode()" + "=" + (pkt.getPersistent() ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT));
}
if (pkt.getPersistent()) {
return DeliveryMode.PERSISTENT;
} else {
return DeliveryMode.NON_PERSISTENT;
}
}
/**
* Get the <CODE>Destination</CODE> object for this message.
*
* <P>
* The <CODE>JMSDestination</CODE> header field contains the destination to which the message is being sent.
*
* <P>
* When a message is sent, this field is ignored. After completion of the <CODE>send</CODE> or <CODE>publish</CODE>
* method, the field holds the destination specified by the method.
*
* <P>
* When a message is received, its <CODE>JMSDestination</CODE> value must be equivalent to the value assigned when it
* was sent.
*
* @return the destination of this message
*
* @throws JMSException if the JMS provider fails to get the destination due to some internal error.
*
* @see jakarta.jms.Message#setJMSDestination(Destination)
*/
@Override
public Destination getJMSDestination() throws JMSException {
if (_logFINE) {
_loggerJM.fine(_lgrMID_INF +
/* "messageId="+messageId+":"+ */"getJMSDestination()");
}
String destName = null;
String className = null;
if (this.jmsDestination == null) {
// Initialize when accessed for the first time
// if (destination == null && messageID != null),
// this is a received message.
// we need to construct the dest object if this is a received
// message and when accessed for the first time.
if ((this.getReceivedSysMessageID() != null) || browserMessage) {
try {
destName = this.pkt.getDestination();
className = this.pkt.getDestinationClass();
// instantiate destination object
this.jmsDestination = (com.sun.messaging.Destination) Class.forName(className).getDeclaredConstructor().newInstance();
// set destination name
((com.sun.messaging.Destination) this.jmsDestination).setProperty(DestinationConfiguration.imqDestinationName, destName);
} catch (Exception e) {
// e.printStackTrace();
// if there is a problem, we create a default one
this.jmsDestination = this._constructMQDestination(destName);
}
}
}
return this.jmsDestination;
}
/**
* Get the message's expiration value.
*
* <P>
* When a message is sent, the <CODE>JMSExpiration</CODE> header field is left unassigned. After completion of the
* <CODE>send</CODE> or <CODE>publish</CODE> method, it holds the expiration time of the message. This is the sum of the
* time-to-live value specified by the client and the GMT at the time of the <CODE>send</CODE> or <CODE>publish</CODE>.
*
* <P>
* If the time-to-live is specified as zero, <CODE>JMSExpiration</CODE> is set to zero to indicate that the message does
* not expire.
*
* <P>
* When a message's expiration time is reached, a provider should discard it. The JMS API does not define any form of
* notification of message expiration.
*
* <P>
* Clients should not receive messages that have expired; however, the JMS API does not guarantee that this will not
* happen.
*
* @return the time the message expires, which is the sum of the time-to-live value specified by the client and the GMT
* at the time of the send
*
* @throws JMSException if the JMS provider fails to get the message expiration due to some internal error.
*
* @see jakarta.jms.Message#setJMSExpiration(long)
*/
@Override
public long getJMSExpiration() throws JMSException {
if (_logFINE) {
_loggerJM.fine(_lgrMID_INF + /* "messageId="+messageId+":"+ */"getJMSExpiration()");
}
return this.pkt.getExpiration();
}
/**
* Sets the message's delivery time value.
*
* <P>
* This method is for use by JMS providers only to set this field when a message is sent. This message cannot be used by
* clients to configure the delivery time of the message. This method is public to allow one JMS provider to set this
* field when sending a message whose implementation is not its own.
*
* @param deliveryTime the message's delivery time value
*
* @exception JMSException if the JMS provider fails to set the delivery time due to some internal error.
*
* @see jakarta.jms.Message#getJMSDeliveryTime()
*
* @since 2.0
*/
@Override
public void setJMSDeliveryTime(long deliveryTime) throws JMSException {
if (_logFINE) {
_loggerJM.fine(_lgrMID_INF + /* "messageId="+messageId+":"+ */
"setJMSDeliveryTime()" + deliveryTime);
}
this.pkt.setDeliveryTime(deliveryTime);
}
/**
* Gets the message's delivery time value.
*
* <P>
* When a message is sent, the <CODE>JMSDeliveryTime</CODE> header field is left unassigned. After completion of the
* <CODE>send</CODE> or <CODE>publish</CODE> method, it holds the delivery time of the message. This is the sum of the
* deliveryDelay value specified by the client and the GMT at the time of the <CODE>send</CODE> or <CODE>publish</CODE>.
*
* <P>
* A message's delivery time is the earliest time when a provider may make the message visible on the target destination
* and available for delivery to consumers.
*
* <P>
* Clients must not receive messages before the delivery time has been reached.
*
* @return the message's delivery time, which is the sum of the deliveryDelay value specified by the client and the GMT
* at the time of the <CODE>send</CODE> or <CODE>publish</CODE>.
*
* @exception JMSException if the JMS provider fails to get the message expiration due to some internal error.
*
* @see jakarta.jms.Message#setJMSDeliveryTime(long)
*
* @since 2.0
*/
@Override
public long getJMSDeliveryTime() throws JMSException {
if (_logFINE) {
_loggerJM.fine(_lgrMID_INF + /* "messageId="+messageId+":"+ */"getJMSJMSDeliveryTime()");
}
return this.pkt.getDeliveryTime();
}
/**
* Get the message ID.
*
* <P>
* The <CODE>JMSMessageID</CODE> header field contains a value that uniquely identifies each message sent by a provider.
*
* <P>
* When a message is sent, <CODE>JMSMessageID</CODE> can be ignored. When the <CODE>send</CODE> or <CODE>publish</CODE>
* method returns, it contains a provider-assigned value.
*
* <P>
* A <CODE>JMSMessageID</CODE> is a <CODE>String</CODE> value that should function as a unique key for identifying
* messages in a historical repository. The exact scope of uniqueness is provider-defined. It should at least cover all
* messages for a specific installation of a provider, where an installation is some connected set of message routers.
*
* <P>
* All <CODE>JMSMessageID</CODE> values must start with the prefix <CODE>'ID:'</CODE>. Uniqueness of message ID values
* across different providers is not required.
*
* <P>
* Since message IDs take some effort to create and increase a message's size, some JMS providers may be able to
* optimize message overhead if they are given a hint that the message ID is not used by an application. By calling the
* <CODE>MessageProducer.setDisableMessageID</CODE> method, a JMS client enables this potential optimization for all
* messages sent by that message producer. If the JMS provider accepts this hint, these messages must have the message
* ID set to null; if the provider ignores the hint, the message ID must be set to its normal unique value.
*
* @return the message ID
*
* @throws JMSException if the JMS provider fails to get the message ID due to some internal error.
* @see jakarta.jms.Message#setJMSMessageID(String)
* @see jakarta.jms.MessageProducer#setDisableMessageID(boolean)
*/
@Override
public String getJMSMessageID() throws JMSException {
if (_logFINE) {
_loggerJM.fine(_lgrMID_INF + /* "messageId="+messageId+":"+ */"getJMSMessageID()");
}
if (this.jmsMessageIDSet) {
return this.jmsMessageID;
} else {
return "ID:" + this.pkt.getMessageID();
}
}
/**
* Get the message priority level.
*
* <P>
* The JMS API defines ten levels of priority value, with 0 as the lowest priority and 9 as the highest. In addition,
* clients should consider priorities 0-4 as gradations of normal priority and priorities 5-9 as gradations of expedited
* priority.
*
* <P>
* The JMS API does not require that a provider strictly implement priority ordering of messages; however, it should do
* its best to deliver expedited messages ahead of normal messages.
*
* @return the default message priority
*
* @throws JMSException if the JMS provider fails to get the message priority due to some internal error.
*
* @see jakarta.jms.Message#setJMSPriority(int)
*/
@Override
public int getJMSPriority() throws JMSException {
if (_logFINE) {
_loggerJM.fine(_lgrMID_INF + /* "messageId="+messageId+":"+ */"getJMSPriority()");
}
return this.pkt.getPriority();
}
/**
* Get an indication of whether this message is being redelivered.
*
* <P>
* If a client receives a message with the <CODE>JMSRedelivered</CODE> field set, it is likely, but not guaranteed, that
* this message was delivered earlier but that its receipt was not acknowledged at that time.
*
* @return true if this message is being redelivered
*
* @throws JMSException if the JMS provider fails to get the redelivered state due to some internal error.
*
* @see jakarta.jms.Message#setJMSRedelivered(boolean)
*/
@Override
public boolean getJMSRedelivered() throws JMSException {
if (_logFINE) {
_loggerJM.fine(_lgrMID_INF + /* "messageId="+messageId+":"+ */"getJMSRedelivered()");
}
return this.pkt.getRedelivered();
}
/**
* Get the <CODE>Destination</CODE> object to which a reply to this message should be sent.
*
* @return <CODE>Destination</CODE> to which to send a response to this message
*
* @throws JMSException if the JMS provider fails to get the <CODE>JMSReplyTo</CODE> destination due to some internal
* error.
*
* @see jakarta.jms.Message#setJMSReplyTo(Destination)
*/
@Override
public Destination getJMSReplyTo() throws JMSException {
if (_logFINE) {
_loggerJM.fine(_lgrMID_INF + /* "messageId="+messageId+":"+ */"getJMSReplyTo()");
}
String destName = null;
String className = null;
if (this.jmsReplyTo == null) {
// construct new reply to only for a received msg
if ((this.getReceivedSysMessageID() != null) || browserMessage) {
// if not set, return null
if (this.pkt.getReplyTo() == null) {
return null;
}
// construct dest obj based on bits set in the pkt
try {
destName = this.pkt.getReplyTo();
className = this.pkt.getReplyToClass();
// instantiate replyTo destination obj
this.jmsReplyTo = (com.sun.messaging.Destination) Class.forName(className).getDeclaredConstructor().newInstance();
// set the destination name
((com.sun.messaging.Destination) this.jmsReplyTo).setProperty(DestinationConfiguration.imqDestinationName, destName);
} catch (Exception e) {
// e.printStackTrace();
// if there is a problem, we create a default one
this.jmsReplyTo = this._constructMQDestination(destName);
}
}
}
return this.jmsReplyTo;
}
/**
* Get the message timestamp.
*
* <P>
* The <CODE>JMSTimestamp</CODE> header field contains the time a message was handed off to a provider to be sent. It is
* not the time the message was actually transmitted, because the actual send may occur later due to transactions or
* other client-side queueing of messages.
*
* <P>
* When a message is sent, <CODE>JMSTimestamp</CODE> is ignored. When the <CODE>send</CODE> or <CODE>publish</CODE>
* method returns, it contains a time value somewhere in the interval between the call and the return. The value is in
* the format of a normal millis time value in the Java programming language.
*
* <P>
* Since timestamps take some effort to create and increase a message's size, some JMS providers may be able to optimize
* message overhead if they are given a hint that the timestamp is not used by an application. By calling the
* <CODE>MessageProducer.setDisableMessageTimestamp</CODE> method, a JMS client enables this potential optimization for
* all messages sent by that message producer. If the JMS provider accepts this hint, these messages must have the
* timestamp set to zero; if the provider ignores the hint, the timestamp must be set to its normal value.
*
* @return the message timestamp
*
* @throws JMSException if the JMS provider fails to get the timestamp due to some internal error.
*
* @see jakarta.jms.Message#setJMSTimestamp(long)
* @see jakarta.jms.MessageProducer#setDisableMessageTimestamp(boolean)
*/
@Override
public long getJMSTimestamp() throws JMSException {
if (_logFINE) {
_loggerJM.fine(_lgrMID_INF + /* "messageId="+messageId+":"+ */"getJMSTimestamp()");
}
return this.pkt.getTimestamp();
}
/**
* Get the message type identifier supplied by the client when the message was sent.
*
* @return the message type
*
* @throws JMSException if the JMS provider fails to get the message type due to some internal error.
*
* @see jakarta.jms.Message#setJMSType(String)
*/
@Override
public String getJMSType() throws JMSException {
if (_logFINE) {
_loggerJM.fine(_lgrMID_INF + /* "messageId="+messageId+":"+ */"getJMSType()");