web stats
Dynamically set Http Sender username/password - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Thread Tools Display Modes
Old 02-24-2016, 12:00 PM
GregDit GregDit is offline
Mirth Newb
Join Date: Feb 2016
Posts: 12
GregDit is on a distinguished road
Default Dynamically set Http Sender username/password

Is there anyway to dynamically set a channel's HTTP Sender destination's username and password? Ours change too often to maintain them. Our solution for this in other products is to get the username password from a global key store and our web app sets that keystore when a password changes in the web app.

Was looking to get the username/password during the deployment in the deployment script. Find the channel's HTTP Sender destination. Then set the username and password.

Then in addition to that, maybe do that fetch and set if we get a 401 or 403 status code back.
Reply With Quote
Old 02-25-2016, 08:27 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
Join Date: Oct 2010
Posts: 7,123
narupley is on a distinguished road

Yep, that's very easy to do. There are several maps available to you:
  • Global Map: Map that is shared across the entire server, so it can be used in all channels across multiple messages, the global scripts, even in other places like alerts and data pruner template replacement.

  • Global Channel Map: This is limited in scope to each respective channel, but can still be used across multiple messages.

  • Source Map: This is a read-only map that is available throughout a message's lifecycle to all connectors. It contains entries injected by the receiver. For example, the File Reader will inject the "originalFilename" variable, among others.

  • Channel Map: This is available throughout a single message's lifecycle to all connectors. So for example if you place something in the channel map in the source transformer, you can then reference it in any destination connector, or in the postprocessor script.

  • Connector Map: This is limited in scope to only a particular connector. So if you place something in the connector map in the source transformer, you will not be able to access it in any destinations. You can still technically access it in the postprocessor script however because there you have access to all connector messages.

  • Response Map: This is like the channel map, except that the values that go in should be Response objects. When placing a custom value in the response map, you can then select it from the response drop-down menu on the source connector settings.

  • Configuration Map: This is like the global map, except that you have access to edit it directly in the Administrator (Settings -> Configuration Map tab). It's actually stored as a properties file in the appdata folder. As such, it only allows string values. But it's actually quite useful for global properties you want to use across multiple channels.

So in your case, it sounds like you want to use either the configuration map, global map, or global channel map.

If you need to pull the values dynamically on deploy from some remote source (like a database), then the global map or global channel map is what you should use. Which one depends on whether you want it to be available to all channels or just a specific channel.

You can do something like this in the global deploy script (if you're using the global map), or the channel's deploy script (if you're using the global channel map):

var dbConn;
var result;

try {
	dbConn = DatabaseConnectionFactory.createDatabaseConnection('org.postgresql.Driver', 'jdbc:postgresql://localhost:5432/test', 'user', 'pass');
	result = dbConn.executeCachedQuery('SELECT username, password FROM credentials');

	if (result.next()) {
		globalMap.put('username', result.getString('username'));
		globalMap.put('password', result.getString('password'));
} finally {
	if (dbConn) {
Then on any deploy it will run that script, and load the values into the global map. You can then view them on the dashboard:

Once you have the values in the map, setting them on the HTTP Sender is easy. Just use "${username}" and "${password}". For channel / connector map variables, the variable names will show up on the right in that Destination Mappings list, and you can just drag them over into the text fields you want to use them in. Global map variables won't show up in that list, but you can still use them by typing in the Velocity replacement token syntax, like "${varName}".

If you want to do something custom after the HTTP dispatch based on the response code, that's possible as well. You can do that in the response transformer. Since it sounds like you want to be able to do that even if you don't receive a response payload at all (likely in the case of 401/403), then set your response data types to Raw to ensure that the response transformer will always run even if no response payload exists.

Then, you can pull the "responseStatusLine" and "responseHeaders" entries out of the connector map in there. Those variables are added automatically by the HTTP Sender after it attempts the dispatch. From there you can do whatever you want.
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.

- How do I foo?
- You just bar.
Reply With Quote
Old 02-25-2016, 10:21 AM
GregDit GregDit is offline
Mirth Newb
Join Date: Feb 2016
Posts: 12
GregDit is on a distinguished road

Okay. I had tried that and couldn't get it to work. But, because of you, I went back, looked at it again, tried again, and, of course, I had a syntax error.

Suggestion: Would be very nice to have a button that unhides the password. That way I could have seen my syntax error.
Reply With Quote

deploy script, http sender, password, username

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -8. The time now is 03:37 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation