|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Follow up to Java API question |
« View previous topic :: View next topic » |
Author |
Message
|
DanielSonFocus |
Posted: Thu Aug 04, 2005 1:08 pm Post subject: Follow up to Java API question |
|
|
 Apprentice
Joined: 05 Jun 2005 Posts: 35 Location: Louisville, Kentucky
|
Hi... so im able put a message via amqsputc and rfhutilc to a queue on a remote queue manager. However, when i use the java client to just create an MQQueueManager object, i get a 2035... i've double checked that i am specifying the correct values and am setting MQEnvironment.userID to the same value used by amqsputc and rfhutilc. Here is the code that i am using:
Code: |
/*
* Created on Jul 18, 2005
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.themancorp.mq;
import java.util.*;
import com.ibm.mq.*;
import java.io.*;
/**
* @author danielSonFocus
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class MQClient {
public static final String NL = System.getProperty("line.separator");
MQQueueManager _qMgr;
String _hostName;
String _channel;
String _qName;
String _qMgrName;
String _user;
String _replyToQ = null;
String _replyToQMgr = null;
int _port;
public MQClient(String qMgrName, String hostName, int port, String channel,
String qName) throws Exception
{
this(qMgrName, hostName, port, channel, qName, null, null);
}
/*************************************************************************/
public MQClient(String qMgrName, String hostName, int port, String channel,
String qName, String replyToQ, String replyToQMgr) throws Exception
{
this(qMgrName, hostName, port, channel, qName, null, null, null);
}
/*************************************************************************/
public MQClient(String qMgrName, String hostName, int port, String channel,
String qName, String replyToQ, String replyToQMgr, String user) throws Exception
{
if(qMgrName == null || hostName == null)
{
System.out.println("QueueManager name AND/OR Host name is NULL.");
throw new Exception("QueueManager name AND/OR Host name is NULL.");
}
if (qMgrName != null)
this._qMgrName = qMgrName;
if (qName != null)
this._qName = qName;
if (channel != null)
{
this._channel = channel;
MQEnvironment.channel = channel;
}
if (hostName != null)
{
this._hostName = hostName;
MQEnvironment.hostname = hostName;
}
if (port != 0)
{
this._port = port;
MQEnvironment.port = port;
}
if (replyToQ != null)
{
this._replyToQ = replyToQ;
}
if (replyToQMgr != null)
{
this._replyToQMgr = replyToQMgr;
}
if (user != null && !(user.equals("")))
{
this._user = user;
MQEnvironment.userID = user;
}
else
{
this._user = MQEnvironment.userID;
}
System.out.println(this._hostName);
System.out.println(this._channel);
System.out.println(this._qName);
System.out.println(this._qMgrName);
System.out.println(this._user);
System.out.println(this._replyToQ);
System.out.println(this._replyToQMgr);
System.out.println(this._port);
try
{
_qMgr = new MQQueueManager(_qMgrName);
}
catch(MQException mqexception)
{
mqexception.printStackTrace ();
String excep = "An MQSeries error occurred : Completion"
+ " code: " + mqexception.completionCode
+ " Reason code: " + mqexception.reasonCode;
System.out.println(excep);
throw new Exception(excep);
}
}
/*************************************************************************/
public void close()
{
if(_qMgr != null)
try
{
_qMgr.disconnect();
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("An error occured while trying to close the" +
" connection to the MQ Queue Manager.");
}
}
/*************************************************************************/
public void finalize() throws Throwable
{
close();
super.finalize();
}
/*************************************************************************/
public byte[] sendReqRepMsgAsync(String msg) throws Exception
{
if(_qMgr == null)
{
System.out.println("Null qmgr object");
throw new Exception("Fatal Error: Null QueueManager. Try " +
"recreating this object");
}
try
{
int options = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING;
MQQueue mqQueue = _qMgr.accessQueue(_qName, options);
MQMessage mqMessage = new MQMessage();
mqMessage.format = MQC.MQFMT_STRING;
if(_replyToQ != null && _replyToQMgr != null)
{
mqMessage.replyToQueueName = _replyToQ;
mqMessage.replyToQueueManagerName = _replyToQMgr;
}
mqMessage.writeString(msg);
MQPutMessageOptions mqPMO = new MQPutMessageOptions();
//MQPutMessageOptions pmo = new MQPutMessageOptions();
//pmo.options = pmo.options + MQC.MQPMO_NEW_MSG_ID;
//pmo.options = pmo.options + MQC.MQPMO_SYNCPOINT;
System.out.println("Putting message... ");
mqQueue.put(mqMessage, mqPMO);
byte[] messageId = new byte[32];
messageId = mqMessage.messageId;
System.out.println("Message was put successfully!");
System.out.println("Message Id: " + Util.printHexId(messageId));
mqQueue.close();
return messageId;
}
catch(MQException mqe)
{
mqe.printStackTrace();
String excep = "An MQSeries error occurred : Completion code "
+ mqe.completionCode + " Reason code "
+ mqe.reasonCode;
System.out.println(excep);
throw new Exception(excep);
}
catch(IOException ioexception)
{
ioexception.printStackTrace ();
String excep = "An error occurred while writing to the message" +
" buffer: " + ioexception.getMessage();
System.out.println(excep);
throw new Exception(excep);
}
catch(Throwable throwable)
{
System.out.println(throwable.getMessage());
throwable.printStackTrace();
System.out.println("Message has been sent successfully.");
return null;
}
}
/*************************************************************************/
public String getMsg() throws Exception
{
String replyMessage = null;
if(_qMgr == null)
{
System.out.println("Null Queue Manager while trying to get message.");
throw new Exception("Fatal Error: Null QueueManager during get");
}
try
{
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_FAIL_IF_QUIESCING;
MQQueue mqQueue = _qMgr.accessQueue(_replyToQ, openOptions,
_replyToQMgr, null, null);
MQMessage mqMessage = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
//gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_CONVERT |
// MQC.MQGMO_NO_SYNCPOINT | MQC.MQGMO_FAIL_IF_QUIESCING;
gmo.options = MQC.MQGMO_WAIT;
gmo.waitInterval = 30000;
System.out.println("Getting message... ");
//System.out.println("Message Id: " + Util.printHexId(messageId));
mqQueue.get(mqMessage, gmo);
System.out.println("Got message successfully! ");
//System.out.println("Correlation Id: " + Util.printHexId(mqMessage.correlationId));
int i= mqMessage.getMessageLength();
byte[] length = new byte[i];
mqMessage.readFully(length);
replyMessage = new String(length);
mqQueue.close();
}
catch(MQException mqexception)
{
if(mqexception.reasonCode == 2033)
{
String s1 = "No Msg: There is no response message available.";
System.out.println(s1);
throw new Exception(s1);
}
else
{
String s2 = "An MQSeries error occurred : Completion code " + mqexception.completionCode + " Reason code " + mqexception.reasonCode;
System.out.println("An error occurred: " + mqexception);
System.out.println(s2);
throw new Exception(s2);
}
}
catch(IOException ioexception)
{
String s3 = "An error occurred while writing to the message buffer: " + ioexception.getMessage();
System.out.println(s3);
throw new Exception(s3);
}
catch(Throwable throwable)
{
System.out.println(throwable.getMessage());
throwable.printStackTrace();
System.out.println("Message\thas been sent successfully.");
}
return replyMessage;
}
/*************************************************************************/
public int getQueueDepth() throws Exception
{
int depth = 0;
if(_qMgr == null)
{
System.out.println("Null Queue Manager while trying to get message.");
throw new Exception("Fatal Error: Null QueueManager during get");
}
try
{
int openOptions = MQC.MQOO_OUTPUT |
MQC.MQOO_INQUIRE |
MQC.MQOO_FAIL_IF_QUIESCING;
MQQueue mqQueue = _qMgr.accessQueue(_replyToQ, openOptions,
_replyToQMgr, null, null);
depth = mqQueue.getCurrentDepth();
mqQueue.close();
}
catch(MQException mqexception)
{
if(mqexception.reasonCode == 2033)
{
String s1 = "No Msg: There is no response message available.";
System.out.println(s1);
throw new Exception(s1);
}
else
{
String s2 = "An MQSeries error occurred : Completion code " + mqexception.completionCode + " Reason code " + mqexception.reasonCode;
System.out.println("An error occurred: " + mqexception);
System.out.println(s2);
throw new Exception(s2);
}
}
catch(Throwable throwable)
{
System.out.println(throwable.getMessage());
throwable.printStackTrace();
System.out.println("Message\thas been sent successfully.");
}
return depth;
}
/*************************************************************************/
/*************************************************************************/
public static void main(String[] args)
{
try
{
String xml = "<xml>test 1 2 3</xml>";
MQClient mqc = new MQClient("TSTBRK01",
"LPAR666.THEMANCORP.COM",
1420,
"SOME.SVRCONN",
"IN_QUEUE",
"OUT_QUEUE",
"TSTBRK01",
"owner");
System.out.println(mqc.toString());
System.out.println("*** Created Object.");
System.out.println(mqc.toString());
byte[] msgId = mqc.sendReqRepMsgAsync(xml);
System.out.println("*** Put message to input Queue.");
String reply = mqc.getMsg(msgId);
System.out.println(reply);
}
catch(Exception e)
{
e.printStackTrace();
}
}
|
I'm really starting to think that the problem is on the MQ Server side. I dont have access to setmqaut on the queues / queue managers in question... however, like i said i am able to put with amqsputc and rfhutil from my laptop to the the server. is there a setmqaut flag for allowing java clients to communicate? |
|
Back to top |
|
 |
vennela |
Posted: Thu Aug 04, 2005 1:44 pm Post subject: |
|
|
 Jedi Knight
Joined: 11 Aug 2002 Posts: 4055 Location: Hyderabad, India
|
What is the user id that is set on the mcauser field of the SVRCONN channel that you are using for the java program.
Alsopost it in Java/JMS forum next time you post MQ java queustions |
|
Back to top |
|
 |
wschutz |
Posted: Thu Aug 04, 2005 4:15 pm Post subject: |
|
|
 Jedi Knight
Joined: 02 Jun 2005 Posts: 3316 Location: IBM (retired)
|
Quote: |
like i said i am able to put with amqsputc and rfhutil from my laptop to the the server. is there a setmqaut flag for allowing java clients to communicate? |
So you are saying that you use the same channel name with amqsputc as your java program is using ("SOME.SVRCONN"). If thats the case, that would rule out mcauser and it would have failed for amqsputc as well...
and no, there is not setmqaut that applies only to java clients _________________ -wayne |
|
Back to top |
|
 |
DanielSonFocus |
Posted: Fri Aug 05, 2005 5:18 am Post subject: |
|
|
 Apprentice
Joined: 05 Jun 2005 Posts: 35 Location: Louisville, Kentucky
|
yes that's exactly what im saying schutz... i set the $MQServer variable to the same SVRCONN/TRPTYPE/HOSTNAME(PORT) values as my java client. it works for amqsputc and rfhutil but not for my java client... Plus im assuming it cant be an issue with my MQEnvironment values being wrong because im getting a 2035 not a 2058... FYI im getting the 2035 just on instantiation of my MQQueueManager object, not on a put or a get. |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Aug 05, 2005 5:23 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Instantiating the MQQueueManager object is what establishes the connection. So that is why you are getting the error there.
Java doesn't use the MQServer environment variable, unless you code it to do so - which you haven't.
The MQEnvironment is the only thing that is used for establishing the connection, and it looks like you are doing that right.
Are you positive that you are running amqsputc etc. as the user named "owner"? And not, for example, "Domain\owner"? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
wschutz |
Posted: Fri Aug 05, 2005 5:36 am Post subject: |
|
|
 Jedi Knight
Joined: 02 Jun 2005 Posts: 3316 Location: IBM (retired)
|
As an aside, I compiled your code on my machine and I see the userid "owner" coming across the channel, so there's no error in setting the iD. _________________ -wayne |
|
Back to top |
|
 |
DanielSonFocus |
Posted: Fri Aug 05, 2005 5:48 am Post subject: |
|
|
 Apprentice
Joined: 05 Jun 2005 Posts: 35 Location: Louisville, Kentucky
|
Wayne... how would i see if that domain issue is causing the problem? when i look at messages in MQExplorer on XP all i see is "owner" as the user identifier and "MUSR_MQADMIN" when i dont set MQEnvironment.userID.. but then again this is my local test QM. is there a way to see how my request is going out across the wire? kinda like an SNMP trap(dont know if that's a correct analogy) ?!? |
|
Back to top |
|
 |
wschutz |
Posted: Fri Aug 05, 2005 5:50 am Post subject: |
|
|
 Jedi Knight
Joined: 02 Jun 2005 Posts: 3316 Location: IBM (retired)
|
well...umm... errr... I have a security exit that prints the contents of the MQCD on the server side. If you think you can compile and install the exit on your server, I'd be more than happy to post the code (its very short).  _________________ -wayne |
|
Back to top |
|
 |
DanielSonFocus |
Posted: Fri Aug 05, 2005 5:58 am Post subject: |
|
|
 Apprentice
Joined: 05 Jun 2005 Posts: 35 Location: Louisville, Kentucky
|
sure.. id be intersted in trying that out... thanks for your help |
|
Back to top |
|
 |
DanielSonFocus |
Posted: Fri Aug 05, 2005 6:09 am Post subject: |
|
|
 Apprentice
Joined: 05 Jun 2005 Posts: 35 Location: Louisville, Kentucky
|
woops sorry.. i meant to address the question about domain\user to jeff.. thanks. |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Aug 05, 2005 6:13 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
DanielSonFocus wrote: |
woops sorry.. i meant to address the question about domain\user to jeff.. thanks. |
Well, first off, if your laptop isn't Windows, then don't worry about it. But you said XP, so maybe it is.
Secondly, if the queue manager is not running on windows, it may not matter. If I recall correctly, when talking to non-Windows qmgrs, the domain is dropped from the user name, so Domain/owner would be passed as "owner", as you saw.
But, you could be running into case issues, where "Owner" is not the same as "owner". _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
wschutz |
Posted: Fri Aug 05, 2005 7:20 am Post subject: |
|
|
 Jedi Knight
Joined: 02 Jun 2005 Posts: 3316 Location: IBM (retired)
|
Here's the code.
Code: |
/* sample security exit */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cmqc.h"
#include "cmqxc.h"
void MQStart() {;} /* dummy entry point */
void MQENTRY ChannelExit (
PMQCXP pMQCXP,
PMQCD pMQCD,
PMQLONG pDataLength,
PMQLONG pAgentBufferLength,
PMQBYTE pAgentBuffer,
PMQLONG pExitBufferLength,
PMQPTR pExitBufferAddr )
{
FILE *fp = 0;
fp = fopen("/tmp/secexit.trace", "a");
fprintf(fp , "In secutiy exit:");
fprintf(fp, "Exit Id: %ld, Exit reason %ld Channel Type %ld ", pMQCXP->ExitId, pMQCXP->ExitReason, pMQCD->ChannelType);
fprintf(fp, "Userid %.12s, Password %.12s", pMQCD->UserIdentifier, pMQCD->Password);
fprintf(fp, "Remote Userid %.12s, Remote Password %.12s\n", pMQCD->RemoteUserIdentifier, pMQCD->RemotePassword);
fclose(fp);
}
|
The intercommunication manual will give directionsfor compiling and setting up your svrconn channel for the scyexit definition. _________________ -wayne |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Aug 05, 2005 7:24 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Of course, if he doesn't have setmqaut access, he's not likely to have access to install an exit...
But at least he can test locally. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
wschutz |
Posted: Fri Aug 05, 2005 7:37 am Post subject: |
|
|
 Jedi Knight
Joined: 02 Jun 2005 Posts: 3316 Location: IBM (retired)
|
Well... maybe he's on v6 and someone did:
Code: |
setmqaut -m TESTBRK01 -t channel -p owner -n SOME.SVRCONN +chg |
_________________ -wayne |
|
Back to top |
|
 |
DanielSonFocus |
Posted: Fri Aug 05, 2005 7:50 am Post subject: |
|
|
 Apprentice
Joined: 05 Jun 2005 Posts: 35 Location: Louisville, Kentucky
|
thanks for the feedback guys... im still plugging away at it. will make a post when i get it working |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|