我正在将旧的 SpringBoot 2 / Java 8 应用程序迁移到较新的 SpringBoot 3 / Java 17。
我的问题与 Weblogic T3 客户端有关。到目前为止,我使用来自
Weblogic 12.2.1.3安装(由 Java 8 编译)的
wlthint3client
工件,运行没有任何问题。
在新架构中使用相同的工件,基于 SpringBoot 3 / Java 17
new InitialContext(environment)
指令永远卡住!!!
有人可以告诉我是否存在更新版本的 Weblogic 客户端,或者该问题的解决方法吗?
这是使用客户端的代码片段:
public static MyRemoteEJB lookup(
String clusterAddress,
String userName,
String password
)
throws NamingException
{
Properties environment = new Properties();
environment.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
environment.put(Context.PROVIDER_URL, clusterAddress);
if (null != userName) {
environment.put(Context.SECURITY_PRINCIPAL, userName);
}
if (null != password) {
environment.put(Context.SECURITY_CREDENTIALS, password);
}
environment.put("weblogic.jndi.allowExternalAppLookup", "true");
environment.put("weblogic.jndi.relaxVersionLookup", "true");
InitialContext context = new InitialContext(environment);
String resourceName = String.format(
"remote-app#%s",
MyRemoteEJB.class.getName()
);
return (MyRemoteEJB)context.lookup(resourceName);
}
非常感谢!
经过一番努力,终于解决了问题!
我将描述解决方案是什么,以及我如何实现它。
第一步是向我公司提供的 Oracle 支持询问Weblogic 14.1.1.0附带的Jakarta版本的Weblogic T3 Thin Client。
我通过 IntelliJ 内置 java 反编译器对其进行了反编译和调试,以获得足够的信息来激活 T3 客户端调试日志并将其重定向到我的控制台(请查看下面的源代码)。
相关源码在这里:
日志记录属性
handlers=java.util.logging.ConsoleHandler
.level=FINE
java.util.logging.ConsoleHandler.level=FINE
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
Main.java
package org.example;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Properties;
import java.util.logging.Logger;
public class Main {
private static final Logger logger = Logger.getLogger(Main.class.getName());
private static void loggerSetup() {
String pwd = System.getenv("PWD");
System.setProperty(
"java.util.logging.config.file",
(pwd + "/src/main/resources/logging.properties")
);
System.setProperty("com.bea.core.debug.DebugLegacy.stdout", "true");
System.setProperty("weblogic.diagnostics.debug.DebugLogger.DISABLED", "false");
System.setProperty("weblogic.debug.DebugAbbrevs", "true");
System.setProperty("weblogic.debug.DebugAllowList", "true");
//System.setProperty("weblogic.debug.DebugClassLoadingContextualTrace", "true");
//System.setProperty("weblogic.debug.DebugClassLoadingVerbose", "true");
System.setProperty("weblogic.debug.DebugCluster", "true");
System.setProperty("weblogic.debug.DebugClusterVerbose", "true");
System.setProperty("weblogic.debug.DebugConnection", "true");
System.setProperty("weblogic.debug.DebugDGCEnrollment", "true");
System.setProperty("weblogic.debug.DebugFailOver", "true");
System.setProperty("weblogic.debug.DebugGenericMethodDescriptor", "true");
System.setProperty("weblogic.debug.DebugJNDI", "true");
System.setProperty("weblogic.debug.DebugJVMID", "true");
System.setProperty("weblogic.debug.DebugLegacy", "true");
System.setProperty("weblogic.debug.DebugLoadBalancing", "true");
System.setProperty("weblogic.debug.DebugMessaging", "true");
System.setProperty("weblogic.debug.DebugRMIRequestPerf", "true");
System.setProperty("weblogic.debug.DebugRouting", "true");
System.setProperty("weblogic.debug.DebugStubGeneration", "true");
System.setProperty("weblogic.debug.ServerHelp", "true");
}
private static Object lookup(
String clusterAddress,
String userName,
String password
)
throws NamingException
{
Properties environment = new Properties();
environment.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
environment.put(Context.PROVIDER_URL, clusterAddress);
if (null != userName) {
environment.put(Context.SECURITY_PRINCIPAL, userName);
}
if (null != password) {
environment.put(Context.SECURITY_CREDENTIALS, password);
}
environment.put("weblogic.jndi.allowExternalAppLookup", "true");
environment.put("weblogic.jndi.relaxVersionLookup", "true");
InitialContext context = new InitialContext(environment);
String resourceName = String.format(
"remote-app#%s",
MyRemoteEJB.class.getName()
);
return context.lookup(resourceName);
}
public static void main(String[] args) {
loggerSetup();
logger.info("Connecting...");
try {
Object myRemoterEJB = lookup("t3://127.0.0.1:7002", null, null);
if (null != sogeiAdapterEJB) {
logger.info("Remove EJB got!");
}
} catch(NamingException e) {
String message = e.getMessage();
if (message.contains("MyRemoteEJB")) {
logger.info("Remote EJB got, but not marshaled.");
} else {
logger.severe(message);
}
}
}
}
运行它时,我遇到了几个异常,但只有一个真正与我的问题相关:
java.lang.reflect.InaccessibleObjectException: Unable to make private static java.lang.ClassLoader java.io.ObjectInputStream.latestUserDefinedLoader() accessible: module java.base does not "opens java.io" to unnamed module @50675690
上述的根本原因是:
Try to create JVM connection 1 time, encounter : java.io.IOException: Timed out while attempting to establish connection to :t3://127.0.0.1:7002
解决方案是由这篇文章提供的,所以我添加了 JVM 参数:
--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED
所有连接问题都消失了!