Hi,
I had a post for help on JAXB not working in ServiceMix earlier. But that
configuration was quite complex. I now simplified it to a simple JAXB client
bundle (no longer embedded/wrapped). It has a single class, Person, which is
annotated with @XmlRootElement and a jaxb.index resource file that contains a
single line of the class name "Person". The JAXB client code simply calls
JAXBContext.newInstance("package") to get the JAXB context in the constructor.
A blueprint deployment descriptor simply defines the JAXB client as a bean. I
deployed it into the ServiceMix and the bean creation causes the "package
doesnt contain ObjectFactory.class or jaxb.index" exception from the call to
the JAXBContext.newInstance(). Here's the details about the code. Hope someone
can spot what's missing:
The Person class:
package
mil.army.security.ts3.jaxb.personnel;
import
javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public
class
Person {
private int customerNumber
;
...
// getters and setters
......
}
The JAXB client code:
package mil.army.security.ts3.jaxb;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import mil.army.security.ts3.jaxb.personnel.Person;
public class PersonTransformer {
JAXBContext jaxbContext = null;
Marshaller marshaller = null;
Unmarshaller unmarshaller = null;
public PersonTransformer() {
try {
jaxbContext =
JAXBContext.newInstance("mil.army.security.ts3.jaxb.personnel");
marshaller = jaxbContext.createMarshaller();
unmarshaller = jaxbContext.createUnmarshaller();
}
catch (JAXBException jaxbE) {
System.err.println("PersonTransformer.PersonTransformer():
JAXBException: " + jaxbE);
jaxbE.printStackTrace();
}
}
}
The blueprint deployment descriptor:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/blueprint/jaxws"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://cxf.apache.org/blueprint/jaxws
http://cxf.apache.org/schemas/blueprint/jaxws.xsd">
<bean id="jaxbTransformer"
class="mil.army.security.ts3.jaxb.PersonTransformer"/>
</blueprint>
The bundle is built with maven-bundle-plugin using the following imports and
exports:
<Import-Package>
org.osgi.service.blueprint,
javax.xml.bind,
javax.xml.bind.annotation
</Import-Package>
<Export-Package>
mil.army.security.ts3.jaxb
</Export-Package>
To me, it's such a simple JAXB client that should've had every thing that
runtime needs to run it. Unfortunately it failed in ServiceMix. The stacktrace
is at the end of this email. Would appreciate help and suggestions.
Thanks,
Gang
------------------
Stacktrace:
karaf@root<mailto:karaf@root>> PersonTransformer.PersonTransformer():
JAXBException: javax.xml.bind.JAXBException: "mil.army.security.ts3.j
axb.personnel" doesnt contain ObjectFactory.class or jaxb.index
javax.xml.bind.JAXBException: "mil.army.security.ts3.jaxb.personnel" doesnt
contain ObjectFactory.class or jaxb.index
at
com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:197)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:143)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:310)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:446)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:409)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:313)
at
mil.army.security.ts3.jaxb.PersonTransformer.<init>(PersonTransformer.java:21)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at
org.apache.aries.blueprint.utils.ReflectionUtils.newInstance(ReflectionUtils.java:329)
at
org.apache.aries.blueprint.container.BeanRecipe.newInstance(BeanRecipe.java:962)
at
org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:331)
at
org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:806)
at
org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)
at
org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at
org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)
at
org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:245)
at
org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:183)
at
org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl
.java:681)
at
org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:378)
at
org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:269)
at
org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:276)
at
org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:245)
at
org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:235)
at
org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker
.java:500)
at
org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker
.java:433)
at
org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java
:725)
at
org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java
:463)
at
org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java
:422)
at
org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1127)
at
org.apache.felix.framework.util.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:696)
at
org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:484)
at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4429)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2100)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:976)
at
org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1245)
at
org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1217)
at
org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:509)
at
org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:358)
at
org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:310)