【问题标题】:Using EclipseLink MOXy as JAXB provider for JAX-WS on JBoss EAP 6.1在 JBoss EAP 6.1 上使用 EclipseLink MOXy 作为 JAX-WS 的 JAXB 提供程序
【发布时间】:2013-06-25 09:44:27
【问题描述】:

我正在尝试使用 EclipseLink MOXy 作为部署在 JBoss EAP 6.1.0.Beta1 应用服务器上的 JAX-WS Web 服务的 JAXB 提供程序。现在我已经按照here 的描述实现了javax.xml.ws.Provider,并将jaxb.properties 文件放入包含我的Provider 实现和Web 服务中使用的域类的包中。这是该文件的内容:

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

当我尝试部署包含该服务的 Web 应用程序时,日志中出现以下错误:

@XmlValue is not allowed on a class that derives another class

在我的例子中,使用 MOXy 作为 JAXB 提供者的主要原因是能够在子类中使用 @XmlValue 注释。当我尝试在使用 MOXy 的测试应用程序中使用与 Web 服务相同的类解组时,不会发生此错误。此外,堆栈跟踪中没有来自org.eclipse.persistence 包及其子包的类,只有com.sun.xml.bind.v2 类。显然,在部署 Web 应用程序时不使用 MOXy。来自org.eclipse.persistence 的所有必需的 Maven 工件都在 WAR 文件中:

$ jar tf my-app.war | grep org.eclipse.persistence
WEB-INF/lib/org.eclipse.persistence.antlr-2.5.0.jar
WEB-INF/lib/org.eclipse.persistence.asm-2.5.0.jar
WEB-INF/lib/org.eclipse.persistence.moxy-2.5.0.jar
WEB-INF/lib/org.eclipse.persistence.core-2.5.0.jar 

我做错了什么?据我了解,Provider 在调用 web 服务时在运行时被调用。但是错误发生在部署时。除了Provider,我还应该重新实现一些东西吗?

【问题讨论】:

    标签: jboss jaxb jax-ws eclipselink moxy


    【解决方案1】:

    第一步是确保 EclipseLink 库位于正确的位置。您可以尝试直接使用 MOXy API,而不是将 MOXy 配置为 JAXB 提供程序吗?

    import org.eclipse.persistence.jaxb.JAXBContext;
    import org.eclipse.persistence.jaxb.JAXBContextFactory;
    
    public class Demo {
    
        public static void main(String[] args) {
            JAXBContext jc = JAXBContextFactory.createContext(new Class[] {Foo.class, Bar.class}), null);
        }
    
    }
    

    【讨论】:

      【解决方案2】:

      似乎无法将自定义 JAXB 提供程序与 ApacheCXF 2.6.6 一起使用,后者在 JBoss EAP 6.1.0.Beta1 中用作 JAX-WS 提供程序。实例化 JAXBContext 的上下文工厂被硬编码为在 ApacheCXF 中实例化 com.sun.xml.bind.v2.ContextFactory(参见 ApacheCXF 源代码中 JAXBContextCache 类的 createContext 静态方法)。

      UPD:抱歉回答错误。有一种方法可以在 ApacheCXF 支持的 Web 服务中使用 MOXy 作为 JAXB 提供程序。例如:

      import org.eclipse.persistence.jaxb.JAXBContextFactory;
      ...
      
      @ServiceMode(Service.Mode.PAYLOAD)
      @WebServiceProvider(
              portName = "...",
              serviceName = "...",
              targetNamespace = "...",
              wsdlLocation = "..."
      )
      public class MyService implements Provider<Source>{
      
          private JAXBContext jaxbContext;
      
          public MyService() {
              try {
                  this.jaxbContext = JAXBContextFactory.createContext(new Class[]{
                          ...
                  }, null);
              } catch (JAXBException e) {
                  throw new WebServiceException(e);
              }
          }
      
          @Override
          public Source invoke(Source request) {
              try {
                  Unmarshaller unmarshaller = this.jaxbContext.createUnmarshaller();
                  ...
              } catch (JAXBException e) {
                  throw new WebServiceException(e);
              }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-19
        • 2013-08-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多