Spring Web服务响应具有不同Web服务的多个命名空间(java)
您好,我正在使用 Spring Web 服务 这是我的 xsd 的外观
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.test-software.co.uk/abcportal/schema/abcportaltokendetailsws"
targetNamespace="http://www.test-software.co.uk/abcportal/schema/abcportaltokendetailsws"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="abcPortalTokenDetailsRequest">
<xs:complexType>
<xs:annotation>
<xs:documentation>The data structure required to get token details</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element name="token" type="token3rdParty"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="abcPortalTokenDetailsResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="tokenDetails" type="TokenDetailsType" />
<xs:element name="result" type="resultStructure"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="token3rdParty">
<xs:restriction base="xs:token">
<xs:minLength value="1"></xs:minLength>
<xs:maxLength value="60"></xs:maxLength>
<xs:pattern value="([A-Za-z0-9]+)" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="TokenDetailsType">
<xs:annotation>
<xs:documentation>token details</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element name="sNumber" type="SNumberType"/>
<xs:element name="sId" type="SIdType"/>
<xs:element name="sName" type="SNameType"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="SNumberType">
<xs:restriction base="xs:string">
<xs:minLength value="1"></xs:minLength>
<xs:maxLength value="60"></xs:maxLength>
<xs:pattern value="([A-Za-z0-9]+)" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="SIdType">
<xs:restriction base="xs:string">
<xs:minLength value="1"></xs:minLength>
<xs:maxLength value="2"></xs:maxLength>
<xs:pattern value="([A-Za-z]+)" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="SNameType">
<xs:restriction base="xs:string">
<xs:minLength value="1"></xs:minLength>
<xs:maxLength value="128"></xs:maxLength>
<xs:pattern value="([A-Za-z0-9]+)" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="resultStructure">
<xs:sequence>
<xs:element name="resultCode" minOccurs="1" maxOccurs="1">
<xs:annotation>
<xs:documentation>The result code indicates the outcome of the available list for request.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="OK"/>
<xs:enumeration value="INVALID"/>
<xs:enumeration value="ERROR"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="resultMessage" minOccurs="1" maxOccurs="1">
<xs:annotation>
<xs:documentation>The associated message for this result</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="255"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
端点
@Endpoint
public class abcPortalTokenDetailsEndpoint {
private IabcPortalManager abcPortalManager;
private static final Logger logger = Logger.getLogger(abcPortalTokenDetailsEndpoint.class);
public void setAbcPortalManager(IabcPortalManager abcPortalManager) {
this.abcPortalManager = abcPortalManager;
}
@PayloadRoot(localPart= "AbcPortalTokenDetailsRequest", namespace="http://www.test-software.co.uk/abcportal/schema/abcportaltokendetailsws")
public abcPortalTokenDetailsResponse doit(abcPortalTokenDetailsRequest request){
abcPortalTokenDetailsResponse response = new abcPortalTokenDetailsResponse();
// check that the token is currently valid
String token = request.getToken().trim();
String resultCode = "ERROR", resultMessage = "Internal error occured - valid response could not be generated";
boolean okResult = true, valid = false;
TAuth tp = null;
Integer sId = 0;
String sName = "";
String errorMsg = null;
try {
//validate token
if (token != null) {
resultCode = "OK";
resultMessage = "Valid session";
} else {
resultCode = "INVALID";
resultMessage = "No record of user being logged in";
okResult = false;
}
} catch (DataAccessException ex) {
String fmtStr = "Could not determine whether end user token (%s) is valid.\n %s";
String errMsg = String.format(fmtStr, token, ex.getMessage());
okResult = false;
logger.error(errMsg);
assert(false) : errMsg;
}
if(okResult){
if(logger.isDebugEnabled()){
logger.debug("abcPortalTokenDetailsResponse Authenticate user" );
}
tp = abcPortalManager.getTpAuth(token);
if(logger.isDebugEnabled()){
if(tp != null){
if (tp.getSId()!= null){
sName = "ct"; abcPortalManager.getSName(tp.getSId());
}
} else {
logger.debug("abcPortalTokenDetailsResponse tparty details not found");
}
}
valid = true;
}
TokenDetailsType tokenDetailsPart = constructResponseTokenDetailsPart(valid, okResult, tp, sName);
response.setTokenDetails(tokenDetailsPart);
ResultStructure resultPart = constructResponseResultPart(valid, okResult, errorMsg);
response.setResult(resultPart);
return response;
}
private TokenDetailsType constructResponseTokenDetailsPart(
boolean valid, boolean okResult, TAuth tp,String sName) {
TokenDetailsType tdt = null;
if (valid && okResult) {
tdt = new TokenDetailsType();
tdt.setSId(tp.getSId());
tdt.setSNumber(tp.getSNumber);
tdt.setSName(sName);
}
return tdt;
}
/**
*
* @param response
* @param okResult
* void
*
*/
private ResultStructure constructResponseResultPart(
boolean valid, boolean okResult, String errorMessage) {
// Determine result part of response
String resultCode, resultMessage;
if (okResult) {
resultCode = (valid) ? "OK" : "INVALID";
resultMessage = (valid) ? "Successfull query" : "User not authorised";
} else {
resultCode = "ERROR";
resultMessage = "Valid response could not be generated: " + errorMessage;
}
ResultStructure resp_result = new ResultStructure();
resp_result.setResultCode(resultCode);
resp_result.setResultMessage(resultMessage);
return resp_result;
}
}
这是当我尝试使用 SoapUI 测试 Web 服务时的 为什么响应在我的项目中具有不同 Web 服务的多个命名空间???我只期待 abcportaltokendetailsws 而不是 abcportalloginstatusws 等其他服务,abcportallogoutws 不确定为什么会显示此内容?
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns10:abcPortalTokenDetailsResponse
xmlns:ns10="http://www.test-software.co.uk/abcportal/schema/abcportaltokendetailsws"
xmlns:ns2="http://www.test-software.co.uk/abcportal/schema/abcportalloginstatusws" xmlns:ns4="http://www.test-software.co.uk/abcportal/schema/abcportallpaymentws" xmlns:ns5="http://www.test-software.co.uk/abcportal/schema/abcportallogoutws" xmlns:ns6="http://www.test-software.co.uk/abcportal/schema/abcportalfundservicews" xmlns:ns7="http://www.test-software.co.uk/abcportal/schema/abcportalpayservicews"
<ns10:tokenDetails>
<ns10:sNumber>43454</ns10:sNumber>
<ns10:sId/>
<ns10:sName>Bridge Market</ns10:sName>
</ns10:tokenDetails>
<ns10:result>
<ns10:resultCode>OK</ns10:resultCode>
<ns10:resultMessage>Successfull query</ns10:resultMessage>
</ns10:result>
</ns10:abcPortalTokenDetailsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Hi I am using Spring web service Here is how my xsd looks
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.test-software.co.uk/abcportal/schema/abcportaltokendetailsws"
targetNamespace="http://www.test-software.co.uk/abcportal/schema/abcportaltokendetailsws"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="abcPortalTokenDetailsRequest">
<xs:complexType>
<xs:annotation>
<xs:documentation>The data structure required to get token details</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element name="token" type="token3rdParty"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="abcPortalTokenDetailsResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="tokenDetails" type="TokenDetailsType" />
<xs:element name="result" type="resultStructure"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="token3rdParty">
<xs:restriction base="xs:token">
<xs:minLength value="1"></xs:minLength>
<xs:maxLength value="60"></xs:maxLength>
<xs:pattern value="([A-Za-z0-9]+)" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="TokenDetailsType">
<xs:annotation>
<xs:documentation>token details</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element name="sNumber" type="SNumberType"/>
<xs:element name="sId" type="SIdType"/>
<xs:element name="sName" type="SNameType"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="SNumberType">
<xs:restriction base="xs:string">
<xs:minLength value="1"></xs:minLength>
<xs:maxLength value="60"></xs:maxLength>
<xs:pattern value="([A-Za-z0-9]+)" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="SIdType">
<xs:restriction base="xs:string">
<xs:minLength value="1"></xs:minLength>
<xs:maxLength value="2"></xs:maxLength>
<xs:pattern value="([A-Za-z]+)" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="SNameType">
<xs:restriction base="xs:string">
<xs:minLength value="1"></xs:minLength>
<xs:maxLength value="128"></xs:maxLength>
<xs:pattern value="([A-Za-z0-9]+)" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="resultStructure">
<xs:sequence>
<xs:element name="resultCode" minOccurs="1" maxOccurs="1">
<xs:annotation>
<xs:documentation>The result code indicates the outcome of the available list for request.</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="OK"/>
<xs:enumeration value="INVALID"/>
<xs:enumeration value="ERROR"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="resultMessage" minOccurs="1" maxOccurs="1">
<xs:annotation>
<xs:documentation>The associated message for this result</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="255"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
Here is the Endpoint
@Endpoint
public class abcPortalTokenDetailsEndpoint {
private IabcPortalManager abcPortalManager;
private static final Logger logger = Logger.getLogger(abcPortalTokenDetailsEndpoint.class);
public void setAbcPortalManager(IabcPortalManager abcPortalManager) {
this.abcPortalManager = abcPortalManager;
}
@PayloadRoot(localPart= "AbcPortalTokenDetailsRequest", namespace="http://www.test-software.co.uk/abcportal/schema/abcportaltokendetailsws")
public abcPortalTokenDetailsResponse doit(abcPortalTokenDetailsRequest request){
abcPortalTokenDetailsResponse response = new abcPortalTokenDetailsResponse();
// check that the token is currently valid
String token = request.getToken().trim();
String resultCode = "ERROR", resultMessage = "Internal error occured - valid response could not be generated";
boolean okResult = true, valid = false;
TAuth tp = null;
Integer sId = 0;
String sName = "";
String errorMsg = null;
try {
//validate token
if (token != null) {
resultCode = "OK";
resultMessage = "Valid session";
} else {
resultCode = "INVALID";
resultMessage = "No record of user being logged in";
okResult = false;
}
} catch (DataAccessException ex) {
String fmtStr = "Could not determine whether end user token (%s) is valid.\n %s";
String errMsg = String.format(fmtStr, token, ex.getMessage());
okResult = false;
logger.error(errMsg);
assert(false) : errMsg;
}
if(okResult){
if(logger.isDebugEnabled()){
logger.debug("abcPortalTokenDetailsResponse Authenticate user" );
}
tp = abcPortalManager.getTpAuth(token);
if(logger.isDebugEnabled()){
if(tp != null){
if (tp.getSId()!= null){
sName = "ct"; abcPortalManager.getSName(tp.getSId());
}
} else {
logger.debug("abcPortalTokenDetailsResponse tparty details not found");
}
}
valid = true;
}
TokenDetailsType tokenDetailsPart = constructResponseTokenDetailsPart(valid, okResult, tp, sName);
response.setTokenDetails(tokenDetailsPart);
ResultStructure resultPart = constructResponseResultPart(valid, okResult, errorMsg);
response.setResult(resultPart);
return response;
}
private TokenDetailsType constructResponseTokenDetailsPart(
boolean valid, boolean okResult, TAuth tp,String sName) {
TokenDetailsType tdt = null;
if (valid && okResult) {
tdt = new TokenDetailsType();
tdt.setSId(tp.getSId());
tdt.setSNumber(tp.getSNumber);
tdt.setSName(sName);
}
return tdt;
}
/**
*
* @param response
* @param okResult
* void
*
*/
private ResultStructure constructResponseResultPart(
boolean valid, boolean okResult, String errorMessage) {
// Determine result part of response
String resultCode, resultMessage;
if (okResult) {
resultCode = (valid) ? "OK" : "INVALID";
resultMessage = (valid) ? "Successfull query" : "User not authorised";
} else {
resultCode = "ERROR";
resultMessage = "Valid response could not be generated: " + errorMessage;
}
ResultStructure resp_result = new ResultStructure();
resp_result.setResultCode(resultCode);
resp_result.setResultMessage(resultMessage);
return resp_result;
}
}
when i try to test the webservice using SoapUI why response has multiple namespace of different webservices within my project??? i am expecting just abcportaltokendetailsws and not other services like abcportalloginstatusws ,abcportallogoutws not sure why this is displayed?
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns10:abcPortalTokenDetailsResponse
xmlns:ns10="http://www.test-software.co.uk/abcportal/schema/abcportaltokendetailsws"
xmlns:ns2="http://www.test-software.co.uk/abcportal/schema/abcportalloginstatusws" xmlns:ns4="http://www.test-software.co.uk/abcportal/schema/abcportallpaymentws" xmlns:ns5="http://www.test-software.co.uk/abcportal/schema/abcportallogoutws" xmlns:ns6="http://www.test-software.co.uk/abcportal/schema/abcportalfundservicews" xmlns:ns7="http://www.test-software.co.uk/abcportal/schema/abcportalpayservicews"
<ns10:tokenDetails>
<ns10:sNumber>43454</ns10:sNumber>
<ns10:sId/>
<ns10:sName>Bridge Market</ns10:sName>
</ns10:tokenDetails>
<ns10:result>
<ns10:resultCode>OK</ns10:resultCode>
<ns10:resultMessage>Successfull query</ns10:resultMessage>
</ns10:result>
</ns10:abcPortalTokenDetailsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可以避免使用 Spring 2.5 和 spring-ws 1.5.9 abcPortalTokenDetailsEndpoint 可以扩展 MarshallingMethodEndpointAdapter。同样在配置文件中,如果我们为每个端点使用不同的 beanid 编组器,它也可以正常工作。我也在 Spring 3.0 和 spring-ws 1.5.9 中尝试了同样的事情,官方不支持它,它不能与多个 beanid marshaller 一起使用,它需要 bean id 中的单词 marshaller ???
例子
整个问题是使用带有“:”或“列表”的上下文路径(这会在响应中添加所有名称空间)
如果我们将上面的代码更改为如下,它在 Spring 2.5.6 中工作,而不是在 Spring 3.0 中工作,为什么???
This is possible to avoid using Spring 2.5 along with spring-ws 1.5.9 abcPortalTokenDetailsEndpoint can extend MarshallingMethodEndpointAdapter. Also in the config file if we have different beanid marshallers for each end points it works fine. I also tried the same thing in Spring 3.0 and spring-ws 1.5.9 officially not supported , it does not work with multiple beanid marshaller, it needs the word marshaller in the bean id ???
example
the whole problem is using contextpath with ":" or "list" (this adds all the namesapce in the response)
if we change the above code to as following it works in Spring 2.5.6 not spring 3.0 why???
不需要单独的编组器。可以通过将
Endpoint
中的Response
方法注释为@ResponsePayload
来解决。前任:
No need to have separate marshaller. Can be solved by having the
Response
method in yourEndpoint
annotated as@ResponsePayload
.Ex: