# Injecting own client into internal node

**URL:** <https://discuss.elastic.co/t/injecting-own-client-into-internal-node/6011>\
**Category:** Elasticsearch\
**Created:** [November 29, 2011, 3:18pm UTC](https://discuss.elastic.co/t/injecting-own-client-into-internal-node/6011 "2011-11-29T15:18:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Reelsen](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@Alexander\_Reelsen](https://discuss.elastic.co/u/Alexander_Reelsen)\
**Post date:** [November 29, 2011, 3:18pm UTC](https://discuss.elastic.co/t/injecting-own-client-into-internal-node/6011/1 "2011-11-29T15:18:27Z")

</div>

Hi there,

While writing my plugin I came across the problem that I would like to  
inject my custom self written client with a suggest method, whenever  
node.client() is called - this would be especially useful for my  
tests, as I am currently doing integration tests against the rest  
controller.

--Alexander

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [November 29, 2011, 3:22pm UTC](https://discuss.elastic.co/t/injecting-own-client-into-internal-node/6011/2 "2011-11-29T15:22:33Z")

</div>

Hey,

Sadly, there isn't really an option to do it. But, you could get the  
TransportXXAction one and use it (from the internal injector). Need to  
think more on custom APIs and how to add them to a statically typed  
language 🙂

-shay.banon

On Tue, Nov 29, 2011 at 5:18 PM, Alexander Reelsen \<  
[alexander.reelsen@googlemail.com](mailto:alexander.reelsen@googlemail.com)\> wrote:

> Hi there,
> 
> While writing my plugin I came across the problem that I would like to  
> inject my custom self written client with a suggest method, whenever  
> node.client() is called - this would be especially useful for my  
> tests, as I am currently doing integration tests against the rest  
> controller.
> 
> --Alexander

---

<div class="post-metadata">

**Author:** ![Alexander\_Reelsen](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@Alexander\_Reelsen](https://discuss.elastic.co/u/Alexander_Reelsen)\
**Post date:** [November 30, 2011, 10:56pm UTC](https://discuss.elastic.co/t/injecting-own-client-into-internal-node/6011/3 "2011-11-30T22:56:28Z")

</div>

Hey

On 29 Nov., 16:22, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Sadly, there isn't really an option to do it. But, you could get the  
> TransportXXAction one and use it (from the internal injector). Need to  
> think more on custom APIs and how to add them to a statically typed  
> language 🙂  
> Hm, it feels a bit like maven downloading half the internet three  
> times when I try to resolve the dependencies of a  
> TransportBroadcastOperationAction manually, as it needs a  
> clusterservice, a transport service and a indicesservice - which in  
> turn needs all kinds of modules injected.

Does it make sense to resolve all these dependencies or is there some  
trick I just dont see? Or some even better solution?

Thanks a lot for helping!

--Alexander

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [December 1, 2011, 2:08pm UTC](https://discuss.elastic.co/t/injecting-own-client-into-internal-node/6011/4 "2011-12-01T14:08:15Z")

</div>

What? You have your action implemented, no? You can get the guice injector  
and get its (singleton) instance.

On Thu, Dec 1, 2011 at 12:56 AM, Alexander Reelsen \<  
[alexander.reelsen@googlemail.com](mailto:alexander.reelsen@googlemail.com)\> wrote:

> Hey
> 
> On 29 Nov., 16:22, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > Sadly, there isn't really an option to do it. But, you could get the  
> > TransportXXAction one and use it (from the internal injector). Need to  
> > think more on custom APIs and how to add them to a statically typed  
> > language 🙂  
> > Hm, it feels a bit like maven downloading half the internet three  
> > times when I try to resolve the dependencies of a  
> > TransportBroadcastOperationAction manually, as it needs a  
> > clusterservice, a transport service and a indicesservice - which in  
> > turn needs all kinds of modules injected.
> 
> Does it make sense to resolve all these dependencies or is there some  
> trick I just dont see? Or some even better solution?
> 
> Thanks a lot for helping!
> 
> --Alexander

---

<div class="post-metadata">

**Author:** ![Alexander\_Reelsen](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@Alexander\_Reelsen](https://discuss.elastic.co/u/Alexander_Reelsen)\
**Post date:** [December 3, 2011, 4:49pm UTC](https://discuss.elastic.co/t/injecting-own-client-into-internal-node/6011/5 "2011-12-03T16:49:00Z")

</div>

Hi

On Dec 1, 3:08 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> What? You have your action implemented, no? You can get the guice injector  
> and get its (singleton) instance.  
> Works now, I did the same as in the HdfsGatewayTests:

TransportSuggestAction suggestAction = ((InternalNode)  
node).injector().getInstance(TransportSuggestAction.class);

Thanks for helping, I shouldnt check/search/ask for such issues after  
midnight during the week I guess.

--Alexander

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:46am UTC](https://discuss.elastic.co/t/injecting-own-client-into-internal-node/6011/6 "2017-07-06T03:46:32Z")

</div>


