2 Replies Latest reply on Oct 7, 2014 4:52 PM by Erhard Siegl

    Calling Webservices: undertow reverse proxy, invm-http-protocol and mod_cluster

    Erhard Siegl Novice



      When I read about the possibility to define reverse proxy in undertow, I thought this could be a great possibility to call a web service "the right way". So I want to ask wether there are plans or work in progress to implement this. So what is the idea:


      Lets say you want to call a REST-service on another server from within WildFly. It might look somehow like this:

        public Book getSingleBook() {

             Client client = ClientBuilder.newClient();

             return client




      In a real-world application there are some obvious problems with this. I want to focus on the hardcoded "http://somehost:8080". If the host or port changes, you have to redeploy. So you probably will put this to a system-property to make it configurable or some other application-specific configuration. But then you still have a problem when this "somehost" is clustered. Is load balancing supported in the client, how is it configured? So probably will go through a loadbalancer (Apache+mod_cluster) even if these services are close in the same network. More problems might arise with DMZs and firewalls. All this can be solved but it is kind of ugly.


      But then there is a reverse proxy in undertow. So I can call myself and leave the configuration to the proxy, which is a good place to put it:


        public Book getSingleBook() {






      So I just have to figure out which host I am, probably localhost (might not be true) and my port, which can be obtained e.g. from JMX. This is nice, because I know that this server (myself) is running (Cogito ergo sum ) and the reverse proxy takes care about the rest. However getting the host and port should be taken care better. Like his:


        ClientExecutor executor = new URLConnectionClientExecutor();

        ClientRequest request = new ClientRequest(




      If you you use java.net.URL for the connection and implement a new URL-protocol (invmhttp), this can take care to connect to "localhost:8080" or wherever the server lives. Actually it would be nice if the call doesn't have to go through the TCP-stack and could connect directly to a in-vm listener of undertow (like in HornetQ invm). So this already looks quite nice. Simple for the user and all the configuration is in standalone.xml.


      But in my opinion the real cool thing is when you use this together with the mod_cluster protocol in local networks. When undertow implements a mod_cluster proxy, you don't have to configure the proxy anymore. You can add servers which provide your REST-services, remove them or move them as you like without any changes in the configuration. You get something like a service-bus for your http services.


      So that is the idea. Most likely I'm not the first one who is thinking along these lines, but I don't know wether there are plans to implement something like this.


      I did some research wether the idea is reasonable. So far the result is:

      1) I did implement a URL-protocol in WildFly that forwards the above URL ("invmhttp://someproxyname/jaxrs-ws-1.0.0-SNAPSHOT/rest/book/002") to localhost and the port from the MBean "jboss.as:socket-binding-group=standard-sockets,socket-binding=http", which is the local http-port. So the idea should work.

      2) I looked at the code from the undertow listeners. I didn't figure out how I could implement something like an in-memory listener. I would need some (lots of) help with this.

      3) The undertow documentation (http://undertow.io/documentation/core/reverse-proxy.html) says:

           Undertow provides two instances of ProxyClient (there is a third one under development that has mod_cluster support).

      Anybody knows when this can be expected?


      What do you think about all this stuff?