簡體   English   中英

如何使用Scala REPL測試Java代碼-Java和Scala REPL提供不同的輸出

[英]How can I use the Scala REPL to test java code - java and scala REPL giving different outputs

我正在嘗試使用REPL測試我的Java代碼。 我已經設置了類路徑並啟動了REPL,並且可以在REPL中訪問我的應用程序類。

我啟動了一個方法,該方法進行Web服務調用,並引發java.lang.ClassCastException。 我編寫了一個Java程序,該程序與在REPL中輸入的一系列命令具有相同的功能,並使用相同的類路徑運行它,它運行時沒有問題並給出了結果。

關於它為什么不在scala下運行的任何線索? 在scala中強制轉換的規則是否嚴格?如果我使用的API無法控制我如何讓Scala表現得像Java,那么我可以測試進行大量API調用的方法,其他人編寫的代碼。

java.lang.ClassCastException: weblogic.webservice.encoding.ImageCodec cannot be cast to weblogic.xml.schema.binding.Serializer
        at weblogic.xml.schema.binding.internal.XSDTypeMapping.addOptionalEntries(XSDTypeMapping.java:762)
        at weblogic.xml.schema.binding.internal.XSDTypeMapping.createOptionalMapping(XSDTypeMapping.java:665)
        at weblogic.xml.schema.binding.internal.XSDTypeMapping.createPrimaryMapping(XSDTypeMapping.java:655)
        at weblogic.xml.schema.binding.internal.XSDTypeMapping.createInstance(XSDTypeMapping.java:138)
        at weblogic.xml.schema.binding.internal.XSDTypeMapping.<clinit>(XSDTypeMapping.java:118)
        at weblogic.xml.schema.binding.internal.TypeMappingFactoryBase.createDefaultMapping(TypeMappingFactoryBase.java:18)
        at weblogic.webservice.core.encoding.DefaultRegistry.<init>(DefaultRegistry.java:110)
        at weblogic.webservice.core.encoding.DefaultRegistry.<init>(DefaultRegistry.java:37)
        at weblogic.webservice.core.rpc.ServiceImpl.<init>(ServiceImpl.java:91)

由於許多人都要求源代碼來回答這個問題,因此這是我在scala REPL中輸入的代碼段。 它使API調用受版權保護,並且不能在此處共享。我可以回答問題以提供有關此問題的更多信息,而不會違反規范。

val clientManager=new ClientManager()
val client=clientManager.getClient(<clientId>)
/*client location is stored in another system which exposes its data as a webservice.
 We use weblogic tools to compile the WSDL to create client (Web service client, not to
 be confused with the client object which represent a customer) to access the system
 hosting the data*/
val res=client.getLocation //exception is thrown at this line where a web-service call is made

我做了一些不同的事情,這次我得到了完全不同的異常,而不是使用val res=client.getLocation我沒有將client.getLocation分配給變量,而這次拋出的異常是

java.lang.NoClassDefFoundError: Could not initialize class weblogic.xml.schema.binding.internal.XSDTypeMapping
        at weblogic.xml.schema.binding.internal.TypeMappingFactoryBase.createDefaultMapping(TypeMappingFactoryBase.java:18)
        at weblogic.webservice.core.encoding.DefaultRegistry.<init>(DefaultRegistry.java:110)
        at weblogic.webservice.core.encoding.DefaultRegistry.<init>(DefaultRegistry.java:37)
        at weblogic.webservice.core.rpc.ServiceImpl.<init>(ServiceImpl.java:91)

我用-nobootcp選項運行了解釋器,並且沒有拋出任何異常,但在兩種情況下我得到的結果都是null

是否有人使用Scala REPL測試從weblogic 10.3生成的存根編寫的客戶端,並成功使用了它?

您的堆棧跟蹤與Scala無關。 某些WebLogic代碼中深處發生了異常。 您為什么認為Scala引起了問題? 最可能的原因是庫中的不匹配,例如,您在Scala測試中使用的類路徑與Java測試中使用的類路徑不同。

不過,我將嘗試回答您的隱式問題:對於可以在Java和Scala中等效表示的引用類型,Scala的轉換規則與Java相同。

沒有代碼,很難說是怎么回事。 但是...由於您提到要啟動Web服務,所以我猜您正在使用Scala遠程角色。

start actor之前,請嘗試執行classLoader = getClass().getClassLoader()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM