您好我正在使用Spring网络服务以下是我的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>
答案 0 :(得分:0)
这可以避免使用Spring 2.5和spring-ws 1.5.9 abcPortalTokenDetailsEndpoint可以扩展MarshallingMethodEndpointAdapter。同样在配置文件中,如果我们为每个端点都有不同的beanid marshallers,它可以正常工作。我也尝试过在Spring 3.0和spring-ws 1.5.9中正式不支持的相同的东西,它不适用于多个beanid marshaller,它需要在bean id中的单词marshaller ??? 例 整个问题是使用带有“:”或“list”的contextpath(这会在响应中添加所有namesapce)
<oxm:jaxb2-marshaller id="marshaller" contextPath="com.abc.web.ws.login.status.schema:com.abc.web.ws.profile.schema:com.abc.web.ws.tokendetails.schema>
如果我们将上面的代码改为如下,则它在Spring 2.5.6中工作而不是spring 3.0为什么???
<bean id="abcPortalTokenDetailsEndpoint" class="com.abc.web.ws.tokendetails.abcPortalTokenDetailsEndpoint">
<property name="marshaller" ref="marshaller1"/>
<property name="unmarshaller" ref="marshaller1"/>
</bean>
<bean id="abcPortalTrustedAccessLogInEndpoint" class="com.abc.web.ws.login.trustedaccess.abcPortalTrustedAccessLogInEndpoint">
<property name="marshaller" ref="marshaller2"/>
<property name="unmarshaller" ref="marshaller2"/>
</bean>
<bean id="abcPortalThirdPartyLogInEndpoint" class="com.abc.web.ws.login.thirdparty.abcPortalThirdPartyLogInEndpoint">
<property name="marshaller" ref="marshaller"/>
<property name="unmarshaller" ref="marshaller"/>
</bean>
<bean id="marshaller1" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath" value="com.abc.web.ws.tokendetails.schema"/>
</bean>
<bean id="marshaller2" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath" value="com.abc.web.ws.login.trustedaccess.schema"/>
</bean>
<bean id="marshaller3" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath" value="com.abc.web.ws.login.thirdparty.schema"/>
</bean>
public class abcPortalTokenDetailsEndpoint extends MarshallingMethodEndpointAdapter{
private IabcPortalManager abcPortalManager;
private static final Logger logger = Logger.getLogger(abcPortalTokenDetailsEndpoint.class);
public void setAbcPortalManager(IabcPortalManager abcPortalManager) {
this.abcPortalManager = abcPortalManager;
}
public abcPortalTokenDetailsResponse handleabcPortalTokenDetailsRequest(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;
}
答案 1 :(得分:0)
无需单独的编组。可以通过Response
注释为Endpoint
的{{1}}方法来解决。
例如:
@ResponsePayload