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.
Related
I'm trying to connect to my localhost kafka server from java function saved into Oracle database 19.3.
The problem is that i cannot reach the server. In database trace files i see that kafka library is using java.nio package to connect to server. Any connection attempt is ending with "Connection refused". I admit also that I can send data to topics from command line tool.
To check if my requests from database are incoming to localhost server at port 9092 i have run Hercules TCP Server and setup it to listen on this port. Then when i'm using my java function it nothing happens.
I write some "test" functions to make only simple connection to my local server, to see if there is some network problem.
The function where i use java.net package is working and i can see that i receive connection requests from database, but the function where i use java.nio package is returning always "Connection refused"
I have granted java.net.SocketPermission to my database user:
exec dbms_java.grant_permission( 'KAFKA', 'SYS:java.net.SocketPermission', '*', 'connect,resolve' );
commit;
Are there needed some special permissions to use java.nio package into oracle database java functions or maybe i'm doing something wrong?
Here are my java "test" functions code:
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "testTCP" AS
import java.net.Socket;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;
public class testTCP {
public static String conn_nio(){
String response;
try {
InetSocketAddress hostAddress = new InetSocketAddress("localhost", 9092);
SocketChannel client = SocketChannel.open(hostAddress);
client.close();
response = "OK";
}
catch(Exception e){
response = "Message: " + e.getMessage() + " Cause: " + e.getCause();
}
return response;
}
public static String conn_net() {
String response;
try
{
Socket socket = new Socket( "localhost", 9092 );
socket.close();
response = "OK";
}
catch( Exception e )
{
response = "Message: " + e.getMessage() + " Cause: " + e.getCause();
}
return response;
}
}
Cannot reproduce. I pointed it to port 8080 of a local HTTP server which I started with
python -m SimpleHTTPServer 8080
and both connection methods are ok:
CREATE OR REPLACE FUNCTION test_net RETURN VARCHAR2 AS
LANGUAGE JAVA NAME 'testTCP.conn_net() return java.lang.String';
/
CREATE OR REPLACE FUNCTION test_nio RETURN VARCHAR2 AS
LANGUAGE JAVA NAME 'testTCP.conn_nio() return java.lang.String';
/
SELECT test_net FROM DUAL;
OK
SELECT test_nio FROM DUAL;
OK
I'm successfully pushing message into ActiveMQ from local Eclipse setup. However, the same code does not push message when I try to execute from server as a cron job. It does not even throw an exception during code execution.
Java environment - 1.8
Supporting jars used:
slf4j-api-1.8.0-beta2.jar
javax.annotation-api-1.2.jar
javax.jms-api-2.0.1.jar
management-api-1.1-rev-1.jar
activemq-core-5.7.0.jar
Code:
try {
map = getMessageDetails(session,"MessageQueueEmail");
userName = map.get("userName");
password = map.get("password");
hostName = map.get("mqHostName");
queue = map.get("queueName");
// Create a ConnectionFactory
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(userName, password, hostName);
// Create a Connection
connection = factory.createConnection();
// start the Connection
connection.start();
System.out.println("MQ started connection");
// Create a Session
sessionMQ = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create the destination Queue
Destination destination = sessionMQ.createQueue(queue);
// Create a MessageProducer from the Session to the Queue
messageProducer = sessionMQ.createProducer(destination);
messageProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// Create a message
Message message = sessionMQ.createTextMessage(textMsg);
System.out.println("MQ Message sent successfully");
// Tell the producer to send the message
messageProducer.send(message);
} catch(Exception e) {
e.printStackTrace();
System.out.println("\n::::::::::::Error occurred sendEmailMessageToIntranet::::::::::::: " + e.getMessage());
}
Thanks everyone for response. The issue is resolved after importing correct certificate file to the server. Wondering, why MQ attempts failure notification had not logged
Your code looks ok except you might have expiration going. Try with PERSISTENT and most likely is the issues that you are not redirecting stderr in your cronjob ? Make sure you do something like this:
*/1 * * * * /something/send.sh &>> /something/out.log
And then check in the morning.
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)
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."
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.