4 Replies Latest reply on Dec 22, 2014 6:26 PM by David Jensen

    @ArquillianResource url has wrong host behind a NAT

    Alexis Hassler Apprentice

      Hi all,


      I'm runing an Arquillian Test suite toward a JBoss AS 7 deployed on a EC2 instance. I wanted to run an "as-client" test but I'm facing difficulties with the injected URL.


          URL deploymentUrl;
          @Test @RunAsClient
          public void testGreet() throws Exception { 
              System.out.println(" ==== " + deploymentUrl + " === ");
              String who = "World";
              ClientRequest request = new ClientRequest(deploymentUrl.toString() + "rest/greeter/" + who);
              request.header("Accept", MediaType.TEXT_PLAIN);
              ClientResponse<String> responseObj = request.get(String.class);
              assertEquals("Status code is wrong", 200, responseObj.getStatus());
              assertEquals("Hello " + who, responseObj.getEntity());        


      The host in the injected URL is the JBoss public interface one. But in my case, the public interface should be bound on or on the server private IP.


      Is there a way tohave the public address of my server ?





        • 1. Re: @ArquillianResource url has wrong host behind a NAT
          Aslak Knutsen Master

          You mean you get the EC2 JBoss Servers private address injected by @ArquillianResource, but you want the public one so you can invoke it?


          There is currently no direct way to override this behavior. The URL injection is based on what the Container return on deploy, which is what is defined in the mgm api as "bound-address". (not sure what the rules are there for resolving it)


          I assume you have configured the public address as managementAddress in arquillian.xml, so this is known to you already. What you can do is to create a extension that rewrites the ProtocolMetaData.


          Something similar should do the trix:



          import org.jboss.arquillian.core.spi.LoadableExtension;
          public class EC2AddressExtension implements LoadableExtension {
            public void register(ExtensionBuilder builder) {
          import org.jboss.arquillian.core.api.annotation.Inject;
          import org.jboss.arquillian.core.api.annotation.Observes;
          import org.jboss.arquillian.container.spi.context.annotation.DeploymentScoped;
          public class ProtocolMetadataRewriter {
            @Inject @DeploymentScoped
            private InstanceProducer<ProtocolMetaData> prod;
            public void rewrite(@Observes ProtocolMetaData metadata) {
              if(needToRewriteMetadata(metadata)) {
                ProtocolMetaData newData = cloneAndRewrite(metadata);
                // Since your observing the creation of a ProtocolMetaData you will get called again 
                // when you set cloned/recreated metadata on the InstanceProducer. 
                // The needToRewriteMetadata check should prevent a wild loop
            private ProtocolMetaData cloneAndRewrite(ProtocolMetaData metadata) {
                // do what ever you need to do.. new ProtocolMetadata...
          1 of 1 people found this helpful
          • 2. Re: @ArquillianResource url has wrong host behind a NAT
            Alexis Hassler Apprentice

            Thanks Aslak,


            I will try this. I'm sure I'll have fun, I've never tried to make an Arquillian extension.


            For the moment, I've just added this little work-around :



                public void fixUrl() throws Exception {
                    String serverHost = System.getProperty("arquillian.server");
                    deploymentUrl = new URL(deploymentUrl.getProtocol(), 
                                          serverHost==null ? "localhost" : serverHost, 


            The arquillian.server system property is set in my pom.xml and already used in my arquillian.xml.


            The extension will be much better.



            • 3. Re: @ArquillianResource url has wrong host behind a NAT
              Alexis Hassler Apprentice

              Done. The ProtocolMetadataRewriter class is in my demo project on github.


              Extensions seem to be very powerful. Now I have some other questions with the extensions.


              Is the a documentation on how to write an extension ?

              How could I know all the contexts available ? I'm afraid my code isn't safe ; if someone adds a new context, i'll not take it into account.

              How can I access to the ServletProtocolConfiguration in my extension ?





              • 4. Re: @ArquillianResource url has wrong host behind a NAT
                David Jensen Newbie

                Hi Alexis,

                You said that "The arquillian.server system property is set in my pom.xml and already used in my arquillian.xml".

                Can you show me how you did this?