启动包含 xmldsig 的 xsd 的 cxf 客户端时出错

Error when starting up cxf client for xsd containing xmldsig

我们目前正在开发一个包含第 3 方的网络服务器 XSD。此第 3 方 XSD 包含数字签名(导入 http://www.w3.org/2000/09/xmldsig# XSD)。

该架构有两个主要功能:

  1. 我们的 Web 服务根据第 3 方 XSD 合同接受消息
  2. 我们将其中一些消息转发给另一个(也是第 3 方) 通过小型客户端的网络服务

1) 完美运行,这里没有涉及签名的问题。

2) 是奇数。只要签名元素

<xs:element ref="sig:Signature" minOccurs="0" maxOccurs="1"/>

存在,软件将无法启动,而是崩溃并显示此错误消息:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [net.eucaris.services.GenericServiceSoap]: Factory method 'genericServiceSoap' threw exception; nested exception is java.lang.IllegalArgumentException: can't parse argument number: ''{0}'' at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) [spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) [spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE] ... 38 more Caused by: java.lang.IllegalArgumentException: can't parse argument number: ''{0}'' at java.text.MessageFormat.makeFormat(MessageFormat.java:1429) [rt.jar:1.8.0_131] at java.text.MessageFormat.applyPattern(MessageFormat.java:479) [rt.jar:1.8.0_131] at java.text.MessageFormat.(MessageFormat.java:362) [rt.jar:1.8.0_131] at java.text.MessageFormat.format(MessageFormat.java:840) [rt.jar:1.8.0_131] at com.sun.xml.bind.v2.model.impl.Messages.format(Messages.java:132) [jaxb-impl-2.2.11.jar:2.2.11]

我追踪到生成的文件,准确地说是端口类型接口:

@WebService(targetNamespace = "http://services.eucaris.net/", name = "GenericServiceSoap")
@XmlSeeAlso({org.w3._2000._09.xmldsig_.ObjectFactory.class, ObjectFactory.class})
public interface GenericServiceSoap {
...

这里只要引用了xmldsig-ObjectFactory,系统就会崩溃。一旦它出来,一切正常(好吧,直到有人发送签名,然后无法识别)。

深入挖掘(即调试)使我得到以下信息:

这段代码抛出异常(java.text.MessageFormat,从第1415行开始,jdk 1.8.131)

 private void makeFormat(int position, int offsetNumber,
                            StringBuilder[] textSegments)
    {
        String[] segments = new String[textSegments.length];
        for (int i = 0; i < textSegments.length; i++) {
            StringBuilder oneseg = textSegments[i];
            segments[i] = (oneseg != null) ? oneseg.toString() : "";
        }

        // get the argument number
        int argumentNumber;
        try {
            argumentNumber = Integer.parseInt(segments[SEG_INDEX]); // always unlocalized!
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("can't parse argument number: "
                                               + segments[SEG_INDEX], e);
        }

方法参数是 73、0 和一个包含以下数据的 StringBuilder

[Es ist keine ObjectFactory mit @XmlElementDecl für das Element ', ''{0}'', null, null]

这表明,不知何故,在某处,此 StringBuffer 填充错误,因为该方法显然需要一个数字。 “{0}”有点像占位符。考虑到消息的内容,应用程序本身会尝试引发错误或至少发出警告。

更多信息:

我们将 CXF 3.1.11 与 Spring 4.3.8 一起使用。我们正在从 wsdl 和 xsd 文件生成代码。客户端是通过

创建的
@Bean
public GenericServiceSoap genericServiceSoap() {
    final JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setAddress(http://example.com);
    factory.setServiceClass(GenericServiceSoap.class);
    factory.setInInterceptors(createInInterceptors());
    factory.setOutInterceptors(createOutInterceptors());
    return (GenericServiceSoap) factory.create();
}

签名生成这段代码,我觉得没问题:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SignatureType", propOrder = {
    "signedInfo",
    "signatureValue",
    "keyInfo",
    "objects"
})
@XmlRootElement(name = "Signature")
public class Signature implements Serializable
{

    private final static Long serialVersionUID = 5363422069410258353L;
    @XmlElement(name = "SignedInfo", required = true)
    @NotNull
    protected SignedInfo signedInfo;
    @XmlElement(name = "SignatureValue", required = true)
    @NotNull
    protected SignatureValue signatureValue;
    @XmlElement(name = "KeyInfo")
    protected KeyInfo keyInfo;
    @XmlElement(name = "Object")
    protected List<org.w3._2000._09.xmldsig_.Object> objects;
    @XmlAttribute(name = "Id")
    @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
    @XmlID
    @XmlSchemaType(name = "ID")
    @Pattern(regexp = "[\i-[:]][\c-[:]]*")
    protected String id;
    // getters/setters omitted

我只是不明白为什么会发生这种情况。还是我 运行 遇到了错误?

主要问题是

的一个实例

com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions Two classes have the same XML type name "xxx". Use @XmlType.name and @XmlType.namespace

那个问题已经解决了。

至于为什么这个错误在框架的深处被破坏而不是清楚地给出,我不知道。我以前见过这个错误,一旦知道该怎么做就很清楚了。也许那里某处有错误,谁知道呢。