maven 将Weblogic T3 RMI客户端移植到Java 17

7y4bm7vi  于 2023-10-17  发布在  Maven
关注(0)|答案(2)|浏览(149)

我正在将旧的SpringBoot 2 / Java 8应用程序迁移到更新的SpringBoot 3 / Java 17
我的问题与Weblogic T3客户端有关。到目前为止,我使用的wlthint3client工件来自Weblogic 12.2.1.3安装(由Java 8编译),运行时没有任何问题。
在新架构中使用相同的工件,基于SpringBoot 3 / Java 17new 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);
}

太感谢你了!

ukdjmx9f

ukdjmx9f1#

经过一番努力,我终于解决了这个问题!
我将描述解决方案是什么,以及我是如何实现它的。
第一步是向我的公司提供的Oracle支持人员询问Weblogic 14.1.1.0附带的Weblogic T3瘦客户机雅加达版本。
我通过IntelliJ内置的java反编译器对它进行了反编译和调试,以获得足够的信息来激活并将T3客户端调试日志重定向到我的控制台(请查看下面的源代码)。
下面是相关的源代码:

logging.properties

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

解决方案由this post提供,因此我添加了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

所有的连接问题都解决了!!!

2sbarzqh

2sbarzqh2#

谢谢,我也遇到了同样的错误。添加以下标志有助于:

--add-opens=java.base/java.io=ALL-UNNAMED

很高兴知道如何启动和运行日志记录。

相关问题