Return-Path: Delivered-To: apmail-cxf-dev-archive@www.apache.org Received: (qmail 11564 invoked from network); 29 Jan 2009 14:20:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 29 Jan 2009 14:20:43 -0000 Received: (qmail 31901 invoked by uid 500); 29 Jan 2009 14:20:43 -0000 Delivered-To: apmail-cxf-dev-archive@cxf.apache.org Received: (qmail 31662 invoked by uid 500); 29 Jan 2009 14:20:42 -0000 Mailing-List: contact dev-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list dev@cxf.apache.org Received: (qmail 31645 invoked by uid 99); 29 Jan 2009 14:20:41 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Jan 2009 06:20:41 -0800 X-ASF-Spam-Status: No, hits=-4.0 required=10.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of Gary.Tong@morganstanley.com designates 205.228.53.69 as permitted sender) Received: from [205.228.53.69] (HELO hqmtaint02.ms.com) (205.228.53.69) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Jan 2009 14:20:32 +0000 Received: from hqmtaint02 (localhost.ms.com [127.0.0.1]) by hqmtaint02.ms.com (output Postfix) with ESMTP id 2A007E38818 for ; Thu, 29 Jan 2009 09:20:11 -0500 (EST) Received: from ny0019as01 (unknown [144.203.194.205]) by hqmtaint02.ms.com (internal Postfix) with ESMTP id 02E15110035 for ; Thu, 29 Jan 2009 09:20:11 -0500 (EST) Received: from ny0019as01 (localhost [127.0.0.1]) by ny0019as01 (msa-out Postfix) with ESMTP id DEFF21045477 for ; Thu, 29 Jan 2009 09:20:10 -0500 (EST) Received: from PIWEXOB02.msad.ms.com (piwexob02 [205.228.46.104]) by ny0019as01 (mta-in Postfix) with ESMTP id DB2C31A4004 for ; Thu, 29 Jan 2009 09:20:10 -0500 (EST) Received: from piexcat01.msad.ms.com ([10.163.2.210]) by PIWEXOB02.msad.ms.com with Microsoft SMTPSVC(6.0.3790.1830); Thu, 29 Jan 2009 09:19:59 -0500 Received: from OZWEXHUB01.msad.ms.com (10.174.147.76) by piexcat01.msad.ms.com (10.163.2.210) with Microsoft SMTP Server (TLS) id 8.1.291.1; Thu, 29 Jan 2009 09:19:58 -0500 Received: from LNWEXMBX0144.msad.ms.com ([10.174.172.42]) by OZWEXHUB01.msad.ms.com ([10.174.147.76]) with mapi; Thu, 29 Jan 2009 14:19:57 +0000 From: "Tong, Gary \(FID\)" To: Date: Thu, 29 Jan 2009 14:19:55 +0000 Subject: Issues with @Context injected fields in ExceptionMapper Thread-Topic: Issues with @Context injected fields in ExceptionMapper thread-index: AcmCHKjbP8cMwn3fQru7fIbMyZjEmQ== Content-class: urn:content-classes:message Message-ID: X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.3168 Importance: normal Priority: normal Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginalArrivalTime: 29 Jan 2009 14:19:59.0394 (UTC) FILETIME=[AADAF020:01C9821C] X-Anti-Virus: Kaspersky Anti-Virus for MailServers 5.5.35/RELEASE, bases: 29012009 #1552536, status: clean X-Virus-Checked: Checked by ClamAV on apache.org Hello, There seem to be issues with @Context-injected fields in = ExceptionMapper, where it throws an NPE with this: public class MyMapper implements ExceptionMapper { @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 =3D 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).