Java JAXB解组异常
在底部编辑 当前正在经历一个又一个错误。似乎我向前迈出了一步,不得不后退两步:)不幸的是,我在本地没有可以配对的人,所以我的很多调试都是通过谷歌完成的,等等 我不太熟悉jaxb,也不太熟悉使用它进行soap调用(这是我目前正在尝试的——连接到soap服务),但有人告诉我,这是我想要做的最简单的方法,我应该研究一下,因为我在项目的其余部分使用spring boot,所以我找到了一个教程()并从那里开始 下面是我的pom的插件部分,它创建了基于wsdl的类包:Java JAXB解组异常,java,maven-jaxb2-plugin,Java,Maven Jaxb2 Plugin,在底部编辑 当前正在经历一个又一个错误。似乎我向前迈出了一步,不得不后退两步:)不幸的是,我在本地没有可以配对的人,所以我的很多调试都是通过谷歌完成的,等等 我不太熟悉jaxb,也不太熟悉使用它进行soap调用(这是我目前正在尝试的——连接到soap服务),但有人告诉我,这是我想要做的最简单的方法,我应该研究一下,因为我在项目的其余部分使用spring boot,所以我找到了一个教程()并从那里开始 下面是我的pom的插件部分,它创建了基于wsdl的类包: <plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>vantiveGenericWebService.wsdl</generatePackage>
<schemas>
<schema>
<url>http://hostname:port/GenericWebService/ws?service=InstalledComponentService2&appl=vantive&wsdl</url>
</schema>
</schemas>
</configuration>
</plugin>
以及客户端配置类:
@Configuration
public class VantiveGenericWebServiceConfig {
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("vantiveGenericWebService.wsdl");
return marshaller;
}
@Bean
public VantiveGenericWebServiceClient vantiveGenericWebServiceClient(Jaxb2Marshaller marshaller) {
VantiveGenericWebServiceClient client = new VantiveGenericWebServiceClient();
client.setDefaultUri("http://hostname:port/GenericWebService/ws?&service=InstalledComponentService2&appl=vantive");
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
// ClientInterceptor[] interceptors = new ClientInterceptor[] { new ClientInterceptor() {
// @Override
// public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
// return false;
// }
//
// @Override
// public boolean handleResponse(MessageContext messageContext) throws WebServiceClientException {
// return true;
// }
//
// @Override
// public boolean handleFault(MessageContext messageContext) throws WebServiceClientException {
// return true;
// }
//
// @Override
// public void afterCompletion(MessageContext messageContext, Exception e) throws WebServiceClientException {
//
// }
// }};
// client.setInterceptors(interceptors);
return client;
}
}
现在来看看错误!首先,我得到一个像这样的:
org.springframework.oxm.MarshallingFailureException: JAXB marshalling exception; nested exception is javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type "vantiveGenericWebService.wsdl.GetICDetailsByAssetTag" as an element because it is missing an @XmlRootElement annotation]
@XmlRootElement(name = "assetTag")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "getICDetailsByAssetTag", propOrder = {
"assetTag"
})
public class GetICDetailsByAssetTag {
因此,我修改了GetICDetailsByAssetTag类(从wsdl生成的类)如下所示:
org.springframework.oxm.MarshallingFailureException: JAXB marshalling exception; nested exception is javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type "vantiveGenericWebService.wsdl.GetICDetailsByAssetTag" as an element because it is missing an @XmlRootElement annotation]
@XmlRootElement(name = "assetTag")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "getICDetailsByAssetTag", propOrder = {
"assetTag"
})
public class GetICDetailsByAssetTag {
我不能100%确定它是正确的xml根,但是错误消失了。现在,我的第二个(也是当前)错误是:
org.springframework.oxm.UnmarshallingFailureException: JAXB unmarshalling exception; nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Fault"). Expected elements are <{http://hostname/vantive/ws/InstalledComponentService2}DuplicateException>,<{http://hostname/vantive/ws/InstalledComponentService2}FunctionalException>,<{http://hostname/vantive/ws/InstalledComponentService2}GetICDetailsByAssetTagResponse>,<{http://hostname/vantive/ws/InstalledComponentService2}GetInstalledComponentDetailsByAssetTagAndStatusResponse>,<{http://hostname/vantive/ws/InstalledComponentService2}InvalidValuesException>,<{http://hostname/vantive/ws/InstalledComponentService2}SetClientDeviceXrefResponse>,<{http://hostname/vantive/ws/InstalledComponentService2}SetInstalledComponentAssetTagResponse>,<{http://hostname/vantive/ws/InstalledComponentService2}TechnicalException>,<{http://hostname/vantive/ws/InstalledComponentService2}assetTag>,<{http://hostname/vantive/ws/InstalledComponentService2}getICDetailsByAssetTag>,<{http://hostname/vantive/ws/InstalledComponentService2}getInstalledComponentDetailsByAssetTagAndStatus>,<{http://hostname/vantive/ws/InstalledComponentService2}installedComponentAssetTagDetails>,<{http://hostname/vantive/ws/InstalledComponentService2}installedComponentDetails>,<{http://hostname/vantive/ws/InstalledComponentService2}setClientDeviceXref>,<{http://com.savvis.it/vantive/ws/InstalledComponentService2}setClientDeviceXrefResult>,<{http://hostname/vantive/ws/InstalledComponentService2}setInstalledComponentAssetTag>,<{http://hostname/vantive/ws/InstalledComponentService2}setInstalledComponentAssetTagResult>
查看这篇博客文章,了解关于XmlRootElement的非常好的解释:嘿,感谢@jonckwanderkogel的链接!这是很多信息(好东西),实际上我带着更多的问题离开了,但我将把这些问题留给另一个主题:)我带走的一件很快的事情是我将XmlRootElement设置为“assetTag”实际上可能是正确的元素…基于soap请求。查看这篇博客文章,了解关于XmlRootElement的非常好的解释:嘿,谢谢@jonckwanderkogel的链接!这是很多信息(好东西),实际上我带着更多的问题离开了,但我将把这些问题留给另一个主题:)我带走的一件很快的事情是,我将XmlRootElement设置为“assetTag”实际上可能是正确的元素……基于soap请求。
@XmlSchema(namespace = "http://hostname/vantive/ws/InstalledComponentService2")
package vantiveGenericWebService.wsdl;