【问题标题】:Moxy error with KarafKaraf 的 Moxy 错误
【发布时间】:2012-10-08 05:00:33
【问题描述】:

我在 fuse ESB 下使用 MOXy(基于 karaf),我将 org.eclipse.persistence.jar 转换为一个包,我在 fuse ESB 下部署了这个包,我得到了这个错误

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

当尝试创建 JAXBContextmy 代码的新实例时,我的代码尝试将 Java 模型转换为 XML,并且模型部署在 fuse ESB 下的单独包中,我在模型的同一包中添加了 jaxb.properties 文件

注意:从主类中的主方法运行时,相同的代码可以成功运行,没有问题。

以下是我的代码,错误发生在 第 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);

有什么想法吗?

更新

堆栈跟踪:

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

【问题讨论】:

    标签: jaxb eclipselink moxy apache-karaf


    【解决方案1】:

    您可以从以下位置下载我们预构建的 OSGi 包,而不是将 eclipselink.jar 转换为包:

    EclipseLink 2.4.1 捆绑包

    对于EclipseLink JAXB (MOXy),您将需要以下捆绑包:

    • 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

    如果您使用 MOXy 的 JSON 绑定(请参阅:http://blog.bdoughan.com/2011/08/json-binding-with-eclipselink-moxy.html),您还需要以下捆绑包:

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

    更新 #1

    在 OSGi 环境中,您需要确保导入 MOXy 包或 org.eclipse.persistence.jaxb 包。

    我上面代码第 2 行的另一个问题,我发现 JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY 在 您在回答中提到的日食捆绑包,有没有 替换它?

    我们引入了新类,以便更轻松地查找 JAXBContextMarshallerUnmarshaller 上的属性。这些类称为JAXBContextPropertiesMarshallerPropertiesUnmarshallerProperties,可以在org.eclipse.persistence.jaxb 包中找到。

    • 以下:JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY
    • 被替换为:JAXBContextProperties.OXM_METADATA_SOURCE

    更新 #2

    我没有使用过 Karaf,但下面是一个我可以在 Eclipse Equinox 中运行的 OSGi 示例:

    example/Activator.java

    我发现您需要使用上下文路径创建JAXBContext。这允许您传入ClassLoader。此类加载器需要了解 EclipseLink JAXB (MOXy) 实现。我还包含了一个指定 MOXy 的外部映射文档的示例。

    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.in​​dex

    从上下文路径创建JAXBContext 时,您需要在上下文路径中包含一个名为jaxb.index 的文件,并用回车分隔的短类名列表。

    Customer
    

    example/jaxb.properties

    要将 MOXy 指定为您的 JAXB 提供程序,您需要在与您的域模型相同的包中包含一个名为 jaxb.properties 的文件,其中包含以下条目:

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

    example/oxm.xml

    下面是一个示例 MOXy 映射文档。

    <?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

    以下是清单的示例。在这个例子中,我使用了包导入:

    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
    

    输出

    下面是运行Activator的输出:

    <?xml version="1.0" encoding="UTF-8"?>
    <customer>
       <personal-info>
          <name>Jane Doe</name>
       </personal-info>
    </customer>
    

    【讨论】:

    • 我使用了前三个包而不是将 eclipselink.jar 转换为包,我得到了同样的错误(org.apache.cxf.interceptor.Fault: property "eclipselink-oxm-xml" is not支持”),有什么想法吗?
    • @eman - 你使用了哪个版本的 EclipseLink 包?
    • 我使用以下包: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 我从这个链接下载了它们eclipse.org/downloads/download.php?file=/rt/eclipselink/…
    • 我的代码中的另一个问题在第 2 行,我发现 JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY 在您在回答中提到的 Eclipse 捆绑包中已弃用,是否有任何替代品?
    • 1. @Blaise - 我导入了 org.eclipse.persistence.jaxb 包,我得到了同样的错误,是否应该导入其他包?
    【解决方案2】:

    已通过替换这段代码解决了问题

    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");
    

    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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-27
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多