-
1. Re: @ArquillianResource url has wrong host behind a NAT
aslak Dec 20, 2011 9:45 AM (in response to sewatech)1 of 1 people found this helpfulYou 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:
META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension=EC2AddressExtension import org.jboss.arquillian.core.spi.LoadableExtension; public class EC2AddressExtension implements LoadableExtension { public void register(ExtensionBuilder builder) { builder.observer(ProtocolMetadataRewriter.class); } } 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 prod.set(newData); } } private ProtocolMetaData cloneAndRewrite(ProtocolMetaData metadata) { // do what ever you need to do.. new ProtocolMetadata... } }
-
2. Re: @ArquillianResource url has wrong host behind a NAT
sewatech Dec 20, 2011 10:19 AM (in response to aslak)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 :
@Before public void fixUrl() throws Exception { String serverHost = System.getProperty("arquillian.server"); deploymentUrl = new URL(deploymentUrl.getProtocol(), serverHost==null ? "localhost" : serverHost, deploymentUrl.getPort(), deploymentUrl.getFile()); }
The arquillian.server system property is set in my pom.xml and already used in my arquillian.xml.
The extension will be much better.
Alexis
-
3. Re: @ArquillianResource url has wrong host behind a NAT
sewatech Dec 23, 2011 6:36 PM (in response to aslak)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 ?
Thanks.
Alexis
-
4. Re: @ArquillianResource url has wrong host behind a NAT
davidj Dec 22, 2014 6:26 PM (in response to sewatech)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?
Thanks!