9 Replies Latest reply on Feb 3, 2014 11:17 AM by simski

    Is it possible to set the REST gateway binding address at runtime?

    simski

      I am looking for a way to set the target address for a REST service at runtime. Is it possible?

       

      Thanks in advance

           Simon

        • 1. Re: Is it possible to set the REST gateway binding address at runtime?
          mageshbk

          Could you be a bit more specific and let us know if you want the service binding or the reference binding to be dynamic?

          • 2. Re: Is it possible to set the REST gateway binding address at runtime?
            simski

            Jep, Sorry. The overall problem is that I have to call an external REST service where the exact address (and security info, like username and pasword, as well) is given at runtime. So I guess I have to dynamically specify the reference binding. If I leave e.g. the address configuration empty it defaults to http://localhost:8080, but I found no way to set this value programmatically per message scope.

             

            Hope that exlains a bit more what I try to achieve.

             

            Greetings

                 Simon

            • 3. Re: Is it possible to set the REST gateway binding address at runtime?
              kcbabo

              Doing this from a message/exchange property is not possible at the moment, but you can use property substitution to assign the value as a system property:

              Properties - SwitchYard - Project Documentation Editor

              • 4. Re: Is it possible to set the REST gateway binding address at runtime?
                simski

                Thanks Keith

                 

                I will give it a try tomorrow. Will there be another, say more practical way to set the address (and security infos) at runtime in the future? Although the use of system properties will do it in most situations, it will at least fail when there are many calls in parallel.

                 

                Simon

                • 5. Re: Is it possible to set the REST gateway binding address at runtime?
                  simski

                  Hi

                   

                  I tried the proposed solution but got the following exception during deployment:

                   

                  Caused by: java.lang.RuntimeException: java.net.URISyntaxException: Illegal character in path at index 1: ${p23r.projektleitstelle.url}

                    at org.switchyard.component.resteasy.util.ClientInvoker.createUri(ClientInvoker.java:107)

                    at org.switchyard.component.resteasy.util.ClientInvoker.<init>(ClientInvoker.java:133)

                    at org.switchyard.component.resteasy.OutboundHandler.doStart(OutboundHandler.java:95)

                    at org.switchyard.deploy.BaseServiceHandler.start(BaseServiceHandler.java:60)

                    at org.switchyard.deploy.internal.Deployment.deployReferenceBindings(Deployment.java:310)

                    at org.switchyard.deploy.internal.Deployment.start(Deployment.java:143)

                    at org.switchyard.as7.extension.deployment.SwitchYardDeployment.start(SwitchYardDeployment.java:101)

                    at org.switchyard.as7.extension.services.SwitchYardService.start(SwitchYardService.java:73)

                    ... 5 more

                  Caused by: java.net.URISyntaxException: Illegal character in path at index 1: ${p23r.projektleitstelle.url}

                    at java.net.URI$Parser.fail(URI.java:2829) [rt.jar:1.7.0_21]

                    at java.net.URI$Parser.checkChars(URI.java:3002) [rt.jar:1.7.0_21]

                    at java.net.URI$Parser.parseHierarchical(URI.java:3086) [rt.jar:1.7.0_21]

                    at java.net.URI$Parser.parse(URI.java:3044) [rt.jar:1.7.0_21]

                    at java.net.URI.<init>(URI.java:595) [rt.jar:1.7.0_21]

                    at org.switchyard.component.resteasy.util.ClientInvoker.createUri(ClientInvoker.java:105)

                    ... 12 more

                   

                  Any Idea? Any help would be highly appreciated. If there is no way, I will try to use RESTEasy "manually" :-) which should work as we do it already in another project successfully.

                  • 6. Re: Is it possible to set the REST gateway binding address at runtime?
                    kcbabo

                    What version of SY are you using?  Please attach the switchyard.xml you are using.  This definitely works as it's used in lots of places.  In fact, the rest binding quickstart uses it:

                    quickstarts/rest-binding/src/main/resources/META-INF/switchyard.xml at master · jboss-switchyard/quickstarts · GitHub

                    • 7. Re: Is it possible to set the REST gateway binding address at runtime?
                      simski

                      Ok, got it. It works now. I thought I could use the system property directly without going via the domain property defined in the switchyard.xml.

                       

                      But I still not see this solution as final. If there are two calls in parallel I am afraid they will collide...

                       

                      Thanks

                           Simon

                      • 8. Re: Is it possible to set the REST gateway binding address at runtime?
                        kcbabo

                        You don't need the domain property - that's optional.  Where are you defining the system property?  Sounds like it's not getting set, which explains why the property is not being substituted.

                         

                        Can you explain your concern about two calls in parallel?  Property substitution allows a single property to be set during startup (via property definition in standalone.xml for example) and that value applies to all invocations.  There are no issues with concurrent reads of the substituted value because the substitution only takes place once on startup.  This is sufficient for use cases where you want to change the address at a global level.  If you want to change it per invocation, you'll need support for setting the address from a property.  That doesn't exist now, but it's something we've definitely discussed.  Feel free to file a JIRA requesting that enhancement if you're interested:

                         

                        SwitchYard - JBoss Issue Tracker

                        1 of 1 people found this helpful
                        • 9. Re: Is it possible to set the REST gateway binding address at runtime?
                          simski

                          You're right. May be the fix for the deployment exception is just the provision of the default value if the system property is not already set. In my second test run system properties are still set from the first run and therefore the expected values are used during my test.

                           

                          The use case I am trying to implement is simple. I have a service "on the left side" which gets the address and user credentials from where the bean has to catch a package for processing from "the right side". the service to catch the package from is always the same, just another url and different credentials.

                           

                          I will file the Issue.

                           

                          Thank you

                               Simon