You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Shamik Bandopadhyay <sh...@gmail.com> on 2011/06/21 01:31:39 UTC

Spring ApplicationContextAware issue

Hi,

  I'm using spring ApplicationContextAware to set the Application context to
my web services endpoint. There's no exception when In install ans start the
bundle in service, but when I'm trying to hit the service, the application
context is showing up as "null". Here's the app context entry :

 <jaxws:endpoint id="taxonomyquery"
  implementor="com.autodesk.taxonomy.soap.query.service.TaxonomySoapQueryServiceImpl"
  address="/taxonomyquery" />

And here's my sample code

 @WebService(endpointInterface =
"com.autodesk.taxonomy.soap.query.service.ITaxonomySoapQueryService")
public class TaxonomySoapQueryServiceImpl implements
ITaxonomySoapQueryService, ApplicationContextAware {
 private static ApplicationContext ctx = null;
 private static Logger LOGGER =
LoggerFactory.getLogger(TaxonomySoapQueryServiceImpl.class);

 @Override
 public void setApplicationContext(ApplicationContext ctx) throws
BeansException {
  this.ctx = ctx;
 }



 public ProductReleaseResponse queryProductRelease(ProductReleaseRequest
req) {
  ProductReleaseResponse response = new ProductReleaseResponse ();
  try {
   req.status = RequestHelper.transformStatus(req.status);
  * ITaxonomySoapPluginQuery tp = (ITaxonomySoapPluginQuery)
ctx.getBean("taxonomyQueryPlugin");
*   response = tp.queryProductRelease(req);
  }
  catch (Exception ex) {
   LOGGER.error(ex.getMessage());
   response.status = "ERROR";
  }
  return response;
 }

The bolded portion is throwing a null pointer exception since ctx has not
been set.

Can someone share their experience on this issue ?

- Thanks

Re: Spring ApplicationContextAware issue

Posted by Shamik Bandopadhyay <sh...@gmail.com>.
My bad, found the issue. I used it incorrectlt in app context. Should be :

<jaxws:endpoint id="taxonomyquery"
implementor="#taxonomyqueryImpl"
  address="/taxonomyquery" />

<bean id="taxonomyqueryImpl"
class="com.test.taxonomy.soap.query.service.TaxonomySoapQueryServiceImpl"/>


On Mon, Jun 20, 2011 at 4:31 PM, Shamik Bandopadhyay <sh...@gmail.com>wrote:

> Hi,
>
>   I'm using spring ApplicationContextAware to set the Application context
> to my web services endpoint. There's no exception when In install ans start
> the bundle in service, but when I'm trying to hit the service, the
> application context is showing up as "null". Here's the app context entry :
>
>  <jaxws:endpoint id="taxonomyquery"
>
>   implementor="com.autodesk.taxonomy.soap.query.service.TaxonomySoapQueryServiceImpl"
>   address="/taxonomyquery" />
>
> And here's my sample code
>
>  @WebService(endpointInterface =
> "com.autodesk.taxonomy.soap.query.service.ITaxonomySoapQueryService")
> public class TaxonomySoapQueryServiceImpl implements
> ITaxonomySoapQueryService, ApplicationContextAware {
>  private static ApplicationContext ctx = null;
>  private static Logger LOGGER =
> LoggerFactory.getLogger(TaxonomySoapQueryServiceImpl.class);
>
>  @Override
>  public void setApplicationContext(ApplicationContext ctx) throws
> BeansException {
>   this.ctx = ctx;
>  }
>
>
>
>  public ProductReleaseResponse queryProductRelease(ProductReleaseRequest
> req) {
>   ProductReleaseResponse response = new ProductReleaseResponse ();
>   try {
>    req.status = RequestHelper.transformStatus(req.status);
>   * ITaxonomySoapPluginQuery tp = (ITaxonomySoapPluginQuery)
> ctx.getBean("taxonomyQueryPlugin");
> *   response = tp.queryProductRelease(req);
>   }
>   catch (Exception ex) {
>    LOGGER.error(ex.getMessage());
>    response.status = "ERROR";
>   }
>   return response;
>  }
>
> The bolded portion is throwing a null pointer exception since ctx has not
> been set.
>
> Can someone share their experience on this issue ?
>
> - Thanks
>
>