cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tong, Gary \(FID\)" <Gary.T...@morganstanley.com>
Subject Issues with @Context injected fields in ExceptionMapper
Date Thu, 29 Jan 2009 14:19:55 GMT
Hello,

There seem to be issues with @Context-injected fields in ExceptionMapper, where it throws
an NPE with this:

public class MyMapper implements ExceptionMapper<Exception> {
  @Context
  private HttpServletRequest request;

  public Response toResponse(Exception ex) {
    System.out.println(request.getRequestURI()); // NPE happens here.
    return Response.ok().build();
  }
}

The request is a ThreadLocalHttpServletRequest, but there is nothing in the thread local.

As far as I can tell, the flow is:

JAXRSInvoker.invoke: InjectionUtils.injectContextFields(...) injects from exchange.getInMessage()
into various threadlocals.
JAXRSInvoker.invoke: result = invoke(...) throws a fault because the service throws an exception
JAXRSInvoker.invoke: JAXRSUtils.convertFaultToResponse(ex.getCause()) handles the fault
JAXRSUtils.convertFaultToResponse: ProviderFactory.getInstance().createExceptionMapper(ex.getClass(),
new MessageImpl()) sends a blank MessageImpl into the exception mapper init method.
ProviderFactory.createExceptionMapper: InjectionUtils.injectContextFields(...) injects from
the blank Message object into the various threadlocals on the ExceptionMapper
ExceptionMapper.toResponse: Retrieves the threadlocal and gets an NPE.

One way to fix this would be to add a Message argument to JAXRSUtils.convertFaultToResponse

Cheers,
Gary
--------------------------------------------------------

This is not an offer (or solicitation of an offer) to buy/sell the securities/instruments
mentioned or an official confirmation.  Morgan Stanley may deal as principal in or own or
act as market maker for securities/instruments mentioned or may advise the issuers.  This
is not research and is not from MS Research but it may refer to a research analyst/research
report.  Unless indicated, these views are the author's and may differ from those of Morgan
Stanley research or others in the Firm.  We do not represent this is accurate or complete
and we may not update this.  Past performance is not indicative of future returns.  For additional
information, research reports and important disclosures, contact me or see https://secure.ms.com/servlet/cls.
 You should not use e-mail to request, authorize or effect the purchase or sale of any security
or instrument, to send transfer instructions, or to effect any other transactions.  We cannot
guarantee that any such requests received via e-mail will be processed in a timely manner.
 This communication is solely for the addressee(s) and may contain confidential information.
 We do not waive confidentiality by mistransmission.  Contact me if you do not wish to receive
these communications.  In the UK, this communication is directed in the UK to those persons
who are professional and eligible counterparties (as defined in the UK Financial Services
Authority's rules).

Mime
View raw message