如何更改Spring-WS的“SOAP-ENV”默认前缀(How to change “SOAP-ENV” default prefix of Spring-WS)
我使用Spring-WS创建了一个Web服务。 为了保持与旧系统的兼容性,我需要将名称空间前缀从
SOAP-ENV
更改为soap
。我知道
SOAP-ENV
和soap
只是命名空间前缀。 只要他们引用了正确的名称空间("http://schemas.xmlsoap.org/soap/envelope/"
),它应该没问题。但旧系统对解析器代码进行了硬编码,只期望
soap
名称空间前缀。当前的回应:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header/> <SOAP-ENV:Body> ... </SOAP-ENV:Body> </SOAP-ENV:Envelope>
预期回应:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header/> <soap:Body> ... </soap:Body> </soap:Envelope>
这是迄今为止我尝试过的
创建
EndpointInterceptorAdapter
子类。 这将拦截SOAP响应/错误并更改SOAP信封。 这有效,但在性能方面并不理想。public class CustomEndpointInterceptor extends EndpointInterceptorAdapter { private static final String DEFAULT_NS = "xmlns:SOAP-ENV"; private static final String SOAP_ENV_NAMESPACE = "http://schemas.xmlsoap.org/soap/envelope/"; private static final String PREFERRED_PREFIX = "soap"; private static final String HEADER_LOCAL_NAME = "Header"; private static final String BODY_LOCAL_NAME = "Body"; private static final String FAULT_LOCAL_NAME = "Fault"; @Override public boolean handleResponse(MessageContext messageContext, Object endpoint) throws Exception { SaajSoapMessage soapResponse = (SaajSoapMessage) messageContext.getResponse(); alterSoapEnvelope(soapResponse); return super.handleResponse(messageContext, endpoint); } @Override public boolean handleFault(MessageContext messageContext, Object endpoint) throws Exception { SaajSoapMessage soapResponse = (SaajSoapMessage) messageContext.getResponse(); alterSoapEnvelope(soapResponse); return super.handleFault(messageContext, endpoint); } private void alterSoapEnvelope(SaajSoapMessage soapResponse) { Document doc = soapResponse.getDocument(); Element rootElement = doc.getDocumentElement(); rootElement.setPrefix(PREFERRED_PREFIX); // Remove default SOAP namespace rootElement.removeAttribute(DEFAULT_NS); NodeList headerNodes = doc.getElementsByTagNameNS(SOAP_ENV_NAMESPACE, HEADER_LOCAL_NAME); NodeList bodyNodes = doc.getElementsByTagNameNS(SOAP_ENV_NAMESPACE, BODY_LOCAL_NAME); NodeList faultNodes = doc.getElementsByTagNameNS(SOAP_ENV_NAMESPACE, FAULT_LOCAL_NAME); // Remove Header node. if (headerNodes.getLength() != 0) { rootElement.removeChild(headerNodes.item(0)); } // Change Body's SOAP namespace prefix. if (bodyNodes.getLength() != 0) { Element bodyElement = (Element) bodyNodes.item(0); bodyElement.setPrefix(PREFERRED_PREFIX); } if (faultNodes.getLength() != 0) { Element faultElement = (Element) faultNodes.item(0); faultElement.setPrefix(PREFERRED_PREFIX); } } }
在包含WSDL生成的类的包中更改
package-info.java
。 我用我公司的名称空间前缀成功完成了这项工作,但它不适用于SOAP-ENV
前缀。@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.example.com/ns/2008/02/02/webservices/blah", xmlns = { @javax.xml.bind.annotation.XmlNs(namespaceURI = "http://www.example.com/ns/2008/02/02/webservices/blah", prefix = ""), @javax.xml.bind.annotation.XmlNs(namespaceURI = "http://schemas.example.com/ns/2007/10/blah", prefix = "ns2"), @javax.xml.bind.annotation.XmlNs(namespaceURI = "http://example.com/ns/2007/23/05/blah/fundamental", prefix = "ns3"), @javax.xml.bind.annotation.XmlNs(namespaceURI = "http://schemas.xmlsoap.org/soap/envelope/", prefix = "soap") // doesn't work }, elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) package com.thomsonreuters.ts.ets.interdayws.soap.webservice;
有没有一种理想的方法可以在Spring-WS中将
SOAP-ENV
更改为soap
?顺便说一句,这是设置这个前缀的代码。 StroapElement.java
I've created a web service using Spring-WS. To maintain compatibility with the old system, I need to change namespace prefix from
SOAP-ENV
tosoap
.I know that
SOAP-ENV
andsoap
are just namespace prefixes. As long as they refer to the correct namespace ("http://schemas.xmlsoap.org/soap/envelope/"
), it should be fine.But the old system hard coded the parser code to expect only
soap
namespace prefix.Current response:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header/> <SOAP-ENV:Body> ... </SOAP-ENV:Body> </SOAP-ENV:Envelope>
Expected response:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header/> <soap:Body> ... </soap:Body> </soap:Envelope>
Here's what I've tried so far
Create
EndpointInterceptorAdapter
subclass. This will intercept SOAP response/fault and alter the SOAP envelope. This works, but it's not ideal in terms of performance.public class CustomEndpointInterceptor extends EndpointInterceptorAdapter { private static final String DEFAULT_NS = "xmlns:SOAP-ENV"; private static final String SOAP_ENV_NAMESPACE = "http://schemas.xmlsoap.org/soap/envelope/"; private static final String PREFERRED_PREFIX = "soap"; private static final String HEADER_LOCAL_NAME = "Header"; private static final String BODY_LOCAL_NAME = "Body"; private static final String FAULT_LOCAL_NAME = "Fault"; @Override public boolean handleResponse(MessageContext messageContext, Object endpoint) throws Exception { SaajSoapMessage soapResponse = (SaajSoapMessage) messageContext.getResponse(); alterSoapEnvelope(soapResponse); return super.handleResponse(messageContext, endpoint); } @Override public boolean handleFault(MessageContext messageContext, Object endpoint) throws Exception { SaajSoapMessage soapResponse = (SaajSoapMessage) messageContext.getResponse(); alterSoapEnvelope(soapResponse); return super.handleFault(messageContext, endpoint); } private void alterSoapEnvelope(SaajSoapMessage soapResponse) { Document doc = soapResponse.getDocument(); Element rootElement = doc.getDocumentElement(); rootElement.setPrefix(PREFERRED_PREFIX); // Remove default SOAP namespace rootElement.removeAttribute(DEFAULT_NS); NodeList headerNodes = doc.getElementsByTagNameNS(SOAP_ENV_NAMESPACE, HEADER_LOCAL_NAME); NodeList bodyNodes = doc.getElementsByTagNameNS(SOAP_ENV_NAMESPACE, BODY_LOCAL_NAME); NodeList faultNodes = doc.getElementsByTagNameNS(SOAP_ENV_NAMESPACE, FAULT_LOCAL_NAME); // Remove Header node. if (headerNodes.getLength() != 0) { rootElement.removeChild(headerNodes.item(0)); } // Change Body's SOAP namespace prefix. if (bodyNodes.getLength() != 0) { Element bodyElement = (Element) bodyNodes.item(0); bodyElement.setPrefix(PREFERRED_PREFIX); } if (faultNodes.getLength() != 0) { Element faultElement = (Element) faultNodes.item(0); faultElement.setPrefix(PREFERRED_PREFIX); } } }
Change
package-info.java
in the package that contain WSDL generated classes. I've successfully done this with my company's namespace prefix, but it doesn't work forSOAP-ENV
prefix.@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.example.com/ns/2008/02/02/webservices/blah", xmlns = { @javax.xml.bind.annotation.XmlNs(namespaceURI = "http://www.example.com/ns/2008/02/02/webservices/blah", prefix = ""), @javax.xml.bind.annotation.XmlNs(namespaceURI = "http://schemas.example.com/ns/2007/10/blah", prefix = "ns2"), @javax.xml.bind.annotation.XmlNs(namespaceURI = "http://example.com/ns/2007/23/05/blah/fundamental", prefix = "ns3"), @javax.xml.bind.annotation.XmlNs(namespaceURI = "http://schemas.xmlsoap.org/soap/envelope/", prefix = "soap") // doesn't work }, elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) package com.thomsonreuters.ts.ets.interdayws.soap.webservice;
Is there an ideal way to change
SOAP-ENV
tosoap
in Spring-WS?By the way, here's the code that set this prefix. StroapElement.java
原文:https://stackoverflow.com/questions/39242197
满意答案
INSERT INTO co_names ( id, English, Spanish, French, German, Italian, Portugues, Turkish ) SELECT CONVERT(country_numeric_code, UNSIGNED), IFNULL((SELECT MAX(country_name) FROM ulkeler WHERE u.lang_name = 'ENGLISH'), 'Unknown'), IFNULL((SELECT MAX(country_name) FROM ulkeler WHERE u.lang_name = 'SPANISH'), 'Unknown'), IFNULL((SELECT MAX(country_name) FROM ulkeler WHERE u.lang_name = 'FRENCH'), 'Unknown'), IFNULL((SELECT MAX(country_name) FROM ulkeler WHERE u.lang_name = 'GERMAN'), 'Unknown'), IFNULL((SELECT MAX(country_name) FROM ulkeler WHERE u.lang_name = 'ITALIAN'), 'Unknown'), IFNULL((SELECT MAX(country_name) FROM ulkeler WHERE u.lang_name = 'PORTUGUESE'), 'Unknown'), IFNULL((SELECT MAX(country_name) FROM ulkeler WHERE u.lang_name = 'TURKISH'), 'Unknown') FROM ulkeler u GROUP BY country_numeric_code;
请注意
co_names
表中拼写错误的“葡萄牙语”列(缺少最后“e”)。INSERT INTO co_names ( id, English, Spanish, French, German, Italian, Portugues, Turkish ) SELECT CONVERT(country_numeric_code, UNSIGNED), IFNULL((SELECT MAX(country_name) FROM ulkeler WHERE u.lang_name = 'ENGLISH'), 'Unknown'), IFNULL((SELECT MAX(country_name) FROM ulkeler WHERE u.lang_name = 'SPANISH'), 'Unknown'), IFNULL((SELECT MAX(country_name) FROM ulkeler WHERE u.lang_name = 'FRENCH'), 'Unknown'), IFNULL((SELECT MAX(country_name) FROM ulkeler WHERE u.lang_name = 'GERMAN'), 'Unknown'), IFNULL((SELECT MAX(country_name) FROM ulkeler WHERE u.lang_name = 'ITALIAN'), 'Unknown'), IFNULL((SELECT MAX(country_name) FROM ulkeler WHERE u.lang_name = 'PORTUGUESE'), 'Unknown'), IFNULL((SELECT MAX(country_name) FROM ulkeler WHERE u.lang_name = 'TURKISH'), 'Unknown') FROM ulkeler u GROUP BY country_numeric_code;
Note misspelling of the 'Portuguese' column (missing last 'e') in your
co_names
table.
相关问答
更多原子上复制一个MySQL表的另一个?(Atomically copying one MySQL table over another?)
INSERT INTO从表复制到另一个(INSERT INTO copying from table to another)
将数据从一个表复制到另一个表的存储过程(Stored Procedure for copying data from one table to another)
我无法使用SQL Ce将日期时间复制到另一个日期时间表(I cant copying datetime to another datetime table with SQL Ce)
使用perl和DBI将一个非常大的表从一个DB2复制到另一个(copying a very large table from one DB2 to another, using perl and DBI)
将日期从一个表复制到另一个表并更改mysql中的格式(Copying date from one table to another and change format in mysql)
SQL Server使用STUFF和GROUP BY将数据复制到另一个表(SQL Server copying data to another table using STUFF and GROUP BY)
如何在其他表中复制数据时插入数据(How to Insert data while Copying data in other Table)
将行从一个表复制到另一个表?(Copying row from one table to another?)
Oracle - 将表数据从一个模式复制到另一个模式(Oracle - Copying table data from one schema to another schema)
相关文章
更多Spring MVC 3 深入总结
eclipse的默认(打开)编辑器的更改
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!