Liferay OSGi bundle deploy with FirebirdSQL jdbc driver error - liferay

I am new to Liferay 7.x and am having trouble with, I suspect, OSGI.
I am trying to write an DB Authenticator which just checks for users in a separate DB. The DB is a FirebirdSQL DB.
When setting the depenency in build.gradle like this
compileInclude group: 'org.firebirdsql.jdbc', name: 'jaybird', version: '4.0.9.java11'
The error I get when the bundle tries to deploy is:
2023-02-14 01:52:59.128 ERROR [fileinstall-directory-watcher][DirectoryWatcher:1173] Unable to start bundle: file:/home/me/Documents/IdeaProjects/liferay/labsys-authentication/bundles/osgi/modules/com.myapp.intranet.auth-1.0.0.jar
com.liferay.portal.kernel.log.LogSanitizerException: org.osgi.framework.BundleException: Could not resolve module: com.myapp.intranet.auth [1591]_ Unresolved requirement: Import-Package: com.sun.jna_ [Sanitized]
at org.eclipse.osgi.container.Module.start(Module.java:444) ~[org.eclipse.osgi.jar:?]
at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:428) ~[org.eclipse.osgi.jar:?]
at com.liferay.portal.file.install.internal.DirectoryWatcher._startBundle(DirectoryWatcher.java:1156) [bundleFile:?]
at com.liferay.portal.file.install.internal.DirectoryWatcher._startBundles(DirectoryWatcher.java:1189) [bundleFile:?]
at com.liferay.portal.file.install.internal.DirectoryWatcher._startAllBundles(DirectoryWatcher.java:1130) [bundleFile:?]
at com.liferay.portal.file.install.internal.DirectoryWatcher._process(DirectoryWatcher.java:1041) [bundleFile:?]
at com.liferay.portal.file.install.internal.DirectoryWatcher.run(DirectoryWatcher.java:247) [bundleFile:?]
I have looked at
https://liferay.dev/blogs/-/blogs/osgi-module-dependencies and
https://liferay.dev/blogs/-/blogs/gradle-compile-vs-compileonly-vs-compileinclude
and tried option 1 (adding the DB driver in tomcats lib dir), and that still did not seem to work (in that case, the driver can't be found).
Just not sure how to include the Firebird jdbc driver in an OSGi bundle... of if I have to add any transitive dependencies (and if so, how do I know what they are and how do I best add them).
Just wondering if anyone has deployed a Firebird JDBC driver in a Liferay service app.

The important part of the error is "Unresolved requirement: Import-Package: com.sun.jna_ [Sanitized]". Jaybird itself doesn't provide OSGi metadata. I have no experience with OSGi, but I guess due to the lack of metadata, it scans the class files and notices that Jaybird uses JNA and that there is no dependency providing JNA. In practice this is a optional dependency of Jaybird (you only need it if you use native or embedded connections, which are not the default), but OSGi isn't aware of that and requires that you declare it.
Adding the dependency with compileInclude 'net.java.dev.jna:jna:5.5.0' to your build.gradle should do the trick.
(NOTE: This answer is based on my earlier comment and the comment by cfnz)

Related

Not able to connect to Cassandra from my spring boot application , throwing exception as couldn't reach any contact-point [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 20 days ago.
Improve this question
added config file to take contact-point programatically
#Bean(destroyMethod = "close")
public CqlSession session() {
CqlSession session = CqlSession.builder()
.addContactPoint(InetSocketAddress.createUnresolved("[240b:c0e0:1xx:xxx8:xxxx:x:x:x]", port))
.withConfigLoader(
DriverConfigLoader.programmaticBuilder()
.withString(DefaultDriverOption.LOAD_BALANCING_LOCAL_DATACENTER, localDatacenter) .withString(DefaultDriverOption.AUTH_PROVIDER_USER_NAME,username)
.withString(DefaultDriverOption.AUTH_PROVIDER_PASSWORD,password)
.withString(DefaultDriverOption.CONNECTION_INIT_QUERY_TIMEOUT,"10s")
.withString(DefaultDriverOption.CONNECTION_CONNECT_TIMEOUT, "20s")
.withString(DefaultDriverOption.REQUEST_TIMEOUT, "20s")
.withString(DefaultDriverOption.CONTROL_CONNECTION_TIMEOUT, "20s")
.withString(DefaultDriverOption.SESSION_KEYSPACE,keyspace)
.build())
//.addContactPoint(InetSocketAddress.createUnresolved(InetAddress.getByName(contactPoints).getHostName(), port))
.build();
}
return session;
`Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.datastax.oss.driver.api.core.CqlSession]: Factory method 'cassandraSession' threw exception with message: Since you provided explicit contact points, the local DC must be explicitly set (see basic.load-balancing-policy.local-datacenter in the config, or set it programmatically with SessionBuilder.withLocalDatacenter). Current contact points are: Node(endPoint=/127.0.0.1:9042, hostId=0323221f-9a0f-ec92-ea4a-c1472c2a8b94, hashCode=39075b16)=datacenter1. Current DCs in this cluster are: datacenter1
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:171) ~[spring-beans-6.0.2.jar:6.0.2]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:648) ~[spring-beans-6.0.2.jar:6.0.2]
... 89 common frames omitted
Caused by: java.lang.IllegalStateException: Since you provided explicit contact points, the local DC must be explicitly set (see basic.load-balancing-policy.local-datacenter in the config, or set it programmatically with SessionBuilder.withLocalDatacenter). Current contact points are: Node(endPoint=/127.0.0.1:9042, hostId=0323221f-9a0f-ec92-ea4a-c1472c2a8b94, hashCode=39075b16)=datacenter1. Current DCs in this cluster are: datacenter1
at com.datastax.oss.driver.internal.core.loadbalancing.helper.MandatoryLocalDcHelper.discoverLocalDc(MandatoryLocalDcHelper.java:91) ~[java-driver-core-4.11.4-yb-1-RC1.jar:na]
at com.datastax.oss.driver.internal.core.loadbalancing.DefaultLoadBalancingPolicy.discoverLocalDc(DefaultLoadBalancingPolicy.java:119) ~[java-driver-core-4.11.4-yb-1-RC1.jar:na]
at
this is the application.yml file
spring:
data:
cassandra:
keyspace-name: xxx
contact-points: [xxxx:xxxx:xxxx:xxx:xxx:xxx]
port: xxx
local-datacenter: xxxx
use-dc-aware: true
username: xxxxx
password: xxxxx
ssl: true
SchemaAction: CREATE_IF_NOT_EXISTS
but still the application is pointing towards the localhost , even though i've explicitly mentioned the contact-points and localDC
logs of stg evn are :
caused by: com.datastax.oss.driver.api.core.AllNodesFailedException: Could not reach any contact point, make sure you've provided valid addresses (showing first 1 nodes, use getAllErrors() for more): Node (endPoint=/[240b:cOe0:102:xxxx:xxxx:x:x:x]:3xxx,hostId-null,hashCode=4e9ba6a8):[com.datastax.oss.driver.api.core.connection.ConnectionInitException:[s0|controllid:0x984419ed,L:/[240b:cOe0:102:5dd7:
xxxx:x:x:xxx]:4xxx - R:/[240b:c0e0:102:xxxx:xxxx:x:x:x]:3xxx] Protocol initialization request,
step 1 (OPTIONS: unexpected tarlure com.datastax.oss.driver.apt.core.connection.closedconnectiontxception:
Lost connection to remote peer)]
thanks for the question!
I'll try to provide some pointers that might help you identify the problem but it should be noted that you appear to have some non-standard elements to your application. Specifically I note that "java-driver-core-4.11.4-yb-1-RC1.jar" isn't a Java driver artifact released by DataStax (there isn't even a 4.11.4 Java driver release). This could be relevant for reasons we'll get into in a moment. I also don't recognize the configuration file you cite above. Could you provide some more detail on how your app is configured? At first blush it looked as though you might be using spring-data-cassandra but there wasn't any mention of it in your stack trace... so perhaps you're using some kind of custom configuration code?
As to your specific question: my guess is that you might have a Java driver configuration file in your staging environment which is providing a default value for "datastax-java-driver.basic.contact-points". The 4.x Java driver is configured via the Lightbend Config library. Most relevant to our case it searches for a set of configuration files with various default names on the classpath; these files are then merged together to generate the config passed to the driver. So if you have an application.conf in staging which specifies some contact points and is in the classpath the code you cite above would run fine in your local environment but fail in staging.
To validate this, create an application.conf file in your local environment in src/main/resources (or somewhere else that's explicitly included in the classpath) and give it the following contents:
datastax-java-driver {
basic {
contact-points: ["127.0.0.1:9042"]
}
}
If you then re-run the app in your local environment you should see the error there as well.
Note that the core Java driver JAR already includes a reference.conf file which serves as a default configuration. Here's where the part about a custom JAR figures in; because your not using a standard DataStax Java driver JAR I don't know if you're using the standard reference.conf file defined within that JAR. It's possible that the contact points are defined in that file, although if that were the case I'd expect you to already be seeing the error in any environment where you use that JAR.
One final note: the Java driver should be fine with IPv6 addresses. The issue described above isn't related to IPv6; it's entirely a function of how you're using the Java driver's configuration mechanism.
Hopefully some of the above is helpful!

.NET Core Keyword not supported: 'server'

The sample application on the following page does not start.
https://learn.microsoft.com/en-us/azure/app-service/tutorial-dotnetcore-sqldb-app?pivots=platform-linux
https://github.com/azure-samples/dotnetcore-sqldb-tutorial
As stated in the documentation
After downloading the sample application and creating the DataBase to connect to, an error will occur when the database migration is executed.
$ export ConnectionStrings__MyDbConnection="Server=tcp:db-host.database.windows.net,1433;Database=coreDB;User ID=<username>;Password=<password>;Encrypt=true;Connection Timeout=30;"
$ dotnet ef database update
Build started...
Build succeeded.
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 3.1.3 initialized 'MyDatabaseContext' using provider 'Microsoft.EntityFrameworkCore.Sqlite' with options: None
System.ArgumentException: Keyword not supported: 'server'.
at Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.GetIndex(String keyword)
at Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.set_Item(String keyword, Object value)
at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value)
at Microsoft.Data.Sqlite.SqliteConnectionStringBuilder..ctor(String connectionString)
at Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteDatabaseCreator.Exists()
at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Keyword not supported: 'server'.
Do you know the cause?
I'm using .NET Core 3.1.
If your intention is really use SQLite then you should check this patterns of connections string:
https://learn.microsoft.com/en-us/dotnet/standard/data/sqlite/connection-strings
If not, your code is accidentally calling the SQLite extension to configure your DbContext... Do a full search (Ctrl+Shift+F) in the entire solution for UseSqlite method and replace it for the desired database provider extension (probably will require a new package reference to your project)
The cause was that SQlite was specified where SQL server should be specified.
services.AddDbContext<MyDatabaseContext>(options =>
options. UseSqlite(Configuration.GetConnectionString("MyDbConnection")));
services.AddDbContext<MyDatabaseContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("MyDbConnection")));
Thank you for your cooperation.

Duplicating debug configuration for multi Scheme is not working in React native-iOS

I've developed my project using react native, and now I am trying to implement multi-scheme for my dev, uat, and prod environments.
For the above, I've setup schemes and duplicated the release and debug configuration for each one of the scheme, and specified the different bundle ids, different app names, user defined variables. Now my situation is if I am running the scheme locally( as for run the debug configuration is set) then I'm falling into the below error:
Thread 6: "Unhandled JS Exception: Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'DevSettings' could not be found. Verify that a module by this name is registered in the na..., stack:\ngetEnforcing#4725:28\n#41349:50\nloadModuleImplementation#271:14\n#41308:40\nloadModuleImplementation#271:14\n#35877:18\nloadModuleImplementation#271:14\n#28987:16\nloadModuleImplementation#271:14\nguardedLoadModule#163:47\nglobal code#326655:4\n"
Terminating app due to uncaught exception 'RCTFatalException: Unhandled JS Exception: Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'DevSettings' could not be found. Verify that a module by this name is registered in the native binary.', reason: 'Unhandled JS Exception: Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'DevSettings' could not be found. Verify that a module by this name is registered in the na..., stack:
*** I've attached screenshot of my Development scheme setting where I've used release build config(Development) and debug build config(DevelopmentDebug)
Check this image
FYI:
If I choose release build configuration for Run, Test and Analyse and run the scheme then it is working fine, but in this case I can't use debugger for my development purpose.
Also, I don't have any issues with archiving or releasing the archive to testflight using CICD, as I've selected the release configuration for Archive and Profile under the scheme setting.
Please help me out, as this will make the development very difficult, as I don't have access to the debugger window.
Looking forward to get positive help.
Thanks
(: Please try to add some logs that would be very helpful

Hazelcast not injecting spring dependencies

I'm using hazelcast 3.8.5 as the store for jcache.
It appears hazelcast is not injecting SpringAware dependencies into the CacheLoader.
I took a peek at AbstractCacheRecordStore and it seems like only Hazelcast InstanceAware dependencies are injected, not SpringAware + Autowired
I'm setting up the cluster managedContext programatically like:
config.setManagedContext(springManagedContext);
Update
A work around I've found is put the ApplicationContext into the UserContext of hazelcast. Make the CacheLoader implement HazelcastInstanceAware. Pull the context out of there and finish autowiring the CacheLoader. Not ideal, but it works.
Created https://github.com/hazelcast/hazelcast/issues/11384
Only work around is getting spring app context out of hazelcast user context.

Getting No such algorithm exception while using TLSV1.2 in java 1.4

I am trying to hit a webservice which supports TLSv1.2. I am using Java 1.4. It does not support TLSv1.2.
Now someone told me that BC could solve my problem.
Though does it work with a SSLEngine as drop in replacement somehow?
Is this possible with BC?
What do I have to do to get a working SSLEngine (for use with TLSv1 in a
nonblocking io scenario) without such low restrictions on primesize for DH.
What I tried:
Security.addProvider(new BouncyCastleProvider());
This alone seems not to solve the problem.
So instead of
SSLContext.getInstance("TLSv1"); //which works alas only little DH keys.
I tried calling the following:
SSLContext.getInstance("TLSv1","BC");
SSLContext.getInstance("TLS","BC");
SSLContext.getInstance("TLSv1.2","BC");
SSLContext.getInstance("ssl","BC");
Though all of them throws NoSuchAlgorithmException.
I could solve this by using bctls lib, but unfortunatelly it doesn't seem to have a version for Java 1.4.
The only version that I could find in Bouncy Castle's website and in Mvn Repository is bctls-jdk15on-157 (for Java >= 1.5).
Anyway, if an upgrade of your Java version is possible, you just need to add this jar to your project and use the org.bouncycastle.jsse.provider.BouncyCastleJsseProvider class (I've used Java 1.7 for this test):
// add the JSSE provider
Security.addProvider(new BouncyCastleJsseProvider());
// tests
SSLContext.getInstance("TLSv1.1", BouncyCastleJsseProvider.PROVIDER_NAME);
SSLContext.getInstance("TLSv1.2", BouncyCastleJsseProvider.PROVIDER_NAME);
SSLContext.getInstance("TLSv1", BouncyCastleJsseProvider.PROVIDER_NAME);
All tests above run without error.
Checking all the SSL protocols supported:
SSLContext context = SSLContext.getInstance("TLSv1", BouncyCastleJsseProvider.PROVIDER_NAME);
System.out.println(Arrays.toString(context.getSupportedSSLParameters().getProtocols())); // [TLSv1.1, TLSv1, TLSv1.2]
The output is:
[TLSv1.1, TLSv1, TLSv1.2]

Resources