I'm trying to implement Apache CXF in CQ. I've generated proxy classes from WSDL using cxf-codegen-plugin. Now my CxfServiceImpl.java looks like below -
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 looks like -
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);
}
}
}
I am able to create OSGI bundle and uploaded in Felix console. But when I try to activate bundle then I get error as below and bundle status is showing as 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>
In my case I needed to roll back to Java 8 from Java 11 on this project.
I know this is not a long term solution, but it might be helpful for someone.
The more general solution would be to use:
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency>
This error happens when CXF delegates to the JDK for the proxy generation. The problem there is that for all interfaces the proxy has to implement you can only set one classloader. Typically users do not have the BindpProvider in their classpath. SO cxf uses the bus classpath which looks in the bundle classpath first and then in the cxf classpath.
Which CXF version do you use? In older CXF versions this error was misleading sometimes. It was not only issues when the BindingProvider class was not found. It also happened when BindingProvider was loaded by cxf and the user bundle but from different classloaders.
The best way to avoid this problem is to import javax.xml.ws. So you have the highest chance you find the same interface as cxf. If the error then still happens you might have two bundles exporting the package.
In any case your bundle plugin instruction should not look as complicated as in your question. This only leads to problem. Just try.
<instructions>
<Bundle-SymbolicName>com.adobe.cq.customer-bundle</Bundle-SymbolicName>
<Include-Resource>{maven-resources}</Include-Resource>
<Import-Package>
javax.xml.ws,
*
</Import-Package>
</instructions>
Is there any special reason why you embed all your dependencies? CXF typically does work to well when used like this. Instead you can use the bundles from the CXF DOSGi multi bundle distro to install CXF into CQ.
add javax/xml/ws/BindingProvider class to your classpath
If you are using maven, here a quick link to the possible artifacts
I'd say check your MANIFEST.MF first. It is complaining it's missing javax.xml.ws packages, so check if it is there in the Import-Package header.
If it isn't: Thats your problem, I guess you need to add it to your pom.xml.
If it is there, it's a bit more subtle.
In case you have installed the JDK 1.6 (Java SE 6) I suggest you read the document Using JAX-WS 2.x / Metro 1.x/2.0 with Java SE 6
I solved a similar problem just by reading the attached document.
Related
I looked for similar posts on this blog, but couldn't find an answer to my question, so I decided to ask for help.
I wrote this simple function in Java:
public void open(InputStream stream) throws FoliumFatalException {
try {
InputSource is = new InputSource(stream);
DocumentBuilderFactory dfact = DocumentBuilderFactory.newInstance();
// /* OWASP: inhibit access to External Entities */
dfact.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
dfact.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
_doc = dfact.newDocumentBuilder().parse(is);
} catch (Throwable t) {
_logger.error(t, t);
throw new FoliumFatalException("ENG-0017", "Errore di parsing su stream", t);
}
}
My goal is applying OWASP standards as exposed here, but I get the following error:
java.lang.IllegalArgumentException: Property 'http://javax.xml.XMLConstants/property/accessExternalDTD' is not recognized.
java.lang.IllegalArgumentException: Property 'http://javax.xml.XMLConstants/property/accessExternalDTD' is not recognized.
at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.setAttribute(Unknown Source) ~[xercesImpl-2.8.0.jar:?]
at agora.folium.engine.impl.j2ee.FoliumJ2eeXmlParserImpl.open(FoliumJ2eeXmlParserImpl.java:108) [classes/:?]
at agora.folium.engine.impl.FoliumAbstractEngine.loadServices(FoliumAbstractEngine.java:268) [classes/:?]
at agora.folium.engine.impl.j2ee.FoliumJ2eeEngineImpl.startup(FoliumJ2eeEngineImpl.java:110) [classes/:?]
at agora.folium.engine.Folium.startup(Folium.java:258) [classes/:?]
at agora.folium.control.impl.j2ee.FoliumActionServlet.init(FoliumActionServlet.java:94) [classes/:?]
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1230) [catalina.jar:7.0.85]
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1174) [catalina.jar:7.0.85]
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1066) [catalina.jar:7.0.85]
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5370) [catalina.jar:7.0.85]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5668) [catalina.jar:7.0.85]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) [catalina.jar:7.0.85]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1015) [catalina.jar:7.0.85]
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:991) [catalina.jar:7.0.85]
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652) [catalina.jar:7.0.85]
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:712) [catalina.jar:7.0.85]
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:2002) [catalina.jar:7.0.85]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_141]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_141]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_141]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_141]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_141]
I'm using Eclipse Oxygen, Tomcat 7 and Java 1.8.
Can anyone help me?
Thanks for your support.
javax.xml.XMLConstants.ACCESS_EXTERNAL_DTD is defined in JAXP 1.5, but Xerces does not support it. If you can't remove Xerces dependency, you should add another implementation to your classpath before Xerces.
Alternatively, since JDK contains an implementation of Xerces you can configure DocumentBuilderFactory to return the JDK version using System.properties.
System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
"com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
The issue is coming due to Xerces/XercesImpl in classpath. Xerces doesn't provide support for ACCESS_EXTERNAL_DTD property.
Solution 1. If possible, remove xerces jar from the class path.
Solution 2. Use JDK default implementation
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance("com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", null);
Apache Xerces-J 2.12.0 and earlier implement older versions of JAXP that do not support either of the properties that you are trying to set. To block access to external entities, you could write an EntityResolver (that always throws a SAXException) and register that EntityResolver with the DocumentBuilder. See documentation here [1].
[1] http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/parsers/DocumentBuilder.html#setEntityResolver(org.xml.sax.EntityResolver)
Our Java project was being built with Maven. As the team decided to integrate SonarQube in the pipeline, we faced something similar. "SonarQube doesn't run your tests or generate reports. It only imports pre-generated reports" (more on that here). In the case of Java/Kotlin/Scala/JVM, SonarQube needs some "JaCoCo XML coverage report". So, we had to add a dependency to our pom.xml:
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
</dependency>
After some tweaking, we had it all up and running. But some tests were failing with "java.lang.IllegalArgumentException: Property 'http://javax.xml.XMLConstants/property/accessExternalDTD' is not recognized.
at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.setAttribute(Unknown Source)...".
Long story short, the solution was to leave xerces out of the picture, as already stated in other answers:
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<exclusions>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
</exclusions>
</dependency>
I need some features from Infinispan 8+. Therefore I have updated my company app pom.xml with the newest Infinispan pom.
It was quite straightforward, but the app uses jgroups (or its default config in default-configs/default-jgroups-udp.xml - this location is different from previous versions of infinispan). The default versions have some parameters (and the XSD from Jgroups version 3.6) - so I also bumped jgroups to 3.6.8.Final as it looks like it is the intended version (and the version that does not complain about unknown parameters in default config in infinispan 8.2)
so the pom is the following:
<dependency>
<groupId>org.jgroups</groupId>
<artifactId>jgroups</artifactId>
<version>3.6.8.Final</version>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
<version>8.2.0.Final</version>
</dependency>
Anyway - this application starts with no problems using spring-boot with Jetty. I am pretty sure it would start on any application server.
But then I have no choice but to run it on JBoss 6.4.
There I got an exception involving some jboss.as classes (this is kind of unexpected) during the deployment:
Caused by: org.infinispan.commons.CacheException: Unable to invoke method public void org.infinispan.remoting.transport.jgroups.JGroupsTransport.start() on object of type JGroupsTransport
at org.infinispan.commons.util.ReflectionUtil.invokeAccessibly(ReflectionUtil.java:172)
at org.infinispan.factories.AbstractComponentRegistry$PrioritizedMethod.invoke(AbstractComponentRegistry.java:859)
at org.infinispan.factories.AbstractComponentRegistry.invokeStartMethods(AbstractComponentRegistry.java:628)
at org.infinispan.factories.AbstractComponentRegistry.internalStart(AbstractComponentRegistry.java:617)
at org.infinispan.factories.AbstractComponentRegistry.start(AbstractComponentRegistry.java:542)
at org.infinispan.factories.GlobalComponentRegistry.start(GlobalComponentRegistry.java:234)
... 141 more
Caused by: java.lang.ExceptionInInitializerError
at org.jgroups.conf.XmlConfigurator.<clinit>(XmlConfigurator.java:35)
at org.jgroups.conf.ConfiguratorFactory.getStackConfigurator(ConfiguratorFactory.java:62)
at org.jgroups.JChannel.<init>(JChannel.java:129)
at org.infinispan.remoting.transport.jgroups.JGroupsTransport.buildChannel(JGroupsTransport.java:419)
at org.infinispan.remoting.transport.jgroups.JGroupsTransport.initChannel(JGroupsTransport.java:320)
at org.infinispan.remoting.transport.jgroups.JGroupsTransport.initChannelAndRPCDispatcher(JGroupsTransport.java:366)
at org.infinispan.remoting.transport.jgroups.JGroupsTransport.start(JGroupsTransport.java:190)
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.infinispan.commons.util.ReflectionUtil.invokeAccessibly(ReflectionUtil.java:168)
... 146 more
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: org.jboss.as.clustering.jgroups.LogFactory from [Module "deployment.mymodule-5.0.0.0-SNAPSHOT.ear.appName.war:main" from Service Module Loader]
at org.jgroups.logging.LogFactory.<clinit>(LogFactory.java:31)
... 158 more
Caused by: java.lang.ClassNotFoundException: org.jboss.as.clustering.jgroups.LogFactory from [Module "deployment.mymodule-5.0.0.0-SNAPSHOT.ear.appName.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:213)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:459)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:408)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:389)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:134)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.jgroups.logging.LogFactory.<clinit>(LogFactory.java:28)
... 158 more
My guess is that org.jgroups.logging.LogFactory somehow discovers that is is running on a Jboss and tries to use org.jboss.as.clustering.jgroups.LogFactory but this version of Jboss does not have one. (the server directory EAP-6.4.0\modules\system\layers\base\org\jgroups\main contains jgroups version 3.2.X).
Is there any walkaround to use this jgroups version (and so Infinispan 8.2) in Jboss 6.4?
This is (the application) an ear file so I can manipulate jboss-deployment-structure.xml file, but so far I only came with excluding Jboss original jgroups, and this did not help.
<exclusions>
<module name="org.jgroups"/>
</exclusions>
This is currently bug with Infinispan 8 + EAP 6.4 combination. The reason is exactly as #Flavius says in comments. Currently there is discussion where to fix it, but it'll mostly likely be fixed in EAP 6.4. I'm sure it will be done soon.
I can only offer you a working workarounds.
Use WildFly - the issue is not present there anymore
Little nasty workaround, but it works:
Call System.clearProperty("jgroups.logging.log_factory_class"); in the deployment
Include JBoss Logging of version specified in infinispan-bom in your deployment (e.g. add jboss-logging Maven dependency in your pom.xml)
Provide jboss-deployment-structure.xml to your deployment, which excludes the server's JBoss logging, see below:
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.jboss.logging" />
</exclusions>
</deployment>
</jboss-deployment-structure>
Another possibility if none of the above workarounds work (for instance the app uses other log mechanisms) is to implement an own
http://www.jgroups.org/javadoc/org/jgroups/logging/CustomLogFactory.html
The log factory must return a log instance, implementing it for any other logger is straightforward with methods trace/error/debug etc.
Then this logger class can be set with System.setProperty("jgroups.logging.log_factory_class","my.company.logging.MyJgroupsLog");
I have an OSGi bundle, which has an activator class. I embedded Equinox in my webapp, and installed my bundle in it. The installation goes well, but when I try to start the bundle, the following error comes:
org.osgi.framework.BundleException: The activator com.rr.fr.base.barcode.activator.Activator for bundle fr-base-barcode is invalid
at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:171)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:679)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:299)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:291)
at com.rr.fr.base.osgi.BundleStarter.launch(BundleStarter.java:43)
at com.rr.fr.base.osgi.OsgiInitServletContextListener.contextInitialized(OsgiInitServletContextListener.java:41)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4210)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4709)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1060)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:822)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1060)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:759)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
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:497)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.ClassNotFoundException: com.rr.fr.base.barcode.activator.Activator
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.eclipse.osgi.internal.loader.BundleLoader.loadClass(BundleLoader.java:345)
at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:229)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:164)
... 21 more
I can see that my activator class was not found. I searched for a solution and find some interesting thing here in SO, but none of them helped me.
Here is my manifest:
Manifest-Version: 1.0
Bnd-LastModified: 1431100911346
Build-Jdk: 1.6.0_45
Bundle-Activator: com.rr.fr.base.barcode.activator.Activator
Bundle-ManifestVersion: 2
Bundle-SymbolicName: fr-base-barcode;singleton:=true
Bundle-Version: 0.1.2.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Import-Package: com.rr.fr.base.barcode.qrcode.interfaces,com.rr.fr.base.
exception,com.rr.fr.base.messages,com.rr.fr.base.system,com.rr.fr.base.
types,com.rr.fr.interfaces,com.rr.fr.interfaces.eb.rms,com.rr.fr.ui.htt
p,hu.posta.rsaqrgen,javax.servlet,javax.servlet.http,org.apache.avalon.
framework.configuration,org.apache.commons.logging,or
g.krysalis.barcode4j,org.krysalis.barcode4j.output,org.krysalis.barcode
4j.output.bitmap,org.krysalis.barcode4j.output.eps,org.osgi.framework,org.osgi.service.http,org.osgi.util.
tracker
I can include my Activator, but I don't think it would help since it isn't even found so I don't think its source has anything to do with the error.
My bundle's library structure inside the JAR is the following:
META-INF
/MANIFEST.MF
target
/classes
/com
/rr
/fr
/base
/barcode
...
fr-base-barcode.jar
plugin.xml
I create my bundle with Eclipse PDE: Export.../Deployable Plug-ins and fragments
My build.properties includes the META-INF and target libraries, a JAR and plugin.xml as it can be seen in the bundle structure.
Any help would be appreciated.
I'm going to restate bkail's suggestion as the answer. When your packages are included in the "target/classes" folder, they are essentially in that package:
target.classes.com.rr.fr.base.barcode.*
The root of your package structure (com) should be a peer of META-INF and/or OSGI-INF, etc.
From : https://netbeans.org/kb/docs/javaee/maven-osgiservice-cdi.html#Exercise_3
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
<manifestEntries>
<Bundle-ClassPath>WEB-INF/classes/</Bundle-ClassPath>
</manifestEntries>
</archive>
</configuration>
</plugin>
Recently, I've been playing a little bit with depency injections in Java. I'm a complete newbie in this field, and I don't really get, why in this simple example I keep receiving an error.
package michal.dependency;
import com.google.inject.Guice;
import com.google.inject.Injector;
public class Main {
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Injector injector = Guice.createInjector(new ProjectModule());
Person person = injector.getInstance(Person.class);
person.greetFriend();
}
}
The error message I receive is as follows:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableList
at com.google.inject.internal.Errors.<clinit>(Errors.java:656)
at com.google.inject.internal.InternalInjectorCreator.<init>(InternalInjectorCreator.java:62)
at com.google.inject.Guice.createInjector(Guice.java:96)
at com.google.inject.Guice.createInjector(Guice.java:73)
at com.google.inject.Guice.createInjector(Guice.java:62)
at michal.dependency.Main.main(Main.java:14)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.ImmutableList
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
I'm pretty sure by the way the necessary .jar file is included in the classpath.
Here comes the requested Person class, as requested:
package michal.dependency;
import com.google.inject.Inject;
public class Person {
private MessageService messageService;
#Inject
public Person (MessageService messageService)
{
this.messageService = messageService;
}
public void greetFriend ()
{
messageService.sendMessage("Hey!", "How are you?");
}
}
Thanks in advance.
I think you are missing Google collections, now known as Guava.
See Google Guice Wiki
JSR 330
Guice 4.0 requires JSR 330 on your classpath. This is the javax.inject.jar included in the guice download.
com.google.inject.internal
Many things inside com.google.inject.internal changed and/or moved. This is especially true for repackaged Guava (formerly Google Collections), cglib, and asm classes. All these classes are now hidden from IDE auto-import suggestions and are in new locations. You will have to update your code if you relied on any of these classes.
As other have suggested, it seems that something is missing from your classpath.
Maybe you could try using some sort of dependency management tool, for example Apache Maven?
It's a great tool for handling dependencies, used extensively in the java world. Depending on your IDE you will have lots of supportfor using it (my personal favourite is Intellij Idea with really great maven support, though Netbeans also does it pretty well).
I tried to prepare a maven pom.xml file it should look something like this. I tested the project with this and there are no compilation errors:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>test-project</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
</dependency>
</dependencies>
</project>
I' m trying to access an OSGI Bundle from my main application. But if a class in the bundle is accessed that uses javax.xml.* package. A NoClassDefFoundError is thrown.
java.lang.NoClassDefFoundError: javax/xml/transform/Source
at de.foo.bar.test.Builder.<init>(Builder.java:46) ~[test-bundle-1.4.0.jar:1.4.0]
at de.foo.bar.test.request.Factory.createRequest(Factory.java:99) ~[?:?]
at de.foo.bar.test.request.Request.prepareRequest(Request.java:93) ~[?:?]
at de.foo.bar.test.request.Request.process(Request.java:60) ~[?:?]
at de.foo.bar.test.TestClass.execute(TestClass.java:74) ~[?:?]
at de.foo.bar.test.TestClass.execute(TestClass.java:1) ~[?:?]
at de.foo.bar.service.system.OsgiTransactionHandler.handleTransaction(OsgiTransactionHandler.java:71) ~[bin/:?]
at de.foo.bar.service.system.TransactionRequestService.processTransaction(TransactionRequestService.java:110) ~[bin/:?]
at de.foo.bar.service.system.TransactionRequestService.runService(TransactionRequestService.java:72) ~[bin/:?]
at de.foo.bar.service.model.InfiniteService.run(InfiniteService.java:57) ~[bin/:?]
at com.google.common.util.concurrent.AbstractExecutionThreadService$1$2.run(AbstractExecutionThreadService.java:60) [guava-16.0.1.jar:?]
at com.google.common.util.concurrent.Callables$3.run(Callables.java:93) [guava-16.0.1.jar:?]
at java.lang.Thread.run(Thread.java:662) [?:1.6.0_43]
Caused by: java.lang.ClassNotFoundException: javax.xml.transform.Source not found by test-bundle [1]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532) ~[org.apache.felix.framework-4.2.1.jar:?]
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75) ~[org.apache.felix.framework-4.2.1.jar:?]
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955) ~[org.apache.felix.framework-4.2.1.jar:?]
at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ~[?:1.6.0_43]
... 13 more
I've checked the imported packages in the MANIFEST.MF and can see, that the package javax.xml.transform is stated (I've shortend it a bit):
Import-Package: com.fasterxml.jackson.core;resolution:=optional,com.fast
...
500;resolution:=optional,javax.servlet;resolution:=optional,javax.sql;r
esolution:=optional,javax.swing;resolution:=optional,javax.xml.bind;res
olution:=optional,javax.xml.bind.annotation;resolution:=optional,javax.
xml.bind.annotation.adapters;resolution:=optional,javax.xml.parsers;res
olution:=optional,javax.xml.transform;resolution:=optional,javax.xml.tr
ansform.stream;resolution:=optional,javax.xml.validation;resolution:=op
tional,org.bson;resolution:=optional,org.lightcouch;resolution:=optiona
l,org.osgi.framework;resolution:=optional;version="[1.5,2)",org.osgi.fr
amework.wiring;resolution:=optional,org.w3c.dom;resolution:=optional,or
g.xml.sax;resolution:=optional,sun.misc;resolution:=optional
I'm using apache felix in version 4.2.1 as an embedded framework and the maven-bundle-plugin is configured as follows:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-Name>Test Bundle</Bundle-Name>
<Bundle-Activator>de.foo.bar.test.activator.TestActivator</Bundle-Activator>
<Service-Component>OSGI-INF/component.xml</Service-Component>
<Export-Package>de.foo.bar.test</Export-Package>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Import-Package>*;resolution:=optional</Import-Package>
<Embed-Transitive>true</Embed-Transitive>
<Embed-Dependency>*;scope=compile|runtime;inline=false;artifactId=!org.osgi.core</Embed-Dependency>
<_failok>true</_failok>
<_nouses>true</_nouses>
<_nodefaultversion>true</_nodefaultversion>
<_snapshot>${osgi-version-qualifier}</_snapshot>
</instructions>
</configuration>
</plugin>
I tried to export the missing packages by using FRAMEWORK_SYSTEMPACKAGES_EXTRA property. But that seems to result in exporting all Java packages. I've stopped it on the 7th package.
Is there a way to provide these java standard packages without exporting them explicitly?
The cause of this problem was located in the framework configuration. Based on an online tutorial I had added following parameter to my config:
config.put(Constants.FRAMEWORK_SYSTEMPACKAGES, "org.osgi.framework; version=1.5.0");
This caused that the default system packages have been replaced and only org.osgi.framework has been available besides the extra packages I exported.
After I'd removed this line the default packages where available again and so javax.xml.transform.