我想从.xml文件中获取SoapMessage对象。这是我的方法:
private void parseSoapXml() throws XMLStreamException, IOException, SOAPException, JAXBException {
SOAPMessage message = readSoapMessage(PATH);
Unmarshaller unmarshaller = JAXBContext.newInstance(Transactions.class).createUnmarshaller();
Transactions transactions = (Transactions) unmarshaller.unmarshal(message.getSOAPBody().extractContentAsDocument());
System.out.println("NUMBER: " + transactions.getTransaction().length);
}
public SOAPMessage readSoapMessage(String filename) throws SOAPException,
IOException {
File initialFile = new File(PATH);
InputStream is = new FileInputStream(initialFile);
SOAPMessage request = MessageFactory.newInstance().createMessage(null, is);
return request;
}
我有XML,我需要使用JAXB解析为Java类。调试器显示的请求正文为null。但是文件已正确读取我在哪里错了?我试图以一些不同的方式阅读,每次都是空的。代码为我提供了下一个例外。
例外是:
org.apache.wicket.WicketRuntimeException: Can't instantiate page using constructor 'public com.giffing.examples.wicket.spring.boot.simplewar.HomePage() throws java.io.FileNotFoundException,javax.xml.bind.JAXBException,javax.xml.soap.SOAPException,javax.xml.stream.XMLStreamException'. An exception has been thrown during construction!
org.apache.wicket.DefaultMapperContext.newPageInstance(DefaultMapperContext.java:102) ~[wicket-core-7.9.0.jar:7.9.0]
at org.apache.wicket.core.request.handler.PageProvider.resolvePageInstance(PageProvider.java:271) ~[wicket-core-7.9.0.jar:7.9.0]
...
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_91]
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:175) ~[wicket-core-7.9.0.jar:7.9.0]
... 33 common frames omitted
Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 10 counts of IllegalAnnotationExceptions
at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:91) ~[na:1.8.0_91]
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:445) ~[na:1.8.0_91]
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:277) ~[na:1.8.0_91]
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:124) ~[na:1.8.0_91]
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1123) ~[na:1.8.0_91]
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:147) ~[na:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_91]