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>
Related
I have a Spring boot project that using connection pool. It work properly in my computer but when my colleague pull the code from git then try to run. It thrown an error as below:
2018-02-28 14:49:24.527 WARN 11856 --- [ost-startStop-1] o.a.tomcat.util.scan.StandardJarScanner : Failed to scan [file:/C:/Users/ABC/.m2/repository/com/mchange/c3p0/0.9.5.2/mchange-commons-java-0.2.11.jar] from classloader hierarchy
java.io.FileNotFoundException: C:\Users\ABC\.m2\repository\com\mchange\c3p0\0.9.5.2\mchange-commons-java-0.2.11.jar (The system cannot find the file specified)
at java.util.zip.ZipFile.open(Native Method) ~[na:1.8.0_60]
at java.util.zip.ZipFile.<init>(ZipFile.java:219) ~[na:1.8.0_60]
at java.util.zip.ZipFile.<init>(ZipFile.java:149) ~[na:1.8.0_60]
at java.util.jar.JarFile.<init>(JarFile.java:166) ~[na:1.8.0_60]
at java.util.jar.JarFile.<init>(JarFile.java:130) ~[na:1.8.0_60]
at org.apache.tomcat.util.scan.JarFileUrlJar.<init>(JarFileUrlJar.java:60) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.tomcat.util.scan.JarFactory.newInstance(JarFactory.java:49) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.tomcat.util.scan.StandardJarScanner.process(StandardJarScanner.java:338) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java:288) ~[tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.jasper.servlet.TldScanner.scanJars(TldScanner.java:262) [tomcat-embed-jasper-8.5.23.jar:8.5.23]
at org.apache.jasper.servlet.TldScanner.scan(TldScanner.java:104) [tomcat-embed-jasper-8.5.23.jar:8.5.23]
at org.apache.jasper.servlet.JasperInitializer.onStartup(JasperInitializer.java:101) [tomcat-embed-jasper-8.5.23.jar:8.5.23]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5196) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419) [tomcat-embed-core-8.5.23.jar:8.5.23]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) [tomcat-embed-core-8.5.23.jar:8.5.23]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_60]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_60]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_60]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]
I also tried to add dependency for mchange-commons-java-0.2.11, but it still doesn't work:
<dependency>
<groupId>com.mchange</groupId>
<artifactId>mchange-commons-java</artifactId>
<version>0.2.11</version>
</dependency>
If you faced or had experiences about it, please leave me a comment/idea.
Your advice or suggestions will be much appreciated and welcomed!
From the StandardJarScanner javadoc:
The default JarScanner implementation scans the WEB-INF/lib directory
followed by the provided classloader and then works up the classloader
hierarchy. This implementation is sufficient to meet the requirements
of the Servlet 3.0 specification as well as to provide a number of
Tomcat specific extensions. The extensions are:
Scanning the classloader hierarchy (enabled by default) Testing all files to see if they are JARs (disabled by default)
Testing all directories to see if they are exploded JARs (disabled by default)
All of the extensions may be controlled via configuration.
To disable that particular jar from being scanned at startup you can add this spring boot specific property:
server.tomcat.additional-tld-skip-patterns=*mchange-commons-java*.jar
The problem is the c3p0 .jar file with the wrong Class-Path:
Somehow your spring boot transitive dependency is referring the wrong
mchange-commons-java. From your error, it's searching for path .m2\repository\com\mchange\c3p0\0.9.5.2\mchange-commons-java-0.2.11.jar. See highlighted c3p0.
Ideally the path has to be com\mchange\mchange-commons-java\0.2.11\mchange-commons-java-0.2.11.jar.
It seems that mchange-commons-java dependency is conflicted.
When you open pom.xml in eclipse or in any editor, you see dependency hierarchy where it lists all the transitive dependencies. See if there is any mchange-commons-java of c3p0 and if it is there, exclude that dependency. Then your explicit declaration of dependency of mchange-commons-java dependency may work.
My problem is solved this way, see if you can solve your problem.
Problem solving method https://my.oschina.net/antsdot/blog/1634440
After 2 days of googling I am still unable to find the solution of my issue with Tess4j version 3.0: java.lang.UnsatisfiedLinkError: The specified module could not be found.
I write server side Spring boot app on my Windows 10 x64. I used this tutorial http://tess4j.sourceforge.net/tutorial/
I make ant test in tess4j project's source and this command works ok in my PC. I also have Visual C++ Redistributable for VS2012 and Visual C++ Redistributable for VS2013 installed.
But I have missed dlls in my PC, libtesseract304.dll depends on:
Can it be the reason of problem? But how it is possible, that Tess4J-3.0-src project works ok in my PC?
My full stack trace:
java.lang.UnsatisfiedLinkError: The specified module could not be found.
at com.sun.jna.Native.open(Native Method) ~[jna.jar:4.2.1 (b0)]
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:263) ~[jna.jar:4.2.1 (b0)]
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:403) ~[jna.jar:4.2.1 (b0)]
at com.sun.jna.Library$Handler.<init>(Library.java:147) ~[jna.jar:4.2.1 (b0)]
at com.sun.jna.Native.loadLibrary(Native.java:502) ~[jna.jar:4.2.1 (b0)]
at com.sun.jna.Native.loadLibrary(Native.java:481) ~[jna.jar:4.2.1 (b0)]
at net.sourceforge.tess4j.util.LoadLibs.getTessAPIInstance(Unknown Source) ~[tess4j-3.0.jar:na]
at net.sourceforge.tess4j.TessAPI.<clinit>(Unknown Source) ~[tess4j-3.0.jar:na]
at net.sourceforge.tess4j.Tesseract.init(Unknown Source) ~[tess4j-3.0.jar:na]
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source) ~[tess4j-3.0.jar:na]
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source) ~[tess4j-3.0.jar:na]
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source) ~[tess4j-3.0.jar:na]
at ocr.OCRController.handleFileUpload(OCRController.java:109) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_51]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_51]
My code:
ITesseract instance = new Tesseract(); // JNA Interface Mapping
instance.setDatapath(new File(datapath).getPath());
instance.setLanguage("eng");
try {
String result = instance.doOCR(imageFile); //error here
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
maven:
<dependency>
<groupId>jai_imageio</groupId>
<artifactId>com.jai_imageio</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jai_imageio.jar</systemPath>
</dependency>
<dependency>
<groupId>commons-io-2.4</groupId>
<artifactId>com.commons-io-2.4</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/commons-io-2.4.jar</systemPath>
</dependency>
<dependency>
<groupId>jna</groupId>
<artifactId>com.jna</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jna.jar</systemPath>
</dependency>
<dependency>
<groupId>tess4j-3.0</groupId>
<artifactId>com.tess4j-3.0</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/tess4j-3.0.jar</systemPath>
</dependency>
I also tried to load libs in force way:
Runtime.getRuntime().loadLibrary("lib/win32-x86-64/gsdll64");
Runtime.getRuntime().loadLibrary("lib/win32-x86-64/libtesseract304");
But without success:
There was an unexpected error (type=Internal Server Error, status=500).
C:\Users\Iuliia\IdeaProjects\ENumbersBackend\lib\win32-x86-64\libtesseract304.dll: Can't find dependent libraries
Thank you for any help!
I think you our misled by the output of depends.exe.
The DLL only imports these other dlls:
dumpbin libtesseract304.dll /imports|find ".dll"
Dump of file libtesseract304.dll
WS2_32.dll
liblept171.dll
MSVCP120.dll
MSVCR120.dll
KERNEL32.dll
To doublecheck you can get the linker version used to compile that dll:
dumpbin libtesseract304.dll /headers | find "linker version"
12.00 linker version
So all you need is the Visual Studio 2013 Runtime (again: don't be misled: 12.0 is 2013, which can be rather confusing)
Presumably the liblept171.dll is the thing that is missing, so you should check where it is stored and why the one project is able to find it and not the other. A good idea is to copy all dependencies into a common path and setting java.library.path to that directory (just for testing purposes)
liblept171.dll is part of lept4j, there is a accordingly named .jar in your lib directory which contains that dll:
7z l lib\lept4j-1.0.1.jar | find ".dll"
2015-11-14 11:46:04 ..... 2406400 2406400 win32-x86-64\liblept171.dll
2015-11-14 11:46:04 ..... 1834496 1834496 win32-x86\liblept171.dll
In addition you should take care that the bitness of your JRE, the Visual Studio Runtime and Tesseract do match. If in doubt: install x86 and x64.
As a further troubleshooting aid you might want to find out where the dll is being searched for. Use procmon.exe with a filter for that dll.
The problem is not connected with Windows 10.
I've already fix the error with adding
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>3.0.0</version>
</dependency>
instead all previous maven dependencies.
I am using Java6,Apache Tomcat and Jersey RESTful. While unmarshelling the XML to JAXB, I am getting the following exception.Can any body help me on this ?
Note: This Exception is inconsistent.
java.lang.NoClassDefFoundError: org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl$Parser
at org.apache.xerces.jaxp.datatype.XMLGregorianCalendarImpl.<init>(Unknown Source)
at org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl.newXMLGregorianCalendar(Unknown Source)
at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$13.parse(RuntimeBuiltinLeafInfoImpl.java:543)
at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$13.parse(RuntimeBuiltinLeafInfoImpl.java:517)
at com.sun.xml.bind.v2.runtime.reflect.TransducedAccessor$CompositeTransducedAccessorImpl.parse(TransducedAccessor.java:241)
at com.sun.xml.bind.v2.runtime.unmarshaller.LeafPropertyLoader.text(LeafPropertyLoader.java:61)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.text(UnmarshallingContext.java:462)
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.processText(StAXStreamConnector.java:367)
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleEndElement(StAXStreamConnector.java:245)
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:214)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:358)
at com.sun.xml.bind.v2.runtime.BridgeImpl.unmarshal(BridgeImpl.java:120)
at com.sun.xml.bind.api.Bridge.unmarshal(Bridge.java:233)
at com.sun.xml.ws.server.sei.EndpointArgumentsBuilder$DocLit.readRequest(EndpointArgumentsBuilder.java:517)
at com.sun.xml.ws.server.sei.EndpointArgumentsBuilder$Composite.readRequest(EndpointArgumentsBuilder.java:188)
at com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:243)
at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:93)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:598)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:557)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:542)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:439)
at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:243)
at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:444)
at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:134)
at weblogic.wsee.jaxws.HttpServletAdapter$AuthorizedInvoke.run(HttpServletAdapter.java:272)
at weblogic.wsee.jaxws.HttpServletAdapter.post(HttpServletAdapter.java:185)
at weblogic.wsee.jaxws.JAXWSServlet.doPost(JAXWSServlet.java:180)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at weblogic.wsee.jaxws.JAXWSServlet.service(JAXWSServlet.java:64)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3498)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
I have, you been adding xerces jar in your classpath ?
If not download it from xerces jar link and add it to your project classpath.
Give me feedback please. enjoy :)
EXPLANATION: New versions of java have xerces lib in jdk. This lib conflict with apache's xerses lib.
Even when it says "no class" it's because there are two of them.
SOLUTION: Check if this is true for your project and remove one of them from the dependencies and build the project.
This is due to multiple xercesImpl.jar in class path. This jar may be from your application, from JDK and from servlet container. Following changes in POM resolved this issue for me.
<dependency>
<groupId>xerces</groupId>
<artifactId>resolver</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>serializer</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<scope>provided</scope>
</dependency>
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.
Java developer here. I am using JAXB to create bind objects. When I attempt to create a JAXBContext like this:
JAXBContext.newInstance("com.mycompany.jaxb.pkg1:com.mycompany.jaxb.pkg2");
I get a NullPointerException:
Exception in thread "main" java.lang.NullPointerException
at com.sun.xml.bind.v2.model.impl.PropertyInfoImpl.calcXmlName(PropertyInfoImpl.java:287)
at com.sun.xml.bind.v2.model.impl.PropertyInfoImpl.calcXmlName(PropertyInfoImpl.java:260)
at com.sun.xml.bind.v2.model.impl.ElementPropertyInfoImpl.getTypes(ElementPropertyInfoImpl.java:100)
at com.sun.xml.bind.v2.model.impl.RuntimeElementPropertyInfoImpl.getTypes(RuntimeElementPropertyInfoImpl.java:50)
at com.sun.xml.bind.v2.model.impl.ElementPropertyInfoImpl$1.size(ElementPropertyInfoImpl.java:42)
at java.util.AbstractList$Itr.hasNext(AbstractList.java:416)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.getClassInfo(ModelBuilder.java:139)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:49)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.getClassInfo(RuntimeModelBuilder.java:41)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:189)
at com.sun.xml.bind.v2.model.impl.RegistryInfoImpl.<init>(RegistryInfoImpl.java:63)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.addRegistry(ModelBuilder.java:232)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:201)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$3.run(JAXBContextImpl.java:357)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$3.run(JAXBContextImpl.java:351)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:350)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:216)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:76)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:55)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:132)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:286)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:244)
at com.mycompany.jaxb.JAXBContextFactory.initIfNeeded(JAXBContextFactory.java:66)
Googling for the relevant keywords led me to several discussion threads saying that this is a known bug and I should upgrade to version 2.0.3. But here is my maven POM file:
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
</dependency>
...as you can see, I am already beyond version 2.0.3. (And yes, I tried rolling back to the old version; it didn't help.)
Has anyone seen this for a reason OTHER than version 2.0.2 or older, or does anyone have pointers for how to go about tracking down the problem?
Okay, for the record: I found the solution.
As several threads had suggested, the source of this bug was using a version of JAXB which was older than 2.0.2. My error was that my maven POM file was being overridden by another POM file which was importing an older version of the library.
Thanks to skaffman, and everyone else who took a look.