4

I'm using MOXy under fuse ESB (based on karaf), I converted org.eclipse.persistence.jar to a bundle, I deployed this bundle under fuse ESB and I got this error

Error : "org.apache.cxf.interceptor.Fault: property "eclipselink-oxm-xml" is not supported"

When trying to create new instance of JAXBContextmy code is trying to convert Java model to XML, and the model is deployed in a separate bundle under fuse ESB and I added jaxb.properties file in the same package of the model

Note: The same code runs successfully without problems when running from a main method in a main class.

The following is my code and the error happens at line no.6.

    Map<String, Source> metadataSourceMap = new HashMap<String, Source>();      
    InputStream is = getClass().getClassLoader().getResourceAsStream
            ("com/syngenta/mint/security/service/transformation/User.xml");             

    metadataSourceMap.put("com.syngenta.mint.security.model",new StreamSource(is));

    1. Map<String, Object> properties = new HashMap<String, Object>();
    2. properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY,
            metadataSourceMap);
    3. properties.put("javax.xml.bind.context.factory",
                 "org.eclipse.persistence.jaxb.JAXBContextFactory");

    4. Class[] classes = new Class[1];
    5. classes[0] = User.class;

    6. JAXBContext jc = JAXBContext.newInstance(classes, properties);

Any Idea?

Update

Stack Trace:

org.apache.cxf.interceptor.Fault: property "eclipselink.oxm.metadata-source" is not supported
    at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:155)[131:org.apache.cxf.bundle:2.5.0.fuse-70-084]
    at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:121)[131:org.apache.cxf.bundle:2.5.0.fuse-70-084]
    at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:167)[131:org.apache.cxf.bundle:2.5.0.fuse-70-084]
    at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:94)[131:org.apache.cxf.bundle:2.5.0.fuse-70-084]
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)[131:org.apache.cxf.bundle:2.5.0.fuse-70-084]
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94)[131:org.apache.cxf.bundle:2.5.0.fuse-70-084]
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)[131:org.apache.cxf.bundle:2.5.0.fuse-70-084]
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:123)[131:org.apache.cxf.bundle:2.5.0.fuse-70-084]
    at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:344)[131:org.apache.cxf.bundle:2.5.0.fuse-70-084]
    at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:310)[131:org.apache.cxf.bundle:2.5.0.fuse-70-084]
    at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)[131:org.apache.cxf.bundle:2.5.0.fuse-70-084]
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:943)[72:org.eclipse.jetty.server:7.5.4.v20111024]
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:879)[72:org.eclipse.jetty.server:7.5.4.v20111024]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)[72:org.eclipse.jetty.server:7.5.4.v20111024]
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:250)[72:org.eclipse.jetty.server:7.5.4.v20111024]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)[72:org.eclipse.jetty.server:7.5.4.v20111024]
    at org.eclipse.jetty.server.Server.handle(Server.java:349)[72:org.eclipse.jetty.server:7.5.4.v20111024]
    at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:441)[72:org.eclipse.jetty.server:7.5.4.v20111024]
    at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:919)[72:org.eclipse.jetty.server:7.5.4.v20111024]
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:582)[73:org.eclipse.jetty.http:7.5.4.v20111024]
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:218)[73:org.eclipse.jetty.http:7.5.4.v20111024]
    at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:51)[72:org.eclipse.jetty.server:7.5.4.v20111024]
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:586)[68:org.eclipse.jetty.io:7.5.4.v20111024]
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:44)[68:org.eclipse.jetty.io:7.5.4.v20111024]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:598)[76:org.eclipse.jetty.util:7.5.4.v20111024]
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:533)[76:org.eclipse.jetty.util:7.5.4.v20111024]
    at java.lang.Thread.run(Thread.java:619)[:1.6.0_12]
Caused by: javax.xml.bind.JAXBException: property "eclipselink.oxm.metadata-source" is not supported
    at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:118)
    at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:202)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.6.0_12]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)[:1.6.0_12]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)[:1.6.0_12]
    at java.lang.reflect.Method.invoke(Method.java:597)[:1.6.0_12]
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:143)[:2.0.0.fuse-70-084]
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:269)[:2.0.0.fuse-70-084]
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:412)[:2.0.0.fuse-70-084]
    at com.syngenta.transport1.security.transformation.Transformer.fromJavaToXML(Transformer.java:72)[311:com.syngenta.transport1.security.transformation:1.0.0.SNAPSHOT]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.6.0_12]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)[:1.6.0_12]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)[:1.6.0_12]
    at java.lang.reflect.Method.invoke(Method.java:597)[:1.6.0_12]
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    at org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:58)
    at org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:62)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.osgi.service.util.internal.aop.ServiceTCCLInterceptor.invokeUnprivileged(ServiceTCCLInterceptor.java:56)
    at org.springframework.osgi.service.util.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:39)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.osgi.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:59)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.Cglib2AopProxy$FixedChainStaticTargetInterceptor.intercept(Cglib2AopProxy.java:572)
    at com.syngenta.transport1.security.transformation.Transformer$$EnhancerByCGLIB$$1aed98eb.fromJavaToXML(<generated>)
    at com.syngenta.transport1.security.restservice.UserRestService.handleGetUserRequest(UserRestService.java:53)[310:com.syngenta.transport1.security.restservice:1.0.0.SNAPSHOT]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.6.0_12]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)[:1.6.0_12]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)[:1.6.0_12]
    at java.lang.reflect.Method.invoke(Method.java:597)[:1.6.0_12]
    at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:173)[131:org.apache.cxf.bundle:2.5.0.fuse-70-084]
    at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:89)[131:org.apache.cxf.bundle:2.5.0.fuse-70-084]
    ... 25 more
bdoughan
  • 147,609
  • 23
  • 300
  • 400
eman
  • 167
  • 3
  • 11

2 Answers2

2

Instead of converting eclipselink.jar to a bundle, you can download our pre-built OSGi bundles from the following location:

EclipseLink 2.4.1 Bundles

For EclipseLink JAXB (MOXy) you will need the following bundles:

  • org.eclipse.persistence.moxy_2.4.1.v20121003-ad44345.jar
  • org.eclipse.persistence.core_2.4.1.v20121003-ad44345.jar
  • org.eclipse.persistence.asm_3.3.1.v201206041142.jar

If you are using MOXy's JSON binding (see: http://blog.bdoughan.com/2011/08/json-binding-with-eclipselink-moxy.html) you will also need the following bundle:

  • org.eclipse.persistence.antlr_3.2.0.v201206041011.jar

UPDATE #1

In an OSGi environment you will need to ensure that you import either the MOXy bundle, or the org.eclipse.persistence.jaxb packages.

another question in my code above at line 2, I found that JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY is deprecated in the eclipse bundles that you mentioned in your answer, is there any replacement for it?

We have introduced new classes to make it easier to find the properties on JAXBContext, Marshaller, and Unmarshaller. These classes are called JAXBContextProperties, MarshallerProperties, and UnmarshallerProperties and can be found in the org.eclipse.persistence.jaxb package.

  • The following: JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY
  • Is replaced by: JAXBContextProperties.OXM_METADATA_SOURCE

UPDATE #2

I haven't used Karaf, but below is an OSGi example I'm able to run in Eclipse Equinox:

example/Activator.java

I find you need to create the JAXBContext using a context path. This allows you to pass in a ClassLoader. This class loader needs to be aware of the EclipseLink JAXB (MOXy) implementation. I've also included an example of specifying MOXy's external mapping document.

package example;

import java.util.*;
import javax.xml.bind.*;
import org.eclipse.persistence.jaxb.JAXBContextProperties;
import org.osgi.framework.*;

public class Activator implements BundleActivator {

    private static BundleContext context;

    static BundleContext getContext() {
        return context;
    }

    public void start(BundleContext bundleContext) throws Exception {
        Activator.context = bundleContext;

        Map<String, Object> properties = new HashMap<String, Object>(1);
        properties.put(JAXBContextProperties.OXM_METADATA_SOURCE,
                "example/oxm.xml");
        JAXBContext jc = JAXBContext.newInstance("example",
                Customer.class.getClassLoader(), properties);

        Customer customer = new Customer();
        customer.setName("Jane Doe");

        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(customer, System.out);
    }

    public void stop(BundleContext bundleContext) throws Exception {
        Activator.context = null;
    }

}

example/jaxb.index

When creating a JAXBContext from a context path you need to include a file called jaxb.index in the context path with a carriage return separated list of short class names.

Customer

example/jaxb.properties

To specify MOXy as your JAXB provider you need to include a file called jaxb.properties in the same package as your domain model with the following entry:

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

example/oxm.xml

Below is an example MOXy mapping document.

<?xml version="1.0" encoding="UTF-8"?>
<xml-bindings
    xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
    package-name="example">
    <java-types>
        <java-type name="Customer">
            <xml-root-element/>
             <java-attributes>
                <xml-element java-attribute="name" xml-path="personal-info/name/text()"/>
            </java-attributes>
        </java-type>
    </java-types>
</xml-bindings>

META-INF/MANIFEST.MF

Below is an example of the manifest. In this example I have used bundle imports:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Example
Bundle-SymbolicName: Example
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: example.Activator
Import-Package: org.osgi.framework;version="1.3.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.persistence.antlr,
 org.eclipse.persistence.asm,
 org.eclipse.persistence.core,
 org.eclipse.persistence.moxy,
 javax.xml.bind

Output

Below is the output from running the Activator:

<?xml version="1.0" encoding="UTF-8"?>
<customer>
   <personal-info>
      <name>Jane Doe</name>
   </personal-info>
</customer>
bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • I used the previous three bundles instead of converting eclipselink.jar to a bundle and I got the same error (org.apache.cxf.interceptor.Fault: property "eclipselink-oxm-xml" is not supported"), any Idea? – eman Oct 18 '12 at 09:23
  • @eman - Which version of the EclipseLink bundles did you use? – bdoughan Oct 18 '12 at 09:38
  • I use the following bundles : org.eclipse.persistence.moxy_2.4.1.v20121003-ad44345.jar org.eclipse.persistence.core_2.4.1.v20121003-ad44345.jar org.eclipse.persistence.asm_3.3.1.v201206041142.jar and I downloaded them from this link http://www.eclipse.org/downloads/download.php?file=/rt/eclipselink/releases/2.4.1/eclipselink-plugins-2.4.1.v20121003-ad44345.zip – eman Oct 18 '12 at 10:14
  • another question in my code above at line 2, I found that JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY is deprecated in the eclipse bundles that you mentioned in your answer, is there any replacement for it? – eman Oct 18 '12 at 10:41
  • 1. @Blaise - I imported org.eclipse.persistence.jaxb package and I got the same error, is there any other package should be imported? – eman Oct 18 '12 at 16:55
  • 2. @Blaise - regarding the second question, which property in MarshallerProperties class should I use instead of JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY property? – eman Oct 18 '12 at 16:59
  • @eman - `JAXBContextProperties.OXM_METADATA_SOURCE` is the new property that replaces `JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY`. – bdoughan Oct 18 '12 at 17:27
  • 5. @Blaise - I got the following error after modifying my code like the sample you provide "The context path com.syngenta.transport1.security.model contains no ObjectFactory or jaxb.index, no external metadata was found in properties Map, and sessions.xml was found or was invalid." any idea? – eman Oct 18 '12 at 21:33
  • @eman - The good news is that is an EclipseLink exception. Do you have a `jaxb.index` file in that package? – bdoughan Oct 18 '12 at 21:43
  • _. @Blaise -No, I'll include it and try again on next sunday, tell you the result next sunday, but where exactly should I include jaxb.index file? in the same Models Package? Thank you – eman Oct 18 '12 at 23:29
  • @eman - The `jaxb.index` file goes in the same package as the domain classes. Then you only specify the short class names from that package in it. – bdoughan Oct 19 '12 at 17:50
  • _. @Blais- after including the jaxb.index file I got this error ["Caused by: javax.xml.bind.JAXBException: property "eclipselink.oxm.metadata-source" is not supported"] while the same code runs successfully when calling it from a main method which means as I think that Karaf couldn't load the jaxb.properties file, I think I missed to include the bundle which is responsible of loading jaxb.properties, could you please send me your code with all bundles that you depend on as .zip file and I'll compare my code with yours to detect my mistake? my email: eman.azmy@itworx.com – eman Oct 19 '12 at 22:26
  • @eman - In your latest stack trace an JAXB RI exception is being thrown. Your comment on `Oct 18 at 21:33` indicated an EclipseLink JAXB exception. What changed in your setup between those two exceptions? – bdoughan Oct 22 '12 at 16:55
  • _. @Blais-I added the jaxb.inedx file – eman Oct 22 '12 at 17:02
  • @eman - If you remove the `jaxb.index` file you get the EclipseLink exception? – bdoughan Oct 22 '12 at 17:04
  • _. @Blais - yes. I got this exception [Caused by: javax.xml.bind.JAXBException: "com.syngenta.transport1.security.model" doesnt contain ObjectFactory.class or jaxb.index], I just re-tried now to double check – eman Oct 22 '12 at 17:13
  • @eman - Is it the exact same you were getting before: _The context path com.syngenta.transport1.security.model contains no ObjectFactory or jaxb.index, no external metadata was found in properties Map, and sessions.xml was found or was invalid_ – bdoughan Oct 22 '12 at 17:39
  • _. @Blais - not the exact same one, the current exception after removing the jaxb.index is **["Caused by: javax.xml.bind.JAXBException: "com.syngenta.transport1.security.model" doesnt contain ObjectFactory.class or jaxb.index"]** _without this part_ [, no external metadata was found in properties Map, and sessions.xml was found or was invalid –] – eman Oct 22 '12 at 22:05
  • _. @Blais - **Note:** the same code runs successfully if it's called from a main method without deploying it under fuse ESB – eman Oct 22 '12 at 22:13
  • _. @Blais - could you please send me the complete OSGi example that you have – eman Oct 23 '12 at 10:45
  • @eman - Just sent you an OSGi example. I ran it using Eclipse Equinox as the OSGi implementation. – bdoughan Oct 23 '12 at 15:34
  • _. @Blais - Thank you, but I havn't recieved any e-mails, did you send it to my e-mail? – eman Oct 23 '12 at 15:38
  • @eman - I just resent to example. I renamed the .zip extension in case that was causing the problem. If you don't receive it, could you send me an email through my contact page: http://blog.bdoughan.com/p/contact_01.html – bdoughan Oct 23 '12 at 15:49
1

the problem has been solved by replacing this piece of code

Map<String, Source> metadataSourceMap = new HashMap<String, Source>();      
InputStream is = getClass().getClassLoader().getResourceAsStream("com/syngenta/mint/security/service/transformation/User.xml");               metadataSourceMap.put("com.syngenta.mint.security.model",new StreamSource(is));
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY,metadataSourceMap);
        properties.put("javax.xml.bind.context.factory","org.eclipse.persistence.jaxb.JAXBContextFactory");

With

InputStream is = getClass().getClassLoader().getResourceAsStream("com/syngenta/mint/security/service/transformation/User.xml");    
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, is);
Lii
  • 11,553
  • 8
  • 64
  • 88
eman
  • 167
  • 3
  • 11