From dev-return-1696-apmail-juneau-dev-archive=juneau.apache.org@juneau.apache.org Thu Mar 29 17:19:26 2018 Return-Path: X-Original-To: apmail-juneau-dev-archive@minotaur.apache.org Delivered-To: apmail-juneau-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E66851814D for ; Thu, 29 Mar 2018 17:19:25 +0000 (UTC) Received: (qmail 57057 invoked by uid 500); 29 Mar 2018 17:19:25 -0000 Delivered-To: apmail-juneau-dev-archive@juneau.apache.org Received: (qmail 57021 invoked by uid 500); 29 Mar 2018 17:19:25 -0000 Mailing-List: contact dev-help@juneau.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@juneau.apache.org Delivered-To: mailing list dev@juneau.apache.org Received: (qmail 57011 invoked by uid 99); 29 Mar 2018 17:19:25 -0000 Received: from mail-relay.apache.org (HELO mailrelay2-lw-us.apache.org) (207.244.88.137) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Mar 2018 17:19:25 +0000 Received: from mail-qt0-f170.google.com (mail-qt0-f170.google.com [209.85.216.170]) by mailrelay2-lw-us.apache.org (ASF Mail Server at mailrelay2-lw-us.apache.org) with ESMTPSA id 0B21AFC0 for ; Thu, 29 Mar 2018 17:19:24 +0000 (UTC) Received: by mail-qt0-f170.google.com with SMTP id j3so6971878qtn.9 for ; Thu, 29 Mar 2018 10:19:24 -0700 (PDT) X-Gm-Message-State: AElRT7HL8L8As6dIMSAKNAsEEoO2imq34EkXKuiak41mfQIb6zhi0F5C SO2M/kCsm8MiDZKUOyzUlZQ/rqrNsDXYjemDqlI= X-Google-Smtp-Source: AIpwx496IPbw22Bf4mLTkSvNyiX+vTaG6I3iaKn38GLNhBaAnxFinVwa9+sFvmTHzaEC36LNcOZi9E6KxBjKxp0gCa4= X-Received: by 10.237.57.231 with SMTP id m94mr13180307qte.12.1522343964576; Thu, 29 Mar 2018 10:19:24 -0700 (PDT) MIME-Version: 1.0 Received: by 10.12.135.130 with HTTP; Thu, 29 Mar 2018 10:18:44 -0700 (PDT) In-Reply-To: References: From: James Bognar Date: Thu, 29 Mar 2018 13:18:44 -0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Trouble getting servlets to initialize on startup (probably user error) To: dev@juneau.apache.org Content-Type: multipart/alternative; boundary="001a11405d183c13ea056890533c" --001a11405d183c13ea056890533c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Steve, I don't have a complete answer, but.... The behavior is defined in Jetty. It looks like ServletHolder.setInitOrder(0) is the programmatic way of forcing a servlet to initialize during startup. The XML you see below.... / com.peoplepattern.streams.execution.api.RootResources /* ...is equivalent to calling... servletContextHandler.addServlet(" com.peoplepattern.streams.execution.api.RootResources", "/*"); There is a 2nd method on ServletContextHandler that allows you to pass in a ServletHolder... addServlet(ServletHolder servlet, java.lang.String pathSpec) So just taking a stab at it, maybe something like this would work? (I'm no expert on the jetty.xml files, so I have no idea if this is valid syntax).... / com.peoplepattern.streams.execution.api.RootResources 0 /* On Thu, Mar 29, 2018 at 12:16 PM, Steve Blackmon wrote: > I=E2=80=99m trying to configure Juneau to ensure that initialization of m= y > resources occurs as the server comes up. > > I=E2=80=99m using @RestHook(INIT) and @RestHook(POST_INIT_CHILD_FIRST) to > annotate methods which instantiate helper classes, and confirm that > everything is healthy, respectively. > > I=E2=80=99m finding however that those methods are not called until the f= irst > request comes in. > > My RootResources class extends ResourceGroup and has RestHook annotated > methods. It also defines ~10 sub-resources which have them as well. > > I=E2=80=99ve attached my microservice.cfg and jetty.xml files. > > Any advice would be greatly appreciated! > > Steve > > > --001a11405d183c13ea056890533c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Steve,

I don't have a complete a= nswer, but....

The behavior is defined in Jetty.=C2= =A0 It looks like ServletHolder.setInitOrder(0) is the programmatic way of = forcing a servlet to initialize during startup.

Th= e XML you see below....

=C2= =A0 =C2=A0 <New id=3D"context" class=3D"org.eclipse.jetty= .servlet.ServletContextHandler">
=C2=A0 =C2=A0 =C2=A0 =C2=A0 <Set name=3D"context= Path">/</Set>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 <Call name=3D"addServlet">= ;
=C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 <Arg>com.peoplepattern.streams.execution.api.Ro= otResources</Arg>
=C2=A0 =C2=A0 =C2=A0 =C2=A0= </Call>
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 <Set name=3D"sessionHandler">
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 <New class=3D"org.eclipse.jetty.server.session.Sessio= nHandler" />
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 </Set>
=C2=A0 =C2=A0 </New>

...is equivalent to calling...
servletContextHandler.addServlet("com.peoplepattern.streams.ex= ecution.api.RootResources", "/*");

There is a 2nd method on ServletContextHandler that allow= s you to pass in a ServletHolder...
= addServlet(ServletHolder servlet, java.lang.String pathSpec)

So just taking a stab at it, maybe something li= ke this would work?=C2=A0 (I'm no expert on the jetty.xml files, so I h= ave no idea if this is valid syntax)....

=C2=A0 =C2=A0 <New id=3D"context&quo= t; class=3D"org.eclipse.jetty.servlet.ServletContextHandler"><= /font>
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 <Set name=3D"contextPath">/</Set>
=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 <Ca= ll name=3D"addServlet">
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <Arg>
=C2=A0 =C2=A0= =C2=A0=C2=A0 =C2=A0= =C2=A0=C2=A0 =C2=A0=C2=A0<= /span>=C2=A0 =C2=A0=C2=A0<= /span><New class=3D"org.eclipse.jetty.servlet.ServletHolder"&g= t;
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0<= ;Set name=3D"servlet">com.peoplep= attern.streams.execution.api.RootResources</Set>
<= div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0<Call name=3D"= ;setInitOrder">
= =C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0= =C2=A0<Arg>0</Arg>
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0</Call&= gt;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <Arg>/= *</Arg>
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 </Call>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 <Set= name=3D"sessionHandler">
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <New class=3D= "org.eclipse.jetty.server.session.SessionHandler" />
=C2=A0 =C2=A0 =C2=A0 =C2=A0 <= ;/Set>
=C2=A0 =C2= =A0 </New>

</Arg>




On Thu, Mar 29, 2018 at 12:16 PM, Steve Blackmon <sblackmon@apache.org= > wrote:
=20 =20 =20 =20 =20 =20
I=E2=80=99m trying to configure Juneau to ensure that initialization o= f my resources occurs as the server comes up. =C2=A0

I=E2=80=99m using @RestHook(INIT) and @RestHook(POST_INIT_CHILD_FIRST) to annotate methods w= hich instantiate helper classes, and confirm that everything is healthy, re= spectively.=C2=A0

I=E2=80=99m finding = however that those methods are not called until the first request comes in.= =C2=A0

My RootResources class extends ResourceGro= up and has RestHook annotated methods.=C2=A0 It also defines ~10 sub-resour= ces which have them as well.

I=E2=80=99ve att= ached my microservice.cfg and jetty.xml files.

Any advice would be greatly appreciated!

Steve



--001a11405d183c13ea056890533c--