Hello Karaf users,
Short summary: eBay SDK stops with "NoClassDefFoundError: Could not
initialize class" when it tries to initialize a JAX WS service.
I use karaf 3.0.3 on arch linux with the Oracle 7 JDK
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
I created an OSGi bundle from the eBay SDK source and it deployed
nicely (generated MANIFEST.MF is at the end of this mail).
Unfortunetely, when I use the eBay SDK classes I get a
"NoClassDefFoundError: Could not initialize class":
org.osgi.framework.BundleException: Activator start error in bundle
my.ebay.demo [83]. at
org.apache.felix.framework.Felix.activateBundle(Felix.java:2196)[org.apache.felix.framework-4.2.1.jar:]
at
org.apache.felix.framework.Felix.startBundle(Felix.java:2064)[org.apache.felix.framework-4.2.1.jar:]
at
org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)[org.apache.felix.framework-4.2.1.jar:]
at
org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1245)[7:org.apache.felix.fileinstall:3.4.2]
at
org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1217)[7:org.apache.felix.fileinstall:3.4.2]
at
org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1207)[7:org.apache.felix.fileinstall:3.4.2]
at
org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:504)[7:org.apache.felix.fileinstall:3.4.2]
at
org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:358)[7:org.apache.felix.fileinstall:3.4.2]
at
org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:310)[7:org.apache.felix.fileinstall:3.4.2]
Caused by: java.lang.NoClassDefFoundError: Could not initialize class
com.ebay.sdk.SdkAPIInterfaceServiceLocator at
com.ebay.sdk.ApiCall.executeByApiName(ApiCall.java:594) at
com.ebay.sdk.ApiCall.execute(ApiCall.java:348) at
com.ebay.sdk.call.GeteBayOfficialTimeCall.geteBayOfficialTime(GeteBayOfficialTimeCall.java:63)
at my.ebay.demo.Activator.start(Activator.java:29) at
org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:645)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2146) ...
8 more
The code I ran is a HelloWorld style sample from the SDK I adapted into
an OSGi bundle activator (code is at the end of this mail).
I traced the problem to the static initializer inside the
SdkAPIInterfaceServiceLocator where an constructor is called for an
eBay object (EBayAPIInterfaceService) object gets called [1]. This
object extends javax.xml.ws.Service and also does static initializer
magic [2].
My first question is: Am I correct that I don't get a "proper"
exception of what the actual problem is due to the classes' static
initializer? (On several occasions I have read that they're a bad
practice in OSGi)
When I step debug through the class initializers of
SdkAPIInterfaceServiceLocator and EBayAPIInterfaceService I can see
that they resolve different location URLs for the WSDL:
SdkAPIInterfaceServiceLocator was resolving to a bundle URL just fine
(e.g. bundle://83.12:1/eBaySvc.wsdl), but EBayAPIInterfaceService's URL
resolved to null. Changing one line to get the WSDL
through .class.getResource("/eBaySvc.wsdl") made it resolve to the same
URL as SdkAPIInterfaceServiceLocator. But there still is the
"hard-wired" URL in the wsdlLocation property of @WebServiceClient in
EBayAPIInterfaceService. One comment on stackoverlow [3] states that it
"is only a logical path and can be ignored at runtime".
So my second questions, whether the wsdlLocation in the attribute may
be a problem here.
Also, am I overlooking a proper way to debug the static initializers?
Or is it a problem with SPI to find the proper implementation of the
service? [4]
I'm pretty stumped, since I can't figure out the exact problem. Sorry
if this is mail so long and vague. Thanks for any insights into the
matter!
Best regards,
Simon
Links:
[1]
https://github.com/mamthal/getItemJava/blob/master/ebaysdkcore/src/main/java/com/ebay/sdk/SdkAPIInterfaceServiceLocator.java#L55
[2]
https://github.com/mamthal/getItemJava/blob/master/ebaysdkcore/src/main/java/com/ebay/soap/eBLBaseComponents/EBayAPIInterfaceService.java#L33
[3] http://stackoverflow.com/q/23159909
[4] http://www.dankulp.com/blog/2011/11/apache-cxf-in-osgi/
OSGi bundle's generated Manifest:
---------------------------------------------------------------
Manifest-Version: 1.0
Export-Package: de.stadesign.pim.platform.ebay;uses:="de.stadesign.cor
elib.log,org.osgi.framework,com.ebay.sdk,com.ebay.sdk.call,org.slf4j"
,de.stadesign.corelib.log;uses:="org.slf4j",com.ebay.soap.eBLBaseComp
onents;uses:="javax.xml.bind.annotation.adapters,javax.xml.bind,javax
.jws.soap,javax.jws,javax.xml.ws",com.ebay.sdk.attributes.model;uses:
="com.ebay.soap.eBLBaseComponents,com.ebay.sdk.util,org.w3c.dom,com.e
bay.sdk",com.ebay.sdk.handler;uses:="javax.xml.ws.handler,javax.xml.w
s.handler.soap,javax.xml.soap,com.ebay.sdk,org.slf4j,com.ebay.sdk.log
ging,com.ebay.sdk.util",com.ebay.sdk.helper.cache;uses:="com.ebay.soa
p.eBLBaseComponents,com.ebay.sdk,com.ebay.sdk.call",com.ebay.sdk.logg
ing;uses:="com.ebay.sdk.util",com.ebay.sdk.model;uses:="com.ebay.soap
.eBLBaseComponents",com.ebay.sdk.call;uses:="com.ebay.soap.eBLBaseCom
ponents,com.ebay.sdk,com.ebay.sdk.pictureservice.eps,com.ebay.sdk.pic
tureservice,com.ebay.sdk.util,org.w3c.dom,org.xml.sax",com.ebay.sdk.u
til;uses:="com.ebay.soap.eBLBaseComponents,org.apache.xml.utils,org.a
pache.xpath,org.apache.xpath.objects,org.w3c.dom,org.xml.sax,com.ebay
.sdk",com.ebay.sdk.attributes;uses:="com.ebay.soap.eBLBaseComponents,
com.ebay.sdk.attributes.model,org.apache.log4j,com.ebay.sdk.util,com.
ebay.sdk,org.w3c.dom,org.xml.sax,com.ebay.sdk.call,org.apache.oro.tex
t.regex",com.ebay.sdk.helper;uses:="com.ebay.soap.eBLBaseComponents,c
om.ebay.sdk.call,com.ebay.sdk,com.ebay.sdk.helper.ui,javax.swing,java
x.swing.tree,com.ebay.sdk.util,org.w3c.dom",com.ebay.sdk.pictureservi
ce.eps;uses:="com.ebay.sdk.pictureservice,com.ebay.sdk,com.ebay.soap.
eBLBaseComponents,com.ebay.sdk.util,org.slf4j,org.w3c.dom,javax.net.s
sl,javax.xml.bind",com.ebay.sdk.pictureservice;uses:="com.ebay.sdk,co
m.ebay.soap.eBLBaseComponents",com.ebay.sdk.helper.ui;uses:="javax.sw
ing,com.ebay.soap.eBLBaseComponents,javax.swing.border,com.ebay.sdk,c
om.ebay.sdk.call,javax.swing.text,com.ebay.sdk.util",com.ebay.sdk;use
s:="javax.xml.ws.http,com.ebay.soap.eBLBaseComponents,com.ebay.sdk.ut
il,javax.swing.event,com.ebay.sdk.logging,org.slf4j,javax.xml.ws.soap
,org.w3c.dom,org.xml.sax,javax.xml.ws.handler,com.ebay.sdk.handler,ja
vax.xml.ws,javax.xml.soap"
Built-By: simon
Tool: Bnd-0.0.357
Bundle-Name: eBay
Created-By: Apache Maven Bundle Plugin
Build-Jdk: 1.7.0_80
Bundle-Version: 2.0.0.SNAPSHOT
Bnd-LastModified: 1435249937994
Bundle-ManifestVersion: 2
Bundle-Activator: de.stadesign.pim.platform.ebay.Activator
Import-Package: javax.activation;version="1.1",javax.jws,javax.jws.soa
p,javax.naming,javax.net.ssl,javax.swing,javax.swing.border,javax.swi
ng.event,javax.swing.text,javax.swing.tree,javax.xml.bind;version="2.
2.1",javax.xml.bind.annotation.adapters;version="2.2.1",javax.xml.bin
d.attachment;version="2.2.1",javax.xml.soap,javax.xml.transform.stax,
javax.xml.ws;version="2.2",javax.xml.ws.handler;version="2.2",javax.x
ml.ws.handler.soap;version="2.2",javax.xml.ws.http;version="2.2",java
x.xml.ws.soap;version="2.2",org.apache.log4j;version="[1.2,2)",org.ap
ache.oro.text.regex;version="[2.0,3)",org.apache.xml.utils,org.apache
.xpath,org.apache.xpath.objects,org.osgi.framework;version="[1.6,2)",
org.slf4j;version="[1.7,2)",org.w3c.dom,org.w3c.dom.ls,org.xml.sax,or
g.xml.sax.ext,org.xml.sax.helpers
Bundle-SymbolicName: de.stadesign.pim.platforms.ebay
eBay test Activator class:
---------------------------------------------------------------
public class Activator implements BundleActivator {
private static final Logger _log =
LoggerFactory.getLogger(Activator.class);
@Override
public void start(BundleContext context) throws Exception {
_log.info("===== [1] Account Information ====");
ApiContext apiContext = getApiContext();
// [Step 2] Create call object and execute the call
GeteBayOfficialTimeCall apiCall = new
GeteBayOfficialTimeCall(apiContext); _log.info("Begin to call
eBay API, please wait ... "); Calendar cal =
apiCall.geteBayOfficialTime(); _log.info("End to call eBay API,
show call result ...");
// [Setp 3] Handle the result returned
_log.info("Official eBay Time : " + cal.getTime().toString());
}
@Override
public void stop(BundleContext context) throws Exception {
}
/**
* Populate eBay SDK ApiContext object with data input from user
* @return ApiContext object
*/
private static ApiContext getApiContext() throws IOException {
String input;
ApiContext apiContext = new ApiContext();
//set Api Token to access eBay Api Server
ApiCredential cred = apiContext.getApiCredential();
input =
"<MY_EBAY_TOKEN>";
cred.seteBayToken(input);
//set Api Server Url
input = "https://api.sandbox.ebay.com/wsapi";
apiContext.setApiServerUrl(input);
return apiContext;
}
}