当前位置:  开发笔记 > 编程语言 > 正文

混淆了Oracle java存储过程中的类解析

如何解决《混淆了Oraclejava存储过程中的类解析》经验,为你挑选了1个好方法。

我正在尝试在oracle中使用第三方java库.该库似乎有相同的1.4版本的JVM,我们的Oracle 10g服务器主机的兼容,因为它运行Oracle的罚款之外,所以我觉得我应该能得到这个工作.这个库最终使基于SOAP的HTTP请求,我也得到类解析错误,当我在Oracle中运行.

这是一条显示差异的线:

Class msgfact = Class.forName("com.sun.xml.messaging.saaj.soap.MessageFactoryImpl");

我尝试使用loadjava实用程序将这些库注册到Oracle中,我得到了我认为是成功的结果:

C:\>loadjava -verbose -schema MYUSER -user MYUSER/MYPWD@dbinstance -force saaj-impl.jar

看起来所有东西都被加载了,我可以在该列表中看到这个MessageFactoryImpl类.但后来我尝试从Oracle SQL运行这行代码(在我编写的另一个类中并使用loadjava加载),此行抛出一个ClassNotFoundException(java.lang.ClassNotFoundException:com/sun/xml/messaging/saaj/soap/MessageFactoryImpl ).

然后我回去尝试在loadjava命令行添加"-resolve"开关.它就像这些saaj类正在注册,但它们没有正确解析.

如何成功地将这些saaj类放入Oracle中,或者如果由于某种原因Oracle已经加载了这些类,那么如何说服我自己的代码成功使用现有类?

FWIW,我已经采取措施确保授予适当的套接字权限,并且我的代码可以成功地向目标URL发出通用的http请求.它只是在使用库的SOAP栈来实现它时遇到了麻烦.

编辑:这是我的loadjava结果的示例.这似乎正好显示了什么是失败的,但我很困惑为什么这些特定类在解决前步骤中似乎得到正确处理时没有得到解决.我在这里删除了大约80%的文件,但还有其他类显示相同的类解决问题.

arguments: '-verbose' '-schema' 'MYSCHEMA' '-user' 'MYSCHEMA/MYSCHEMA@actest' '-resolve' '-force' 'saaj-impl.jar' 
[snip]
creating : class MYSCHEMA.com/sun/xml/messaging/saaj/soap/EnvelopeFactory
loading  : class MYSCHEMA.com/sun/xml/messaging/saaj/soap/EnvelopeFactory
creating : class MYSCHEMA.com/sun/xml/messaging/saaj/soap/GifDataContentHandler
loading  : class MYSCHEMA.com/sun/xml/messaging/saaj/soap/GifDataContentHandler
creating : class MYSCHEMA.com/sun/xml/messaging/saaj/soap/JpegDataContentHandler
loading  : class MYSCHEMA.com/sun/xml/messaging/saaj/soap/JpegDataContentHandler
creating : class MYSCHEMA.com/sun/xml/messaging/saaj/soap/MessageFactoryImpl
loading  : class MYSCHEMA.com/sun/xml/messaging/saaj/soap/MessageFactoryImpl
creating : class MYSCHEMA.com/sun/xml/messaging/saaj/soap/MessageImpl
loading  : class MYSCHEMA.com/sun/xml/messaging/saaj/soap/MessageImpl
[snip]
resolving: class MYSCHEMA.com/sun/xml/messaging/saaj/soap/AttachmentPartImpl
resolving: class MYSCHEMA.com/sun/xml/messaging/saaj/soap/Envelope
resolving: class MYSCHEMA.com/sun/xml/messaging/saaj/soap/EnvelopeFactory
errors   : class MYSCHEMA.com/sun/xml/messaging/saaj/soap/EnvelopeFactory
    ORA-29534: referenced object MYSCHEMA.com/sun/xml/messaging/saaj/soap/SOAPPartImpl could not be resolved
resolving: class MYSCHEMA.com/sun/xml/messaging/saaj/soap/GifDataContentHandler
resolving: class MYSCHEMA.com/sun/xml/messaging/saaj/soap/JpegDataContentHandler
resolving: class MYSCHEMA.com/sun/xml/messaging/saaj/soap/MessageFactoryImpl
errors   : class MYSCHEMA.com/sun/xml/messaging/saaj/soap/MessageFactoryImpl
    ORA-29534: referenced object MYSCHEMA.com/sun/xml/messaging/saaj/soap/MessageImpl could not be resolved
errors   : class MYSCHEMA.com/sun/xml/messaging/saaj/soap/MessageImpl
    ORA-29534: referenced object MYSCHEMA.com/sun/xml/messaging/saaj/soap/impl/EnvelopeImpl could not be resolved
errors   : class MYSCHEMA.com/sun/xml/messaging/saaj/soap/MessageImpl$1
    ORA-29534: referenced object MYSCHEMA.com/sun/xml/messaging/saaj/soap/MessageImpl could not be resolved
skipping : class MYSCHEMA.com/sun/xml/messaging/saaj/soap/MessageImpl$2
[snip]
The following operations failed
    class MYSCHEMA.com/sun/xml/messaging/saaj/soap/EnvelopeFactory: resolution
    class MYSCHEMA.com/sun/xml/messaging/saaj/soap/MessageFactoryImpl: resolution
    class MYSCHEMA.com/sun/xml/messaging/saaj/soap/MessageImpl: resolution
    class MYSCHEMA.com/sun/xml/messaging/saaj/soap/MessageImpl$1: resolution
[snip]
exiting  : Failures occurred during processing

Dave Costa.. 9

首先,在Oracle之外验证您要查找的类实际上是在该jar文件中.我希望它是,但检查没有坏处.

然后,我会检查已加载的类以及它们是否具有有效状态.

SELECT object_name, dbms_java.longname(object_name), status
  FROM user_objects
  WHERE object_type='JAVA CLASS'
  ORDER BY 1

如果有很多类,你可能想要稍微限制一下,例如:

WHERE dbms_java.longname(object_name) LIKE '%MessageFactoryImpl'

如果该类不存在,或者它的包名错误,那么问题在于loadjava命令.

如果该类存在但其状态为INVALID,则检查USER_ERRORS以查看错误是什么.我不记得我是否在Oracle中完成了动态类加载,但我记得静态链接会产生错误,这意味着当一个类确实存在但是有错误时它不存在.

发布loadjava输出后的新信息

loadjava输出似乎与您在数据库中查找类的尝试不一致.如果正在加载但未解决,则仍应列出,但处于INVALID状态.

我得到了JAR并在一个空架构中自己尝试了.类加载但是按预期无效:

dev> select object_name, dbms_java.longname(object_name),status
  2  from user_objects
  3  where object_name like '%MessageFactoryImpl';

OBJECT_NAME
--------------------------------------------------------------------------------
DBMS_JAVA.LONGNAME(OBJECT_NAME)
--------------------------------------------------------------------------------
STATUS
-------
/3e484eb0_MessageFactoryImpl
com/sun/xml/messaging/saaj/soap/MessageFactoryImpl
INVALID

然后我检查了课程中的错误:

dev> alter java class "com/sun/xml/messaging/saaj/soap/MessageFactoryImpl" resolve;
dev> /

Warning: Java altered with compilation errors.

dev> show error
Errors for JAVA CLASS "/3e484eb0_MessageFactoryImpl":

LINE/COL ERROR
-------- -----------------------------------------------------------------
0/0      ORA-29521: referenced name javax/xml/soap/MessageFactory could
         not be found

0/0      ORA-29521: referenced name javax/xml/soap/SOAPMessage could not
         be found

0/0      ORA-29521: referenced name javax/xml/soap/MimeHeaders could not
         be found

0/0      ORA-29521: referenced name javax/xml/soap/SOAPException could not
         be found

(这些错误也会列在USER_ERRORS中,假设至少尝试过一次.)

很明显,这个类引用了基本SOAP库中的类.你也必须加载 - 你做到了吗?

仅供参考,当我编写一些代码来进行Class.forName()调用时,我确实得到了ClassNotFoundException.这可能看起来违反直觉,因为类对象确实存在于模式中.但是,从Oracle中的类加载器的角度来看,无效的类实际上并不"存在"; 为了使类有效,Oracle必须能够解析其对所有类的引用.



1> Dave Costa..:

首先,在Oracle之外验证您要查找的类实际上是在该jar文件中.我希望它是,但检查没有坏处.

然后,我会检查已加载的类以及它们是否具有有效状态.

SELECT object_name, dbms_java.longname(object_name), status
  FROM user_objects
  WHERE object_type='JAVA CLASS'
  ORDER BY 1

如果有很多类,你可能想要稍微限制一下,例如:

WHERE dbms_java.longname(object_name) LIKE '%MessageFactoryImpl'

如果该类不存在,或者它的包名错误,那么问题在于loadjava命令.

如果该类存在但其状态为INVALID,则检查USER_ERRORS以查看错误是什么.我不记得我是否在Oracle中完成了动态类加载,但我记得静态链接会产生错误,这意味着当一个类确实存在但是有错误时它不存在.

发布loadjava输出后的新信息

loadjava输出似乎与您在数据库中查找类的尝试不一致.如果正在加载但未解决,则仍应列出,但处于INVALID状态.

我得到了JAR并在一个空架构中自己尝试了.类加载但是按预期无效:

dev> select object_name, dbms_java.longname(object_name),status
  2  from user_objects
  3  where object_name like '%MessageFactoryImpl';

OBJECT_NAME
--------------------------------------------------------------------------------
DBMS_JAVA.LONGNAME(OBJECT_NAME)
--------------------------------------------------------------------------------
STATUS
-------
/3e484eb0_MessageFactoryImpl
com/sun/xml/messaging/saaj/soap/MessageFactoryImpl
INVALID

然后我检查了课程中的错误:

dev> alter java class "com/sun/xml/messaging/saaj/soap/MessageFactoryImpl" resolve;
dev> /

Warning: Java altered with compilation errors.

dev> show error
Errors for JAVA CLASS "/3e484eb0_MessageFactoryImpl":

LINE/COL ERROR
-------- -----------------------------------------------------------------
0/0      ORA-29521: referenced name javax/xml/soap/MessageFactory could
         not be found

0/0      ORA-29521: referenced name javax/xml/soap/SOAPMessage could not
         be found

0/0      ORA-29521: referenced name javax/xml/soap/MimeHeaders could not
         be found

0/0      ORA-29521: referenced name javax/xml/soap/SOAPException could not
         be found

(这些错误也会列在USER_ERRORS中,假设至少尝试过一次.)

很明显,这个类引用了基本SOAP库中的类.你也必须加载 - 你做到了吗?

仅供参考,当我编写一些代码来进行Class.forName()调用时,我确实得到了ClassNotFoundException.这可能看起来违反直觉,因为类对象确实存在于模式中.但是,从Oracle中的类加载器的角度来看,无效的类实际上并不"存在"; 为了使类有效,Oracle必须能够解析其对所有类的引用.

推荐阅读
pan2502851807
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有