systemValue for proxying in Standalone Wiremock

485 views
Skip to first unread message

Michal Labuda

unread,
Feb 12, 2020, 11:28:37 AM2/12/20
to wiremock-user
I'm using Standalone Wiremock v 2.25.1
I'm running Standalone Wiremock with the following among my command line options: "--global-response-templating", "--permitted-system-keys","/API_INTERNAL_GATEWAY_URL/".

When using the following response:"response"
{
   "proxyBaseUrl": "{{systemValue type='ENVIRONMENT' key='API_INTERNAL_GATEWAY_URL'}}"
},

Wiremock return [ERROR: Access to API_INTERNAL_GATEWAY_URL is denied]. Did anyone run into a similar situation? Am I missing something?


Mark Gargan

unread,
Apr 14, 2020, 10:15:11 AM4/14/20
to wiremock-user
Hi Michal, 

            I'm also attempting to use the system permitted variables to no avail. I have --global-response-templating in the settings and --permitted-system-keys=wiremock.* --wiremock.systemkey=somkey

but keep getting
Exception in thread "main" joptsimple.UnrecognizedOptionException: wiremock.systemkey is not a recognized option
        at joptsimple.OptionException.unrecognizedOption(OptionException.java:108)
        at joptsimple.OptionParser.handleLongOptionToken(OptionParser.java:510)
        at joptsimple.OptionParserState$2.handleArgument(OptionParserState.java:56)
        at joptsimple.OptionParser.parse(OptionParser.java:396)
        at com.github.tomakehurst.wiremock.standalone.CommandLineOptions.<init>(CommandLineOptions.java:148)
        at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.run(WireMockServerRunner.java:52)
        at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.main(WireMockServerRunner.java:125)

I'm running wiremock through yarn which is a wrapper around the wiremock jar file.

Have you had any luck yourself?

thanks,
Mark.

Tom Akehurst

unread,
Apr 14, 2020, 10:21:45 AM4/14/20
to wiremock-user
To specify Java system properties, you need use the following form and put this before the -jar part:

-Dwiremock.somekey=my_value

Mark Gargan

unread,
Apr 14, 2020, 10:58:03 AM4/14/20
to wiremock-user
Hi Tom, 

           Thanks very much for getting back to me yourself! Alas I don't know that I have the option to specify the -D options on the commandline as we use the npm wrapper for running wiremock. 

Our commandline is 
yarn wiremock --global-response-templating --verbose --root-dir ./mocks 

and the cli.js that runs this kicks off the process like 

const result = spawnSync(
'java',
[ '-jar', compilerPath ].concat(process.argv.slice(2)),
{ stdio: 'inherit' },
);

Alas it doesn't appear that I can add -D options unless I hack the cli.js which will be frowned on as it is installed into the node_modules and as such isn't part of our codebase. 

I'll continue to dig around. 

Thanks,
Mark.

Mark Gargan

unread,
Apr 14, 2020, 11:01:17 AM4/14/20
to wiremock-user

Tom Akehurst

unread,
Apr 14, 2020, 11:04:15 AM4/14/20
to wiremock-user
You might be better off using environment variables rather than system properties in that case.

Mark Gargan

unread,
Apr 14, 2020, 11:38:19 AM4/14/20
to wiremock-user
Fantastic Tom, thanks very much for your help!
Just in case anyone else is using the wrapper and running the wrapper, to use system variables in the handlerbars expressions :-

in both cases the handlebars expression in the mapping file is 
{{systemValue type='ENVIRONMENT' key='WIREMOCK_DIGITAL_HOST'}}

1)
  • export WIREMOCK_DIGITAL_HOST=http://localhost:9090 on the command line
  • yarn wiremock --global-response-templating --verbose --root-dir ./mocks --permitted-system-keys=WIREMOCK_.*
2)
  • create a .env.development.local file with WIREMOCK_DIGITAL_HOST=http://localhost:9090
  • Run the command yarn env-cmd -f .env.development.local yarn wiremock --global-response-templating --verbose --root-dir ./mocks --permitted-system-keys=WIREMOCK_.*
Thanks for your help Tom, got me out of a bind. 
Mark.






(Just in case I've updated wiremock.systemKey to be WIREMOCK_DIGITAL_HOST instead.)
1) 
adding
WIREMOCK_DIGITAL_HOST=localhost:9090
to our .env.development.local file and starting wiremock with 

yarn env-cmd -f .env.development.local yarn wiremock --global-response-templating --verbose --root-dir ./mocks --permitted-system-keys=WIREMOCK_*

and also

export WIREMOCK_DIGITAL_HOST=localhost:9090

but the {{systemValue type='ENVIRONMENT' key='WIREMOCK_DIGITAL_HOST'}} handlebars expression returns [ERROR: Access to WIREMOCK_DIGITAL_HOST is denied] 
in the response? 

Have I got the syntax in the permitted-system-keys argument correct? 

Mark Gargan

unread,
Apr 14, 2020, 11:52:00 AM4/14/20
to wiremock-user
Apologies, I started that mail before I saw your response. Should just read 
Reply all
Reply to author
Forward
0 new messages