I am working on spring boot app and in my config file I have couple o file and I want to read them. so I have tried below stuffs.
-Dspring.profiles.active=local -Dserver.port=8080 -Dajp.port=0 -Dspring.datasource.url=jdbc:oracle:thin:#localhost:1521:OraDoc -Dspring.datasource.username=system -Dspring.datasource.password=MyPasswd123 -Dspring.config.additional-location=file:/Users/bharatsuthar/HGW/codebaseDevelopmentRepo1/data-generation-tool/rdk-factory-data-config/ -Dlogging.config=file:/Users/bharatsuthar/HGW/codebaseDevelopmentRepo1/data-generation-tool/rdk-factory-data-config/logback-spring.xml
I am able to read all files since spring is supporting this by using -Dspring.config.additional-location but I am not sure how to read test.pem file in my java code as a String only.
below is my test.pem file location under rdk-factory-data-config directory
[location of test pem file]
(https://i.stack.imgur.com/4T0Y8.png)
I tried with -Dspring.config.additional-location here i am able to read file like application.yml and application-dev.yml but how can I read the test.pem file to String in my java code.
I want to read pem file into String so that I can read the data in my spring boot app.
content of pem file :
-----BEGIN CERTIFICATE-----
MIIChjCCAg2gAwIBAgIQKgFtzZclg1CxcBAHZDc2cTAKBggqhkjOPQQDAzAzMQsw
CQYDVQQGEwJTSzEUMBIGA1UEChMLUkRLIEZhY3RvcnkxDjAMBgNVBAMTBVNLIFIx
MB4XDTIyMTAxMzA5MDAzMloXDTQ3MTAxMzIzNTk1OVowMzELMAkGA1UEBhMCU0sx
FDASBgNVBAoTC1JESyBGYWN0b3J5MQ4wDAYDVQQDEwVTSyBDMTB2MBAGByqGSM49
AgEGBSuBBAAiA2IABDSRscO50mm3uzavmLTS2DEw/J/1dRp5nmyWJNMp+B0/w5y7
AAvOLtcJDpulCFCXa/UhEfvbGEVvDtS9jY75YtOqvQkPIIuE6IUC6kyTXZaPOe+3
WwYbzYxpOXuMDOzZbaOB5TCB4jAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFJJS
jPquJiIZ49geOU/NCAsvRaPOMB8GA1UdIwQYMBaAFPS8o9tW37TZ6W+OKy7hznHt
FR0dMBIGA1UdEwEB/wQIMAYBAf8CAQAwNwYDVR0fBDAwLjAsoCqgKIYmaHR0cDov
L2NybC5yZGsudGVsZXNlasdfasdfsYy5kZS9ybC9TS19SMS5jcmwwQwYIKwYBBQUHAQEENzA1
MDMGCCsGAQUFBzAqwrrewrChidodHRwOi8vY3J0LnJkay50ZWxlc2VjLmRlL2NydC9TS19S
MS5jcnQwCgYIKoZIzj0EAwMDZwAwZAIwITubLwiMJ6KpTmyI41kOcCd3VzjbdPsx
NB3RZIBf4o3BYBzT1FQqbXvnYHsEGX/oAjAm8cTa9+tcLrrxN/RGwr53apg6FYlz
xRKbLjARTg/dFAn4W0w59XZXJ/fBZ4F6m5A=
-----END CERTIFICATE-----
I have tried this -
String s = new String(Files.readAllBytes(Paths.get("test.pem"))); System.out.println("s=" + s);
-> it gives me no such file exception -->
Caused by: java.nio.file.NoSuchFileException: test.pem
---> I don't want to give full absolute path since my requirement is to read from directory which is in the root of my spring boot folder
thank you so much
As far as I understand, -Dspring.config.additional-location reads any property file or equivalent of it. *.pem files are not equivalent of property files so they should be ignored. Read Spring documentation
What you should do instead, put a property in your property file specifying your .pem file location and later, use that property to read the contents of your .pem file in whatever format seems fit to you.
Related
I have an issue not reading properties from a file as a file system backend.
I tried to use these lines shown below to reach the file but it didn't work.
Here is my APIConfig.properties file shown below beneath file-system-backend-config
token.expiration_time = 8640000
token.secret = hfgry463hf746hf573ydh475fhy57414141
login.url.path = /users/login
Here is my application.properties under PhotoAppAPIConfigServer
server.port=8042
# File System Backend
spring.profiles.active= native
spring.cloud.config.server.native.search-locations= file:///C:/Users/Noyan/Desktop/dev/file-system-backend-config
# Bus Refresh
management.endpoints.web.exposure.include=busrefresh
# Rabbit MQ
spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
I got an issue when I run this config server. Here is my error message shown below.
java.lang.IllegalArgumentException: Pattern cannot be null or empty
How can I fix it?
To use a file system backend, just write into application.properties file:
server.port=8042
spring.application.name=photo-app-config # Not mandatory
spring.profiles.active=native
spring.cloud.config.server.native.search-locations=classpath:/config
# spring.cloud.config.server.native.search-locations=file:///C:/config # Or your preferred absolute path
Put your configurations into:
classpath:/config:(project directory)
resources/config/api-config.properties
file:///C:/config:(your system directory)
C:/config/api-config.properties
Now read your configurations through the URL:
http://localhost:8042/api-config/default
100% tested.
I am struggling with Azure wasb on spark
I am reading loading a .json.gz file from disk and loading it into hdfs. I have used the following code extensively on other systems.
val file_a_raw = sqlContext.read.json('/home/users/repo_test/file_a.json.gz')
However, on Azure, this returns:
java.io.FileNotFoundException: Filewasb://server-2017-03-07t08-13-41-314z#server.blob.core.windows.net/home/users/repo_test/file_a.json.gz does not exist.
I have checked this location and the file is there and correct.
I think there should be a : between .net and then file path, but I get a java error trying to manually add that in.
java.lang.IllegalArgumentException: java.net.URISyntaxException: Expected scheme name at index 0:
I've also tried:
Filewasb:///home/users/repo_test/file_a.json.gz
But that returns:
java.io.IOException: No FileSystem for scheme: Filewasb
This code works fine on non Azure spark
For Azure, you'll need to configure Spark with the proper credentials. Databricks has documentation on this: https://docs.databricks.com/user-guide/faq/azure-blob-storage.html
In my Java/Maven application, I'm trying to read some files that is in resources folder. I just can read this files when execute the application in Eclipse, but when I try to run the application with the command bellow I get a Nullpointer because the file is not found.
java -Dserver.port=$PORT -Dspring.profiles.active=dev -jar my-war.war
I'm reading the file with this command:
String string = new String(
Files.readAllBytes(
Paths.get(ClassLoader.getSystemResource("fileFolder/file.html").toURI())));
the problem was solved changing the way that I read the resource:
IOUtils.toString((new ClassPathResource("fileFolder/file.html").getInputStream()));
because the resources when in .war not are treated as files, so read them as file will throw an exception
I have written a basic jsp code for storing and retrieving the data from db.
Before that am checking validation of user.
When i click submit button it will redirect to my jsp page.
i have written a db.properties file separately.
When i gave complete path to read properties file., program is executing fine. (Which is not best way to hard code like below).
FileInputStream in = new FileInputStream("C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ServiceDisplay\db.properties");
But when i specify only "db.properties" like
(FileInputStream in = new FileInputStream("db.properties");) program is not executing i got file not found exception.
Please not this properties file is in current working dir only. (i.e., my db.properties file and my jsp file is under ServiceDisplay
I tried to changing the file name as "//db.properties", "/db.properties", "./db.properties", "\db.properties", .\db.properties, ../db.properties", "..\db.properties" .
But still i am getting java.io.FileNotFoundException: db.properties
The file 'ServiceDisplay\db.properties' is in your resources directory, to load this file is necessary to use the getResoursceAsStream. Code example below:
ServletContext context = request.getSession().getServletContext();
InputStream is = context.getResourceAsStream("/db.properties");
I am using AmazonS3EncryptionClient. I wrote a code to connect to S3 and download the data. The code works all fine from eclipse but when I create a jar out of it and try to run it, it gives the following error
Unable to decrypt symmetric key from object metadata : Illegal key size or default parameters
I am using symmetric encryption and the key is stored in a file. The file is being properly accessed from Eclipse as well as the jar.
What can be missing while running the code from the jar?
Sounds like your private-key is some how invalid, most probably it is not in the JAR file or in classpath, can you make sure the code has access to the key
to check the file
jar tf <your jar> | grep <keyname>