0

Thorntail using project-defaults.yaml

Using the below command line arguments to start the application.

Trying to pass location of a Java .properties file to use as system properties.

java -jar application-thorntail.jar -P ../config/application.properties -P ../config/application-dev.properties -s ../config/project-defaults.yaml

Property key value in application.properties

mail.smtp.password=testpass
tds.username=username

In yaml i want to evaluate the value as below

 mail:
    mail-sessions:
      default:
        smtp-server:
          username: ${mail.smtp.user}
          password: ${mail.smtp.password}
          outbound-socket-binding-ref: mail-smtp
        jndi-name: java:jboss/mail/Default

However, on a statup values are not getting evaluated

Error getting subresources for ConnectionDefinitions
java.lang.RuntimeException: Failed to adopt value java.lang.String
    at org.wildfly.swarm.config.runtime.invocation.EntityAdapter.fromEntity(EntityAdapter.java:346)
    at org.wildfly.swarm.config.runtime.invocation.Marshaller.appendNode(Marshaller.java:33)
    at org.wildfly.swarm.config.runtime.invocation.Marshaller.marshalSubresources(Marshaller.java:129)
    at org.wildfly.swarm.config.runtime.invocation.Marshaller.appendNode(Marshaller.java:38)
    at org.wildfly.swarm.config.runtime.invocation.Marshaller.marshalSubresources(Marshaller.java:129)
    at org.wildfly.swarm.config.runtime.invocation.Marshaller.appendNode(Marshaller.java:38)
    at org.wildfly.swarm.config.runtime.invocation.Marshaller.marshalSubresources(Marshaller.java:129)
    at org.wildfly.swarm.config.runtime.invocation.Marshaller.appendNode(Marshaller.java:38)
    at org.wildfly.swarm.config.runtime.invocation.Marshaller.marshal(Marshaller.java:23)
    at org.wildfly.swarm.container.runtime.marshal.SubsystemMarshaller.marshal(SubsystemMarshaller.java:59)
    at org.wildfly.swarm.container.runtime.marshal.SubsystemMarshaller$Proxy$_$$_WeldClientProxy.marshal(Unknown Source)
    at org.wildfly.swarm.container.runtime.marshal.DMRMarshaller.marshal(DMRMarshaller.java:70)
    at org.wildfly.swarm.container.runtime.marshal.DMRMarshaller$Proxy$_$$_WeldClientProxy.marshal(Unknown Source)
    at org.wildfly.swarm.container.runtime.RuntimeServer.start(RuntimeServer.java:194)
    at org.wildfly.swarm.container.runtime.RuntimeServer$Proxy$_$$_WeldClientProxy.start(Unknown Source)
    at org.wildfly.swarm.container.runtime.ServerBootstrapImpl.lambda$bootstrap$1(ServerBootstrapImpl.java:159)
    at org.wildfly.swarm.spi.api.ClassLoading.withTCCL(ClassLoading.java:43)
    at org.wildfly.swarm.container.runtime.ServerBootstrapImpl.bootstrap(ServerBootstrapImpl.java:113)
    at org.wildfly.swarm.Swarm.start(Swarm.java:401)
    at org.wildfly.swarm.Swarm.main(Swarm.java:745)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.wildfly.swarm.bootstrap.MainInvoker.invoke(MainInvoker.java:57)
    at org.wildfly.swarm.bootstrap.Main.run(Main.java:134)
    at org.wildfly.swarm.bootstrap.Main.main(Main.java:87)
Caused by: java.lang.IllegalStateException: Failed to resolve expression: ${tds.username}
    at org.jboss.dmr.ValueExpressionResolver.resolve(ValueExpressionResolver.java:128)
    at org.jboss.dmr.ValueExpression.resolveString(ValueExpression.java:163)
    at org.jboss.dmr.ValueExpression.resolveString(ValueExpression.java:153)
    at org.wildfly.swarm.config.runtime.invocation.SimpleTypeAdapter.toDmr(SimpleTypeAdapter.java:22)
    at org.wildfly.swarm.config.runtime.invocation.EntityAdapter.fromEntity(EntityAdapter.java:343)
    ... 26 more
Dev Fh
  • 586
  • 7
  • 18
  • Where did you get the impression that Thorntail accepts the `-P` flag? I haven't seen that anywhere. – Ladicek Jun 05 '20 at 06:15
  • I have read this on wildfly-swarm user guide. See the link below. https://wildfly-swarm.gitbooks.io/wildfly-swarm-users-guide/configuration/command_line.html – Dev Fh Jun 05 '20 at 07:43
  • @Ladicek is it possible to inject properties that will be resolved using expression language in a project-default.yaml file during a start up ? – Dev Fh Jun 05 '20 at 07:50
  • Wow, that's a really old documentation. I just took a look and indeed we have a `-P` option, even though it isn't documented in the new documentation (docs.thorntail.io). Looking at the code, it should work. Interpolation should work, too -- just looking at the exception, it fails to resolve `${tds.username}`, but that isn't used anywhere in the YAML file you show. Can you put together a standalone reproducer? – Ladicek Jun 05 '20 at 08:08
  • I notice that it works fine if i supply only one `-P` option - if however i supply many e.g `-P application.properties -P application-dev.properties` it seems to get confused and then overrides first one. – Dev Fh Jun 05 '20 at 10:21
  • e.g `INFO [org.jboss.as] (MSC service thread 1-2) WFLYSRV0049: Thorntail 2.6.0.Final (WildFly Core 10.0.3.Final) starting` – Dev Fh Jun 05 '20 at 10:26
  • `INFO [org.wildfly.swarm] (MSC service thread 1-2) THORN0019: Install MSC service for command line args: [--properties, /dev-config/application.properties, -s, /dev-config/project-defaults.yaml]` – Dev Fh Jun 05 '20 at 10:27
  • 1
    Yea, it seems only one `-P` option is allowed: https://github.com/thorntail/thorntail/blob/2.6.0.Final/core/container/src/main/java/org/wildfly/swarm/cli/CommandLine.java#L111 – Ladicek Jun 05 '20 at 15:35

1 Answers1

0

Well, first of all you defined your property as tds.username, but you are tring to access it as mail.smtp.user.

If this was just a mistake when writing the example, maybe you could try using ${env.XXX}.

Change your property file from mail.smtp.user to MAIL_SMTP_USER and then, on project-defaults, use username: ${env.MAIL_SMTP_USER}.

If this works, you could even propose a default value (in the example below, "defaultusername"): username: ${env.MAIL_SMTP_USER:defaultusername}

Important to note that I don't have the tools to test it.

Cássio
  • 329
  • 3
  • 11