- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我似乎对 Jax-WS 和 Jax-b 一起玩得很好有疑问。我需要使用具有预定义 WSDL 的 Web 服务。执行生成的客户端时,我收到以下错误:
javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException - with linked exception: [com.sun.istack.SAXException2: unable to marshal type "java.lang.String" as an element because it is missing an @XmlRootElement annotation]
当我使用外部自定义绑定(bind)文件将不必要的复杂类型映射到 java.lang.string 时,就开始出现这种情况。这是我的绑定(bind)文件的摘录:
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc">
<bindings schemaLocation="http://localhost:7777/GESOR/services/RegistryUpdatePort?wsdl#types?schema1" node="/xs:schema">
<bindings node="//xs:element[@name='StwrdCompany']//xs:complexType//xs:sequence//xs:element[@name='company_name']">
<property>
<baseType name="java.lang.String" />
</property>
</bindings>
<bindings node="//xs:element[@name='StwrdCompany']//xs:complexType//xs:sequence//xs:element[@name='address1']">
<property>
<baseType name="java.lang.String" />
</property>
</bindings>
<bindings node="//xs:element[@name='StwrdCompany']//xs:complexType//xs:sequence//xs:element[@name='address2']">
<property>
<baseType name="java.lang.String" />
</property>
</bindings>
...more fields
</bindings>
</bindings>
当针对提供的 WSDL 执行 wsimport 时,会生成 StwrdCompany,并声明以下变量:
@XmlRootElement(name = "StwrdCompany")
public class StwrdCompany
{
@XmlElementRef(name = "company_name", type = JAXBElement.class)
protected String companyName;
@XmlElementRef(name = "address1", type = JAXBElement.class)
protected String address1;
@XmlElementRef(name = "address2", type = JAXBElement.class)
... more fields
... getters/setters
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"value"
})
public static class CompanyName {
@XmlValue
protected String value;
@XmlAttribute
protected Boolean updateToNULL;
/**
* Gets the value of the value property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getValue() {
return value;
}
/**
* Sets the value of the value property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setValue(String value) {
this.value = value;
}
/**
* Gets the value of the updateToNULL property.
*
* @return
* possible object is
* {@link Boolean }
*
*/
public boolean isUpdateToNULL() {
if (updateToNULL == null) {
return false;
} else {
return updateToNULL;
}
}
/**
* Sets the value of the updateToNULL property.
*
* @param value
* allowed object is
* {@link Boolean }
*
*/
public void setUpdateToNULL(Boolean value) {
this.updateToNULL = value;
}
... more inner classes
}
}
最后,这是来自 WSDL 的相关片段,它似乎导致了这种悲痛。
<xs:element name="StwrdCompany">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="1" minOccurs="0" name="company_name" nillable="true">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute default="false" name="updateToNULL" type="xs:boolean"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element maxOccurs="1" minOccurs="0" name="address1" nillable="true">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute default="false" name="updateToNULL" type="xs:boolean"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
... more fields in the same format
<xs:element maxOccurs="1" minOccurs="0" name="p_source_timestamp" nillable="false" type="xs:string"/>
</xs:sequence>
<xs:attribute name="company_xid" type="xs:string"/>
</xs:complexType>
</xs:element>
自定义绑定(bind)的原因是我可以更轻松地将用户输入从 pojo 映射到 StwrdCompany 对象,无论是直接实例化还是通过使用 Dozer 进行 bean 映射。如果没有自定义绑定(bind),我无法在对象之间成功映射。
最后,我尝试的另一件事是设置 globalBinding 定义:
<globalBindings generateValueClass="false"></globalBindings>
由于 Soap 消息使用 xs:string xml 类型而不是传递已定义的复杂类型,这导致服务器出现参数不匹配异常,因此我放弃了这个想法。
如能深入了解导致 MarshalException 的原因或如何更轻松地解决调用 web 服务和映射这些对象的问题,我们将不胜感激。我已经找了好几天了,可悲的是我觉得自己被难住了。
最佳答案
您需要添加一个 <xjc:simple />
<jaxb:globalBindings>
中的元素使 JAXB 正确处理根元素的部分。只需将以下内容插入您的绑定(bind)文件
<jaxb:globalBindings>
<xjc:simple />
</jaxb:globalBindings>
我有一个 JAXB 映射示例 here你可以用来寻找灵感。
关于java - 带有自定义 JAX-B 绑定(bind)的 JAX-WS MarshalException : Unable to marshal type "java.lang.String" as an element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2626771/
这个问题在这里已经有了答案: android studio adb Syntax error: ")" unexpected (4 个答案) 关闭 5 年前。 我确实将我的工作室更新到 Linux
当我打开 Android Studio 时,它会显示下面的对话框,我的应用程序无法以 Debug模式运行。 最佳答案 找到sdk->platform-tool文件夹,然后运行命令adb tcpip 5
我在 Fedora 33 机器上使用了 VSCode (1.52.1) 一段时间。 我正在使用 Docker 扩展 (v1.9.0) 但由于某种原因,在过去几天中,当我尝试将 VSCode 附加到 D
我正在尝试为我的任务加载一个名为“tr_model.h5”的预训练模型,但出现以下错误: Traceback (most recent call last): File "Trigger_Proje
我最近在 Google Play 中发布了一个 Android 应用程序,到目前为止一切看起来都很棒,但有一个异常(exception)(见下文),我有时会收到控制台崩溃的消息,它只发生在某些用户身上
单击警告时,我收到此消息。这是案件的截图。 错误写道, Unable to open 'warning.cpp': Unable to read file '/Users/dimen/code/C++
重新编译 php 后,当我使用 php cli 时出现以下错误: PHP Warning: PHP Startup: imap: Unable to initialize module Module
使用 git 1.6.4.2,当我尝试 git pull 时出现此错误: error: unable to resolve reference refs/remotes/origin/LT558-op
我是 Kotlin 的新手,我正在学习教程。运行我的应用程序会导致它在运行时崩溃。我在底部导航栏应用程序中有三个 fragment 和一个主要 Activity 。我的目标实际上只是成功运行该应用程序
我在 Windows 10 64 位上运行 Android Studio。我在 5 月 20 日早上升级到了最新的版本和 SDK,从那时起,我在打开 Android Studio 时收到上述错误。我还
因此,我创建了一个 GitHub 操作,该操作应该在发生推送时构建 docker 镜像并将其推送到 docker hub。所以这是我的 GitHub 操作:(第一次创建 GitHub 操作) name
当这些问题中的任何一个都没有帮助我时,这意味着我需要删除并重新安装 Android Studio。 这是错误: Error initializing ADB: Unable to create Deb
Iam running the latest OSX/Flutter/XCode Versions using flutter, android studio and firebase and
我最近重新安装了 ubuntu 20.04.3,在做了一些设置后,我现在在运行 apt update 时总是收到以下错误.我一定是不小心删除了某种缓存文件或目录,但我不知道如何诊断或解决这个问题。 任
今天,当我将更改推送到 Gitlab 中的代码存储库时,我才开始在 Gitlab 中收到此错误消息。 Gitlab fatal: unable to access '.......' SSL Cert
我正在使用 Protractor 和 Jasmine 。 我已经确定了 chrome 驱动程序版本:2.32.498550 (latest)与 Chrome 测试版不兼容 (Version 62.0.
我正在尝试使用 terraform (0.12.24) 和多个 Docker 提供程序(插件版本 2.7.0)执行简单部署。我使用下面的 Terraform 模板的目的是将两个不同的容器部署到两个不同
这个问题我看了很久,最后决定在这里提出来。我需要维护一些用 Delphi 2007 for .NET (ASP.NET 2.0) 编写的应用程序。通常,第一次运行应用程序(使用 IIS)时,我会收到经
如何修复 - 无法创建调试桥:无法启动 adb 服务器:无法检测 adb 版本,adb 输出:/home/dilip/Downloads/sdk/platform-tools/adb: 1:/home
通过命令提示符连接到 android 中的 Sqlite DB 时出现错误。 以下是我遵循的步骤: 我已经在 android 中通过 java 程序创建了 Sqlite 数据库。创建表并向其中插入数据
我是一名优秀的程序员,十分优秀!