You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by Radim Kolar <hs...@sendmail.cz> on 2011/11/10 19:21:29 UTC

custom jndi resources

i have in web.xml

<resource-ref>
<description>Adresa Cassandra clusteru</description>
<res-ref-name>cass</res-ref-name>
<res-type>java.lang.String</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

I need  to define String resource and bind it to jndi to make 
application work. From IBM documentation it seems that writing Gbean is 
needed:

 >>>
If you were exposing resources other than JMS or database resources 
through JNDI, you
can do the same by writing GBeans to act as a wrapper around your 
resources. First,
check for any plug-ins that are already available for exposing such 
resources as part of
JNDI in Community Edition.
<<<

Because i need String then my custom bean must subclass String?

public  class StringWrapperGBeanimplements  InterfaceNamed {

     public  StringWrapperGBean(String  gbeanName) {
	super(gbeanName);
     }

    private  static  final  GBeanInfo GBEAN_INFO;

     static  {
	    GBeanInfoBuilder infoFactory =new  GBeanInfoBuilder(
	    StringWrapperGBean.class.getName(), StringWrapperGBean.class);

	    infoFactory.addAttribute("gbeanName",String.class,false);
	    infoFactory.addInterface(InterfaceNamed.class);
	    infoFactory.setConstructor(new  String[] {"gbeanName"  });

	    GBEAN_INFO = infoFactory.getBeanInfo();
         }

      public  static  GBeanInfo getGBeanInfo() {
		return  GBEAN_INFO;
     }

I am kinda confused

Re: custom jndi resources

Posted by Radim Kolar <hs...@sendmail.cz>.
i was confused by validating xml editor - entries are order sensitive. 
env-entry must be before resource-ref. I will write short blob post on 
this topic because G docs does not have this example.

<env-entry>
<description>dddd</description>
<env-entry-name>cass</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>MyValue</env-entry-value>
</env-entry>
--

JNDI lookups like

  Context initCtx = new InitialContext();
(String)initCtx.lookup("cass"));

fails with

javax.servlet.ServletException: javax.naming.NotContextException:

it works in glassfish that way. in geronimo you must have full path java:comp

both Geronimo and Glassfish pass J2EE test suite, maybe both are correct.


Re: custom jndi resources

Posted by Ivan <xh...@gmail.com>.
For injecting a string, I think env-entry will help you in web.xml , it is
something like :

<env-entry>
        <description>dddd</description>
        <env-entry-name>cass</env-entry-name>
        <env-entry-type>java.lang.String</env-entry-type>
        <env-entry-value>MyValue</env-entry-value>
</env-entry>

You could also overwrite the value in geronimo-web.xml file.

2011/11/11 Radim Kolar <hs...@sendmail.cz>

>
>  Usually strings in jndi are resource-env-ref not resource-ref?
>>
> i can change web.xml to
>
> <resource-env-ref>
>
> <description>Adresa Cassandra clusteru</description>
> <resource-env-ref-name>cass</**resource-env-ref-name>
> <resource-env-ref-type>java.**lang.String</resource-env-ref-**type>
> </resource-env-ref>
>
> but how to write string value for this in geronimo-web.xml?
>
> <ref:resource-env-ref>
> <ref:ref-name>cass</ref:ref-**name>
>    ???
> </ref:resource-env-ref>
>
>
>
>>  i have in web.xml
>>>
>>> <resource-ref>
>>> <description>Adresa Cassandra clusteru</description>
>>> <res-ref-name>cass</res-ref-**name>
>>> <res-type>java.lang.String</**res-type>
>>> <res-auth>Container</res-auth>
>>> <res-sharing-scope>Shareable</**res-sharing-scope>
>>> </resource-ref>
>>>
>>> I need  to define String resource and bind it to jndi to make
>>> application work. From IBM documentation it seems that writing Gbean is
>>> needed:
>>>
>>> If you were exposing resources other than JMS or database resources
>>> through JNDI, you
>>> can do the same by writing GBeans to act as a wrapper around your
>>> resources. First,
>>> check for any plug-ins that are already available for exposing such
>>> resources as part of
>>> JNDI in Community Edition.
>>> <<<
>>>
>>> Because i need String then my custom bean must subclass String?
>>>
>>> public  class StringWrapperGBeanimplements  InterfaceNamed {
>>>
>>>    public  StringWrapperGBean(String  gbeanName) {
>>>        super(gbeanName);
>>>    }
>>>
>>>   private  static  final  GBeanInfo GBEAN_INFO;
>>>
>>>    static  {
>>>            GBeanInfoBuilder infoFactory =new  GBeanInfoBuilder(
>>>            StringWrapperGBean.class.**getName(),
>>> StringWrapperGBean.class);
>>>
>>>            infoFactory.addAttribute("**gbeanName",String.class,false)**;
>>>            infoFactory.addInterface(**InterfaceNamed.class);
>>>            infoFactory.setConstructor(new  String[] {"gbeanName"  });
>>>
>>>            GBEAN_INFO = infoFactory.getBeanInfo();
>>>        }
>>>
>>>     public  static  GBeanInfo getGBeanInfo() {
>>>                return  GBEAN_INFO;
>>>    }
>>>
>>> I am kinda confused
>>>
>>
>


-- 
Ivan

Re: custom jndi resources

Posted by Radim Kolar <hs...@sendmail.cz>.
> Usually strings in jndi are resource-env-ref not resource-ref?
i can change web.xml to

<resource-env-ref>
<description>Adresa Cassandra clusteru</description>
<resource-env-ref-name>cass</resource-env-ref-name>
<resource-env-ref-type>java.lang.String</resource-env-ref-type>
</resource-env-ref>

but how to write string value for this in geronimo-web.xml?

<ref:resource-env-ref>
<ref:ref-name>cass</ref:ref-name>
     ???
</ref:resource-env-ref>

>
>> i have in web.xml
>>
>> <resource-ref>
>> <description>Adresa Cassandra clusteru</description>
>> <res-ref-name>cass</res-ref-name>
>> <res-type>java.lang.String</res-type>
>> <res-auth>Container</res-auth>
>> <res-sharing-scope>Shareable</res-sharing-scope>
>> </resource-ref>
>>
>> I need  to define String resource and bind it to jndi to make application work. From IBM documentation it seems that writing Gbean is needed:
>>
>> If you were exposing resources other than JMS or database resources through JNDI, you
>> can do the same by writing GBeans to act as a wrapper around your resources. First,
>> check for any plug-ins that are already available for exposing such resources as part of
>> JNDI in Community Edition.
>> <<<
>>
>> Because i need String then my custom bean must subclass String?
>>
>> public  class StringWrapperGBeanimplements  InterfaceNamed {
>>
>>     public  StringWrapperGBean(String  gbeanName) {
>> 	super(gbeanName);
>>     }
>>
>>    private  static  final  GBeanInfo GBEAN_INFO;
>>
>>     static  {
>> 	    GBeanInfoBuilder infoFactory =new  GBeanInfoBuilder(
>> 	    StringWrapperGBean.class.getName(), StringWrapperGBean.class);
>>
>> 	    infoFactory.addAttribute("gbeanName",String.class,false);
>> 	    infoFactory.addInterface(InterfaceNamed.class);
>> 	    infoFactory.setConstructor(new  String[] {"gbeanName"  });
>>
>> 	    GBEAN_INFO = infoFactory.getBeanInfo();
>>         }
>>
>>      public  static  GBeanInfo getGBeanInfo() {
>> 		return  GBEAN_INFO;
>>     }
>>
>> I am kinda confused


Re: custom jndi resources

Posted by David Jencks <da...@yahoo.com>.
Usually strings in jndi are resource-env-ref not resource-ref?

david jencks

On Nov 10, 2011, at 10:21 AM, Radim Kolar wrote:

> i have in web.xml
> 
> <resource-ref>
> <description>Adresa Cassandra clusteru</description>
> <res-ref-name>cass</res-ref-name>
> <res-type>java.lang.String</res-type>
> <res-auth>Container</res-auth>
> <res-sharing-scope>Shareable</res-sharing-scope>
> </resource-ref>
> 
> I need  to define String resource and bind it to jndi to make application work. From IBM documentation it seems that writing Gbean is needed:
> 
> >>>
> If you were exposing resources other than JMS or database resources through JNDI, you
> can do the same by writing GBeans to act as a wrapper around your resources. First,
> check for any plug-ins that are already available for exposing such resources as part of
> JNDI in Community Edition.
> <<<
> 
> Because i need String then my custom bean must subclass String?
> 
> public  class StringWrapperGBeanimplements  InterfaceNamed {
> 
>    public  StringWrapperGBean(String  gbeanName) {
> 	super(gbeanName);
>    }
> 
>   private  static  final  GBeanInfo GBEAN_INFO;
> 
>    static  {
> 	    GBeanInfoBuilder infoFactory =new  GBeanInfoBuilder(
> 	    StringWrapperGBean.class.getName(), StringWrapperGBean.class);
> 
> 	    infoFactory.addAttribute("gbeanName",String.class,false);
> 	    infoFactory.addInterface(InterfaceNamed.class);
> 	    infoFactory.setConstructor(new  String[] {"gbeanName"  });
> 
> 	    GBEAN_INFO = infoFactory.getBeanInfo();
>        }
> 
>     public  static  GBeanInfo getGBeanInfo() {
> 		return  GBEAN_INFO;
>    }
> 
> I am kinda confused