How to configure an OSGi service using descriptor file in Sling? - osgi

I want to configure the Apache Sling Service User Mapper Service using a text file. I created a file under jcr_root/apps/sling/config and this file is called org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.json.
This is the content of the file:
{
"jcr:primaryType":"sling:OsgiConfig",
"user.mapping" : "artifact.name=systemUserName"
}
The file is created in the JCR and the properties are correctly resolved, but the service is not being configured. How to fix this?

Turns out, to configure a service in Sling, the descriptor file has to be stored underjcr_root/apps/sling/install directory.
More about Sling Installer can be found here.

Related

SOLVED - Where to place a file for CloudRun to access the file with a Spring Boot application deployed in CloudRun

I am new to GCP/SpringBoot and working on a project where I have a scenario to read a file that is present in the project directory. The below code works fine when I run it with localhost but fails with "File not Found" after deploying the Springboot application to cloudrun.
Can anyone help on how to read the file or what is the location to place the file.
InputStream is = new FileInputStream("Legend.jpg");
Intead of put the file at the root of the project, it's better to use resource files.
You can put your file in the resource folder src/main/resources/images/Legend.png
And retrieve it in the jar as follow :
InputStream stream = ResourceUtil.class.getClassLoader().getResourceAsStream("images/Legend.png");
You can also check this topic to have more explanations on different ways of retrieving files from resource folder.

Spring Cloud Config Server Not picking changes

I am trying to setup spring config cloud using local file system.
Below is my config on cloud server.
server.port=8888
spring.profiles.active=native
spring.cloud.config.server.native.searchLocations=classpath:/
Bootstrap.properties on client app is as shown below
spring.application.name=hello-world
spring.cloud.config.uri=http://localhost:8888
management.endpoints.web.exposure.include=*
I have also created hello-world.yml on class path for the hello-world spring boot application with property, test: Hello World
Followed below steps to make use of config server.
Step 1: Update the config file and start cloud config server. Able to
see config http://localhost:8888/hello-world/default
Step 2: Start client app hello-world, client app able to read the
test property file from cloud config server.
Step 3: Make changes to config by updating test: Good Bye on
hello-world.yaml.
At this moment, if I check
http://localhost:8888/hello-world/default ,it still shows old value.
Step 4: Run /actuator/refresh on client app. But it won't detect
any change on config server.
The new changes are reflected only if I restart the cloud config server.
Is there any configuration issue causing the cloud config server to unable to listen to changes ?
I could see o.s.cloud.commons.util.InetUtils : Cannot determine local hostname INFO log on cloud config app.
First of all I followed the same exact steps you followed and got the same issue, after almost day of search and study on the matter found out the followings,
we shouldn't use classpath:/<whatever> for
spring.cloud.config.server.native.searchLocations
because when we use so and build the project and run the location refers to the directory inside the generated .jar file, so we will not be able to update it in runtime.
To confirm this you can stop config server, open you .jar archive and delete hello-world.yml file then try http://localhost:8888/hello-world/default you will get default null responses
So we have to use some other locations for spring.cloud.config.server.native.searchLocations either with full directory path or just directory from app running location
Examples
For full path in windows use file:///full-path
spring.cloud.config.server.native.searchLocations: file:///E:\configs
Just for a directory (which will search project root directory if you running from IDE, if running jar then target directory or jar location spring.cloud.config.server.native.searchLocations: configs
spring.cloud.config.server.native.searchLocations: configs\whatever
we can configure multiple locations too as follows, spring.cloud.config.server.native.searchLocations: file:///E:\configs, configs

How to connect eclipse IDE to apache Ignite?

I have written Ignite hello world program in Eclipse and want to connect it to localhost(127.0.0.1). But it is giving me error for example "ignite.xml file path is invalid"
I am starting ignition as follows,
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {}
But I got error like:
Spring XML configuration path is invalid: examples/config/example-ignite.xml.
How do I fix it?
You have the following options:
Provide the absolute file path.
Set IGNITE_HOME system property or environment variable, put the file in this folder and provide the path relative to the home.
Add the configuration file on classpath under META-INF and provide the path relative to it.
The last option is usually the most convenient for the applications with an embedded Ignite node.

Spring Cloud Config Server - How to download binary file

I have a Spring Cloud Config Server with the usual properties files in the git repo:
|--application.yml
|--app1.yml
I also added a binary file
|--mybinaryfile
Normally to access the properties I would ask for
http://myconfigserver/app1/dev
Is it possible to download the binaryfile through the config server? I have tried with
http://myconfigserver/mybinaryfile
and
http://myconfigserver/mybinaryfile/dev
but they didn't work.
I found it:
http://myconfigserver/*/dev/master/mybinaryfile

spring cloud config properties from both local filesystem and git repo

I am using spring cloud config server to host a centralized location for all the property files configurations to be used in the project.
I tried using the config files from a local file system using below and it works fine:
spring.profiles.active=native
spring.cloud.config.server.native.searchLocations=file://${HOME}/Documents/test-config/cloud-config-properties/
I also used the git repo using: spring.cloud.config.server.git.uri=ssh://xxxxxx.com:7999/test/cloud-config-properties.git
I would like to try using a combination of this in my project.
Example - for dev/test profile - i would like to use from local filesystem and for the production - I would like to use Git repository.
I enabled both the git uri and native profiles in my application.properties in config server application. But the properties are always picked up from the local file system. Is this possible?
Not supported out of the box, however there is a workaround for this. You can define the basedir for the configuration server, which is where it saves the files it fetches from the remote server, by setting the property (in the config server):
spring.cloud.config.server.git.basedir=<your_dir>
If you are working with docker, you can map this directory to the host filesystem.
Now whatever file you put in there will be picked up by configuration-server if it matches any of the application/profile in the request. For example you could put a file there called application-dynamic.properties, and have all your clients use dynamic as the last profile, for example
spring.profiles.active=systesting,dynamic
This way everything you will put in application-dynamic.properties will override whatever is defined in your config repo.
One thing to notice though is that you need to add the file only after configuartion server starts, because it deletes this folder during startup.
Needles to say, it's not a good practice doing this in production (for example a restart will cause the file to be deleted), but for test/dev this is the best option.

Resources