Return-Path: X-Original-To: apmail-cxf-users-archive@www.apache.org Delivered-To: apmail-cxf-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A75A0435B for ; Fri, 13 May 2011 11:34:28 +0000 (UTC) Received: (qmail 84665 invoked by uid 500); 13 May 2011 11:34:28 -0000 Delivered-To: apmail-cxf-users-archive@cxf.apache.org Received: (qmail 84614 invoked by uid 500); 13 May 2011 11:34:27 -0000 Mailing-List: contact users-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@cxf.apache.org Delivered-To: mailing list users@cxf.apache.org Received: (qmail 84606 invoked by uid 99); 13 May 2011 11:34:27 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 May 2011 11:34:27 +0000 X-ASF-Spam-Status: No, hits=0.6 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of martin.thurau@gmail.com designates 209.85.216.169 as permitted sender) Received: from [209.85.216.169] (HELO mail-qy0-f169.google.com) (209.85.216.169) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 May 2011 11:34:22 +0000 Received: by qyk2 with SMTP id 2so338508qyk.0 for ; Fri, 13 May 2011 04:34:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type:content-transfer-encoding; bh=3zN+hasvvT51D0XW93DSwIfUUoPrwAnP9Hj+fkBPXNM=; b=XwKaGIKYdahpWqfEPc1qh2Vlkv7QOhK6t1nox6K8Vaxp2mUOji9XeJiy5nnTmp98mb cto5NGTrM5tOqxgu5/kMA8QTloljdqb5/zsz/AIv64vI3OapSfGI3lezbJafKuTL5sUg SARreYN3+FMcx3OzdBSwIScSJShBz9nR52eqI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=STWJ+jWIidOAWLuCpGo0eKrdyQS0UXcijHmxxd5dOtFgGcWvbOXdUDhYw23QPrUAJA 7JyJXgkBAPioach5msiVWiNFnKm1MLgcoAACArproLD302iCvHEzwooj5tVyiIYnxZRT W5oqnNpaZRQwy8rsfvJvStnSkljaSts6jseHc= Received: by 10.229.197.13 with SMTP id ei13mr1041491qcb.50.1305286441180; Fri, 13 May 2011 04:34:01 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.18.205 with HTTP; Fri, 13 May 2011 04:33:41 -0700 (PDT) In-Reply-To: References: <4DCAA1DF.9040004@gmail.com> From: Martin Thurau Date: Fri, 13 May 2011 13:33:41 +0200 Message-ID: Subject: Re: NullPointerException at JaxWsDynamicClientFactory.createClient(...) in CXF 2.4.0 - maybe classloader problem To: users@cxf.apache.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org To closes this up (and for people who find this question by Google): A solution was posted in another thread in this list (http://cxf.547215.n5.nabble.com/Upgrade-to-2-4-NullPointerException-tt4386= 230.html) and works for me, too. Simply adding Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); before the creation of the Client solves this. On Thu, May 12, 2011 at 10:54 AM, Sergey Beryozkin w= rote: > I see, I just missed the whole discussion about about classloaders on > the dev list :-) > > On Wed, May 11, 2011 at 3:56 PM, Sergey Beryozkin = wrote: >> Hi >> >> Should we have a handler there in case of 'null' ? Default it to somethi= ng ? >> So that users don't have to start changing the client code ? >> >> Sergey >> >> On Wed, May 11, 2011 at 3:49 PM, Willem Jiang w= rote: >>> Hi, >>> >>> You may consider to set the TCCL like this >>> >>> ClassLoader old =3D Thread.currentThread().getContextClassLoader(); >>> try { >>> >>> Thread.currentThread().setContextClassloader(YourApplicationClassLoader= ); >>> =C2=A0 JaxWsDynamicClientFactory dcf =3D JaxWsDynamicClientFactory.newI= nstance(); >>> =C2=A0 this.client =3D dcf.createClient(new URL(wsdlUrl)); >>> } finally { >>> =C2=A0 Thread.currentThread().setContextClassLoader(old); >>> } >>> >>> On 5/11/11 10:36 PM, Martin Thurau wrote: >>>> >>>> Hello everyone >>>> >>>> I have code, which calls SOAP services using the dynamic client >>>> feature of Apache CXF. The code basically looks like this: >>>> >>>> JaxWsDynamicClientFactory dcf =3D JaxWsDynamicClientFactory.newInstanc= e(); >>>> this.client =3D dcf.createClient(new URL(wsdlUrl)); >>>> >>>> The Exception is thrown within createClient, but only under certain >>>> circumstances. If I run the code within a simple test app everything >>>> runs fine. However, if I move my code to the actual context, as a >>>> plugin within another software, the Exception occurs. The other >>>> software is "Kettle", a tool of the Pentaho BI Suite. I suspect, that >>>> this is because Kettle installs an own classloader in the thread >>>> context and the CXF code that gets executed is somehow incompatible >>>> with this specific classloader. >>>> >>>> Does anyone has a had similar problems when embedding CXF into another >>>> application? What further actions are recommended? >>>> >>>> -- >>>> >>>> I have debugged the NullPointerException within Kettle and have the >>>> exact position where the fault occurs. However, I have no clue *what* >>>> the code inquestion is doing, why it is doing this and what would be a >>>> correct behaviour. >>>> >>>> The NullPointerException is thrown at >>>> org.apache.cxf.wsdl11.WSDLServiceFactory within the constructor >>>> "public WSDLServiceFactory(Bus b, URL url)" at line 67. This line >>>> looks like this: >>>> >>>> definition =3D >>>> getBus().getExtension(WSDLManager.class).getDefinition(wsdlUrl); >>>> >>>> The NullPointerException occures, because the getExtension method >>>> returns null. At run time, the getBus() method returns an instance of >>>> org.apache.cxf.bus.CXFBusImpl. Its complete getExtension in this class >>>> looks like: >>>> >>>> public final =C2=A0T getExtension(Class =C2=A0extensionType) { >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 Object obj =3D extensions.get(extensionTyp= e); >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (obj =3D=3D null) { >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ConfiguredBeanLocator loc = =3D >>>> (ConfiguredBeanLocator)extensions.get(ConfiguredBeanLocator.class); >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (loc =3D=3D null) { >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 loc =3D create= ConfiguredBeanLocator(); >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (loc !=3D null) { >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 //force loadin= g >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Collection = =C2=A0objs =3D loc.getBeansOfType(extensionType); >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (objs !=3D = null) { >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = for (Object o : objs) { >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 extensions.put(extensionType, o); >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = } >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 obj =3D extens= ions.get(extensionType); >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 } >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (null !=3D obj) { >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return extensionType.cast(ob= j); >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 } >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 return null; >>>> =C2=A0 =C2=A0 } >>>> >>>> As you can see, there is a code path that may return null. A case in >>>> which the code at org.apache.cxf.wsdl11.WSDLServiceFactory *will* >>>> fail. In my understanding this is a bug. Am I seeing this right? >>>> >>>> Regards >>>> Martin Thurau >>>> >>> >>> >>> -- >>> Willem >>> ---------------------------------- >>> FuseSource >>> Web: http://www.fusesource.com >>> Blog: =C2=A0 =C2=A0http://willemjiang.blogspot.com (English) >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 http://jnn.javaeye.com (Chinese) >>> Twitter: willemjiang >>> >>> Connect at CamelOne May 24-26 >>> The Open Source Integration Conference >>> http://camelone.com >>> >> >> >> >> -- >> Sergey Beryozkin >> >> Application Integration Division of Talend >> http://sberyozkin.blogspot.com >> > > > > -- > Sergey Beryozkin > > Application Integration Division of Talend > http://sberyozkin.blogspot.com > --=20 Martin Thurau 0176/21131597