You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrf-user@ws.apache.org by Java Helpline <he...@yahoo.co.uk> on 2006/02/25 18:25:34 UTC

Using InitialContext to locate the Home of any Service

Hi,
   
    How I can retrieve the Home of any other WSRF Service deployed in the same Tomcat. Earlier I have used something like:
   
   Context initialContext = new InitialContext();
resourceHome = (HelloWorld240206Home)initialContext.lookup(HelloWorld240206Home.HOME_LOCATION);
   
  where HOME_LOCATION =
      JndiConstants.CONTEXT_NAME_SERVICES + "/" + SERVICE_NAME + "/" +
      JndiConstants.ATOMIC_NAME_HOME;
   
  The print statement prints the following information with proper QName of the Service:
  wsrf/services/{http://www.dl.ac.uk/helloworld2502}HelloWorld240206/home
   
  but I am getting exception.
  javax.naming.NameNotFoundException: Name services is not bound in this Context
   
  Is there any way to link two services together as it is possible in Globus Implementation, so factory service "A "which is independent of actual business service "B" can locate the home of service "B", in stead of hard coding it.
  In Globus this is done in WSDD for Service A with the additon of
  <parameter name="instance" value="B"/>
   
  and in the jndi-config for Service A
  <resourceLink name="home" target="java:comp/env/services/B/home"/>
   
  I hope someone will direct my in correct direction.
   
  Regards
  Asif

		
---------------------------------
Win a BlackBerry device from O2 with Yahoo!. Enter now.

Re: Using InitialContext to locate the Home of any Service

Posted by Java Helpline <he...@yahoo.co.uk>.
Hi,
     I am replying my own question, in case other people may need to implement Factory Design Pattern.
   
  Problem Scenario: One Front-end WSRF service (Service A) has create method and Client call this method, in return Service A creates resources of different WSRF Services e.g Service B, Service C and Service D. Client can't interact directly with Service B, Service C and Service D unless he has EPR for each of them. Service A (which is our Factory Service) creates resources for each of services and returns array of EPR corresponding to each of the Service Resource. 
   
  I don't want to use hard coded locations of Service B, Service C and Service D in my Factory Service i.e. Service A, so I was trying to use JNDI Look-up. It was working with early version and the source code was something like this in the Home class for each service I had final static field:
   
  HOME_LOCATION =
      JndiConstants.CONTEXT_NAME_SERVICES + "/" + SERVICE_NAME + "/" +
      JndiConstants.ATOMIC_NAME_HOME;
   
  At run time it is translated to this value: wsrf/services/{http://AAA.SSS.III/FFF}ServiceB/home.
   
  In the create method of Factory Service i.e. Service A I had something like this, below code is with reference to Service B and can be extended for Service C and Service D:
   
  Context initialContext = new InitialContext();
resourceHome = (ServiceBHome)initialContext.lookup(ServiceBHome.HOME_LOCATION);

   
  But this suddenly gives me error due to no such name bound. Little investigation revealed that each Service Home is bound with the name "wsrf/resource/ServiceB"
   
  Difference is wsrf/services is replaced by wsrf/resource and there is no more /home in the end of binding name and above all WSRF Service name is not qualified name, which is in fact Port Name.
   
  Thus now in each service home we have something like:
  public static final String HOME_LOCATION =  "wsrf/resource/" + PORT_NAME;
   
  Code for Factory Service i.e. Service A will remain the same. I have hard coded "wsrf/resource/" in the Home class and it is still better to hard code in Factory class. 
   
  This is working for me, but not sure if this is the best solution. 
   
  Question why we need Factory Pattern, Work flows are best example of Factory Pattern, where work flow itself is service which orchestrate other services on behalf of client. I am trying to achieve the same through WSRF as case study for research purposes and once I have working implementation I will put it on web.
   
  I hope my own reply will help others.
   
  Regards
  Asif
Java Helpline <he...@yahoo.co.uk> wrote:
    Hi,
   
    How I can retrieve the Home of any other WSRF Service deployed in the same Tomcat. Earlier I have used something like:
   
   Context initialContext = new InitialContext();
resourceHome = (HelloWorld240206Home)initialContext.lookup(HelloWorld240206Home.HOME_LOCATION);
   
  where HOME_LOCATION =
      JndiConstants.CONTEXT_NAME_SERVICES + "/" + SERVICE_NAME + "/" +
      JndiConstants.ATOMIC_NAME_HOME;
   
  The print statement prints the following information with proper QName of the Service:
  wsrf/services/{http://www.dl.ac.uk/helloworld2502}HelloWorld240206/home
   
  but I am getting exception.
  javax.naming.NameNotFoundException: Name services is not bound in this Context
   
  Is there any way to link two servic es together as it is possible in Globus Implementation, so factory service "A "which is independent of actual business service "B" can locate the home of service "B", in stead of hard coding it.
  In Globus this is done in WSDD for Service A with the additon of
  <parameter name="instance" value="B"/>
   
  and in the jndi-config for Service A
  <resourceLink name="home" target="java:comp/env/services/B/home"/>
   
  I hope someone will direct my in correct direction.
   
  Regards
  Asif
    
---------------------------------
  Win a BlackBerry device from O2 with Yahoo!. Enter now.


		
---------------------------------
Yahoo! Messenger  NEW - crystal clear PC to PC calling worldwide with voicemail