删除 Spring WS Web 服务输出中的命名空间前缀 [英] Removing namespace prefix in the output of Spring WS web service

查看:53
本文介绍了删除 Spring WS Web 服务输出中的命名空间前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Spring-WS 创建了 Web 服务.当我向 Web 服务发送请求时,这是我在 soap-ui 中得到的响应:

I have created web service using Spring-WS. When I send a request to the web service, this is the response I get in soap-ui:

enter code here
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <ns2:SendResponse xmlns:ns2="http://mycompany.com/schema/">
         <ns2:SendResult>
            <ns2:Token>A00179-02</ns2:Token>
         </ns2:SendResult>
      </ns2:SendResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

有没有办法从响应中去掉ns2"命名空间前缀?我尝试了几个选项:1) 手动更新 package-info.java 将前缀设置为 "":

Is there any way to get rid of the "ns2" namespace prefix from the response? I tried a couple of options: 1) Manually updated package-info.java to set the prefix to "":

@XmlSchema(namespace = "http://mycompany.com/schema/",  
    xmlns = {   
        @XmlNs(namespaceURI = "http://mycompany.com/schema/", prefix = "")  
    },  
    elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)  

package com.example.foo.jaxb; 

2) 在端点类的 QName 对象中设置前缀为":

2) Set the prefix to "" in the QName object in the endpoint class:

return new JAXBElement<SendAndCommitResponse>(new QName("http://mycompany.com/schema/",
"SendResponse",""), SendResponse.class, response);

两者都不起作用.如何摆脱ns2"命名空间前缀?

Both didn't work. How to get rid off the "ns2" namespace prefix?

推荐答案

我最终找到了解决方案.

I eventually found a solution for this.

我的问题是由于 JDK 6 没有提供完整版本的 rt.jar (http://www.oracle.com/technetwork/java/javase/compatibility-137541.html).

My problem was caused by JDK 6 not shipping a full version of rt.jar (http://www.oracle.com/technetwork/java/javase/compatibility-137541.html).

我在 Maven 配置中添加了以下内容

I added the following to my maven config

<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.2.6</version>
</dependency>

然后添加

@XmlSchema(namespace = "http://mycompany.com/schema/", 
   elementFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED).

在 package-info.java 中(就像上面@acdcjunior 建议的那样)

In the package-info.java (like suggested by @acdcjunior above)

这篇关于删除 Spring WS Web 服务输出中的命名空间前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆