ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » Context returning Null

Post new topic  Reply to topic
 Context returning Null « View previous topic :: View next topic » 
Author Message
elvis_gn
PostPosted: Wed Mar 29, 2006 10:22 pm    Post subject: Context returning Null Reply with quote

Padawan

Joined: 08 Oct 2004
Posts: 1905
Location: Dubai

Hi guys,

This is my first application with JMS, so please bear with the foolishness

I am trying to use the following code to set up a connection to put messages
Code:
String icf ="com.sun.jndi.fscontext.RefFSContextFactory";
    String url ="file://C:/JNDIConfig";

    Hashtable env = new Hashtable();
    env.put( Context.INITIAL_CONTEXT_FACTORY,icf);
    env.put( Context.PROVIDER_URL,url);
    env.put( Context.REFERRAL, "throw" );
    [color=red]Context ctx = new InitialDirContext(env);[/color]
    System.out.println("Context created");

I get an error in the line marked in red, it is a javax.naming.NameNotFoundException....the context is returning a NULL.
Do I need to run something else, or create something

I made the changes in the JMSAdmin.cfg
Code:
INITIAL_CONTEXT_FACTORY=com.sun.jndi.fscontext.RefFSContextFactory
PROVIDER_URL=file:/C:/JMSConfig


I have created the qcf etc, below are the commands i used
Code:
def ctx(JMS_Sample)
chg ctx(JMS_Sample)
def qcf(JMS) qmgr(WBRK_QM)
def q(JMS_Input_LQ) qmgr(WBRK_QM) queue(JMS_Input_LQ)
def q(JMS_Output_LQ) qmgr(WBRK_QM) queue(JMS_Output_LQ)
end

I can see the folder JMS_Sample and JMS created and the .bindings file too.

Can someone tell me what i'm doing wrong.

Regards.
Back to top
View user's profile Send private message Send e-mail
elvis_gn
PostPosted: Wed Mar 29, 2006 10:59 pm    Post subject: Reply with quote

Padawan

Joined: 08 Oct 2004
Posts: 1905
Location: Dubai

Hi guys,

I got it...

I had names the folder as JMSConfig,....and i was trying to reference JNDIConfig....its working.

I need one clarification though...for the line of code below
Code:
qcf = (QueueConnectionFactory)initCtx.lookup("JMS_Sample");

should i be looking up "JMS_Sample" or "JMS_Sample/JMS" or "JMS" alone ?

Regards.
Back to top
View user's profile Send private message Send e-mail
elvis_gn
PostPosted: Wed Mar 29, 2006 11:31 pm    Post subject: Reply with quote

Padawan

Joined: 08 Oct 2004
Posts: 1905
Location: Dubai

Hi guys,

Follow up.

When I change my code from
Code:
PROVIDER_URL=file:/C:/JMSConfig
qcf = (QueueConnectionFactory)initCtx.lookup("JMS_Sample/JMS");

to
Code:
PROVIDER_URL=file:/C:/JMSConfig/JMS_Sample
qcf = (QueueConnectionFactory)initCtx.lookup("JMS");

it works, but I guess then I cannot use this url from a properties file or something for every application of mine....in other words, for every different context, i will have to use a different url...

Am i doing something wrong...can this be fixed ?

Regards.
Back to top
View user's profile Send private message Send e-mail
vennela
PostPosted: Wed Mar 29, 2006 11:47 pm    Post subject: Reply with quote

Jedi Knight

Joined: 11 Aug 2002
Posts: 4055
Location: Hyderabad, India

You can have one file where you store the jndi objects.
You can create contexts within that.

Look at defining contexts in JMSAdmin
Back to top
View user's profile Send private message Send e-mail Visit poster's website
briancop
PostPosted: Wed Mar 29, 2006 11:53 pm    Post subject: Reply with quote

Apprentice

Joined: 04 Apr 2005
Posts: 28
Location: Hursley, UK

What you are now doing looks about right,so 'what am I doing wrong?' gets the answer 'nothing' from me. You should put related objects into 1 context, such that when you do lookups you open the context for all the objects you need for your application (in your case JMS_Sample within the c:/JMSConfig file) then lookup the connection factory and destination objects.

If possible, you should have a good mapping between your context structure and your applications such that this is possible. If your application needs objects from multiple contexts because you cannot get such a good mapping (e.g. this application is using existing contexts that you don't have control over), then you will need multiple initCtx objects.

As for putting the URL into a properties file, you can of course do that, but I wouldn't expect the same properties file to be used for multiple applications. Sure, you can share it across multiple instances of the same application or across related applications which are going to use the same context, but why would you expect unrelated applications using different contexts to use the same properties configuration file?

[As an aside...I might also question why you want to put the URL into a properties file anyway. You already have JNDI as an abstraction such that you don't have to hard code your connection factory and destination properties into your app. You are trying to add a 2nd level of abstraction to lookup a property to get a context name in which to lookup your CFs and Dests. At some point you have to hardcode something; if not the context name then the properties config file name, or a file in which to lookup the properties config file name in which to lookup the context name, or a file to lookup the file to lookup the file to lookup the context name...... I would generally have expected to stop at the first level of abstraction and hardcode the context names, but others may see a benefit to a 2nd level of abstraction.]

Brian
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Mar 30, 2006 4:14 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

You have to know how the file context works.

In your case you should have done something like this for a multilevel context:
Code:
Context ctx = (Context) initCtx.lookup("JMSSample");
qcf = (QueueConnectionFactory) ctx.lookup("JMS");


Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
elvis_gn
PostPosted: Thu Mar 30, 2006 4:24 am    Post subject: Reply with quote

Padawan

Joined: 08 Oct 2004
Posts: 1905
Location: Dubai

Hi guys,

Thanks for all the info...i got the code to work..trying to improve on it.

I found this post from sometime earlier
http://www.mqseries.net/phpBB2/viewtopic.php?t=6977&highlight=namingexception
it explains the last issue that I was having with the url's....wanted to know if it was fixed.

vennela wrote:
Look at defining contexts in JMSAdmin

where do i find this...did you mean this to be a link in infocenter, or in Using Java.....??

briancop: I was going well through the initial para's but then I lost you But i think i got what u were trying to tell me partially.
I understand that i can hardcode the url, but i will have to use different url's in different applications and tomorrow if i want to change it, i will have to go looking for the code and know which url is for which application...that is why i want the url to remain the same across all apps.

My current problem is this...the below is what i have in my properties file
Code:
url=file://C:/JMSConfig
JMS_Sample_Conn=JMS_Sample/JMS

it dosen't work...if I make it
Code:
url=file://C:/JMSConfig/JMS_Sample
JMS_Sample_Conn=JMS

it works....

But if i do this change, then i can use this properties file only for one application...or only for applications which are using the queues within this context...

So, i would have to make a properties file for every independant application....that dosen't sound too good a design
or in one properties file i will have to differentiate the different url's i need...

In simple words, i don't want to tomorrow touch my code for any kind of change in the JMS config parameters....

I am thinking of somehow identifying the context of an application and concatenating it with the standard url and thus getting the context dynamically....how does naming of the property with the name of the application sound ?? for example: as my java class name is JMS_Sample, name the context as the same and append it to the url to get the above How do u guys configure ur context's.

Regards.
Back to top
View user's profile Send private message Send e-mail
fjb_saper
PostPosted: Thu Mar 30, 2006 4:37 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

elvis,

Like I said you have to read up on the Sun Filecontext. It doesn't support retrieving nested contexts with root/nested1/nested2.

However you can always retrieve it with
Code:
ctx = (Context)ctx.lookup("nested1");
ctx = (Context)ctx.lookup("nested2");


Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
elvis_gn
PostPosted: Thu Mar 30, 2006 4:53 am    Post subject: Reply with quote

Padawan

Joined: 08 Oct 2004
Posts: 1905
Location: Dubai

Hi fjb_saper,

Sorry, saw your post only after posting mine(it took me some time to write all that )

I got what you said and i think i should be able to figure out on how to work now...

Are there more limitations in FileContext like this one...Can you just where i can read up on this.

Regards.
Back to top
View user's profile Send private message Send e-mail
fjb_saper
PostPosted: Thu Mar 30, 2006 1:47 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

elvis_gn wrote:
Hi fjb_saper,

Sorry, saw your post only after posting mine(it took me some time to write all that )

I got what you said and i think i should be able to figure out on how to work now...

Are there more limitations in FileContext like this one...Can you just where i can read up on this.

Regards.


I believe its in the using java manual. If not there should be a java doc somwhere.

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » Context returning Null
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.