Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: How to change remote JNDI-name in Jonas

Stefaan Somers <[email protected]> Fri, 26 Aug 2011 12:28:55 +0200
Newsgroups gmane.comp.java.objectweb.jonas
Message-ID <CA+N_TpWL5TS8Lni-dRk0Y2KTxV1Ac+SpKZHC1uOP=N03jzVNTw@mail.gmail.com>
If you use mappedname, you only get the Remote Interface and not the local.

On 26 August 2011 11:54, Florent BENOIT <[email protected]> wrote:
> =A0 =A0Hi,
>
> You may apply the same rule for local bean
>
>
> Regards,
>
> Florent
>
> On 08/26/2011 11:28 AM, Stefaan Somers wrote:
>>
>> Hi,
>>
>> using the ejb-jar.xml, and defining the same class as a different bean
>> using the mappedName worked. So I can access the remote bean now with
>> a specific name.
>> Now I have a similar problem with the local bean. Is there any way I
>> can make a difference in naming there???
>>
>> Greetings,
>>
>> Stefaan Somers
>>
>> <?xml version=3D"1.0" encoding=3D"UTF-8"?>
>> <ejb-jar version=3D"3.0" xmlns=3D"http://java.sun.com/xml/ns/javaee"
>> xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance"
>> xsi:schemaLocation=3D"http://java.sun.com/xml/ns/javaee
>> http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
>> =A0 <display-name>
>> EducationEJB3Beans</display-name>
>> <enterprise-beans>
>> <session>
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0<display-name>ParametersRemote</display-n=
ame>
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0<ejb-name>ParametersRemote</ejb-name>
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0<mapped-name>MyApp_ParametersRemote</mapp=
ed-name>
>> =A0 =A0 =A0 =A0 =A0<business-remote>be.sso.test.ParametersRemote</busine=
ss-remote>
>> =A0 =A0 =A0 =A0 =A0<ejb-class>be.sso.test.Parameters</ejb-class>
>> =A0 =A0 =A0 =A0 =A0<session-type>Stateless</session-type>
>>
>> </session>
>> <session>
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0<display-name>ParametersLocal</display-na=
me>
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0<ejb-name>MyApp_ParametersLocal</ejb-name=
>
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0<mapped-name>MyApp_ParametersLocal</mappe=
d-name>
>>
>> =A0<business-local>be.sso.test.ParametersLocal</business-local>
>> =A0 =A0 =A0 =A0 =A0<ejb-class>be.sso.test.Parameters</ejb-class>
>> =A0 =A0 =A0 =A0 =A0<session-type>Stateless</session-type>
>>
>>
>>
>> </session>
>> </enterprise-beans>
>> =A0</ejb-jar>
>>
>> On 9 August 2011 14:52, Guillaume Sauthier (OW2)
>> <[email protected]> =A0wrote:
>>>
>>> OK I think got it.
>>> The problem with mappedName attribute is that we have only 1 value that
>>> must
>>> be used for all our interfaces: local/remote/ws/...
>>> So, there are names clashes when you specify mappedname and you have
>>> multiple interfaces.
>>> EJB3 Spec is not good on this point :'(
>>>
>>> So it seems we have very few options right now:
>>> * Separate your applications on independant JOnAS (separate JNDI regist=
ry
>>> means no clashes)
>>> * Mutualize your EJB between your applications so that there is only 1
>>> instance of your bean
>>>
>>> But this is an interesting use case that we would like to support, so i
>>> would be grateful if you could open a JIRA explaining the issue.
>>> For the more long term, we may come with a more elegant solution:
>>> Customize the naming strategy to differentiate JNDI names from beans in
>>> different applications:
>>> something that could be placed in the easybeans.xml file (either in
>>> global
>>> or ejbjar configuration)
>>> <strategy>${beanName}-${beanInterface}@${beanMode}</strategy>
>>> or
>>> <mapped-names>
>>> =A0 <local>MyLocalBean</local>
>>> =A0 <remote>MyRemoteBean</remote>
>>> </mapped-names>
>>>
>>> Thanks
>>> --G
>>>
>>> 2011/8/9 Stefaan Somers<[email protected]>
>>>>
>>>> Guillaume,
>>>>
>>>> OK but if 2 Beans normally have the same package-name& =A0ClassName in=
 2
>>>> different applications (different jar-components), there can be only 1
>>>> JNDI-entry for the remote interface. So there is the danger that 1
>>>> application is going to the wrong JNDI-entry.
>>>>
>>>>
>>>> For example we have 2 applications with each an account-component
>>>> (with Account-bean that is used for logon information). Last time when
>>>> I deployed the 2 applications, the one application was using the
>>>> account-data from the other application.
>>>>
>>>> I hope it's a bit clear for you??
>>>>
>>>> Greetings,
>>>>
>>>> Stefaan Somers
>>>>
>>>> On 9 August 2011 13:51, Guillaume Sauthier (OW2)
>>>> <[email protected]> =A0wrote:
>>>>>
>>>>> EasyBeans (the EJB3 container in JOnAS) gives priority to beans found
>>>>> in
>>>>> the
>>>>> same application if there is multiple match.
>>>>> The EJB3 spec mandates that behavior so you're safe :)
>>>>> Just make a try.
>>>>> --G
>>>>>
>>>>> 2011/8/9 Stefaan Somers<[email protected]>
>>>>>>
>>>>>> But,
>>>>>>
>>>>>> our applications are generated, so we can have for example 2
>>>>>> account-beans in 2 different applications. Therefore we must be able
>>>>>> to uniquely identify the 2 remote JNDI interfaces to the 2 different
>>>>>> applications. That's why we are using "mappedName"
>>>>>>
>>>>>> Greetings,
>>>>>>
>>>>>> Stefaan Somers
>>>>>>
>>>>>> On 9 August 2011 11:55, Guillaume Sauthier (OW2)
>>>>>> <[email protected]> =A0wrote:
>>>>>>>
>>>>>>> You should also remove your mapped names (don't needed anymore
>>>>>>> because
>>>>>>> you
>>>>>>> rely on the container to find the right interface for you).
>>>>>>>
>>>>>>> --G
>>>>>>>
>>>>>>> 2011/8/9 Stefaan Somers<[email protected]>
>>>>>>>>
>>>>>>>> Hello,
>>>>>>>>
>>>>>>>> I'v tried that too, but it also injects the remote-bean then inste=
ad
>>>>>>>> of the local-bean.
>>>>>>>>
>>>>>>>> Greetings,
>>>>>>>>
>>>>>>>> Stefaan Somers
>>>>>>>>
>>>>>>>> On 9 August 2011 11:04, Guillaume Sauthier (OW2)
>>>>>>>> <[email protected]> =A0wrote:
>>>>>>>>>
>>>>>>>>> Can't you change your Calculator.java to something like this:
>>>>>>>>>
>>>>>>>>> It's much more easier to read :)
>>>>>>>>>
>>>>>>>>> /**
>>>>>>>>> =A0* Session Bean implementation class Calculator
>>>>>>>>> =A0*/
>>>>>>>>> @Stateless
>>>>>>>>> public class Calculator implements CalculatorRemote,
>>>>>>>>> CalculatorLocal
>>>>>>>>> {
>>>>>>>>>
>>>>>>>>> =A0 @EJB
>>>>>>>>> =A0 private ParametersLocal params;
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> =A0 =A0 /**
>>>>>>>>> =A0 =A0 =A0* Default constructor.
>>>>>>>>> =A0 =A0 =A0*/
>>>>>>>>> =A0 =A0 public Calculator() {
>>>>>>>>>
>>>>>>>>> =A0 =A0 }
>>>>>>>>>
>>>>>>>>> =A0 =A0 @Override
>>>>>>>>> =A0 =A0 public String returnMessage() {
>>>>>>>>> =A0 =A0 =A0 =A0 result =3D parameters.getParameter();
>>>>>>>>> =A0 =A0 =A0 =A0 return "It's all being calculated :" + result;
>>>>>>>>> =A0 =A0 }
>>>>>>>>>
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> 2011/8/9 Stefaan Somers<[email protected]>
>>>>>>>>>>
>>>>>>>>>> Hi Guillaume,
>>>>>>>>>> Thnks for responding. I'm already banging my head for a few days
>>>>>>>>>> with
>>>>>>>>>> this problem. So any help would be most welcome.
>>>>>>>>>>
>>>>>>>>>> I've included a sample project. For the Parameters-bean I use th=
e
>>>>>>>>>> mappedName parameter, since I need to give it a unique-name.
>>>>>>>>>>
>>>>>>>>>> If I try to get the Local Parameters-bean with the
>>>>>>>>>> Calculator-bean,
>>>>>>>>>> it
>>>>>>>>>> gives me the following exception :
>>>>>>>>>>
>>>>>>>>>> java.lang.ClassCastException: $Proxy63 cannot be cast to
>>>>>>>>>> be.sso.test.ParametersLocal
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> be.sso.test.Calculator.original$EasyBeans$returnMessage(Calculat=
or.java:34)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.ow2.easybeans.gen.invocationcontext.be.sso.test.Calculator.E=
asyBeansInvocationContextImplreturnMessageAROUNDINVOKE1942950347.proceed(Un=
known
>>>>>>>>>> Source)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.ow2.easybeans.transaction.interceptors.CMTRequiredTransactio=
nInterceptor.intercept(CMTRequiredTransactionInterceptor.java:110)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.ow2.easybeans.gen.invocationcontext.be.sso.test.Calculator.E=
asyBeansInvocationContextImplreturnMessageAROUNDINVOKE1942950347.proceed(Un=
known
>>>>>>>>>> Source)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.ow2.jonas.jndi.interceptors.impl.easybeans.ResourceCheckerIn=
terceptor.intercept(ResourceCheckerInterceptor.java:103)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.ow2.easybeans.gen.invocationcontext.be.sso.test.Calculator.E=
asyBeansInvocationContextImplreturnMessageAROUNDINVOKE1942950347.proceed(Un=
known
>>>>>>>>>> Source)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.ow2.jonas.ejb.easybeans.JOnASENCInterceptor.intercept(JOnASE=
NCInterceptor.java:67)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.ow2.easybeans.gen.invocationcontext.be.sso.test.Calculator.E=
asyBeansInvocationContextImplreturnMessageAROUNDINVOKE1942950347.proceed(Un=
known
>>>>>>>>>> Source)
>>>>>>>>>> =A0 =A0 =A0 =A0at be.sso.test.Calculator.returnMessage(Calculato=
r.java)
>>>>>>>>>> =A0 =A0 =A0 =A0at sun.reflect.NativeMethodAccessorImpl.invoke0(N=
ative
>>>>>>>>>> Method)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessor=
Impl.java:39)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethod=
AccessorImpl.java:25)
>>>>>>>>>> =A0 =A0 =A0 =A0at java.lang.reflect.Method.invoke(Method.java:59=
7)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.ow2.easybeans.container.session.stateless.StatelessSessionFa=
ctory.localCall(StatelessSessionFactory.java:161)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.ow2.easybeans.container.session.SessionFactory.rpcInvoke(Ses=
sionFactory.java:237)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.ow2.easybeans.rpc.rmi.server.RMIServerRPCImpl.getEJBResponse=
(RMIServerRPCImpl.java:106)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.ow2.easybeans.rpc.rmi.client.RMIClientRPC.sendEJBRequest(RMI=
ClientRPC.java:105)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.ow2.easybeans.proxy.client.ClientRPCInvocationHandler.invoke=
(ClientRPCInvocationHandler.java:195)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.ow2.easybeans.proxy.client.ClientRPCInvocationHandler.invoke=
(ClientRPCInvocationHandler.java:111)
>>>>>>>>>> =A0 =A0 =A0 =A0at $Proxy62.returnMessage(Unknown Source)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>> be.sso.servlet.CalculateServlet.doGet(CalculateServlet.java:40)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>> javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>> javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter=
(ApplicationFilterChain.java:290)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.apache.catalina.core.ApplicationFilterChain.doFilter(Applica=
tionFilterChain.java:206)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWra=
pperValve.java:233)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.apache.catalina.core.StandardContextValve.invoke(StandardCon=
textValve.java:191)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.ow2.jonas.web.tomcat6.CheckOpenResourcesValve.invoke(CheckOp=
enResourcesValve.java:73)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.ow2.jonas.web.tomcat6.tx.TransactionValve.invoke(Transaction=
Valve.java:90)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.ow2.jonas.web.tomcat6.ResetAuthenticationValve.invoke(ResetA=
uthenticationValve.java:95)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.apache.catalina.core.StandardHostValve.invoke(StandardHostVa=
lve.java:127)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportVa=
lve.java:102)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngi=
neValve.java:109)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapte=
r.java:340)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.apache.coyote.http11.Http11Processor.process(Http11Processor=
.java:857)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.=
process(Http11Protocol.java:588)
>>>>>>>>>> =A0 =A0 =A0 =A0at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.ja=
va:489)
>>>>>>>>>> =A0 =A0 =A0 =A0at java.lang.Thread.run(Thread.java:619)
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On 9 August 2011 10:45, Guillaume Sauthier (OW2)
>>>>>>>>>> <[email protected]> =A0wrote:
>>>>>>>>>>>
>>>>>>>>>>> Can't you rely on container's injection (@EJB) ?
>>>>>>>>>>> --G
>>>>>>>>>>>
>>>>>>>>>>> 2011/8/9 Stefaan Somers<[email protected]>
>>>>>>>>>>>>
>>>>>>>>>>>> Hi all,
>>>>>>>>>>>>
>>>>>>>>>>>> I need to change the remote jndi-name of a Stateless Session
>>>>>>>>>>>> Bean
>>>>>>>>>>>> .
>>>>>>>>>>>> Default the naming for jonas is :
>>>>>>>>>>>>
>>>>>>>>>>>> SessionBean.class.getName()
>>>>>>>>>>>> + "_" + SessionBeanInterface.class.getName() + "@Remote"
>>>>>>>>>>>>
>>>>>>>>>>>> How can I change this. If I add the attribute mappedName in
>>>>>>>>>>>> the
>>>>>>>>>>>> @Stateless-annotation, I cannot get to the Local Interface
>>>>>>>>>>>> anymore.
>>>>>>>>>>>> And I need to be able to get to both.
>>>>>>>>>>>>
>>>>>>>>>>>> Greetings,
>>>>>>>>>>>>
>>>>>>>>>>>> Stefaan Somers
>>>>>>>>>>>
>>>>>>>>>
>>>>>>>
>>>>>
>>>
>
>