Return-Path: X-Original-To: apmail-curator-user-archive@minotaur.apache.org Delivered-To: apmail-curator-user-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8646810BE4 for ; Sat, 20 Jul 2013 22:01:58 +0000 (UTC) Received: (qmail 54519 invoked by uid 500); 20 Jul 2013 22:01:58 -0000 Delivered-To: apmail-curator-user-archive@curator.apache.org Received: (qmail 54491 invoked by uid 500); 20 Jul 2013 22:01:58 -0000 Mailing-List: contact user-help@curator.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@curator.incubator.apache.org Delivered-To: mailing list user@curator.incubator.apache.org Received: (qmail 54483 invoked by uid 99); 20 Jul 2013 22:01:58 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 20 Jul 2013 22:01:58 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of xiaochenchen.git@gmail.com designates 209.85.216.169 as permitted sender) Received: from [209.85.216.169] (HELO mail-qc0-f169.google.com) (209.85.216.169) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 20 Jul 2013 22:01:51 +0000 Received: by mail-qc0-f169.google.com with SMTP id c10so2995493qcz.0 for ; Sat, 20 Jul 2013 15:01:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:message-id:mime-version:subject:date:references :to:in-reply-to:x-mailer; bh=tLUIaf8xtjFJb+TLOZCD5v98nxJdyF3SHAW+fpNUpSw=; b=Tjz8TUb4JmUyzL5Kl9Wku0+GgZOgzJzeeyBpumjzTxYeFpVxVQzZWXE+tN5/9AdKyI TOkrULOLy080D1Jy3azXJsEowOGiJJKw7Zce71GfQJMia/fNndOFWIATJY+bVHUzhKkJ AenmTz9bdj6rKMhReAI+9ss36iHM65wAGde7H9B4a0xZtZ+/mDUP3P3wdX3ghGd3kgSN c6omjYRF3FzHy6pGYen1ONLbZzNKBfACq195053Wye9eWy441pa5rgQbNO0ltVDzYdWt PaChInrkG7H/tcjFz309Y6qwBf354PviqA6wVsw6e0wurSsnLmiJuylR7O4JJTzkcEdQ fDrQ== X-Received: by 10.49.35.108 with SMTP id g12mr24724471qej.86.1374357689806; Sat, 20 Jul 2013 15:01:29 -0700 (PDT) Received: from [192.168.0.14] (cpe-67-243-184-104.nyc.res.rr.com. [67.243.184.104]) by mx.google.com with ESMTPSA id r2sm28935272qeh.7.2013.07.20.15.01.28 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 20 Jul 2013 15:01:28 -0700 (PDT) From: Xiaochen Chen Content-Type: multipart/alternative; boundary="Apple-Mail=_3DCE9C56-1DE2-4AB7-8DD3-2CBDB930EB53" Message-Id: <455A31BC-BB9F-4F56-AABD-28A0DC65A704@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 6.5 \(1508\)) Subject: Re: NPE when a resource tries to use @Context injected ContextResolver Date: Sat, 20 Jul 2013 18:01:26 -0400 References: <74BD4ED5-6D18-43E4-B99D-475C5A19F499@jordanzimmerman.com> To: user@curator.incubator.apache.org In-Reply-To: <74BD4ED5-6D18-43E4-B99D-475C5A19F499@jordanzimmerman.com> X-Mailer: Apple Mail (2.1508) X-Virus-Checked: Checked by ClamAV on apache.org --Apple-Mail=_3DCE9C56-1DE2-4AB7-8DD3-2CBDB930EB53 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 Couldn't agree more! That totally makes sense. Though I'm surprised this hasn't been fixed =85 Thanks Jordan. I'll test it out. And confirm later. On Jul 20, 2013, at 5:26 PM, Jordan Zimmerman = wrote: > BTW - how many thousands of man years have been lost to erasure?!! = What a horrible mistake that decision was. >=20 > -JZ >=20 > On Jul 20, 2013, at 2:24 PM, Jordan Zimmerman = wrote: >=20 >> OK - I have a workaround. You need to create a wrapper class that = acts as the context resolver: >>=20 >> @Provider >> public class MyResolver implements = ContextResolver> >> { >> private final GenericDiscoveryContext context; >>=20 >> public MyResolver(GenericDiscoveryContext = context) >> { >> this.context =3D context; >> } >>=20 >> @Override >> public DiscoveryContext getContext(Class type) >> { >> return context; >> } >> } >>=20 >> In the Singletons, instead of adding discoveryContext, add: >>=20 >> new MyResolver(discoveryContext) >>=20 >> In my tests, this fixed the problem. >>=20 >> -Jordan >>=20 >> On Jul 19, 2013, at 5:01 PM, xiaochen.chen@barclays.com wrote: >>=20 >>> Hello, >>> =20 >>> I am using Curator=92s curator-x-discovery-sever and trying to set = it up with Jersey and Tomcat. >>> =20 >>> I created my resource class, injected the class. Also injected those = singletons mentioned. >>> (following this page = http://curator.incubator.apache.org/curator-x-discovery-server/index.html = ) >>> =20 >>> However, I am getting NPE when the contextResolver tries to = getContext. >>> =20 >>> The ContextResolver singleton is injected, and it looks like the = @Context injection isn=92t happening. >>> =20 >>> Can someone please help me to see what is wrong with my code? >>> =20 >>> Thanks. >>> =20 >>> Here is my code, the highlighted line is where the exception = happens: >>> =20 >>> Resource >>> =20 >>> @Path("compass") >>> public class CompassResource extends = DiscoveryResource >>> { >>> public CompassResource(@Context = ContextResolver> resolver) >>> { >>> super(resolver.getContext(DiscoveryContext.class)); >>> } >>> } >>> =20 >>> Application >>> =20 >>> public class DiscoveryServerApplication extends Application >>> { >>> @Override >>> public Set> getClasses() { >>> Set> s =3D new HashSet>(); >>> //s.add(MyResource.class); >>> s.add(CompassResource.class); >>> return s; >>> } >>> =20 >>> @Override >>> public Set getSingletons() { >>> final Set singletons =3D Sets.newHashSet(); >>> =20 >>> // inject ServiceDiscovery singleton >>> CuratorFrameworkFactory.Builder builder =3D = CuratorFrameworkFactory.builder() >>> = .connectString("localhost:2181").sessionTimeoutMs(300000).connectionTimeou= tMs(30000) >>> .retryPolicy(new ExponentialBackoffRetry(1000,3)); >>> CuratorFramework client =3D builder.build(); >>> client.start(); >>> =20 >>> ServiceDiscovery serviceDiscovery =3D = ServiceDiscoveryBuilder.builder(ServicePayload.class) >>> .client(client).basePath("/").build(); >>> singletons.add(serviceDiscovery); >>> =20 >>> // inject DiscoveryContext singleton >>> GenericDiscoveryContext discoveryContext =3D = new GenericDiscoveryContext >>> (serviceDiscovery, new = RandomStrategy(), 500, ServicePayload.class); >>> singletons.add(discoveryContext); >>> =20 >>> // inject JsonServiceInstanceMarshaller singleton >>> singletons.add(new = JsonServiceInstanceMarshaller(discoveryContext)); >>> =20 >>> // inject JsonServiceInstancesMarshaller singleton >>> singletons.add(new = JsonServiceInstancesMarshaller(discoveryContext)); >>> =20 >>> // inject JsonServiceNamesMarshaller >>> singletons.add(new JsonServiceNamesMarshaller()); >>> =20 >>> return singletons; >>> } >>> } >>> web.xml >>> =20 >>> >>> Curator Discovery Server >>> = org.glassfish.jersey.servlet.ServletContainer >>> >>> javax.ws.rs.Application >>> = com.lb.eqr.discovery.server.DiscoveryServerApplication >>> >>> 1 >>> >>> >>> Curator Discovery Server >>> /* >>> >>> =20 >>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >>> =20 >>> Here is the exception: >>> =20 >>> root cause >>> java.lang.NullPointerException >>> = com.lb.eqr.discovery.server.CompassResource.(CompassResource.java:23= ) >>> = sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) >>> = sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAcc= essorImpl.java:39) >>> = sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstr= uctorAccessorImpl.java:27) >>> = java.lang.reflect.Constructor.newInstance(Constructor.java:513) >>> = org.glassfish.hk2.utilities.reflection.ReflectionHelper.makeMe(ReflectionH= elper.java:1091) >>> = org.jvnet.hk2.internal.ClazzCreator.createMe(ClazzCreator.java:244) >>> = org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:319) >>> = org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:448) >>> = org.glassfish.jersey.process.internal.RequestScope.findOrCreate(RequestSco= pe.java:157) >>> = org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2203) >>> = org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.ja= va:579) >>> = org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.ja= va:566) >>> = org.glassfish.jersey.internal.inject.Injections.getOrCreate(Injections.jav= a:172) >>> = org.glassfish.jersey.server.model.MethodHandler$ClassBasedMethodHandler.ge= tInstance(MethodHandler.java:185) >>> = org.glassfish.jersey.server.internal.routing.PushMethodHandlerRouter.apply= (PushMethodHandlerRouter.java:105) >>> = org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingSt= age.java:118) >>> = org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingSt= age.java:121) >>> = org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingSt= age.java:121) >>> = org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingSt= age.java:121) >>> = org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingSt= age.java:121) >>> = org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingSta= ge.java:102) >>> = org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingSta= ge.java:62) >>> = org.glassfish.jersey.process.internal.Stages.process(Stages.java:197) >>> = org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:215) >>> org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) >>> org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) >>> = org.glassfish.jersey.internal.Errors.process(Errors.java:315) >>> = org.glassfish.jersey.internal.Errors.process(Errors.java:297) >>> = org.glassfish.jersey.internal.Errors.process(Errors.java:267) >>> = org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope= .java:317) >>> = org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:198) >>> = org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.j= ava:946) >>> = org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:323) >>> = org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.jav= a:372) >>> = org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.jav= a:335) >>> = org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.jav= a:218) >>> =20 >>> =20 >>> _______________________________________________ >>>=20 >>> This message is for information purposes only, it is not a = recommendation, advice, offer or solicitation to buy or sell a product = or service nor an official confirmation of any transaction. It is = directed at persons who are professionals and is not intended for retail = customer use. Intended for recipient only. This message is subject to = the terms at: www.barclays.com/emaildisclaimer. >>>=20 >>> For important disclosures, please see: = www.barclays.com/salesandtradingdisclaimer regarding market commentary = from Barclays Sales and/or Trading, who are active market participants; = and in respect of Barclays Research, including disclosures relating to = specific issuers, please see http://publicresearch.barclays.com. >>>=20 >>> _______________________________________________ >>>=20 >>=20 >=20 --Apple-Mail=_3DCE9C56-1DE2-4AB7-8DD3-2CBDB930EB53 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=windows-1252 jordan@jordanzimmerman.com&= gt; wrote:
BTW - = how many thousands of man years have been lost to erasure?!! What a = horrible mistake that decision = was.

-JZ

On Jul 20, 2013, = at 2:24 PM, Jordan Zimmerman <jordan@jordanzimmerman.com&= gt; wrote:

OK - I have a workaround. You = need to create a wrapper class that acts as the context = resolver:

@Provider
public class = MyResolver implements = ContextResolver<DiscoveryContext<ServicePayload>>
{<= /div>
    private final = GenericDiscoveryContext<ServicePayload> = context;

    public = MyResolver(GenericDiscoveryContext<ServicePayload> = context)
    {
        = this.context =3D context;
    = }

    @Override
  =   public DiscoveryContext<ServicePayload> = getContext(Class<?> type)
    = {
        return context;
  =   }
}

In the Singletons, = instead of adding discoveryContext, = add:

= new MyResolver(discoveryContext)

In = my tests, this fixed the = problem.

-Jordan

On Jul = 19, 2013, at 5:01 PM, xiaochen.chen@barclays.com = wrote:

Hello,
I am using = Curator=92s curator-x-discovery-sever and trying to set it up with = Jersey and Tomcat.
I created my = resource class, injected the class. Also injected those singletons = mentioned.
(following this = page  )


<= /blockquote>
= --Apple-Mail=_3DCE9C56-1DE2-4AB7-8DD3-2CBDB930EB53--