jndiContext.lookup
Please help !
Broker and subscriber are on different servers - can't figure out how to lookup my ConnectionFactory
try{
jndiContext = getInitialContext();
topicConnectionFactory = (TopicConnectionFactory)
jndiContext.lookup("mq://rumble-j2ee:7676/jms/MyTopicConnectionFactory");
topic = (Topic) jndiContext.lookup(destName);
}catch (NamingException e){
System.out.println("JNDI API lookup failed: " +
e.toString());
e.printStackTrace();
System.exit(1);
}
[778 byte] By [
oakgroup] at [2007-11-25 17:02:54]

# 1
Hi,
It seems from your description that you are trying to use the default file store that comes with the broker
for your administered objects repository. Please let us know if you are trying to use LDAP.
One thing that is not clear though is how you are creating the jndicontext. The following code will be helpful
This is for the filestore.
Hashtable env = new Hashtable();
env.put (Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
env.put (Context.PROVIDER_URL,
"file:///c:/imq_admin_objects");
Context ctx = new InitialContext(env);QueueConnectionFactory myQConnFactory = (QueueConnectionFactory)
ctx.lookup("MyQueueConnectionFactory");
If you are a subscriber tyring to get a handle to the filestore on the other machine. Then you'll have to make sure that filestore is accessible on the network.
In case of solaris/linux the ProviderURl will change to
file:///imq_admin_objects
assuming imq_admin_objects is the filestore folder.
The preffered way to register the administered objects in the production environment is in a LDAP. If you are using LDAP then the code will change to
Hashtable env = new Hashtable();
env.put (Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.com.sun.jndi.ldap.LdapCtxFactory");
env.put (Context.PROVIDER_URL,
"domain name and the port on which the LDAP provider is listening");
Context ctx = new InitialContext(env);QueueConnectionFactory myQConnFactory = (QueueConnectionFactory)
ctx.lookup("MyQueueConnectionFactory");
Please have a look at http://docs.sun.com/source/817-3727/adminobj.html
to get more understanding on managing administerd objects.
thx
Vibhor
# 2
Bless you !
I am pretty new at this - I am using the default file store - I'll change to imq_admin_objects and try changing the PROVIDER_URL in my subscriber code as suggested - I guess I also need to SHARE the imq_admin_objects folder ?
I don't have an LDAP Server at this client
# 3
One more thing - the subscriber and MQ server are connected via a VPN tunnel - does that change anything ?
# 4
another question -I'm not using linux nor solaris - what is the url format for Windows platform ?
# 5
On windows if you share a folder and then map that shared folder on to a drive of your local machine. That shared file can be accessed in a manner similar to a file existing on your local machine.
For example you have a machine1 where your broker resides. If you have configured a folder called c:\temp
for the file store,you can make that folder shareable and give permissions to people to use it. Now assume that machine2 has your subscribers. You can map the shared folder on machine1 to a drive g:
When you use this shared folder for creating the ProviderURL you'll use
file:\\\g:\temp
i hope this helps
# 6
Thanks again - I'll try this todayHow would I enable subscribers to access the broker without a VPN tunnel ? HTTP ?
# 7
Apart from TCP we support HTTP protocol andyou can access the broker if you are restricted by a firewall too. To get more details please refer the the following link http://docs.sun.com/source/817-3727/a_http.html
# 8
After further review and discussions with colleagues -I don't believe I need HTTP - JMS should work fine as long as we open port 7676 on the firewall - and JMS is a more reliable protocol
Is that information correct ?
Which leads me back to trying to refer to the broker from a remote subscriber - I've been following the guide at:
http://docs.sun.com/source/817-3728/runtime.html#wp26987
This doesn't work - mq://rumbleRTE:7676/jms
I'm getting this error message:
javax.naming.InvalidNameException
[root exception is java.naming.malformedURLException: Unknown protocol: mq]
mq://rumbleRTE:7676/jms
Thanks again for the great support !!
# 9
yes that is correct you can expose the service port on the firewall that you want and then access the broker.
It's always a good idea to expose a particular port of the service desired than to expose all the ports.
Are you trying the firewall setup to access your broker?
can you ping your broker from the remote machine where you intend to create the subscriber?
If you are using MQ3.5 then then you'll need to set up
imqaddresslist attribute in the connectionfactory object with the address syntax.
Refer table 4.3 on
http://docs.sun.com/source/817-3728/runtime.html#wp26987
have you done that ?
when you use the following as the address syntax
mq://host name:7676/jms
you are accessing the port mapper and then the port mapper will allocate the port dynamically for the service that you want in your case it is jms service.
The service port that you want can be found out by performing telnet to the broker host and it will give you all the dynamically allocated ports for all the supported service.
If you just want to access a particular port get the corresponding port number from the above mentioned step and then use
mqtcp://hostname and port number/jms
in the imqaddesslist of the connection factory object.
# 10
I've updated the connection factory (Connection Handling -> Message Server Address List ) and I'm using this code in the remote subscriber
private static InitialContext getInitialContext() throws NamingException {
Hashtable env = new Hashtable();
env.put(
Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "mq://rumbleRTE:7676/jms");
return new InitialContext(env);
}
Still getting error:
malformedURL invalid protocol mq
What am I doing incorrectly ? Thank You !
# 11
While creating the Administrator Object, what attribute value did you
give for "java.naming.provider.url" ?
Following is an example I executed on my system. Let me know if this help ?
Creating the queue connection factory object:
imqobjmgr add -t qf -l "cn=testQCF" -o "imqBrokerHostName=aparna" -o "imqBrokerHostPort=7676" -j "java.naming.factory.initial=
com.sun.jndi.fscontext.RefFSContextFactory" -j "java.naming.provider.url=file:///space/temp/fsc"
Code :
Hashtable env = new Hashtable();
env.put (Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");
env.put (Context.PROVIDER_URL,"file:///space/temp/fsc");
Context ctx = new InitialContext(env);
queueConnectionFactory = (QueueConnectionFactory)ctx.lookup("cn=testQCF");
queueConnection = queueConnectionFactory.createQueueConnection();
# 12
1 - I am trying to access my broker through the firewall
2 - I am able to ping my broker machine
3 - I have used the MQ3.5 Administrator to create MyTopicConnectionFactory with the following attributes:
java.naming.provider.url = mq://rumbleRTE:7676/jms
java.naming.factory.initial = com.sun.jndi.fscontext.RefFSContextFactory
I believe this is setting up imqaddresslist with the address syntax recommended in table 4.3 - correct ?
4 - My code looks like this
private static InitialContext getInitialContext() throws NamingException {
Hashtable env = new Hashtable();
env.put(
Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
//env.put(Context.PROVIDER_URL, "file:///C:/Temp"); this worked fine when broker and subscriber were on same machine
env.put(Context.PROVIDER_URL, "mq://rumbleRTE:7676/jms");
return new InitialContext(env);
}
5. MY QUESTION IS -
Why is the broker giving me a naming exception - malformed URL error message when it tries "mq://rumbleRTE:7676/jms" ?
Thanks again for the help !
# 13
couple of things first
a)When you say that you have added the connection factory it seems that you have added the object store. The values that you have provided appear to be those of object store. Please remember that the default object store is a filestore.
While adding the object store you are supposed to use the correct protocol since we support file store and ldap the valid protocols should start with either file: or ldap and not mq. Hence it gives you a malformed URL exception because mq is not a supported protocol for the providerURL for the object stores.
please check
http://docs.sun.com/source/817-6024/tutorial.html
b)Once you have added the object store now add the connection factory object. If you are using imqadmin GUI to add the CF, then right click on the connectionfactories option(underneath the object store you created) and select addconnectionfactoryobject. There specify the connection handling details in your case it is
mq://rumbleRTE:7676/jms and this will be added to the mqaddresslist. Please also add the lookup name for this connection factory object for example myCF.
c)In case you are using filestore which you are and if you want to enable the filestore to be accessed remotely then you'll have to map the filestore and make it accesible or rather shared. From your code it appears that the file store has been created at c:\temp. Can you share this location and map this file on your remote subscriber machine. In case you map this c:\temp to a g: drive on your remote subscriber then the providerURL will become file:///g:/temp.
d)Finally telnet on your broker(running state) machine and you'll come to know the services running on your broker. It will also give the port number. So once you know the port number of your desired service(jms) expose that port also on the firewall. So now you'll not only expose 7676 but also the desired service port .
thanks
Vibhor
# 14
In addition to point d of the previous described steps
if you do not want to expose two ports on the firewall you can ignore 7676 and only expose the desired service port(obtained by performing telnet on the broker). In this case the mq addresslist will have
this value.
mqtcp://rumbleRTE portnumber/jms
and in the config.properties of the broker please set the value of the imq.jms.tcp.port
property to the exposed port number.
thanks
Vibhor
# 15
Vibhor -Thank you so much for your response - This should get me moving forward again - I'll get this all done today and give you an update
# 16
It works !!!I had everything done except the mapped drive - that's all I needed to do - Thanks again !!
# 17
> couple of things first
> c)In case you are using filestore which you are and
> if you want to enable the filestore to be accessed
> remotely then you'll have to map the filestore and
> make it accesible or rather shared. From your code it
> appears that the file store has been created at
> c:\temp. Can you share this location and map this
> file on your remote subscriber machine. In case you
> map this c:\temp to a g: drive on your remote
> subscriber then the providerURL will become
> file:///g:/temp.
>
I am currently trying to enable JMS through the HttpTunnel capabilities of the Enterprise Trial version of IMQ. From this statement, it appears as though I can only use the File Object Store if I enable filesharing through my firewall. Otherwise, the remote subscriber has no way of locating the broker's managed administration objects. Is this correct?
Carl
# 18
The ldap can be an object store apart from the default file store. If you are using a HTTP tunnel support then even if you want to use ldap to store the administered objects you can very well do that but the ldapURL required to access the directory server should be allowed access through firewall. For example if the directory server is running on default 389 port number then this port number can be given access on the firewall.
Only configurations in the connection factory is required the other programming model for the client remains the same. The required cofigurations for the CF are:
Set the imqConnectionType attribute to HTTP
Set the imqConnectionURL to the HTTP tunnel servlet URL eg http://hostName:port/imq/tunnel
Please refer the admin guide for more details regarding configuration of tunnel servlet and the connection factory attributes.
http://docs.sun.com/source/817-6024/a_http.html
Thanks
Vibhor
http://wwws.sun.com/software/products/message_queue/
# 19
Dear Vibhor,Can you explain this lookup process a little more lucidly ?