Spring Cloud Config encrypted property as default value - java

Having application.yml like this:
foo.bar: '{cipher}aaa'
works OK.
I'd like to use the encrypted value as a default only. So something like:
foo.bar: '${xyz:{cipher}aaa}'
This however doesn't work, as the {cipher}aaa part is not recognized as encrypted.
How should I fix it?

The {cipher} bit is only recognized at the beginning of a property. Try setting
foo.bar.default: {cipher}aaa
foo.bar: '${xyz:${foo.bar.default}}'

Related

application.yaml file setting field with OR condition (Providing default value)

There is a Java SpringBoot application, with an application.yaml file where all the properties are configured. some of the fields are configured to read from the deployment.yaml file st eince we use different environments, and the values for these fields changes. However I wan't to define a field which will consider the value from deployment.yaml file if it is present, else it should take the default value given.
Something like this:
root:
some-sub-level:
some-key: ${VALUE_FROM_DEPLOYMENT_YAML:${default.level.value}}
default:
level:
value: some-default-value
I tried several ways and couldn't succeed. It takes blank value since VALUE_FROM_DEPLOYMENT_YAML will be null in one particular environment.
PS: I'm aware of adding default value in Java code like with #Value("${value.from.application.yaml:"some default value"}, but I'm not interested in this. The requirement is not to read this in Java code but it will be a configuration for Azure Application Insight.
Could anyone help me what I'm missing here
According to this answer, it supports this notation which is called Placeholder property:
spring:
profiles:
active: ${APP_PROFILE:test}
# ... #

How to change the format of S3Client.getURL

I'm using the AWS Java SDK within my Spring Boot app.
Currently, when i want to return the URL of the s3 object i use:
s3Client.putObject(new PutObjectRequest(S3_BUCKET_NAME, key,fileToUpload));
URL signedUrl = s3Client.getUrl(S3_BUCKET_NAME, key);
And the signedUrl looks like this :
https://<my_bucket_name>.s3.eu-central-1.amazonaws.com/<my_key>
The problem is that this URL is invalid (it returns HTTPS error during connection). Right now, i cant configure my custom domain and resolve the problem via CloudFront configuration.
So my idea is to force the different format on the SDK. Something like this:
https://s3.eu-central-1.amazonaws.com/<my_bucket_name>/<my_key>
Can someone point me in the right direction?
PS:
I know that, i can do a simple replace on the URL but it is not an elegant solution.
Ok, the problem was with bucket name. The dot character in bucket name was causing all the trouble.
foo-bar-com as bucket name works as expected.
foo.bar.cam.s3. bucket name is causing the https exception.

How to obtain Felix Framework's properties in the config.properties file?

I have this line of code that returns me null and it should return 9193 which is the value that the property really has in my config.properties file...
System.getProperty("org.osgi.service.http.port") // returns null dunno why
My config.properties has the property correctly set up:
org.osgi.service.http.port=9193
Probably I am missing something here, because it is the first time I try to access those properties. I've googled a lot, so there is lack of examples online or I didn't search for the correct keywords.
What should I add/change to that line to make it return the correct value?
Thanks!
Try to use BundleContext.getProperty. The config.properties are set as OSGi framework properties. So this should be a way to retrieve them.

How to set JMS_IBM_MQMD_ACCOUNTINGTOKEN in JMSMessage

After processing a message I need to set the Accounting Token on the msg. How do I set it in the outbound message. I have tried the following and it does not work
msg.setObjectProperty(JmsConstants.JMS_IBM_MQMD_ACCOUNTINGTOKEN,value)
where value set is a byte[]. But when I observe the message the AccountingToken is not getting set.
Is there something I am missing over here?
After further analysis I found that the reason why it was not getting set was because the following property was not set.
((JmsDestination) dest).setBooleanProperty(WMQConstants.WMQ_MQMD_WRITE_ENABLED, true);
After setting the above value the accounting token was available.
From IBM Knowledge Center:
For certain properties, you must also set the WMQ_MQMD_MESSAGE_CONTEXT
property on the Destination object. (...)
The following properties require WMQ_MQMD_MESSAGE_CONTEXT to be set to
WMQ_MDCTX_SET_IDENTITY_CONTEXT or WMQ_MDCTX_SET_ALL_CONTEXT:
JMS_IBM_MQMD_UserIdentifier
JMS_IBM_MQMD_AccountingToken
JMS_IBM_MQMD_ApplIdentityData

Logback configuration via jvm argument

How can we load logback.xml via jvm argument if this is not present in project classpath?
I'm using
-Dlogback.configuration=file:C:\logbacs\logback.xml
but this is not working.
I found the solution
-Dlogging.config="C:\logbacs\logback.xml"
is working fine for me.
Updated because the previous answer was obsolete
If you're not using SpringBoot the above won't work.
I'm using the ch.qos.logback.logback-classic library, and in this case the solution is
-Dlogback.configurationFile=file:/app/logback.xml
I've found this property in ch.qos.logback.classic.util.ContextInitializer:
final public static String CONFIG_FILE_PROPERTY = "logback.configurationFile"
The original answer to this question doesn't appear to be working anymore as it produces this warning instead:
o.s.b.l.logback.LogbackLoggingSystem : Ignoring 'logback.configurationFile' system property. Please use 'logging.config' instead.
Therefore, you would want to use something like this:
-Dlogging.config="C:\logbacs\logback.xml"
For me it works only with this property:
-Dconfig.dir= "YOUR PATH TO CONFIG FILE"
As per https://logback.qos.ch/manual/configuration.html, use -Dlogback.configurationFile
java -Dlogback.configurationFile=/path/to/config.xml chapters.configuration.MyApp1

Categories

Resources