Is that a third-party servlet that you can't change?

Andrus

> On Mar 10, 2016, at 12:23 PM, Lon Varscsak <[email protected]> wrote:
> 
> Okay, that’s where I ended up (so I’m glad I was on the right track)…my
> servlet that I’m using gets all of it’s values from the init parameters and
> the only way I know to set them programmatically (no web-xml) is to use a
> ServletHolder.  Thoughts?
> 
> I might be able to create a subclass and do some tricks.
> 
> -Lon
> 
> On Wed, Mar 9, 2016 at 6:49 PM, Andrus Adamchik <[email protected]>
> wrote:
> 
>> Hi Lon,
>> 
>> Yeah, we need to make this a bit more transparent (servlet-related API is
>> still minimal, as we focsed on other areas like web services). But you are
>> going in the right direction. JettyModule.contributeServlets(Binder) is
>> what you need. We wrap the servlet in Bootique MappedServlet class to
>> attach the URL mapping. So the whole thing may look like this:
>> 
>> public class App implements Module {
>> 
>>  @Override
>>  public void configure(Binder binder) {
>>    Set<String> urlPatterns = Collections.singleton("/*");
>>    MyServlet servlet = new MyServlet();
>>    JettyModule.contributeServlets(binder).addBinding().toInstance(new
>> MappedServlet(servlet, urlPatterns));
>>  }
>> }
>> 
>> Since you create the servlet in the code, you don't need init parameters.
>> Instead you treat the servlet as a Java object, and pass anything you need
>> in constructor or via setters. (The whole point is to avoid web.xml).
>> 
>> We may improve this API in the future (a bit too much code for my liking;
>> also servlet has to be instantiated and initialized manually instead of
>> using injection). But it is fully functional and will get you going.
>> 
>> Andrus
>> 
>>> On Mar 9, 2016, at 6:28 PM, Lon Varscsak <[email protected]> wrote:
>>> 
>>> I also need to add init parameters to my servlet, but I only know how to
>> do
>>> it through ServletHolder (which bootique doesn’t support).
>>> 
>>> -Lon
>>> 
>>> On Wed, Mar 9, 2016 at 3:11 PM, Lon Varscsak <[email protected]>
>> wrote:
>>> 
>>>> Since I can’t find an email list for Bootique… :D
>>>> 
>>>> How do I add a servlet to Jetty through Bootique.  I see
>>>> JettyModule.contributeServlets(Binder)…but I can’t figure it out.  DI is
>>>> still magical to me.
>>>> 
>>>> Thanks,
>>>> 
>>>> Lon
>>>> 
>> 
>> 

Reply via email to