MQ (websphere) connection issue java.lang.NoClassDefFoundError - java

I am trying to establish a connection with MQ from Java. I am using the following sample code from IBM, but it is possible to be outdated. How can i resolve the issue / what am i missing?
import com.ibm.mq.*; // Include the WebSphere MQ classes for Java package
import com.ibm.mq.jmqi.*;
import com.ibm.mq.constants.MQConstants;
public class MQSample
{
private String qManager = "your_Q_manager"; // define name of queue
// manager to connect to.
private MQQueueManager qMgr; // define a queue manager
// object
public static void main(String args[]) {
new MQSample();
}
public MQSample() {
try {
// Create a connection to the queue manager
qMgr = new MQQueueManager(qManager);
// Set up the options on the queue we wish to open...
// Note. All WebSphere MQ Options are prefixed with MQC in Java.
int openOptions = MQConstants.MQOO_INPUT_AS_Q_DEF |
MQConstants.MQOO_OUTPUT ;
// Now specify the queue that we wish to open,
// and the open options...
MQQueue system_default_local_queue =
qMgr.accessQueue("SYSTEM.DEFAULT.LOCAL.QUEUE",
openOptions);
// Define a simple WebSphere MQ message, and write some text in UTF format..
MQMessage hello_world = new MQMessage();
hello_world.writeUTF("Hello World!");
// specify the message options...
MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the // defaults,
// same as MQPMO_DEFAULT
// put the message on the queue
system_default_local_queue.put(hello_world,pmo);
// get the message back again...
// First define a WebSphere MQ message buffer to receive the message into..
MQMessage retrievedMessage = new MQMessage();
retrievedMessage.messageId = hello_world.messageId;
// Set the get message options...
MQGetMessageOptions gmo = new MQGetMessageOptions(); // accept the defaults
// same as MQGMO_DEFAULT
// get the message off the queue...
system_default_local_queue.get(retrievedMessage, gmo);
// And prove we have the message by displaying the UTF message text
String msgText = retrievedMessage.readUTF();
System.out.println("The message is: " + msgText);
// Close the queue...
system_default_local_queue.close();
// Disconnect from the queue manager
qMgr.disconnect();
}
// If an error has occurred in the above, try to identify what went wrong
// Was it a WebSphere MQ error?
catch (MQException ex)
{
System.out.println("A WebSphere MQ error occurred : Completion code " +
ex.completionCode + " Reason code " + ex.reasonCode);
}
// Was it a Java buffer space error?
catch (java.io.IOException ex)
{
System.out.println("An error occurred whilst writing to the message buffer: " + ex);
}
}
} // end of sample
The error I'm getting:
"C:\Program Files\Java\jdk1.7.0_09\bin\java" -Didea.launcher.port=7536 "-Didea.launcher.bin.path=M:\IntelliJ IDEA 12.1.4\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.7.0_09\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\jce.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\jfxrt.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\resources.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\rt.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\ext\access-bridge.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\ext\zipfs.jar;M:\untitled\out\production\untitled;D:\MavenRepository\com\ibm\mq\mq\7.0.1.1\mq-7.0.1.1.jar;D:\MavenRepository\com\ibm\mq\jmqi\7.0.1.1\jmqi-7.0.1.1.jar;M:\Monitor_NEW\Engine\lib\ojdbc14_g-10.2.0.jar;D:\MavenRepository\com\ibm\mq\mqjms\7.0.1.1\mqjms-7.0.1.1.jar;M:\IntelliJ IDEA 12.1.4\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain MQSample
Exception in thread "main" java.lang.NoClassDefFoundError: javax/resource/ResourceException
at com.ibm.mq.MQQueueManager.<clinit>(MQQueueManager.java:153)
at MQSample.<init>(MQSample.java:28)
at MQSample.main(MQSample.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.ClassNotFoundException: javax.resource.ResourceException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 8 more

add the connector-1.0.jar dependency into your project.

According to IBM, the NoClassDefFoundError exception can be due to a missing jar: "Connector cannot find file jms.jar from the IBM WebSphere MQ Java client libraries. Ensure that variable MQSERIES_JAVA_LIB in start_connector.bat points to the IBM WebSphere MQ Java client library folder."

Related

Unreachable remote akka actor

I'm trying to send a message to an actor that is not brought up yet. When I do so, I see following message on the console but how to capture this error programatically / through configuration.
[WARN] [09/25/2017 14:15:01.127] [JavaEngineSystem-akka.remote.default-remote-dispatcher-6] [akka.tcp://JavaEngineSystem#018x02h2:1727/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2FScalaEngineSystem%40018x02h2%3A4090-0] Association with remote system [akka.tcp://ScalaEngineSystem#018x02h2:4090] has failed, address is now gated for [5000] ms. Reason: [Association failed with [akka.tcp://ScalaEngineSystem#018x02h2:4090]] Caused by: [Connection refused]
[INFO] [09/25/2017 14:15:01.141] [JavaEngineSystem-akka.actor.default-dispatcher-3] [akka://JavaEngineSystem/deadLetters] Message [com.impl.ActorMessage] from Actor[akka://JavaEngineSystem/temp/$a] to Actor[akka://JavaEngineSystem/deadLetters] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
This is my system initialization part of the code:
system = ActorSystem.create("JavaEngineSystem", ConfigFactory.load(ScalaAkkaAccessor.class.getClassLoader()));
thisActor = system.actorOf(Props.create(AvroActor.class), "javaEngine");
List<String> paths = new ArrayList<String>();
StringTokenizer tokenizer = new StringTokenizer(akkaUrl, ",");
while(tokenizer.hasMoreTokens()) {
paths.add(tokenizer.nextToken());
}
scalaEngineRouterRemote = system.actorOf(new RoundRobinGroup(paths).props(), "router4");
Message sending code:
Timeout timeout = new Timeout(Duration.create(timeoutDuration, "minute"));
ActorMessage msg = new ActorMessage();
msg.setStr(OPER);
Future<Object> future = Patterns.ask(scalaEngineRouterRemote, msg, timeout);
Object retn = Await.result(future, timeout.duration());
Basically i'm trying to recover immediately after I know that remote actor is not available (or not running) rather than waiting for timeout.

Glassfish JMS Queue Not Found In JNDI Context

I need help.
The Glassfish Admin Console screen below shot below shows that I've set up three JMS Destination Resources. All are identical except for the names. But my JNDI lookup from a local java client (Glassfish is also local) can only see the first two. Client code and console out put is below screen shot.
I don't even know where to look to begin figuring out why one and two work, and three doesn't. Can anyone suggest anything. This should be as basic as it get's. All three are identically set up. None have any additional properties set. I really need help or direction.
CODE:
public class SrackOverflow1 {
public static void main(String[] args) {
Properties env = new Properties();
env.put ("java.naming.factory.initial", "com.sun.jndi.fscontext.RefFSContextFactory");
env.put ("java.naming.provider.url","file:///C:/glassfish4/mq/opt/java/my_broker");
try {
Context jndiContext = (Context) new InitialContext(env);
Queue queueOne = (Queue) jndiContext.lookup("jms/goSendQueue");
System.out.println("queueOne ok:\n" + queueOne);
Queue queueTwo = (Queue) jndiContext.lookup("jms/goReceiveQueue");
System.out.println("\nqueueTwo ok:\n" + queueTwo);
Queue queueThree = (Queue) jndiContext.lookup("jms/goTestQueue");
System.out.println("\nqueueThree ok:\n" + queueThree);
} catch (NamingException e) {
System.out.println("\nThrew Naming Exception\nerror msg: " + e.getMessage() +"\n");
e.printStackTrace();
}
}
CONSOLE:
queueOne ok:
Sun Java System MQ Destination
getName(): goSendQueuq
Class: com.sun.messaging.Queue
getVERSION(): 3.0
isReadonly(): false
getProperties(): {imqDestinationName=goSendQueuq, imqDestinationDescription=A Description for the Destination
Object}
queueTwo ok:
Sun Java System MQ Destination
getName(): goReceiveQueue
Class: com.sun.messaging.Queue
getVERSION(): 3.0
isReadonly(): false
getProperties(): {imqDestinationName=goReceiveQueue, imqDestinationDescription=A Description for the Destinati
on Object}
Threw Naming Exception
error msg: jms/goTestQueue
javax.naming.NameNotFoundException: jms/goTestQueue
at com.sun.jndi.fscontext.RefFSContext.getObjectFromBindings(RefFSContext.java:400)
at com.sun.jndi.fscontext.RefFSContext.lookupObject(RefFSContext.java:327)
at com.sun.jndi.fscontext.RefFSContext.lookup(RefFSContext.java:146)
at com.sun.jndi.fscontext.FSContext.lookup(FSContext.java:127)
at javax.naming.InitialContext.lookup(Unknown Source)
at org.america3.testclasses.SrackOverflow1.main(SrackOverflow1.java:21)

websphere jms queue access from remote client

Background
I am php & frontend web developer developing an application in Java using Netbeans to read from a websphere (V8.5 I think) JMS queue and then issue commands to appropriate scripts/servers. This is my first major run in with Java for about 10 years so please bear with me. My initial test application runs fine on the server that hosts the jms queue but I have been running into one error after another when trying to connect from a remote location (which at the moment happens to be windows but will be linux in the end). I have been battling through both my lack of experience with Java the process of diagnosing jar issues and locating apparently needed jars from websphere and elsewhere but have finally reached a brick wall. I have seen lots of answers that consist of statements such as "you need the right jar files", but not saying which ones or you need thisone.jar and all the jars that one refers to. I don't know how to find out what jars that should be. I have read posts that say that the process should work with only some of the jars in my library. Am completely stuck...
Error
The error which I am having no luck in getting through
javax.naming.NamingException: Failed to initialize the ORB [Root
exception is org.omg.CORBA.INITIALIZE: can't instantiate default ORB
implementation com.ibm.CORBA.iiop.ORB
The full rest of message is this
javax.naming.NamingException: Failed to initialize the ORB [Root exception is
org.omg.CORBA.INITIALIZE: can't instantiate default ORB implementation
com.ibm.CORBA.iiop.ORB vmcid: 0x0 minor code: 0 completed: No]
at com.ibm.ws.naming.util.Helpers.getOrb(Helpers.java:314)
javax.naming.NamingException: Failed to initialize the ORB [Root exception is org.omg.CORBA.INITIALIZE: can't instantiate default ORB implementation
com.ibm.CORBA.iiop.ORB vmcid: 0x0 minor code: 0 completed: No]
at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:384)
at com.ibm.ws.naming.util.WsnInitCtx.getContext(WsnInitCtx.java:113)
at com.ibm.ws.naming.util.WsnInitCtx.getContextIfNull(WsnInitCtx.java:428)
at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:144)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at jmstool2.JmsConn.CreateFactCon(JmsConn.java:101)
at jmstool2.JmsConn.connect(JmsConn.java:56)
at jmstool2.Jmstool2.main(Jmstool2.java:20)
Caused by: org.omg.CORBA.INITIALIZE: can't instantiate default ORB implementation com.ibm.CORBA.iiop.ORB vmcid: 0x0 minor code: 0 completed: No
at org.omg.CORBA.ORB.create_impl(ORB.java:327)
at org.omg.CORBA.ORB.init(ORB.java:367)
at com.ibm.ws.orb.GlobalORBFactory.init(GlobalORBFactory.java:85)
at com.ibm.ejs.oa.EJSORBImpl.initializeORB(EJSORBImpl.java:174)
at com.ibm.ejs.oa.EJSClientORBImpl.<init>(EJSClientORBImpl.java:97)
at com.ibm.ejs.oa.EJSClientORBImpl.<init>(EJSClientORBImpl.java:73)
at com.ibm.ejs.oa.EJSORB.init(EJSORB.java:386)
at com.ibm.ws.naming.util.Helpers.getOrb(Helpers.java:305) ... 8 more
Caused by: java.lang.NoSuchFieldError: UNKNOWN
at com.ibm.rmi.util.RepositoryId.createHashString(RepositoryId.java:738)
at com.ibm.rmi.util.RepositoryId.<clinit>(RepositoryId.java:254)
at com.ibm.rmi.iiop.CDROutputStream.<clinit>(CDROutputStream.java:1107)
at com.ibm.rmi.corba.ORB.<init>(ORB.java:281) at com.ibm.rmi.iiop.ORB.<init>(ORB.java:187) at com.ibm.CORBA.iiop.ORB.<init>(ORB.java:576)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.Class.newInstance(Class.java:374)
at org.omg.CORBA.ORB.create_impl(ORB.java:325) ... 15 more
What I am doing
I have added the following jars to the library
javax.jms-1.1.jar
com.ibm.ws.orb_8.5.0.jar
com.ibm.ws.ejb.thinclient_8.5.0.jar
com.ibm.was.sib.client.thin.jms_8.5.0.jar
com.ibm.was.admin.client_8.5.0.jar
com.ibm.ws.messagingClient.ja
I have also read that the following jars are needed
sibc.jms.jar
sibc.jndi.jar
sibc.orb.jar
I have located these and added them also, although I have also read that these are not needed if you have the thin client I already have.
and am using JDK1.7
context factory: com.ibm.websphere.naming.WsnInitialContextFactory
Provider URL: corbaloc:iiop:192.168.254.202:2809
The context is being created. But am unable to make the queue factory connection. I can create a socket to the ip address and post using a quick test application.
The Code
Here is the class file and all the connectiony bits. It is complete work in progress.
import java.util.Hashtable;
import javax.naming.*;
import javax.jms.*;
import com.ibm.CORBA.*;
import com.ibm.ws.*; /*
/**
* Connection Factory Notes on IBM Websphere
*
* jndi/INConnectionFactory
* jndi/OUTConnectionFactory
*
* jndi/INQueue
* jndi/OUTQueue
*
* jndi/INActivation
* jndi/OUTActivation
*
* websphere server: 192.168.254.202
*
* JMS queued port: 5558 unsecured (MQ) and 5578 secure
* JMS Security Port 5557
* JMS Direct Port: 5559
* SOAP: 9976
* //other ports mentioned: 7276 (unsecured) and 7286 (secured)
* NOTE: A bootstrap address with no port specification defaults to port 2809
*/
public class JmsConn {
/*int jmsQueuedPort = 5558;
int jmsSecrityPort = 5557;
int jmsDirectPort = 5559;
int soapPort = 9976;*/
int bootstrap = 2809; //default port
int bootstrap10 = 2810;
int unSecPort = 7276;
String serverIP = "192.168.254.202";
String scheme = "corbaloc:iiop:"; //e.g. ws, ldap,iiop, corbaloc:iiop
String contextFactory = "com.ibm.websphere.naming.WsnInitialContextFactory";
String queueInName = "jndi/INQueue";
String queueOutName = "jndi/OUTQueue";
String outFactory = "jndi/OUTConnectionFactory";
String inFactory = "jndi/INConnectionFactory";
InitialContext jndiContext;
ConnectionFactory connectionFactory;
Connection qConn;
String providerUrl = scheme+serverIP+":"+bootstrap;
Session qSession;
Queue q;
public void connect() {
this.CreateContext();
this.CreateFactCon(this.outFactory);
this.getQueue(this.queueOutName);
}
public void Lookup(String thingToLookup){
try{
System.out.println("Attempting to lookup "+thingToLookup);
}catch(Exception ex){
System.out.println("ERROR: Could not perform lookup of " + thingToLookup +
System.lineSeparator() + ex.toString());
// System.out.println("Lookup Result: " + this.jndiContext.lookup);
System.exit(3);
}
}
public void CreateContext(){
try{
System.out.println("Attempting to create connection context");
Hashtable env = new Hashtable(); // [jh] in theory this has been superceeded
// and should use HashMap
env.put(Context.INITIAL_CONTEXT_FACTORY,this.contextFactory);
System.out.println("context factory: "+this.contextFactory);
System.out.println("Provider URL: "+this.providerUrl);
env.put(Context.PROVIDER_URL, providerUrl); //+":"+this.jmsDirectPort
try{
this.jndiContext = new InitialContext(env);
//this.jndiContext = new InitialContext();
}catch(NamingException e){
System.out.println("ERROR: Could not create JNDI context: " +
System.lineSeparator() + e.toString());
System.exit(1);
}
System.out.println("End of CreateContext.");
}catch(Exception exc){
System.out.println("ERROR in CreateContext: "+exc.toString());
System.exit(1);
}
}
public void CreateFactCon(String factory){
try{
System.out.println("Attmepting to create factory lookup:");
this.connectionFactory = (ConnectionFactory)this.jndiContext.lookup(factory);
}catch(NamingException e){
System.out.println("ERROR: Could not create factory connection:");
e.printStackTrace(System.err);
System.out.println(e.toString());
System.exit(2);
}
System.out.println("Lookup successfull:");
try{
System.out.println("Attmepting to create connection:");
this.qConn = this.connectionFactory.createConnection();
this.qSession = qConn.createSession(false,Session.AUTO_ACKNOWLEDGE);
}catch(Exception e){
e.printStackTrace(System.err);
System.out.println(e.toString());
System.exit(4);
}
System.out.println("Connection successful.");
System.out.println("End of CreateFactoryConnection.");
}
public void getQueue(String queueName){
try{
this.q = (Queue)this.jndiContext.lookup(queueName);
}catch(Exception e){
System.out.println("ERROR: Could not get Queue:");
e.printStackTrace(System.err);
System.out.println(e.toString());
System.exit(2);
}
}
}
UPDATE
After cutting back the jar files to
com.ibm.ws.orb_8.5.0.jar
com.ibm.ws.wjb.thingclient_8.5.0.jar
com.ibm.ws.sib.client.thin.jms_8.5.0.jar
the following error is thrown
javax.naming.NamingException: Error getting WsnNameService properties [Root exception is org.omg.CORBA.TRANSIENT: initial and forwarded IOR inaccessible vmcid: 0x4942f000 minor code: 3591 completed: No]
at com.ibm.ws.naming.util.WsnInitCtxFactory.mergeWsnNSProperties(WsnInitCtxFactory.java:1552)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootContextFromServer(WsnInitCtxFactory.java:1042)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootJndiContext(WsnInitCtxFactory.java:962)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:614)
at com.ibm.ws.naming.util.WsnInitCtx.getContext(WsnInitCtx.java:128)
at com.ibm.ws.naming.util.WsnInitCtx.getContextIfNull(WsnInitCtx.java:765)
at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:164)
at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:179)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at jmstool2.JmsConn.CreateFactCon(JmsConn.java:104)
at jmstool2.JmsConn.connect(JmsConn.java:59)
at jmstool2.Jmstool2.main(Jmstool2.java:20)
Caused by: org.omg.CORBA.TRANSIENT: initial and forwarded IOR inaccessible vmcid: 0x4942f000 minor code: 3591 completed: No
at com.ibm.rmi.corba.ClientDelegate.createRequest(ClientDelegate.java:1250)
at com.ibm.CORBA.iiop.ClientDelegate.createRequest(ClientDelegate.java:1321)
at com.ibm.rmi.corba.ClientDelegate.createRequest(ClientDelegate.java:1146)
at com.ibm.CORBA.iiop.ClientDelegate.createRequest(ClientDelegate.java:1287)
at com.ibm.rmi.corba.ClientDelegate.request(ClientDelegate.java:1853)
at com.ibm.CORBA.iiop.ClientDelegate.request(ClientDelegate.java:1243)
at org.omg.CORBA.portable.ObjectImpl._request(ObjectImpl.java:449)
at com.ibm.WsnBootstrap._WsnNameServiceStub.getProperties(_WsnNameServiceStub.java:38)
at com.ibm.ws.naming.util.WsnInitCtxFactory.mergeWsnNSProperties(WsnInitCtxFactory.java:1549)
... 11 more
Java Result: 2
Check this - Installing and configuring the Thin Client for JMS with WebSphere Application Server.
The only jars you should need for now are:
com.ibm.ws.orb_8.5.0.jar
com.ibm.was.sib.client.thin.jms_8.5.0.jar
com.ibm.ws.ejb.thinclient_8.5.0.jar
so please remove all other from your classpath.
And make sure these jars are also in your run classpath, not only during build.
For initial context try the following:
Hastable env = new Hastable();
env.put(Context.PROVIDER_URL,"iiop://localhost:2809"); // if using default ports
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
InitialContext ctx = new InitialContext(env);
Update the /etc/resolv.conf file (on Linux) and add the domain name to the search parameter, letting the OS attempt to resolve the hostname, adding the domain name, and calling the DNS. If the IP address changes over time, your system will continue to be able to resolve the domain-less-hostname to the proper IP address.
E.G.: for hostname "jmsserver"
Content of /etc/resolv.conf:
domain mydom.com
nameserver 192.168.1.250
search xyz.com good.com what.ever.ca
If jmsserver is on good.com, the OS will use the DNS and attempt to resolve jmsserver.mydom.com, jmsserver.xyz.com, and will succeed on jmsserver.good.com to obtain the IP address to route to the destination.

Delete top message from MQQueue

I am constructing a messaging system using MQSeries. For some reason, when I perform q.get(...), I am getting an exception thrown (I don't know the specific MQException). Below is the code causing the error:
private static MQGetMessageOptions GMO = new MQGetMessageOptions();
private static int GMO_OPTIONS = MQC.MQGMO_SYNCPOINT | MQC.MQGMO_WAIT;
GMO.options = GMO.options | GMO_OPTIONS;
GMO.waitInterval = MQC.MQWI_UNLIMITED;
MQEnvironment.hostname = args[0];
MQEnvironment.channel = args[2];
MQEnvironment.port = Integer.parseInt(args[1]);
MQQueueManager queueManager = new MQQueueManager(args[3])
MQMessage msg = new MQMessage();
MQQueue q = queueManager.accessQueue("qName1",MQC.MQOO_OUTPUT);
q.get(msg, GMO);
My plan is, when this error occurs, skip the message and delete it. To perform the delete I will call the following function:
private void deleteMsg(MQQueueManager queueManager, String queueName) throws MQException {
MQGetMessageOptions tempGmo = new MQGetMessageOptions();
tempGmo.options |= MQC.MQGMO_WAIT;
tempGmo.waitInterval = 1000;
MQQueue remover = queueManager.accessQueue(queueName, MQC.MQOO_INPUT_AS_Q_DEF);
remover.get(new MQMessage(), tempGmo);
queueManager.commit();
}
Would the remover.get() in my deleteMsg function also, in this specific scenario, fail for the same reason? Or does the option used to construct the MQQueue(MQC.MQOO_INPUT_AS_Q_DEF vs MQC.MQOO_OUTPUT) prevent it from also failing? If I am having trouble accessing my queue's message, how do I discard the top message and move to the next?
To shorten my question:
If I am unable to perform a get() on a given queue to retrieve a message, how can we delete that corrupt message on the same queue?
Thank you!
OMG!
MQQueue q = queueManager.accessQueue("qName1",MQC.MQOO_OUTPUT);
q.get(msg, GMO);
Your are opening a queue for output (writing) but you are trying to get a message. You have your shoes on the wrong feet!! Secondly, why aren't you catching the MQException that MQ would be throwing?? The exception would have included the reason code which would have given you the exact explanation to your issue.
Here's how you should be opening the queue for reading:
try
{
int oo = MQC.MQOO_INPUT_SHARED + MQC.MQOO_FAIL_IF_QUIESCING;
MQQueue q = queueManager.accessQueue("qName1",oo);
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_NO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING;
q.get(msg, gmo);
}
catch (MQException e)
{
System.err.println(e.getLocalizedMessage() );
System.err.println("CC = " + e.completionCode + " - RC = " + e.reasonCode);
}
Also, make sure you use the appropriate "Fail if quiescing" option for the particular MQ API call.
Finally, look up "backout queue". If your application is having an issue with a message then the message should be moved to a backout queue and not simply deleted.
I do not why what you are doing does not work for you but I wonder why are you using proprietary API of MQ Series instead of using JMS API. In JMS terms remove top message just means receive the message, so call of session.receieve() does the work.
Using common JMS API has a lot of advantages. The main of them is that you can easily move from MQ Series to any other messaging solution without changing even one line of your code.
I wonder if the program compiled because there is no option called GMO_OPTIONS. All MQ constants are prefixed MQC

java.RMI socket creation details?

i've looked at doc, tested, debugged ... but remain stumped. time for stackOverflow! i'll set the stage, then describe my error.
Background
i have an RMI client/sever setup that works fine when client, server and rmiregistry
all live together on localhost. so then i fire up rmiregistry on serverHost, with rmi.server.logCalls trace turned on (called RegistryTrace below). the important parts of the server code:
String hostname = "//serverHost.local/project"
String codeBase = "file:/home/rik/Code/eclipse/project/bin/"
System.setProperty("java.rmi.server.hostname", hostname);
System.setProperty("java.rmi.server.codebase", codeBase);
Driver server = new Driver();
Naming.rebind(hostname, server);
when i start the server, i see the rebind() call succeeds (by looking at RegistryTrace). also, looking at the list generated by Naming.list() shows it contains "//serverHost.local:1099/project"
starting my client, it successfully completes Naming.lookup():
server = (ServerInterface)Naming.lookup(serverHost);
looking at RegistryTrace, i am able to confirm that this lookup() query gets to the server end.
Error on first RMI
but now: my next statement tries to call one of server's methods
boolean status = server.initConnection(username);
generates an IllegalArgumentException:
java.lang.IllegalArgumentException: protocol = socket host = null
at sun.net.spi.DefaultProxySelector.select(DefaultProxySelector.java:151)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:424)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:189)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:110)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:178)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
at $Proxy0.initConnection(Unknown Source)
at project.client.View2.main(View2.java:651)
i've traced this down into Java source to a call to java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod()
private Object invokeRemoteMethod(Object proxy,
Method method,
Object[] args)
throws Exception
{
try {
if (!(proxy instanceof Remote)) {
throw new IllegalArgumentException(
"proxy not Remote instance");
}
// EXCEPTION OCCURS WITHIN CALL TO ref.invoke() BELOW
//
return ref.invoke((Remote) proxy, method, args,
getMethodHash(method));
} catch (Exception e) {
if (!(e instanceof RuntimeException)) {
Class<?> cl = proxy.getClass();
try {
method = cl.getMethod(method.getName(),
method.getParameterTypes());
} catch (NoSuchMethodException nsme) {
throw (IllegalArgumentException)
new IllegalArgumentException().initCause(nsme);
}
Class<?> thrownType = e.getClass();
for (Class<?> declaredType : method.getExceptionTypes()) {
if (declaredType.isAssignableFrom(thrownType)) {
throw e;
}
}
e = new UnexpectedException("unexpected exception", e);
}
throw e;
}
}
then i lose it in the source trace. (anyone know the story about source availability for things like sun.rmi.server.UnicastRef ?) the rest of the trace makes it seem like RMI can't create a socket?
i'm sure many parts of this code could be cleaner; any suggestions appreciated. i also need to convert this into jar file distributions, so if specifying them now for java.rmi.server.codebase would be easier...?
thanks for any suggestions, rik
It is constructing a SocksSocketImpl so you must be specifying an invalid SOCKS proxy host or port via socks.proxyHost/socks.proxyPort at the client, or perhaps you have java.rmi.server.hostname set to a strange value at the server.

Categories

Resources