Tenant not found during startup of cloud-s4-sdk-book / RequestContextServletFilter issue - s4sdk

During (local) startup of the example application cloud-s4-sdk-book in the branch 15_2_spring_boot the following exception is thrown:
16:01:38.786 [localhost-startStop-1] DEBUG com.sap.cloud.sdk.cloudplatform.servlet.RequestContextServletFilter - Filter initialization parameter factory not defined.
16:01:38.787 [localhost-startStop-1] INFO com.sap.cloud.sdk.cloudplatform.servlet.RequestContextServletFilter - No RequestContextFactory configured. Falling back to DefaultRequestContextFactory.
16:01:38.798 [localhost-startStop-1] INFO com.sap.cloud.sdk.cloudplatform.servlet.RequestContextListenerChain - Added default listener com.sap.cloud.sdk.cloudplatform.security.user.UserRequestContextListener with priority -4.
16:01:38.798 [localhost-startStop-1] INFO com.sap.cloud.sdk.cloudplatform.servlet.RequestContextListenerChain - Added default listener com.sap.cloud.sdk.cloudplatform.tenant.TenantRequestContextListener with priority -3.
16:01:38.799 [localhost-startStop-1] INFO com.sap.cloud.sdk.cloudplatform.servlet.RequestContextListenerChain - Added default listener com.sap.cloud.sdk.cloudplatform.connectivity.DestinationsRequestContextListener with priority -2.
16:01:38.799 [localhost-startStop-1] INFO com.sap.cloud.sdk.cloudplatform.servlet.RequestContextListenerChain - Added default listener com.sap.cloud.sdk.cloudplatform.security.AuthTokenRequestContextListener with priority -5.
16:01:43.862 [main] WARN com.sap.cloud.s4hana.examples.addressmgr.config.TenantIdentifierResolver - Tenant not found
com.sap.cloud.sdk.cloudplatform.tenant.exception.TenantAccessException: Failed to get current tenant: no RequestContext available. Have you correctly configured a RequestContextServletFilter or have you wrapped your logic in a RequestContextExecutor when executing background tasks that are not triggered by a request?
The exception is thrown inside method "loadFactory" of class RequestContextServletFilter.
I am starting the application using mvn spring-boot:run.
What can I do the get the application started correctly?

This exception is expected and can usually be ignored if you are running this application locally, where no tenant is available. The application should still work, because there is a fallback in place to a tenant identifier default-tenant .
Keep in mind that you need to subscribe the default tenant before interacting with the database - do an HTTP request PUT /api/callback/tenant/default-tenant.
Please note that this exception is only being logged as a warning. If you want to clean the log, adapt the TenantIdentifierResolver class.

Related

spring boot logs strange square brackets

I've been seeing weird square brackets and can't find and info on what there might be,
logs looking like that:
--2022-08-23 08:47:44.882 INFO [,,,] 30446 --- [)-192.168.0.165] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
--2022-08-23 08:47:44.882 INFO [,,,] 30446 --- [)-192.168.0.165] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
--2022-08-23 08:47:44.922 INFO [,,,] 30446 --- [)-192.168.0.165] o.s.web.servlet.DispatcherServlet : Completed initialization in 40 ms
as you can see there are brackets with commas after log level, at some point info in the brackets change like this:
DEBUG [,080578da-b973-450b-9cae-2c5900ab56fe,080578da-b973-450b-9cae-2c5900ab56fe,]
can't really find what that could be, i'am using default spring boot logging pattern,
could it be wrongfully used MDC without redeclaring the logging pattern?
if it is MDC problem then why any value in the brackets look like this: 080578da-b973-450b-9cae-2c5900ab56fe
The logger I'm using is Slf4j
This could happen if you use Spring Cloud Sleuth. Spring Cloud Sleuth is a framework that adds the following to your logs:
The application name (from the spring.application.name property)
A trace ID (a unique ID for each user-initiated request)
A span ID (a unique ID for a unit of work)
These IDs can be used to correlate log messages in a distributed system (eg. microservices), because these IDs will be passed from microservice to microservice. In the documentation you can find an example of what this looks like.
In your case, you're not using these properties, which is why they're empty. The trace ID is automatically generated upon each request, which is why you sometimes see [,,] and [,XXX,].
If you're not interested in these trace/span IDs, you can remove the spring-cloud-sleuth or spring-cloud-starter-sleuth library.

Embedded Keycloak springboot application, upgrading keycloak from 12 to 14

Hello I have an SpringBoot application with embedded Keyclock created using the below example
https://www.baeldung.com/keycloak-embedded-in-spring-boot-app
I am trying to upgrade Keycloak from 12 to 14 and also upgraded resteasy to 3.15.1.Final, infinispan to 11.0.9.Final. The application fails to start and there is not much in the logs except for a NullPointerException. I am trying to see if any one tried the same and has any suggestions as there are not much in logs. Thanks
2021-07-07 10:02:05 [main] INFO org.keycloak.services - KC-SERVICES0050: Initializing master realm
2021-07-07 10:02:07 [main] DEBUG org.keycloak.keys.GeneratedRsaKeyProviderFactory - Generated keys for master
2021-07-07 10:02:07 [main] DEBUG org.keycloak.keys.GeneratedHmacKeyProviderFactory - Generated secret for master
2021-07-07 10:02:07 [main] DEBUG org.keycloak.keys.GeneratedAesKeyProviderFactory - Generated secret for master
2021-07-07 10:02:07 [main] DEBUG org.keycloak.connections.jpa.updater.liquibase.lock.LiquibaseDBLockProvider - Going to release database lock namespace=KEYCLOAK_BOOT
2021-07-07 10:02:07 [main] DEBUG org.keycloak.connections.jpa.updater.liquibase.lock.CustomLockService - Going to release database lock
2021-07-07 10:02:07 [main] DEBUG org.keycloak.models.cache.infinispan.InfinispanUserCacheProviderFactory - Registered cluster listeners
2021-07-07 10:02:07 [main] DEBUG org.keycloak.executors.DefaultExecutorsProviderFactory - We are in managed environment. Executor 'java:jboss/ee/concurrency/executor/default' was available.
2021-07-07 10:02:07 [main] DEBUG org.keycloak.executors.DefaultExecutorsProviderFactory - Found executor for 'storage-provider-threads' under JNDI name 'java:jboss/ee/concurrency/executor/storage-provider-threads'
2021-07-07 10:02:07 [main] FATAL org.keycloak.services - java.lang.NullPointerException
2021-07-07 10:02:07 [main] DEBUG org.keycloak.executors.DefaultExecutorsProviderFactory - Found executor for 'storage-provider-threads' under JNDI name 'java:jboss/ee/concurrency/executor/storage-provider-threads'
$$$$$$$$$$$$$$$$Stachtrace$$$$$$$$$$$$$ : java.lang.NullPointerException
at java.base/java.util.concurrent.ConcurrentHashMap.putVal(ConcurrentHashMap.java:1011)
at java.base/java.util.concurrent.ConcurrentHashMap.put(ConcurrentHashMap.java:1006)
at org.keycloak.executors.DefaultExecutorsProviderFactory.getExecutor(DefaultExecutorsProviderFactory.java:113)
at org.keycloak.executors.DefaultExecutorsProviderFactory$1.getExecutor(DefaultExecutorsProviderFactory.java:68)
at org.keycloak.utils.ServicesUtils.timeBoundOne(ServicesUtils.java:71)
at org.keycloak.storage.AbstractStorageManager.mapEnabledStorageProvidersWithTimeout(AbstractStorageManager.java:135)
at org.keycloak.storage.UserStorageManager.getUsersCount(UserStorageManager.java:374)
at org.keycloak.models.cache.infinispan.UserCacheSession.getUsersCount(UserCacheSession.java:545)
at org.keycloak.storage.user.UserQueryProvider.getUsersCount(UserQueryProvider.java:52)
at org.keycloak.services.managers.ApplianceBootstrap.createMasterRealmUser(ApplianceBootstrap.java:99)
We had similar vague error messages when upgrading our embedded keycloak to 15 in our Spring Boot/Servlet-style application. But we eventually fixed them by crawling through the code/history of the project that this baeldung.com tutorial was based; thomasdarimont's Embedded Keycloak Server running in a Spring Boot App. This repo is a few upgrades past the initial tutorial; up to Keycloak 13. We compared the history to our code and applying/testing fixes incrementally for each version from keycloak 11 to 13. After that, the updates from 13 to 15 were a bit easier to understand, and the errors were not as cryptic.
Our application is not exactly like the example code given in the Baeldung tutorial, but below is a list of changes we needed to upgrade to Keycloak 15.0.1. These changes may not be 1:1 with your project, but hopefully these help someone save some time.
In KeycloakApplication moved the realm-setup functions from constructor method to bootstrap() method. (An example fix found here)
public class EmbeddedKeycloakApplication extends KeycloakApplication {
...
//public EmbeddedKeycloakApplication() {
// createMasterRealmAdminUser();
// createBaeldungRealm();
//}
#Override
protected ExportImportManager bootstrap() {
final ExportImportManager exportImportManager = super.bootstrap();
createMasterRealmAdminUser();
createBaeldungRealm();
return exportImportManager;
}
In the EmbeddedKeycloakConfig we added a couple new bean references/factories (Both found here)
public class EmbeddedKeycloakConfig {
...
#Bean("fixedThreadPool")
public ExecutorService fixedThreadPool() {
return Executors.newFixedThreadPool(5);
}
#Bean
#ConditionalOnMissingBean(name = "springBootPlatform")
protected SimplePlatformProvider springBootPlatform() {
return (SimplePlatformProvider) Platform.getPlatform();
}
In our keycloak-server.json, we removed the default 'concurrenthashmap' name from the mapStorage provider, but still provided the concurrenthashmap properties. This matches other Keycloak 15 examples. As Paul mentioned, the map_storage needs to be enabled, and the simplest solution is to use the system properties -Dkeycloak.profile.feature.map_storage=enabled -Dkeycloak.mapStorage.provider=concurrenthashmap. Similar examples can be found in the Keycloak test suites here and here . HOWEVER: We ran into errors when using these system properties, and decided it is not needed for our code. Luckilly, the 'mapStorage' is no specifically called out in the tutorial; it is only found in the Referenced Tutorial Code. So we simply matched other Keycloak 13+ examples and removed the reference in the keycloak-server.json (shown below) to get rid of the null pointer exception.
//Change this:
"mapStorage": {
"provider": "${keycloak.mapStorage.provider:concurrenthashmap}",
"concurrenthashmap": {
"dir": "${project.build.directory:target}"
}
},
//To This
"mapStorage": {
"provider": "${keycloak.mapStorage.provider:}",
"concurrenthashmap": {
"dir": "${project.build.directory:target}"
}
},
Upgraded the proper infinispan and rest versions with keycloak version. (Tutorial code reference)
< properties>
< keycloak.version>15.0.1</keycloak.version>
< !-- these should be updated together with Keycloak -->
< !-- check keycloak-dependencies-server-all effective pom -->
< infinispan.version>11.0.9.Final</infinispan.version>
< resteasy.version>3.15.1.Final/resteasy.version>
< /properties>
We also added the temp directory location in the SimplePlatformProvider, since this field was required. NOTE: The system temp folder, used in the example, is not recommended for production.
#Override
public File getTmpDirectory() {
return System.getProperty("java.io.tmpdir");
}
I hope someone finds this info useful, Good luck!
I’ve tried the same thing with keycloak 15 and I got the same result. It seems that keycloak’s ConcurrentHashMapStorageProvider isn’t taken in account.
EDIT: after looking into keycloak's code, I've found that MAP_STORAGE functionality is disabled by default (because the feature is tagged as EXPERIMENTAL). To resolve this issue you must launch your springboot app with the following Java option :
-Dkeycloak.profile.feature.map_storage=enabled
Unfortunately, I'm now facing another nullPointerException...
I have applied the changes suggested by #mrieman to the initial baeldung.com tutorial. It works fine with 17.0.1 version of Keycloak as of now. Hope it will help someone. My repository on Github is here

Springboot - validate "native" properties at startup

Context: after a recent springboot/spring migration, I've been scratching my head on why my HAL URLs were now returned as HTTP and not HTTPS anymore.
After investigation, this was related to some deprecated (and removed) property replaced by another one (ok, Intellij was doing a proper job and highlighted this)
server.use-forward-headers=true
#replaced by
server.forward-headers-strategy=native
Whereas I know you can validate your own properties set via your #ConfigurationProperties, its parameters or even your own JSR annotations, is there a way to validate "native" properties (server., spring., ...) at application startup and/or build?
UC1: I want to be sure I'm not using any unknown property (e.g. the property has been totally removed or is misspelt)
UC2: I want to be sure I'm not using any deprecated property
Approaches tried:
Searching for an existing property that would do the job
Overriding ServerProperties (sounds like a bad idea)
Using an existing FailureAnalyzer or defining a custom one
Thanks for your help!
You can rely on your IDE but it can only show you the configuration files that you are managing. Those properties are potentially set as environment variables in an specific environment or using a remote config server you don't have access to.
That's one of the reasons we're providing spring-boot-properties-migrator. It is referenced in the release notes.
Here is a sample demo app that yield the following:
2020-07-18 19:19:54.168 INFO 69898 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on taurus.lan with PID 69898 (/Users/snicoll/Downloads/demo-properties-migrator/target/classes started by snicoll in /Users/snicoll/Downloads/demo-properties-migrator)
2020-07-18 19:19:54.170 INFO 69898 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2020-07-18 19:19:54.545 INFO 69898 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 0.571 seconds (JVM running for 0.924)
2020-07-18 19:19:54.551 ERROR 69898 --- [ main] o.s.b.c.p.m.PropertiesMigrationListener :
The use of configuration keys that are no longer supported was found in the environment:
Property source 'systemProperties':
Key: server.connection-timeout
Reason: Each server behaves differently.
Property source 'applicationConfig: [classpath:/application.properties]':
Key: server.use-forward-headers
Line: 1
Reason: Replaced to support additional strategies.
Please refer to the release notes or reference guide for potential alternatives.
This will work for known properties (your use case) but it won't work for properties that are set and we don't know about (i.e. that don't have metadata). An obvious candidate in that set is typos of course but that's no longer an upgrade problem. Relying on your IDE to make sure that the property you introduce is legit sounds reasonable to me.
We'd like also to offer some validation for users that are adding properties without assistance, see this issue for more details.

spring-cloud-sleuth one of the microserives out of three does not show the spanid, and token id in logs after adding dependency

I am using http://cloud.spring.io/spring-cloud-sleuth/spring-cloud-sleuth.html#_adding_to_the_project for adding Spring Cloud Sleuth without the Zipkin integration
But in one of the microserives out of three, does not show the spanid, and token id in logs after adding dependency for all services (all are http request services, though there are couple of more services which require JMS - on which I need to work)
Service1
2016-06-05 17:12:45.404 INFO [my-service1-id,73b62c0f90d11e06,73b62c0f90d11e06,false] 85184 --- [nio-8080-exec-1] com.example.MyService1MakingARequest
Service2
2016-06-05 17:12:45.404 INFO 85185 --- [nio-8080-exec-1] com.example.MyService2MakingARequest
Service3
2016-06-05 17:12:45.404 INFO [my-service3-id,73b62c0f90d11e06,73b62c0f90d11e06,false] 85185 --- [nio-8080-exec-1] com.example.MyService3MakingARequest
Experts, Please suggest what can be done to see the effect in Service2
The best thing to do would be to show your sample project. Another is to check if you don't have a custom logback.xml or any other type of logging configuration that breaks the current set up (most likely you do cause I can see that the pattern is different).

E1601: Cannot retrieve JMS connection info [JMSTopicService is not initialized. JMS notificationmay not be enabled]

Hi i am following below link .
http://oozie.apache.org/docs/4.0.0/AG_Install.html#Notifications_Configuration
i have done all the configuration in cdh as said in the above link and restarted the oozie
Now for consumer application i have simple java main class for test purpose
code snippet
OozieClient oc = new OozieClient("ooziebaseurl:11000/oozie");
JMSConnectionInfo jmsInfo = oc.getJMSConnectionInfo();
Properties jndiProperties = jmsInfo.getJNDIProperties();
Context jndiContext = new InitialContext(jndiProperties);
while getting JMSConnectionInfo i am having below exception
Exception in thread "main" E1601 : E1601: Cannot retrieve JMS connection info [JMSTopicService is not initialized. JMS notificationmay not be enabled]
at org.apache.oozie.client.OozieClient.handleError(OozieClient.java:508)
at org.apache.oozie.client.OozieClient$JMSInfo.call(OozieClient.java:757)
at org.apache.oozie.client.OozieClient$JMSInfo.call(OozieClient.java:744)
at org.apache.oozie.client.OozieClient$ClientCallable.call(OozieClient.java:479)
at org.apache.oozie.client.OozieClient.getJMSConnectionInfo(OozieClient.java:800)
at com.oozie.jms.OozieJMSClient.main(OozieJMSClient.java:25)
few more info while debug i found that it is trying to call
http://IP:11000/oozie/v2/admin/jmsinfo
Which says 404
when i try to hit in the browser it says
HTTP STATUS 404
The request sent by the client was syntactically incorrect.
one more curious thing for me is as per link
http://oozie.apache.org/docs/4.0.1/WebServicesAPI.html
Admin End-Point
This endpoint is for obtaining Oozie system status and configuration information.
It supports the following sub-resources: status, os-env, sys-props, configuration, instrumentation, systems, available-timezones .
then why /jmsinfo is getting as a rest call ?
please suggest me. Thanks
The above is solved it was my bad. After restart the oozie with correctly updating the notification configuration it is done. Now CDH is also showing those services in the web console.

Resources