You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Sagara Gunathunga <sa...@gmail.com> on 2009/04/02 10:37:26 UTC

Re: Axis2 service and spring problem, can't find Spring's ApplicationContext.

Hi Azazel,

>     <parameter name="ServiceObjectSupplier">
> org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier</parameter>

You are loading SpringAppContext through ContextLoaderListener , so
you should use SpringServletContextObjectSupplier instead of
SpringAppContextAwareObjectSupplier.

<parameter name="ServiceObjectSupplier"
locked="false">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier</parameter>


Thanks ,

-- 
Sagara Gunathunga

Blog - http://ssagara.blogspot.com
Web - http://sagaras.awardspace.com/

RE: Axis2 service and spring problem, can't find Spring's ApplicationContext.

Posted by Azazel Se <az...@hotmail.com>.
Hi.

 

Thanks alot!

When I created my own ApplicationContextHolder everything worked.

Thanks for all your help, much appreciated after this has taken me alot more time then it probably should have.. :)

 

 

-Az.

 

 

> Apart from this code, is spring and axis2 running together in your web
> service? I thought you said it was. I think I know what your are
> asking for, but without knowing what "TavernaBaseProfile" is doing,
> I'd be concerned that it creates two separate Spring worlds in your
> app - you probably don't want that. Anyways, with that caveat, if you
> just need "ApplicationContext" to pass into "TavernaBaseProfile" , I
> would do the following:
> 
> Keep axis2 and spring as is, since its working. The idea behind the
> axis2 ApplicationContextHolder is a known way to get an
> ApplicationContext, and can be used outside axis2. So I think you
> should create your own. Its easy, and it seems far less confusing, at
> least to me, to use your own ApplicationContextHolder outside of axis2
> when using SpringServletContextObjectSupplier. So you'd need this xml
> in your Spring config:
> 
> <!-- Use this trick to get access to Spring beans in junit and other places
> that are not spring aware
> -->
> <bean id="applicationContext"
> class="mypackage.spring.ApplicationContextHolder" />
> 
> 
> And this class in your app:
> 
> package mypackage.spring;
> 
> import org.springframework.beans.BeansException;
> import org.springframework.context.ApplicationContext;
> import org.springframework.context.ApplicationContextAware;
> 
> /** Implementation of a Spring interface who is configured in Spring's
> * applicationContext.xml or some other Spring type of way. This class
> * and the spring bean needed to wire it could be used as an alternative
> * to getting the ApplicationContext from the ServletContext. It also can
> * be used to get access to spring beans in places like junit that are not
> * spring aware.
> */
> public class ApplicationContextHolder implements ApplicationContextAware {
> 
> private static ApplicationContext appCtx;
> 
> public ApplicationContextHolder() {}
> 
> /** Spring supplied interface method for injecting app context. */
> public void setApplicationContext(ApplicationContext applicationContext)
> throws BeansException {
> appCtx = applicationContext;
> }
> 
> /** Access to spring wired beans. */
> public static ApplicationContext getContext() {
> return appCtx;
> }
> 
> }
> 
> Then instead of:
> 
> ApplicationContext context = new
> RavenAwareClassPathXmlApplicationContext("context.xml");
> 
> Do this:
> 
> ApplicationContext ctx = ApplicationContextHolder.getContext();
> TavernaBaseProfile profile = new TavernaBaseProfile(context);
> 
> Good luck,
> Robert


_________________________________________________________________
Ditt liv. Dine ting. Alt på ett sted med Windows Live™.
http://windowslive.no

Re: Axis2 service and spring problem, can't find Spring's ApplicationContext.

Posted by robert lazarski <ro...@gmail.com>.
On Thu, Apr 2, 2009 at 4:05 PM, Azazel Se <az...@hotmail.com> wrote:
>> Date: Thu, 2 Apr 2009 15:01:48 -0300
>> Subject: Re: Axis2 service and spring problem, can't find Spring's
>> ApplicationContext.
>> From: robertlazarski@gmail.com
>> To: axis-user@ws.apache.org
>>
>> On Thu, Apr 2, 2009 at 1:48 PM, Azazel Se <az...@hotmail.com> wrote:
>> >> From: robertlazarski@gmail.com
>> >>
>> >> "ApplicationContextHolder.getContext()" isn't needed when using
>> >> SpringServletContextObjectSupplier. If spring and axis2 are working
>> >> together, you are done. You have to configure Spring to use
>> >> ApplicationContextHolder, otherwise it will return null values.
>> >>
>> >> - R
>> >
>> >> From: sagara.gunathunga@gmail.com
>> >> To: axis-user@ws.apache.org
>> >
>> >> Here, how you try to use context .and can you provide error trace you
>> >> got ....? i cant get any clue with supplied details .
>> >> > .   ApplicationContext ctx = ApplicationContextHolder.getContext();
>> >> I don't think you need to have this line to access SpringContext
>> >> explicitly , because "MyServ " is already a Spring manged bean. if you
>> >> want to access any other bean inside "MyServ " use Spring injection
>> >> instead of access through ApplicationContextHolder.
>> >
>> >
>> >
>> >
>> > Hi, thanks for the replies.
>> >
>> > I have an application which I didn't make which uses spring, it has an
>> > API
>> > which hides the details and preferably I don't add any more stuff to it.
>> > The
>> > goal is to just use a few of the methods and get returns as normal and
>> > not
>> > interact directly with spring. I have never used Spring before so my
>> > knowledge about the innerworkings is small but if I get the API to work
>> > I
>> > shouldn't need to either. The springappl needs the context at
>> > initiating. I
>> > have tested it in a jsp file and it works, but I want to move it to a
>> > web
>> > service. In the jsp file I had the same context stuff added to the
>> > web.xml
>> > and this is in the jsp file:
>> >
>> > MyApplWithSpring  ap = new
>> >
>> > MyApplWithSpring(WebApplicationContextUtils.getWebApplicationContext(getServletContext()));
>> >
>> > This worked and I could use some of its methods afterwards.
>> > So I thought it would work in the web service as well if I used
>> > ApplicationContextHolder.getContext() and used new
>> > MyApplWithSpring(ApplicationContextHolder.getContext()). If possible how
>> > do
>> > I configure spring to use the ApplicationContextHolder so that it isn't
>> > null? Or is there any other(/better) way I can do this?
>> >
>> > -Az.
>> >
>>
>> So the "springappl" you didn't write requires an ApplicationContext
>> reference, even though you are successfully using
>> SpringServletContextObjectSupplier that doesn't really require an
>> ApplicationContext reference? If so, I'll show you how to do it.
>>
>> - R
>
>
>
> At the bottom are the first few lines of the code that works in eclipse. The
> problems arise when wanting to deploy to axis2 and tomcat. The application I
> am making a small wrapper for is very big and complex and the context.xml
> imports several other xml files. The goal of the web service is to receive a
> string from the client, use the application to do some stuff with a file and
> the string as input, then return the results to the client. The application
> uses spring, hibernate etc.
>
> -Az.
>
>
> //Create Platform.
> ApplicationContext context = new
> RavenAwareClassPathXmlApplicationContext("context.xml");
> TavernaBaseProfile profile = new TavernaBaseProfile(context);
> //Get workflow parser, load workflow.
> WorkflowParser parser = profile.getWorkflowParser();
> URL workflowURL = new URL("http://foo.com/workflow.xml");
> Dataflow workflow = parser.createDataflow(workflowURL);
>

Apart from this code, is spring and axis2 running together in your web
service? I thought you said it was. I think I know what your are
asking for, but without knowing what "TavernaBaseProfile" is doing,
I'd be concerned that it creates two separate Spring worlds in your
app - you probably don't want that. Anyways, with that caveat, if you
just need "ApplicationContext" to pass into "TavernaBaseProfile" , I
would do the following:

Keep axis2 and spring as is, since its working. The idea behind the
axis2 ApplicationContextHolder is a known way to get an
ApplicationContext, and can be used outside axis2. So I think you
should create your own. Its easy, and it seems far less confusing, at
least to me, to use your own ApplicationContextHolder outside of axis2
when using SpringServletContextObjectSupplier. So you'd need this xml
in your Spring config:

     <!-- Use this trick to get access to Spring beans in junit and other places
         that are not spring aware
     -->
    <bean id="applicationContext"
      class="mypackage.spring.ApplicationContextHolder" />


And this class in your app:

package mypackage.spring;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/** Implementation of a Spring interface who is configured in Spring's
 *  applicationContext.xml or some other Spring type of way. This class
 *  and the spring bean needed to wire it could be used as an alternative
 *  to getting the ApplicationContext from the ServletContext. It also can
 *  be used to get access to spring beans in places like junit that are not
 *  spring aware.
 */
public class ApplicationContextHolder implements ApplicationContextAware {

    private static ApplicationContext appCtx;

    public ApplicationContextHolder() {}

    /** Spring supplied interface method for injecting app context. */
    public void setApplicationContext(ApplicationContext applicationContext)
        throws BeansException {
        appCtx = applicationContext;
    }

    /** Access to spring wired beans. */
    public static ApplicationContext getContext() {
        return appCtx;
    }

}

Then instead of:

ApplicationContext context = new
RavenAwareClassPathXmlApplicationContext("context.xml");

Do this:

ApplicationContext ctx = ApplicationContextHolder.getContext();
TavernaBaseProfile profile = new TavernaBaseProfile(context);

Good luck,
Robert

RE: Axis2 service and spring problem, can't find Spring's ApplicationContext.

Posted by Azazel Se <az...@hotmail.com>.
> Date: Thu, 2 Apr 2009 15:01:48 -0300
> Subject: Re: Axis2 service and spring problem, can't find Spring's ApplicationContext.
> From: robertlazarski@gmail.com
> To: axis-user@ws.apache.org
> 
> On Thu, Apr 2, 2009 at 1:48 PM, Azazel Se <az...@hotmail.com> wrote:
> >> From: robertlazarski@gmail.com
> >>
> >> "ApplicationContextHolder.getContext()" isn't needed when using
> >> SpringServletContextObjectSupplier. If spring and axis2 are working
> >> together, you are done. You have to configure Spring to use
> >> ApplicationContextHolder, otherwise it will return null values.
> >>
> >> - R
> >
> >> From: sagara.gunathunga@gmail.com
> >> To: axis-user@ws.apache.org
> >
> >> Here, how you try to use context .and can you provide error trace you
> >> got ....? i cant get any clue with supplied details .
> >> > .   ApplicationContext ctx = ApplicationContextHolder.getContext();
> >> I don't think you need to have this line to access SpringContext
> >> explicitly , because "MyServ " is already a Spring manged bean. if you
> >> want to access any other bean inside "MyServ " use Spring injection
> >> instead of access through ApplicationContextHolder.
> >
> >
> >
> >
> > Hi, thanks for the replies.
> >
> > I have an application which I didn't make which uses spring, it has an API
> > which hides the details and preferably I don't add any more stuff to it. The
> > goal is to just use a few of the methods and get returns as normal and not
> > interact directly with spring. I have never used Spring before so my
> > knowledge about the innerworkings is small but if I get the API to work I
> > shouldn't need to either. The springappl needs the context at initiating. I
> > have tested it in a jsp file and it works, but I want to move it to a web
> > service. In the jsp file I had the same context stuff added to the web.xml
> > and this is in the jsp file:
> >
> > MyApplWithSpring  ap = new
> > MyApplWithSpring(WebApplicationContextUtils.getWebApplicationContext(getServletContext()));
> >
> > This worked and I could use some of its methods afterwards.
> > So I thought it would work in the web service as well if I used
> > ApplicationContextHolder.getContext() and used new
> > MyApplWithSpring(ApplicationContextHolder.getContext()). If possible how do
> > I configure spring to use the ApplicationContextHolder so that it isn't
> > null? Or is there any other(/better) way I can do this?
> >
> > -Az.
> >
> 
> So the "springappl" you didn't write requires an ApplicationContext
> reference, even though you are successfully using
> SpringServletContextObjectSupplier that doesn't really require an
> ApplicationContext reference? If so, I'll show you how to do it.
> 
> - R


 

 

At the bottom are the first few lines of the code that works in eclipse. The problems arise when wanting to deploy to axis2 and tomcat. The application I am making a small wrapper for is very big and complex and the context.xml imports several other xml files. The goal of the web service is to receive a string from the client, use the application to do some stuff with a file and the string as input, then return the results to the client. The application uses spring, hibernate etc. 

 

-Az.

 

 

//Create Platform.
ApplicationContext context = new RavenAwareClassPathXmlApplicationContext("context.xml");
TavernaBaseProfile profile = new TavernaBaseProfile(context);

//Get workflow parser, load workflow.
WorkflowParser parser = profile.getWorkflowParser();
URL workflowURL = new URL("http://foo.com/workflow.xml");
Dataflow workflow = parser.createDataflow(workflowURL);


_________________________________________________________________
Windows Live™ Mail. Flere kontoer på ett sted.
http://download.live.com/wlmail

Re: Axis2 service and spring problem, can't find Spring's ApplicationContext.

Posted by robert lazarski <ro...@gmail.com>.
On Thu, Apr 2, 2009 at 1:48 PM, Azazel Se <az...@hotmail.com> wrote:
>> From: robertlazarski@gmail.com
>>
>> "ApplicationContextHolder.getContext()" isn't needed when using
>> SpringServletContextObjectSupplier. If spring and axis2 are working
>> together, you are done. You have to configure Spring to use
>> ApplicationContextHolder, otherwise it will return null values.
>>
>> - R
>
>> From: sagara.gunathunga@gmail.com
>> To: axis-user@ws.apache.org
>
>> Here, how you try to use context .and can you provide error trace you
>> got ....? i cant get any clue with supplied details .
>> > .   ApplicationContext ctx = ApplicationContextHolder.getContext();
>> I don't think you need to have this line to access SpringContext
>> explicitly , because "MyServ " is already a Spring manged bean. if you
>> want to access any other bean inside "MyServ " use Spring injection
>> instead of access through ApplicationContextHolder.
>
>
>
>
> Hi, thanks for the replies.
>
> I have an application which I didn't make which uses spring, it has an API
> which hides the details and preferably I don't add any more stuff to it. The
> goal is to just use a few of the methods and get returns as normal and not
> interact directly with spring. I have never used Spring before so my
> knowledge about the innerworkings is small but if I get the API to work I
> shouldn't need to either. The springappl needs the context at initiating. I
> have tested it in a jsp file and it works, but I want to move it to a web
> service. In the jsp file I had the same context stuff added to the web.xml
> and this is in the jsp file:
>
> MyApplWithSpring  ap = new
> MyApplWithSpring(WebApplicationContextUtils.getWebApplicationContext(getServletContext()));
>
> This worked and I could use some of its methods afterwards.
> So I thought it would work in the web service as well if I used
> ApplicationContextHolder.getContext() and used new
> MyApplWithSpring(ApplicationContextHolder.getContext()). If possible how do
> I configure spring to use the ApplicationContextHolder so that it isn't
> null? Or is there any other(/better) way I can do this?
>
> -Az.
>

So the "springappl" you didn't write requires an ApplicationContext
reference, even though you are successfully using
SpringServletContextObjectSupplier that doesn't really require an
ApplicationContext reference? If so, I'll show you how to do it.

- R

Re: Axis2 service and spring problem, can't find Spring's ApplicationContext.

Posted by Sagara Gunathunga <sa...@gmail.com>.
As mentioned in previous mails "ApplicationContextHolder.getContext()"
is not required to  handle this , i think reading some Spring docs
will helpful to you because this is a problem with the the way you
retrieve beans from spring context.

First create your service as a POJO service and configure it within
SpringContext , then as you already did ,expose this service bean as a
web service using Axis2 "SpringServletContextObjectSupplier"  in this
case you don't need to  modify your java codes to expose your spring
bean as a web service.


Thanks ,

On Thu, Apr 2, 2009 at 10:18 PM, Azazel Se <az...@hotmail.com> wrote:
>> From: robertlazarski@gmail.com
>>
>> "ApplicationContextHolder.getContext()" isn't needed when using
>> SpringServletContextObjectSupplier. If spring and axis2 are working
>> together, you are done. You have to configure Spring to use
>> ApplicationContextHolder, otherwise it will return null values.
>>
>> - R
>
>> From: sagara.gunathunga@gmail.com
>> To: axis-user@ws.apache.org
>
>> Here, how you try to use context .and can you provide error trace you
>> got ....? i cant get any clue with supplied details .
>> > .   ApplicationContext ctx = ApplicationContextHolder.getContext();
>> I don't think you need to have this line to access SpringContext
>> explicitly , because "MyServ " is already a Spring manged bean. if you
>> want to access any other bean inside "MyServ " use Spring injection
>> instead of access through ApplicationContextHolder.
>
>
>
>
> Hi, thanks for the replies.
>
> I have an application which I didn't make which uses spring, it has an API
> which hides the details and preferably I don't add any more stuff to it. The
> goal is to just use a few of the methods and get returns as normal and not
> interact directly with spring. I have never used Spring before so my
> knowledge about the innerworkings is small but if I get the API to work I
> shouldn't need to either. The springappl needs the context at initiating. I
> have tested it in a jsp file and it works, but I want to move it to a web
> service. In the jsp file I had the same context stuff added to the web.xml
> and this is in the jsp file:
>
> MyApplWithSpring  ap = new
> MyApplWithSpring(WebApplicationContextUtils.getWebApplicationContext(getServletContext()));
>
> This worked and I could use some of its methods afterwards.
> So I thought it would work in the web service as well if I used
> ApplicationContextHolder.getContext() and used new
> MyApplWithSpring(ApplicationContextHolder.getContext()). If possible how do
> I configure spring to use the ApplicationContextHolder so that it isn't
> null? Or is there any other(/better) way I can do this?
>
> -Az.
>
>
>
>
> New java class, only added the fourth line and this gives an error since con
> is null:
> -----------------------
> public class MyServ {
>  public String serExe() {
>   ApplicationContext con = ApplicationContextHolder.getContext();
>   MyApplWithSpring ap = new MyApplWithSpring(con);
>   return "testWithSpringAppl";
>  }
> }
>
>
> Exception in eclipse when running client:
> ---------------------------------------
> Exception in thread "main" org.apache.axis2.AxisFault: Cannot attach a
> profile to a null context
>  at
> org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:512)
>  at
> org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:370)
>  at
> org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
>  at
> org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
>  at
> org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
>  at xyz.MyServStub.serExe(MyServStub.java:183)
>  at xyz.MyServClient.main(MyServClient.java:17)
>
>
> Output of Exception at runtime in the tomcat server:
> --------------------------------------------------
> ERROR - RPCMessageReceiver.invokeBusinessLogic(157) | Cannot attach a
> profile to
>  a null context
> java.lang.reflect.InvocationTargetException
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
> java:39)
>         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
> sorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:597)
>         at
> org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.jav
> a:165)
>         at
> org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic
> (RPCMessageReceiver.java:102)
>         at
> org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusines
> sLogic(AbstractInOutMessageReceiver.java:40)
>         at
> org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMe
> ssageReceiver.java:100)
>         at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:176)
>         at
> org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostReq
> uest(HTTPTransportUtils.java:275)
>         at
> org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:1
> 33)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>         at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
> icationFilterChain.java:290)
>         at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
> ilterChain.java:206)
>         at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
> alve.java:233)
>         at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
> alve.java:191)
>         at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
> ava:128)
>         at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
> ava:102)
>         at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
> ve.java:109)
>         at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
> a:286)
>         at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
> :845)
>         at
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
> ss(Http11Protocol.java:583)
>         at
> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
> 7)
>         at java.lang.Thread.run(Thread.java:619)
> Caused by:
> net.sf.taverna.t2.platform.spring.profile.ContextProfileException: Ca
> nnot attach a profile to a null context
>         at
> net.sf.taverna.t2.platform.spring.profile.AbstractContextProfile.<ini
> t>(AbstractContextProfile.java:66)
>         at
> net.sf.taverna.t2.platform.taverna.TavernaBaseProfile.<init>(TavernaB
> aseProfile.java:48)
>         at xyz.MyServ.serExe(MyServ.java:11)
>         ... 25 more
> ERROR - AxisEngine.receive(212) | Cannot attach a profile to a null context
> org.apache.axis2.AxisFault: Cannot attach a profile to a null context
>         at
> org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic
> (RPCMessageReceiver.java:158)
>
> ________________________________
> Få gratisprogrammene fra Windows Live™. Last ned her.



-- 
Sagara Gunathunga

Blog - http://ssagara.blogspot.com
Web - http://sagaras.awardspace.com/

RE: Axis2 service and spring problem, can't find Spring's ApplicationContext.

Posted by Azazel Se <az...@hotmail.com>.
> From: robertlazarski@gmail.com
> 
> "ApplicationContextHolder.getContext()" isn't needed when using
> SpringServletContextObjectSupplier. If spring and axis2 are working
> together, you are done. You have to configure Spring to use
> ApplicationContextHolder, otherwise it will return null values.
> 
> - R


> From: sagara.gunathunga@gmail.com
> To: axis-user@ws.apache.org


> Here, how you try to use context .and can you provide error trace you
> got ....? i cant get any clue with supplied details .
> > .   ApplicationContext ctx = ApplicationContextHolder.getContext();
> I don't think you need to have this line to access SpringContext
> explicitly , because "MyServ " is already a Spring manged bean. if you
> want to access any other bean inside "MyServ " use Spring injection
> instead of access through ApplicationContextHolder.

 

 

 

 

Hi, thanks for the replies.

 

I have an application which I didn't make which uses spring, it has an API which hides the details and preferably I don't add any more stuff to it. The goal is to just use a few of the methods and get returns as normal and not interact directly with spring. I have never used Spring before so my knowledge about the innerworkings is small but if I get the API to work I shouldn't need to either. The springappl needs the context at initiating. I have tested it in a jsp file and it works, but I want to move it to a web service. In the jsp file I had the same context stuff added to the web.xml and this is in the jsp file:

 

MyApplWithSpring  ap = new MyApplWithSpring(WebApplicationContextUtils.getWebApplicationContext(getServletContext()));

 

This worked and I could use some of its methods afterwards.

So I thought it would work in the web service as well if I used ApplicationContextHolder.getContext() and used new MyApplWithSpring(ApplicationContextHolder.getContext()). If possible how do I configure spring to use the ApplicationContextHolder so that it isn't null? Or is there any other(/better) way I can do this?

 

-Az.

 

 

 

 

New java class, only added the fourth line and this gives an error since con is null:

-----------------------

public class MyServ {
 public String serExe() {
  ApplicationContext con = ApplicationContextHolder.getContext();
  MyApplWithSpring ap = new MyApplWithSpring(con);
  return "testWithSpringAppl";
 }
}

 

 

Exception in eclipse when running client:

---------------------------------------

Exception in thread "main" org.apache.axis2.AxisFault: Cannot attach a profile to a null context
 at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:512)
 at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:370)
 at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
 at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
 at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
 at xyz.MyServStub.serExe(MyServStub.java:183)
 at xyz.MyServClient.main(MyServClient.java:17)

 

 

Output of Exception at runtime in the tomcat server:

--------------------------------------------------

ERROR - RPCMessageReceiver.invokeBusinessLogic(157) | Cannot attach a profile to
 a null context
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.jav
a:165)
        at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic
(RPCMessageReceiver.java:102)
        at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusines
sLogic(AbstractInOutMessageReceiver.java:40)
        at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMe
ssageReceiver.java:100)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:176)
        at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostReq
uest(HTTPTransportUtils.java:275)
        at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:1
33)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:286)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:845)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
7)
        at java.lang.Thread.run(Thread.java:619)
Caused by: net.sf.taverna.t2.platform.spring.profile.ContextProfileException: Ca
nnot attach a profile to a null context
        at net.sf.taverna.t2.platform.spring.profile.AbstractContextProfile.<ini
t>(AbstractContextProfile.java:66)
        at net.sf.taverna.t2.platform.taverna.TavernaBaseProfile.<init>(TavernaB
aseProfile.java:48)
        at xyz.MyServ.serExe(MyServ.java:11)
        ... 25 more
ERROR - AxisEngine.receive(212) | Cannot attach a profile to a null context
org.apache.axis2.AxisFault: Cannot attach a profile to a null context
        at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic
(RPCMessageReceiver.java:158)

_________________________________________________________________
Ditt liv. Dine ting. Alt på ett sted med Windows Live™.
http://windowslive.no

Re: Axis2 service and spring problem, can't find Spring's ApplicationContext.

Posted by robert lazarski <ro...@gmail.com>.
On Thu, Apr 2, 2009 at 12:01 PM, Azazel Se <az...@hotmail.com> wrote:
> Thanks Sagara.
> I actually tried that one first but I didn't know which of the suppliers
> was the correct one so I tried both. In my mail I pasted the exception
> from SpringAppContextAwareObjectSupplier twice by accident. When
> using SpringServletContextObjectSupplier I got a "No bean named 'MyServ'
> exception, but when I added:
>
> <bean id="MyServ"
>         class="xyz.MyServ">
>  </bean>
>
> to the context.xml file the error went away. So now it deploys and runs
> without errors, I also got the test string back in my ws-client. But later
> when I tried using the context I get
> from ApplicationContextHolder.getContext() I found that it has value null???
> Anyone know why?
>

"ApplicationContextHolder.getContext()" isn't needed when using
SpringServletContextObjectSupplier. If spring and axis2 are working
together, you are done. You have to configure Spring to use
ApplicationContextHolder, otherwise it will return null values.

- R

Re: Axis2 service and spring problem, can't find Spring's ApplicationContext.

Posted by Sagara Gunathunga <sa...@gmail.com>.
Hi Azazel ,

> But later
> when I tried using the context I get
> from ApplicationContextHolder.getContext() I found that it has value null???
> Anyone know why?

Here, how you try to use context .and can you provide error trace you
got  ....? i cant get any clue with supplied details .



> .   ApplicationContext ctx = ApplicationContextHolder.getContext();

I don't think you need to have this  line to access SpringContext
explicitly , because "MyServ " is already a Spring manged bean. if you
want to access any other bean inside "MyServ " use Spring injection
instead of access through ApplicationContextHolder.

as a example if you want to access "dbService" bean , just add setter
and getter methods to"MyServ " class and use appContext.xml file to
inject that "dbService"

<bean id="MyServ"
        class="xyz.MyServ">
        <property name="dbService"  ref="dbService"/>

 </bean>

I think you already familiar with this approach :)

with Axis2 you can use Spring programing approach without any
modification. I think this will resolve your problem too.


Thanks ,


-- 
Sagara Gunathunga

Blog - http://ssagara.blogspot.com
Web - http://sagaras.awardspace.com/

RE: Axis2 service and spring problem, can't find Spring's ApplicationContext.

Posted by Azazel Se <az...@hotmail.com>.
Thanks Sagara.

I actually tried that one first but I didn't know which of the suppliers was the correct one so I tried both. In my mail I pasted the exception from SpringAppContextAwareObjectSupplier twice by accident. When using SpringServletContextObjectSupplier I got a "No bean named 'MyServ' exception, but when I added:

 

<bean id="MyServ"
        class="xyz.MyServ">
 </bean>

 

to the context.xml file the error went away. So now it deploys and runs without errors, I also got the test string back in my ws-client. But later when I tried using the context I get from ApplicationContextHolder.getContext() I found that it has value null??? Anyone know why?


 

-Az.

 

 

(I have added the information about my files written in my first mail since this might be needed to see the new error.)

 

MyServ.java

-------------

. import org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder;
. import org.springframework.context.ApplicationContext;

. public class MyServ {
.  public String serExe() {
.   ApplicationContext ctx = ApplicationContextHolder.getContext();
.   return "test";
 }
}

 

 

The services.xml:
-----------------
<serviceGroup>
<service name="MyServ" >
 <description>
  blabla
 </description>
    <parameter name="ServiceObjectSupplier"> org.apache.axis2.extensions.spring.receivers.

SpringServletContextObjectSupplier</parameter>
   <parameter name="SpringBeanName">MyServ</parameter>
   <parameter name="ServiceClass" locked="false">xyz.MyServ</parameter>
        <operation name="serExe">
             <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
  </operation>
</service>
</serviceGroup>
 
 

Added to rest of the properties etc in the context.xml file:

-----------------

<bean id="T2Wrapper"

class="xyz.T2Wrapper">



</bean>

 

 


The web.xml:
------------
<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
 
<web-app>
 <display-name>Blabla</display-name>
 <servlet>
  <servlet-name>AxisServlet</servlet-name>
  <display-name>Apache-Axis Servlet</display-name>
  <servlet-class>
   org.apache.axis2.transport.http.AxisServlet
  </servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
 </servlet-mapping>
 
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/context.xml</param-value>
 </context-param>
 <context-param>
  <param-name>contextClass</param-name>
  <param-value>
   (.... path of a specific kind of WebApplicationContext class which the SpringAppl expects...)
  </param-value>
 </context-param>
 <listener>
  <listener-class>
   org.springframework.web.context.ContextLoaderListener
  </listener-class>
 </listener>
</web-app>

_________________________________________________________________
Få nye Windows Live™ Messenger.
http://download.live.com/messenger