我正在尝试在CQ中实现Apache CXF。我使用cxf-codegen-plugin从WSDL生成了代理类。现在我的CxfServiceImpl.java
看起来如下 -
import net.webservicex.ConvertTemperatureSoap;
import net.webservicex.TemperatureUnit;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
@Component(label = "CXF Service", immediate = true, metatype = true)
@Service(CxfService.class)
public class CxfServiceImpl implements CxfService {
private ConvertTemperatureSoap convertTemperatureSoap;
@Override
public double convertCelsiusToFahrenheit(double valueToConvert) {
return convertTemperatureSoap.convertTemp(
valueToConvert,
TemperatureUnit.DEGREE_CELSIUS,
TemperatureUnit.DEGREE_FAHRENHEIT);
}
@Activate
protected final void activate(final ComponentContext context) {
convertTemperatureSoap =
JaxWsClientFactory.create(
ConvertTemperatureSoap.class,
"http://www.w3schools.com/webservices/tempconvert.asmx");
}
}
JaxWsClientFactory.java
看起来像 -
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.BusFactory;
public class JaxWsClientFactory {
public static <T> T create(Class<T> clazz, String portUrl) {
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(BusFactory.class.getClassLoader());
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(clazz);
factory.setAddress(portUrl);
return (T) factory.create();
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
}
我能够创建OSGI包并在Felix控制台中上传。但是当我尝试激活bundle然后我得到如下错误并且bundle状态显示为Active。
24.02.2014 20:38:41.104 *ERROR* [127.0.0.1 [1393254521079] POST /system/console/bundles/300 HTTP/1.1] com.adobe.cq.customer-bundle [com.adobe.cq.CxfServiceImpl] The activate method has thrown an exception (java.lang.NoClassDefFoundError: javax/xml/ws/BindingProvider) java.lang.NoClassDefFoundError: javax/xml/ws/BindingProvider
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl.java:2167)
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1471)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1882)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.adobe.cq.JaxWsClientFactory.create(JaxWsClientFactory.java:12)
at com.adobe.cq.CxfServiceImpl.activate(CxfServiceImpl.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.felix.scr.impl.helper.BaseMethod.invokeMethod(BaseMethod.java:236)
at org.apache.felix.scr.impl.helper.BaseMethod.access$500(BaseMethod.java:37)
at org.apache.felix.scr.impl.helper.BaseMethod$Resolved.invoke(BaseMethod.java:613)
at org.apache.felix.scr.impl.helper.BaseMethod.invoke(BaseMethod.java:496)
at org.apache.felix.scr.impl.helper.ActivateMethod.invoke(ActivateMethod.java:149)
at org.apache.felix.scr.impl.manager.ImmediateComponentManager.createImplementationObject(ImmediateComponentManager.java:251)
at org.apache.felix.scr.impl.manager.ImmediateComponentManager.createComponent(ImmediateComponentManager.java:119)
at org.apache.felix.scr.impl.manager.AbstractComponentManager$Unsatisfied.activate(AbstractComponentManager.java:1518)
at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:550)
at org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManager.java:261)
at org.apache.felix.scr.impl.config.ImmediateComponentHolder.enableComponents(ImmediateComponentHolder.java:328)
at org.apache.felix.scr.impl.BundleComponentActivator.initialize(BundleComponentActivator.java:158)
at org.apache.felix.scr.impl.BundleComponentActivator.<init>(BundleComponentActivator.java:113)
at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:261)
at org.apache.felix.scr.impl.Activator.bundleChanged(Activator.java:179)
at org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:868)
at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:789)
at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:514)
at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4319)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1993)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:947)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:934)
at org.apache.felix.webconsole.internal.core.BundlesServlet.doPost(BundlesServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.felix.webconsole.internal.servlet.OsgiManager.service(OsgiManager.java:493)
at org.apache.felix.webconsole.internal.servlet.OsgiManager.service(OsgiManager.java:418)
at org.apache.felix.http.base.internal.handler.ServletHandler.doHandle(ServletHandler.java:96)
at org.apache.felix.http.base.internal.handler.ServletHandler.handle(ServletHandler.java:79)
at org.apache.felix.http.base.internal.dispatch.ServletPipeline.handle(ServletPipeline.java:42)
at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:49)
at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33)
at org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:127)
at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:88)
at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:76)
at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:47)
at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33)
at com.adobe.granite.license.impl.LicenseCheckFilter.doFilter(LicenseCheckFilter.java:179)
at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:88)
at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:76)
at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:47)
at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33)
at org.apache.felix.http.sslfilter.internal.SslFilter.doFilter(SslFilter.java:55)
at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:88)
at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:76)
at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:47)
at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33)
at org.apache.sling.security.impl.ReferrerFilter.doFilter(ReferrerFilter.java:259)
at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:88)
at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:76)
at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:47)
at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33)
at org.apache.sling.engine.impl.log.RequestLoggerFilter.doFilter(RequestLoggerFilter.java:75)
at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:88)
at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:76)
at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:47)
Caused by: java.lang.ClassNotFoundException: javax.xml.ws.BindingProvider not found by com.adobe.cq.customer-bundle [300]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1499)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1882)
at java.lang.ClassLoader.loadClass(Unknown Source)
pom.xml-
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>com.adobe.cq.customer-bundle</Bundle-SymbolicName>
<Export-Package>
com.adobe.cq.*;version=${project.version}
javax.xml.ws*;version=2.1;-split-package:=merge-first;-noimport:=true
</Export-Package>
<Private-Package>
javax.jws,
javax.jws.*,
javax.wsdl,
org.xml.*,
org.apache.cxf,
org.apache.cxf.*,
javax.xml,
org.apache.servicemix.specs.locator;-split-package:=merge-first
javax.xml.transform.stax,
javax.net.ssl,
org.w3c.dom,
org.apache.ws.commons.schema.resolver.*,
org.apache.ws.commons.schema.extensions.*,
org.apache.ws.commons.schema.*,
net.webservicex
</Private-Package>
<Include-Resource>{maven-resources}</Include-Resource>
<Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Import-Package>
org.osgi.framework,
org.osgi.service.component.*,
com.sun.msv.*;resolution:=optional,
com.sun.xml.bind.marshaller.*;resolution:=optional,
com.sun.xml.fastinfoset.stax.*;resolution:=optional,
net.sf.cglib.*;resolution:=optional,
org.apache.aries.*;resolution:=optional,
org.apache.axiom.*;resolution:=optional,
org.apache.mina.*;resolution:=optional,
org.apache.log4j.spi.*;resolution:=optional,
org.apache.velocity.*;resolution:=optional,
org.osgi.service.blueprint.*;resolution:=optional,
org.junit.*;resolution:=optional,
org.relaxng.*;resolution:=optional,
org.slf4j.spi.*;resolution:=optional,
org.springframework.*;resolution:=optional,
javax.resource.*;resolution:=optional,
javax.mail.*;resolution:=optional,
javax.xml.ws.spi.http.*;resolution:=optional,
junit.framework.*;resolution:=optional,
com.sun.*;resolution:=optional,
sun.*;resolution:=optional,
org.apache.*;resolution:=optional,
org.jvnet.*;resolution:=optional,
javax.net.*,
javax.xml.transform.stax,
!*
</Import-Package>
</instructions>
</configuration>
</plugin>
答案 0 :(得分:3)
就我而言,我需要在该项目中从Java 11回滚到Java 8。
我知道这不是一个长期解决方案,但这可能对某人有所帮助。
更通用的解决方案是使用:
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency>
答案 1 :(得分:1)
当CXF委托JDK进行代理生成时,会发生此错误。问题在于,对于代理必须实现的所有接口,您只能设置一个类加载器。通常,用户的类路径中没有BindpProvider。 SO cxf使用总线类路径,该路径首先在bundle类路径中查找,然后在cxf类路径中查找。
您使用哪种CXF版本?在较旧的CXF版本中,此错误有时会产生误导。不仅在找不到BindingProvider类时出现问题。当BindingProvider由cxf和用户包加载但来自不同的类加载器时也会发生这种情况。
避免此问题的最佳方法是导入javax.xml.ws。因此,您发现与cxf相同的界面的可能性最大。如果错误仍然发生,您可能有两个包导出包。
在任何情况下,您的bundle插件指令都不应该像您的问题那样复杂。这只会导致问题。试试吧。
<instructions>
<Bundle-SymbolicName>com.adobe.cq.customer-bundle</Bundle-SymbolicName>
<Include-Resource>{maven-resources}</Include-Resource>
<Import-Package>
javax.xml.ws,
*
</Import-Package>
</instructions>
为什么嵌入所有依赖项有什么特殊原因?当像这样使用时,CXF通常可以很好地工作。相反,您可以使用CXF DOSGi多捆发行版中的捆绑包将CXF安装到CQ中。
答案 2 :(得分:0)
将javax/xml/ws/BindingProvider
类添加到类路径
答案 3 :(得分:0)
如果您使用 maven ,here可以快速链接到可能的工件
答案 4 :(得分:0)
我先说检查你的MANIFEST.MF。它抱怨它缺少javax.xml.ws包,因此检查它是否在Import-Package头中。
如果不是:那就是你的问题,我想你需要将它添加到你的pom.xml中。
如果 ,那就更加微妙了。
答案 5 :(得分:0)
如果您安装了JDK 1.6(Java SE 6),我建议您阅读文档Using JAX-WS 2.x / Metro 1.x/2.0 with Java SE 6
通过阅读附件,我解决了类似的问题。