Author |
Message
|
mandos_ |
Posted: Tue Jan 16, 2007 1:10 pm Post subject: Event Monitoring Using Java |
|
|
Novice
Joined: 17 Nov 2006 Posts: 17
|
Hail!
I was trying to learn about the analysis of event messages, but when I try to access the parameters from the message got from Event Queue, a java.io.UnsupportedEncodingException is trhow in runtime.
As the code shows:
Code: |
package com.ivs.event;
import java.io.IOException;
import com.ibm.mq.MQC;
import com.ibm.mq.MQException;
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;
import com.ibm.mq.pcf.CMQC;
import com.ibm.mq.pcf.MQCFH;
import com.ibm.mq.pcf.PCFParameter;
public class EventMessageTest {
public static void main(String[] args) {
new EventMessageTest().go();
}
public void go(){
try{
MQQueueManager Qm = new MQQueueManager("QM1");
MQQueue queue = Qm.accessQueue("SYSTEM.ADMIN.PERFM.EVENT", (MQC.MQOO_INPUT_AS_Q_DEF));
MQMessage message = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
queue.get(message, gmo);
MQCFH cfh = new MQCFH(message);
PCFParameter p;
if (cfh.reason == CMQC.MQRC_Q_DEPTH_HIGH){
String qname ="";
for (int i = 0; i < cfh.parameterCount; i++){
p = PCFParameter.nextParameter(message);
if(p.getParameter() == CMQC.MQCA_Q_NAME){
qname = (String) p.getValue();
}
}
System.out.println(qname);
}
}
catch(MQException e){
e.printStackTrace();
}
catch(IOException e){
e.printStackTrace();
}
}
} |
And the exception is:
Code: |
java.io.UnsupportedEncodingException: Cp437
at sun.io.Converters.getConverterClass(Unknown Source)
at sun.io.Converters.newConverter(Unknown Source)
at sun.io.ByteToCharConverter.getConverter(Unknown Source)
at java.lang.StringCoding.decode(Unknown Source)
at java.lang.String.<init>(Unknown Source)
at java.lang.String.<init>(Unknown Source)
at com.ibm.mq.MQMessage.readStringOfByteLength(MQMessage.java:758)
at com.ibm.mq.pcf.MQCFST.initialize(MQCFST.java:176)
at com.ibm.mq.pcf.MQCFST.<init>(MQCFST.java:142)
at com.ibm.mq.pcf.PCFParameter.nextParameter(PCFParameter.java:117)
at com.ibm.mq.pcf.PCFMessage.initialize(PCFMessage.java:512)
at com.ibm.mq.pcf.PCFMessage.<init>(PCFMessage.java:100)
at com.ivs.event.EventMessageTest.go(EventMessageTest.java:38)
at com.ivs.event.EventMessageTest.main(EventMessageTest.java:23) |
Anyone can help me and tell why this exception is throw? May the encoding of the message be wrong?
Thanks. |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Jan 16, 2007 1:23 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
I would use the classes in the Support Pac MS0B instead of trying to write your own. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
mandos_ |
Posted: Tue Jan 16, 2007 6:19 pm Post subject: |
|
|
Novice
Joined: 17 Nov 2006 Posts: 17
|
I'm using the classes in the MS0B (Like PCFParameter and MQCFH)...
I'm just trying to ANALYZE an event message, and, as these messages came with parameters, i try using the same way as analyzing responses of an PCF command.
Have any other way to analyze an Event Message?
Thanks. |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Jan 16, 2007 6:30 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
 _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Jan 17, 2007 5:18 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Okay. To redeem myself, I'm going to suggest you try two things.
Code: |
qname = p.getStringValue(); |
Code: |
PCFMessage pcf = new PCFMessage(message);
qname = pcf.getStringParameterValue(CMQC.MQCA_Q_NAME); |
_________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Jan 17, 2007 5:56 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Man, I'm just not doing well here.
Neither of those will work - it's the BASE_Q_NAME.
This works for me.
Code: |
if(p.getParameter() == CMQC.MQCA_BASE_Q_NAME){
qname = p.getStringValue();;
} |
_________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
mandos_ |
Posted: Wed Jan 17, 2007 8:23 am Post subject: |
|
|
Novice
Joined: 17 Nov 2006 Posts: 17
|
Thanks, jefflowrey!
But, when I try
Code: |
PCFMessage pcf = new PCFMessage(message); |
the same exception is trhow....
Code: |
java.io.UnsupportedEncodingException: Cp437
at sun.io.Converters.getConverterClass(Unknown Source)
at sun.io.Converters.newConverter(Unknown Source)
at sun.io.ByteToCharConverter.getConverter(Unknown Source)
at java.lang.StringCoding.decode(Unknown Source)
at java.lang.String.<init>(Unknown Source)
at java.lang.String.<init>(Unknown Source)
at com.ibm.mq.MQMessage.readStringOfByteLength(MQMessage.java:758)
at com.ibm.mq.pcf.MQCFST.initialize(MQCFST.java:176)
at com.ibm.mq.pcf.MQCFST.<init>(MQCFST.java:142)
at com.ibm.mq.pcf.PCFParameter.nextParameter(PCFParameter.java:117)
at com.ibm.mq.pcf.PCFMessage.initialize(PCFMessage.java:512)
at com.ibm.mq.pcf.PCFMessage.<init>(PCFMessage.java:100)
at com.ivs.event.EventMessageTest.go(EventMessageTest.java:30)
at com.ivs.event.EventMessageTest.main(EventMessageTest.java:20) |
Where (EventMessageTest.java:30) is the line PCFMessage pcf = new PCFMessage(message)...
I was thinking that the encoding is wrong... but... Why?
Can you show your code to me to test?
Thanks. |
|
Back to top |
|
 |
mandos_ |
Posted: Wed Jan 17, 2007 8:55 am Post subject: |
|
|
Novice
Joined: 17 Nov 2006 Posts: 17
|
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Jan 17, 2007 9:16 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
It is probably some kind of wrong MQ configuration. It could potentially be a path/classpath issue, but it's not as likely.
The new PCFMessage code doesn't work at all - event messages aren't castable as PCFMessage objects, I guess.
The code I got working is the same as yours, except I called getStringValue rather than getValue.
You do have a full, proper, MQ install on the machine you're using, right?
From what you've coded, I would expect that QM1 is a local queue manager. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Jan 17, 2007 3:50 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
It might just take the encoding from the request message. Make sure the encoding has a correct value by using the litterals. Remember the encoding field can take any int value but only a few make sense.
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Jan 17, 2007 4:11 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
fjb_saper wrote: |
It might just take the encoding from the request message. |
Except he's reading Event Messages, not PCF Response messages. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Jan 17, 2007 4:25 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
jefflowrey wrote: |
fjb_saper wrote: |
It might just take the encoding from the request message. |
Except he's reading Event Messages, not PCF Response messages. |
Not the right version? Displacement in the header ??
An encoding error message sounds strange here...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Jan 17, 2007 4:27 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
My thought is that the character conversion tables aren't available somehow. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
mandos_ |
Posted: Thu Jan 18, 2007 10:28 am Post subject: |
|
|
Novice
Joined: 17 Nov 2006 Posts: 17
|
Hail!
I have found the problem...
Strangely it was the Java Version... I was running my code with the JRE 1.5 Update 9 and the problem always occurred.
When I ran the code in another PC (JRE 1.5 Update 8) It works fine...
Then, as I already have installed the JRE1.5 Update 10, I have tried to run with this one... And it works!!!!
Probably the problem was that, the java Version. If you want, try to run with the Update 9 and tell me if the problem occurs.
Thanks, anyway! |
|
Back to top |
|
 |
RogerLacroix |
Posted: Sun Jan 21, 2007 10:24 am Post subject: |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3264 Location: London, ON Canada
|
mandos_ wrote: |
Strangely it was the Java Version... I was running my code with the JRE 1.5 Update 9 and the problem always occurred.
|
I would guess that you download the USA / English only version and not the international version of the JRE, as I have had similar problems before.
Regards,
Roger Lacroix
Capitalware Inc. _________________ Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter |
|
Back to top |
|
 |
|