You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@tuscany.apache.org by Ramkumar R <ra...@gmail.com> on 2008/09/04 19:33:08 UTC

Re: sca namespace in spring

Hi Abraham,
Here I have few findings and suggestions for the spring namespace and
application Context issues.

*For Spring Namespace Issue:*
As per my earlier comments, the custom XML tags like <sca:service>,
<sca:reference> and <sca:property> and the sca namespace will be supported
only when Tuscany creates the application context for you.
The reason is Tuscany not only defines the bean definition for these tags,
but also defines the logic. So I believe Tuscany does the right thing to
handle the sca namespace.

A detailed article on how you would go about writing your own custom XML
bean definition parsers and integrating such parsers into the Spring IoC
container can be found here....
http://static.springframework.org/spring/docs/2.5.x/reference/extensible-xml.html

*Loading Application Context using ClassPathXmlApplicationContext:*
Defining a bean as shown below,

<bean id="beanRefFactory"
class="org.springframework.context.support.ClassPathXmlApplicationContext">
    <constructor-arg><list>
        <value>Organization-spring-context.xml</value>
    </list></constructor-arg>
</bean>

would also result in a namespace issue being thrown, as in this case an
application context is being created using ClassPathXmlApplicationContext
(which is not aware of the sca namespace handlers).

Here I have a question to ask, may be I am not good at spring, basically I
am trying to understand what is the special purpose for using the
ClassPathXmlApplicationContext to load the
Organization-spring-context.xml file, while by default Tuscany would create
the application context for this file when its been specified as
<implementation.spring location="Organization-spring-context.xml"/> in the
composite file?

Your Comments on this would help us to come up with a better solution.

*Accessing the Application Context:*
Trying to load an application context using the code shown below,

ApplicationContext applicationContext = (ApplicationContext)
ContextSingletonBeanFactoryLocator.getInstance("beanRefFactory.xml").useBeanFactory("beanRefFactory").getFactory();

to access the beans would also result in a namespace issue for the same
reason shown above.

I believe there is a workaround to this problem, which demostrates how the
runtime instance of the application context can be accessed and also get
access to the beans as shown here.....

http://blog.jdevelop.eu/2008/07/06/access-the-spring-applicationcontext-from-everywhere-in-your-application/

This solution returns the SCAApplicationContext instance which resolves the
namespace for you. Probably, you need to evaluate if this workaround helps
your scenario.


Please provide us with your feedback on the same and let me know if I am
missing something in this whole discussion.


On Fri, Aug 29, 2008 at 10:04 PM, Abraham Washington
<ab...@yahoo.com>wrote:

> hi Ramkumar...thx for helping out.
>
>
>
> https://issues.apache.org/jira/browse/TUSCANY-2573
>
>
>
> thx abe
>
>
>
>
> ----- Original Message ----
> From: Ramkumar R <ra...@gmail.com>
> To: user@tuscany.apache.org
> Sent: Friday, August 29, 2008 1:08:03 AM
> Subject: Re: sca namespace in spring
>
> Hi Abraham,
> Can you please raise a JIRA stating the namespace issue and the application
> context issue? I like to take it up and see what best can be done here.
>
>
> On Fri, Aug 15, 2008 at 12:58 AM, Abraham Washington <abewashton@yahoo.com
> > wrote:
>
>>  thanks for the info.  appeciate it.  i tried to reference the xsd
>> locally, but it's throwing a "no declaration can be found for sca:service"
>> error.
>>
>>
>>
>> <
>> beans xmlns="http://www.springframework.org/schema/beans"
>>
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>
>> xmlns:sca="http://www.springframework.org/schema/sca"
>>
>> xsi:schemaLocation="
>>
>> http://www.springframework.org/schema/beans
>> http://www.springframework.org/schema/beans/spring-beans.xsd
>>
>>
>> http://www.springframework.org/schema/sca=C:\development\Organization-Service-Composite\src\main\resources\spring-sca.xsd<http://www.springframework.org/schema/sca=C:%5Cdevelopment%5COrganization-Service-Composite%5Csrc%5Cmain%5Cresources%5Cspring-sca.xsd>
>> "
>> >
>>
>> <sca:service name="OrganizationService"
>>
>> type="org.soa.services.OrganizationService" target=
>> "OrganizationServiceBean"/>
>>
>>
>> i'll keep trying..thx abe
>>
>>
>>  ----- Original Message ----
>> From: Mike Edwards <mi...@gmail.com>
>> To: user@tuscany.apache.org
>>  Sent: Thursday, August 14, 2008 6:50:26 AM
>> Subject: Re: sca namespace in spring
>>
>> Abe,
>>
>> I wondered why your case was different to that of the Spring tests - the
>> spring-sca.xsd is present
>> in Tuscany at this location:
>>
>>
>> \java\sca\modules\implementation-spring\src\main\resources\org\springframework\sca\xml
>>
>> The file is also present in:
>>
>>   tuscany-implementation-spring-1.4-SNAPSHOT.jar
>>
>> I'm sure that the Spring tests get the xsd from one of these.
>>
>> You're right in that the location
>>
>>   http://www.springframework.org/schema/sca/spring-sca.xsd
>>
>> ...does not work.  We shall have to fix the spec for this.
>>
>> You might try arranging to remove the current location definition and put
>> the xsd in some local
>> place that can be accessed when you run your application.
>>
>>
>> Yours,  Mike.
>>
>>
>>
>> Abraham Washington wrote:
>> > hi all...no luck no matter which way i try.  has anyone had any success
>> > getting the application context using spring has an implementation.  not
>>
>> > sure how I can get a bean if I can't get the application context.
>> >
>> >
>> >
>> > thx abe
>> >
>> >
>> >
>> > ----- Original Message ----
>> > From: Abraham Washington <ab...@yahoo.com>
>> > To: user@tuscany.apache.org
>> > Sent: Monday, August 11, 2008 12:24:12 PM
>> > Subject: Re: sca namespace in spring
>> >
>> > Running it in eclipse using scadomain.  sca-1.3.  spring 2.0.1.
>> >
>> >
>> >
>> > when i make the call to get the application context, it hurls.  here's
>> > my beanRefFactory.xml
>> >
>> >
>> >
>> > <beans>
>> >
>> > <bean id="beanRefFactory"
>> >
>> >
>> class="org.springframework.context.support.ClassPathXmlApplicationContext">
>> >
>> > <constructor-arg>
>> >
>> > <list>
>> >
>> > <value>Organization-spring-context.xml</value>
>> >
>> > </list>
>> >
>> > </constructor-arg>
>> >
>> > </bean>
>> >
>> > </beans>
>> >
>> >
>> >
>> > here's my call to get the applicationContext:
>> >
>> >
>> > org.springframework.context.ApplicationContext applicationContext =
>> >
>> > (org.springframework.context.ApplicationContext)
>> >
>> org.springframework.context.access.ContextSingletonBeanFactoryLocator./getInstance/("beanRefFactory.xml").useBeanFactory("beanRefFactory").getFactory();
>> >
>> >
>> >
>> >
>> > thx abe
>>
>>
>
>
> --
> Thanks & Regards,
> Ramkumar Ramalingam
>
>


-- 
Thanks & Regards,
Ramkumar Ramalingam

Re: sca namespace in spring

Posted by Simon Laws <si...@googlemail.com>.
On Mon, Sep 8, 2008 at 12:05 PM, Ramkumar R <ra...@gmail.com> wrote:

> Hi Abraham,
> I have few corrections to my previous comments. Please see my comments
> inline with my previous comments.
>
> On Thu, Sep 4, 2008 at 11:03 PM, Ramkumar R <ra...@gmail.com> wrote:
>
>> Hi Abraham,
>> Here I have few findings and suggestions for the spring namespace and
>> application Context issues.
>>
>> *For Spring Namespace Issue:*
>> As per my earlier comments, the custom XML tags like <sca:service>,
>> <sca:reference> and <sca:property> and the sca namespace will be supported
>> only when Tuscany creates the application context for you.
>> The reason is Tuscany not only defines the bean definition for these tags,
>> but also defines the logic. So I believe Tuscany does the right thing to
>> handle the sca namespace.
>>
>> A detailed article on how you would go about writing your own custom XML
>> bean definition parsers and integrating such parsers into the Spring IoC
>> container can be found here....
>>
>> http://static.springframework.org/spring/docs/2.5.x/reference/extensible-xml.html
>>
>> *Loading Application Context using ClassPathXmlApplicationContext:*
>> Defining a bean as shown below,
>>
>> <bean id="beanRefFactory"
>> class="org.springframework.context.support.ClassPathXmlApplicationContext">
>>     <constructor-arg><list>
>>         <value>Organization-spring-context.xml</value>
>>     </list></constructor-arg>
>> </bean>
>>
>> would also result in a namespace issue being thrown, as in this case an
>> application context is being created using ClassPathXmlApplicationContext
>> (which is not aware of the sca namespace handlers).
>>
>
> Using the ClassPathXmlApplicationContext as shown above will not throw
> namespace anymore. Identified that the namespace handler registration had
> some issue with Tuscany and its now been fixed as part of TUSCANY-2573.
> As part of this fix, now the SCA namespace handlers are made aware to the
> Spring Container as a whole, these namespaces will be ignored by the
> application context other than SCAApplicationContext.
>
> But still using ClassPathXmlApplicationContext does not provide the
> required results when used with Tuscany as this application context created
> ignores the <sca:service>, <sca:reference> and <sca:property> beans.
> Your comments to my below question would help to understand the scanario
> better.
>
>
>>
>> Here I have a question to ask, may be I am not good at spring, basically I
>> am trying to understand what is the special purpose for using the
>> ClassPathXmlApplicationContext to load the
>> Organization-spring-context.xml file, while by default Tuscany would
>> create the application context for this file when its been specified as
>> <implementation.spring location="Organization-spring-context.xml"/> in the
>> composite file?
>>
>> Your Comments on this would help us to come up with a better solution.
>>
>> *Accessing the Application Context:*
>> Trying to load an application context using the code shown below,
>>
>> ApplicationContext applicationContext = (ApplicationContext)
>> ContextSingletonBeanFactoryLocator.getInstance("beanRefFactory.xml").useBeanFactory("beanRefFactory").getFactory();
>>
>> to access the beans would also result in a namespace issue for the same
>> reason shown above.
>>
>> I believe there is a workaround to this problem, which demostrates how the
>> runtime instance of the application context can be accessed and also get
>> access to the beans as shown here.....
>>
>>
>> http://blog.jdevelop.eu/2008/07/06/access-the-spring-applicationcontext-from-everywhere-in-your-application/
>>
>> This solution returns the SCAApplicationContext instance which resolves
>> the namespace for you. Probably, you need to evaluate if this workaround
>> helps your scenario.
>>
>>
>> Please provide us with your feedback on the same and let me know if I am
>> missing something in this whole discussion.
>>
>
>
> --
> Thanks & Regards,
> Ramkumar Ramalingam
>

So what you are saying here Ram is that you can now read an SCA annotated
application context using the standard Spring APIs. The context file will be
read successfully but that the SCA annotations will be ignored. Sounds right
to me.

We do need to understand better Abraham's point about reading the
application context in order to set other bean properties. I'm assuming that
when he reads the application context from within the component
implementation bean he's expecting to get hold of the context that SCA read
originally so the fact that the context has SCA annotations in it is not so
relevant. The objective is just to go in and set properties on beans and not
re-start the appliation.

Regards

Simon

Re: sca namespace in spring

Posted by Ramkumar R <ra...@gmail.com>.
Hi Abraham,
I have few corrections to my previous comments. Please see my comments
inline with my previous comments.

On Thu, Sep 4, 2008 at 11:03 PM, Ramkumar R <ra...@gmail.com> wrote:

> Hi Abraham,
> Here I have few findings and suggestions for the spring namespace and
> application Context issues.
>
> *For Spring Namespace Issue:*
> As per my earlier comments, the custom XML tags like <sca:service>,
> <sca:reference> and <sca:property> and the sca namespace will be supported
> only when Tuscany creates the application context for you.
> The reason is Tuscany not only defines the bean definition for these tags,
> but also defines the logic. So I believe Tuscany does the right thing to
> handle the sca namespace.
>
> A detailed article on how you would go about writing your own custom XML
> bean definition parsers and integrating such parsers into the Spring IoC
> container can be found here....
>
> http://static.springframework.org/spring/docs/2.5.x/reference/extensible-xml.html
>
> *Loading Application Context using ClassPathXmlApplicationContext:*
> Defining a bean as shown below,
>
> <bean id="beanRefFactory"
> class="org.springframework.context.support.ClassPathXmlApplicationContext">
>     <constructor-arg><list>
>         <value>Organization-spring-context.xml</value>
>     </list></constructor-arg>
> </bean>
>
> would also result in a namespace issue being thrown, as in this case an
> application context is being created using ClassPathXmlApplicationContext
> (which is not aware of the sca namespace handlers).
>

Using the ClassPathXmlApplicationContext as shown above will not throw
namespace anymore. Identified that the namespace handler registration had
some issue with Tuscany and its now been fixed as part of TUSCANY-2573.
As part of this fix, now the SCA namespace handlers are made aware to the
Spring Container as a whole, these namespaces will be ignored by the
application context other than SCAApplicationContext.

But still using ClassPathXmlApplicationContext does not provide the required
results when used with Tuscany as this application context created ignores
the <sca:service>, <sca:reference> and <sca:property> beans.
Your comments to my below question would help to understand the scanario
better.


>
> Here I have a question to ask, may be I am not good at spring, basically I
> am trying to understand what is the special purpose for using the
> ClassPathXmlApplicationContext to load the
> Organization-spring-context.xml file, while by default Tuscany would create
> the application context for this file when its been specified as
> <implementation.spring location="Organization-spring-context.xml"/> in the
> composite file?
>
> Your Comments on this would help us to come up with a better solution.
>
> *Accessing the Application Context:*
> Trying to load an application context using the code shown below,
>
> ApplicationContext applicationContext = (ApplicationContext)
> ContextSingletonBeanFactoryLocator.getInstance("beanRefFactory.xml").useBeanFactory("beanRefFactory").getFactory();
>
> to access the beans would also result in a namespace issue for the same
> reason shown above.
>
> I believe there is a workaround to this problem, which demostrates how the
> runtime instance of the application context can be accessed and also get
> access to the beans as shown here.....
>
>
> http://blog.jdevelop.eu/2008/07/06/access-the-spring-applicationcontext-from-everywhere-in-your-application/
>
> This solution returns the SCAApplicationContext instance which resolves the
> namespace for you. Probably, you need to evaluate if this workaround helps
> your scenario.
>
>
> Please provide us with your feedback on the same and let me know if I am
> missing something in this whole discussion.
>


-- 
Thanks & Regards,
Ramkumar Ramalingam