Skip to content

Commit c175966

Browse files
authored
5838 WLS JMS Object-Based Security (helidon-io#5852)
* 5839 Load JMSException with thin client classloader
1 parent 1dfee15 commit c175966

4 files changed

Lines changed: 23 additions & 9 deletions

File tree

docs/mp/reactivemessaging/weblogic.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ Weblogic installation.
4747
WARNING: Avoid placing `wlthint3client.jar` on Helidon classpath, client library location needs to be
4848
configured and loaded by Helidon messaging connector.
4949
50+
WARNING: Don't forget to start your Helidon app with `--add-opens=java.base/java.io=ALL-UNNAMED` to allow
51+
wlthint3client use reflection.
52+
5053
=== Configuration
5154
5255
Connector name: `helidon-weblogic-jms`

messaging/connectors/jms/src/main/java/io/helidon/messaging/connectors/jms/ConnectionContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -111,7 +111,7 @@ private Object lookup(String jndi) {
111111
try {
112112
return ctx.lookup(jndi);
113113
} catch (NamingException e) {
114-
LOGGER.log(Level.FINE, e, () -> "JNDI lookup of " + jndi + " failed");
114+
LOGGER.log(Level.WARNING, e, () -> "JNDI lookup of " + jndi + " failed");
115115
return null;
116116
}
117117
}

messaging/connectors/wls-jms/src/main/java/io/helidon/messaging/connectors/wls/IsolatedContextFactory.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818
import java.lang.reflect.Constructor;
1919
import java.lang.reflect.InvocationTargetException;
2020
import java.util.Hashtable;
21+
import java.util.Optional;
2122

2223
import javax.naming.Context;
2324
import javax.naming.NamingException;
@@ -28,23 +29,26 @@
2829
*/
2930
public class IsolatedContextFactory implements InitialContextFactory {
3031

31-
private static final String WLS_INIT_CTX_FACTORY = "weblogic.jndi.WLInitialContextFactory";
32+
private static final String WLS_INIT_CTX_FACTORY_DEFAULT = "weblogic.jms.WLInitialContextFactory";
3233

3334
@Override
3435
public Context getInitialContext(Hashtable<?, ?> env) throws NamingException {
3536
return ThinClientClassLoader.executeInIsolation(() -> {
37+
String wlsInitFactoryClass =
38+
Optional.ofNullable((String) env.get("wls-init-ctx-factory"))
39+
.orElse(WLS_INIT_CTX_FACTORY_DEFAULT);
3640
try {
37-
Class<?> wlInitialContextFactory = ThinClientClassLoader.getInstance().loadClass(WLS_INIT_CTX_FACTORY);
41+
Class<?> wlInitialContextFactory = ThinClientClassLoader.getInstance().loadClass(wlsInitFactoryClass);
3842
Constructor<?> contextFactoryConstructor = wlInitialContextFactory.getConstructor();
3943
InitialContextFactory contextFactoryInstance = (InitialContextFactory) contextFactoryConstructor.newInstance();
4044
return contextFactoryInstance.getInitialContext(env);
4145
} catch (ClassNotFoundException e) {
42-
throw new RuntimeException("Cannot find " + WLS_INIT_CTX_FACTORY, e);
46+
throw new RuntimeException("Cannot find " + wlsInitFactoryClass, e);
4347
} catch (NoSuchMethodException
4448
| InvocationTargetException
4549
| InstantiationException
4650
| IllegalAccessException e) {
47-
throw new RuntimeException("Cannot instantiate " + WLS_INIT_CTX_FACTORY, e);
51+
throw new RuntimeException("Cannot instantiate " + wlsInitFactoryClass, e);
4852
}
4953
});
5054
}

messaging/connectors/wls-jms/src/main/java/io/helidon/messaging/connectors/wls/ThinClientClassLoader.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -57,7 +57,9 @@ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundE
5757
try {
5858
return super.loadClass(name, resolve);
5959
} catch (ClassNotFoundException e) {
60-
LOGGER.log(TRACE, "Cannot load class " + name + " from WLS thin client classloader.", e);
60+
LOGGER.log(TRACE, () -> "Cannot load class "
61+
+ name
62+
+ " from WLS thin client classloader, delegating to ctx classloader.", e);
6163
contextClassLoader.loadClass(name);
6264
}
6365
}
@@ -94,6 +96,11 @@ static <T> T executeInIsolation(IsolationSupplier<T> supplier) {
9496
}
9597

9698
boolean inWlsJar(String name) {
99+
// Load jms exceptions from inside the thin jar to avoid deserialization issues
100+
if (name.startsWith("javax.jms") && name.endsWith("Exception")) {
101+
return true;
102+
}
103+
97104
// Load only javax JMS API from outside, so cast works
98105
return !name.startsWith("javax.jms")
99106
&& !name.equals(IsolatedContextFactory.class.getName());

0 commit comments

Comments
 (0)