I'm using Java 6. I have this dependency in my pom ...
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.10.0</version>
</dependency>
I'm trying to parse an XHTML doc with this line
<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>EN-US</w:LidThemeOther> <w:LidThemeAsian>JA</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:EnableOpenTypeKerning/> <w:DontFlipMirrorIndents/> <w:OverrideTableStyleHps/> <w:UseFELayout/> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument> </xml><![endif]-->
using this code ...
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setExpandEntityReferences(false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
final DocumentBuilder builder = factory.newDocumentBuilder();
final InputSource s = new InputSource(new StringReader(str));
org.w3c.dom.Document result = builder.parse(s);
but my parsing is dying with the following exception ...
[Fatal Error] :91:947: The string "--" is not permitted within comments.
org.xml.sax.SAXParseException: The string "--" is not permitted within comments.
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at com.myco.myproject.util.XmlUtilities.getStringAsDocument(XmlUtilities.java:201)
at com.myco.myproject.util.NetUtilities.getUrlAsDocument(NetUtilities.java:67)
at com.myco.myproject.parsers.impl.ForesightEventsParser.getEventsFromElement(ForesightEventsParser.java:133)
at com.myco.myproject.parsers.impl.ForesightEventsParser.parsePage(ForesightEventsParser.java:99)
at com.myco.myproject.parsers.impl.ForesightEventsParser.getEvents(ForesightEventsParser.java:58)
at com.myco.myproject.domain.EventFeed.refresh(EventFeed.java:87)
at com.myco.myproject.domain.EventFeed.getEvents(EventFeed.java:72)
at com.myco.myproject.parsers.impl.ForesightParserTest.testParser(ForesightParserTest.java:49)
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:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Without changing my XHTML, anyone know how I can parse this document successfully?
Edit Per the comments given, I removed the term "well-formed" from my original question. I'm still really interested in how to make this exception go away without changing the text I'm parsing (which I don't have control over). For the purposes of this question, you can assume the "--" within comments is the only violation of the term "well-formed."
By definition:
A comment starts and ends with "--", and does not contain any occurrence of "--".
So no, your XHTML is not well-formed because you can't use -- anywhere inside a comment. Can you replace it by something else? or maybe put a space in-between, like this: - -. There really isn't a clean solution to this problem, any alternatives involve messing around with placeholders, encodings, etc.
Your document must have at least an extra "-". Might be you have written:
<!--- --> or
<!--- ---> or
<!-- ---> etc.
Related
I am trying to create a Distributed Logging system, where my each tomcat instance will put the logs into a exchange/queue and it will be accumulated and stored in one plcae.
I was reading about Log4j + Amqp using rabbitmq.
I have downloaded the following sample code also.
https://nodeload.github.com/SpringSource/spring-amqp-samples/zipball/master
Imported project log4j from the package.
When i run the IntegrationTest.java (Junit). I get a failure. Following is the trace.
java.lang.AssertionError: Time out waiting for message
at org.junit.Assert.fail(Assert.java:91)
at org.junit.Assert.assertTrue(Assert.java:43)
at org.springframework.amqp.rabbit.log4j.web.controller.IntegrationTest.logInfo(IntegrationTest.java:75)
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:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
This is happening because no logs is coming to the listener AmqpLogMessageListener in the watch time.
I have some doubts about the code:
How the listener AmqpLogMessageListener.java is registered for listening to the configured exchange.
Why the Test is failing ?
Juste to be sure, check your log4j properties file against the source https://github.com/SpringSource/spring-amqp-samples/blob/master/log4j/src/main/resources/log4j.properties.
Then, it may be your connection on RabbitMQ which can be long to obtain, so change this:
new CountDownLatch(1);
by this:
new CountDownLatch(5);
I'm using Java 6 and the latest version of Xerces. I'm trying to parse an HTML document that begins like this ...
<!DOCTYPE html>
and later references the entity "»". Parsing dies with the exception ...
org.xml.sax.SAXParseException: The entity "raquo" was referenced, but not declared.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:249)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
at com.myco.myproject.util.XmlUtilities.getStringAsDocument(XmlUtilities.java:147)
at com.myco.myproject.util.NetUtilities.getUrlAsDocument(NetUtilities.java:65)
at com.myco.myproject.parsers.impl.AbstractMetromixParser.parsePage(AbstractMetromixParser.java:107)
at com.myco.myproject.parsers.impl.AbstractMetromixParser.getEvents(AbstractMetromixParser.java:76)
at com.myco.myproject.domain.EventFeed.refresh(EventFeed.java:81)
at com.myco.myproject.domain.EventFeed.getEvents(EventFeed.java:72)
at com.myco.myproject.parsers.impl.MetromixParserTest.testParser(MetromixParserTest.java:21)
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:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Is there any way to tell the parser to ignore these types of entities it cannot resolve? If not, what resolver do I have to plugin?
Edit: Here is how I am parsing the HTML, which is actually XHTML. I pass the String through JSoup to clean it up before I attempt the below ...
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setExpandEntityReferences(false);
final DocumentBuilder builder = factory.newDocumentBuilder();
final InputSource s = new InputSource(new StringReader(str));
org.w3c.dom.Document result = builder.parse(s);
Starting from 1.10.3 version JSoup provides the W3CDom helper class which allows you to convert your org.jsoup.nodes.Document directly to the org.w3c.dom.Document.
Consider the following example:
String str =
"<!DOCTYPE html>" +
"<html>" +
"<dody>" +
"<div>» example</div>" +
"</dody>" +
"</html>";
Document document = Jsoup.parse(str);
W3CDom w3cDom = new W3CDom();
org.w3c.dom.Document result = w3cDom.fromJsoup(document);
I'm using Java 6. I want to find a tool that can clean up ugly HTML. Specifically, I would like a tool that could deal with the following ...
<script type="text/javascript">
document.write(
'<scr'+'ipt src="http://ox-d.journatic.com/w/1.0/jstag"><\/scr'+'ipt>');
</script>
I have tried JSoup v 1.6.2 to deal with the above, but running the above code using
final org.jsoup.nodes.Document doc = Jsoup.parse(html);
final String formattedHtml = doc.toString();
returns the same code. THe problem with the above is taht when I try and parse it with
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
final DocumentBuilder builder = factory.newDocumentBuilder();
final InputSource s = new InputSource(new StringReader(cleanedUpHtml));
org.w3c.dom.Document result = builder.parse(s);
I get the exception ...
org.xml.sax.SAXParseException: Element type "scr" must be followed by either attribute specifications, ">" or "/>".
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:249)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
at com.myco.myproject.util.XmlUtilities.getStringAsDocument(XmlUtilities.java:146)
at com.myco.myproject.util.NetUtilities.getUrlAsDocument(NetUtilities.java:54)
at com.myco.myproject.parsers.impl.AbstractMetromixParser.parsePage(AbstractMetromixParser.java:107)
at com.myco.myproject.parsers.impl.AbstractMetromixParser.getEvents(AbstractMetromixParser.java:76)
at com.myco.myproject.domain.EventFeed.refresh(EventFeed.java:81)
at com.myco.myproject.domain.EventFeed.getEvents(EventFeed.java:72)
at com.myco.myproject.parsers.impl.MetromixParserTest.testParser(MetromixParserTest.java:21)
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:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Any suggestions on an HTML parser that can tidy up the above? - Dave
You do not need to parse the String into a html document. Just use Jsoup.clean() on the raw String. See a simple example at http://jsoup.org/cookbook/cleaning-html/whitelist-sanitizer
I try to load the following yaml sequence :
- Person(paul):
firstName: Paul
lastName: Lumbergh
children :
- Person(bill)
- Person(jane)
which i tried to load in the following bean :
public class Person {
private long id;
private String firstName;
private String lastName;
private Person father;
private Set<Person> children;
}
I got this error which is due to the fact that snakeYaml load my sequence in a java.util.List instead of java.util.Set.
Is it a way to force snakeYAML to load a sequence in a java.util.Set ?
org.yaml.snakeyaml.error.YAMLException: org.yaml.snakeyaml.error.YAMLException: Cannot set property='children' with value='[Person [firstName=Bill, secondName=Lumbergh], Person [firstName=Jane, secondName=Lumbergh]]' (class java.util.ArrayList) in Person [firstName=Paul, secondName=Lumbergh]
at org.yaml.snakeyaml.extensions.compactnotation.CompactConstructor$ConstructCompactObject.construct(CompactConstructor.java:163)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:183)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructSequenceStep2(BaseConstructor.java:277)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructSequence(BaseConstructor.java:248)
at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlSeq.construct(SafeConstructor.java:440)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:183)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:142)
at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:128)
at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480)
at org.yaml.snakeyaml.Yaml.load(Yaml.java:411)
at com.pearson.fixy.Fixy.loadEntities(Fixy.java:105)
at com.pearson.fixy.Fixy.load(Fixy.java:126)
at com.dvidea.TestFixy.test(TestFixy.java:24)
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:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
According to the yaml specification the set syntax is the following one :
- Person(paul):
firstName: Paul
lastName: Lumbergh
children : !!set ? Person(bill) ? Person(jane) –
You force SnakeYAML to use List instead of Set. Sets have different representation in YAML: http://yaml.org/type/set.html
You can change the YAML document or instruct SnakeYAML to use sets instead of lists.
You may need to look in tests
Helo!
I'm trying to create a Web Service client using CXF. My application is in OSGi. And I use the Felix Framework.
But the following error occurs:
[main] ERROR org.apache.cxf.BusFactory - Failed to determine BusFactory implementation class name.
java.lang.ClassCastException: class org.apache.cxf.bus.spring.SpringBusFactory
at java.lang.Class.asSubclass(Unknown Source)
at org.apache.cxf.BusFactory.getBusFactoryClass(BusFactory.java:280)
at org.apache.cxf.BusFactory.newInstance(BusFactory.java:207)
at org.apache.cxf.BusFactory.newInstance(BusFactory.java:194)
at org.apache.cxf.BusFactory.getDefaultBus(BusFactory.java:90)
at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:137)
at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:122)
at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:89)
at javax.xml.ws.Service.<init>(Service.java:36)
at myorg.engine.test.mocks.soapservice.client.CHMService.<init>(CHMService.java:42)
at myorg.engine.service.OSGiServiceTest.testSoapServiceMock(OSGiServiceTest.java:133)
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.ops4j.pax.exam.raw.extender.intern.ProbeInvokerImpl.injectContextAndInvoke(ProbeInvokerImpl.java:112)
at org.ops4j.pax.exam.raw.extender.intern.ProbeInvokerImpl.findAndInvoke(ProbeInvokerImpl.java:71)
at org.ops4j.pax.exam.raw.extender.intern.ProbeInvokerImpl.call(ProbeInvokerImpl.java:58)
at org.ops4j.pax.exam.nat.internal.NativeTestContainer.call(NativeTestContainer.java:83)
at org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactor.invoke(EagerSingleStagedReactor.java:85)
at org.ops4j.pax.exam.junit.JUnit4TestRunner$2.evaluate(JUnit4TestRunner.java:259)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.ops4j.pax.exam.junit.JUnit4TestRunner.run(JUnit4TestRunner.java:86)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
[main] ERROR org.apache.cxf.BusFactory - Failed to instantiate bus factory.
java.lang.ClassCastException: class org.apache.cxf.bus.spring.SpringBusFactory
at java.lang.Class.asSubclass(Unknown Source)
at org.apache.cxf.BusFactory.newInstance(BusFactory.java:218)
at org.apache.cxf.BusFactory.newInstance(BusFactory.java:194)
at org.apache.cxf.BusFactory.getDefaultBus(BusFactory.java:90)
at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:137)
at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:122)
at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:89)
at javax.xml.ws.Service.<init>(Service.java:36)
at myorg.engine.test.mocks.soapservice.client.CHMService.<init>(CHMService.java:42)
at myorg.engine.service.OSGiServiceTest.testSoapServiceMock(OSGiServiceTest.java:133)
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.ops4j.pax.exam.raw.extender.intern.ProbeInvokerImpl.injectContextAndInvoke(ProbeInvokerImpl.java:112)
at org.ops4j.pax.exam.raw.extender.intern.ProbeInvokerImpl.findAndInvoke(ProbeInvokerImpl.java:71)
at org.ops4j.pax.exam.raw.extender.intern.ProbeInvokerImpl.call(ProbeInvokerImpl.java:58)
at org.ops4j.pax.exam.nat.internal.NativeTestContainer.call(NativeTestContainer.java:83)
at org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactor.invoke(EagerSingleStagedReactor.java:85)
at org.ops4j.pax.exam.junit.JUnit4TestRunner$2.evaluate(JUnit4TestRunner.java:259)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.ops4j.pax.exam.junit.JUnit4TestRunner.run(JUnit4TestRunner.java:86)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
[org.ops4j.pax.exam.junit.JUnit4TestRunner] : Exception
org.ops4j.pax.exam.TestContainerException: java.lang.reflect.InvocationTargetException
at org.ops4j.pax.exam.raw.extender.intern.ProbeInvokerImpl.injectContextAndInvoke(ProbeInvokerImpl.java:118)
at org.ops4j.pax.exam.raw.extender.intern.ProbeInvokerImpl.findAndInvoke(ProbeInvokerImpl.java:71)
at org.ops4j.pax.exam.raw.extender.intern.ProbeInvokerImpl.call(ProbeInvokerImpl.java:58)
at org.ops4j.pax.exam.nat.internal.NativeTestContainer.call(NativeTestContainer.java:83)
at org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactor.invoke(EagerSingleStagedReactor.java:85)
at org.ops4j.pax.exam.junit.JUnit4TestRunner$2.evaluate(JUnit4TestRunner.java:259)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.ops4j.pax.exam.junit.JUnit4TestRunner.run(JUnit4TestRunner.java:86)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.reflect.InvocationTargetException
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.ops4j.pax.exam.raw.extender.intern.ProbeInvokerImpl.injectContextAndInvoke(ProbeInvokerImpl.java:112)
... 20 more
Caused by: java.lang.RuntimeException: java.lang.ClassCastException: class org.apache.cxf.bus.spring.SpringBusFactory
at org.apache.cxf.BusFactory.newInstance(BusFactory.java:224)
at org.apache.cxf.BusFactory.newInstance(BusFactory.java:194)
at org.apache.cxf.BusFactory.getDefaultBus(BusFactory.java:90)
at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:137)
at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:122)
at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:89)
at javax.xml.ws.Service.<init>(Service.java:36)
at myorg.engine.test.mocks.soapservice.client.CHMService.<init>(CHMService.java:42)
at myorg.engine.service.OSGiServiceTest.testSoapServiceMock(OSGiServiceTest.java:133)
... 25 more
Caused by: java.lang.ClassCastException: class org.apache.cxf.bus.spring.SpringBusFactory
at java.lang.Class.asSubclass(Unknown Source)
at org.apache.cxf.BusFactory.newInstance(BusFactory.java:218)
... 33 more
I said it could be because of different ClassLoader. Is it possible?
Any idea how to solve the problem?
Thanks!
Yes, it looks like you have two BusFactory class definitions. The SpringBusFactory implements one of them, and the asSubclass() call is made on the other. Since one BusFactory isn't the same class as the other, you'd get a CCE. Look for two different bundles containing the BusFactory class. One of them will be imported by the bundle that defines the SpringBusFactory.
I think the "two BusFactory class definitions" is a red herring.
Not sure what version of CXF you're using (guessing 2.4.2) but that code is trying to do ServiceLoader kind of stuff using the thread context classloader when looking for subclass implementations.
My best guess is there some Spring "magic" that CXF relies on and your missing the bundle that provides it. Looking at the CXF feature for Karaf it has loads of dependencies, check this and ensure you've got them all - at this point it may be easier to try this out using karaf with the CXF feature installed.
If you're using maven the features file can be accessed with this:
<dependency>
<groupId>org.apache.cxf.karaf</groupId>
<artifactId>apache-cxf</artifactId>
<version>2.4.2</version>
<type>xml</type>
<classifier>features</classifier>
</dependency>
Some documentation on bus configuration here
I've seen strange errors like that with pax-exam in the past. Does this run outside of pax-exam in a "normal" OSGi environment? Talend Service Factory ( http://talend.com/products/tsf ) has several examples (in the separate examples download package) of CXF clients and services running in OSGi and they all do work.