我试图以这种方式从端点读取SOAP请求头:
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getCountryRequest")
@ResponsePayload
public GetCountryResponse getCountry(@RequestPayload GetCountryRequest request, MessageContext context) {
GetCountryResponse response = new GetCountryResponse();
response.setCountry(countryRepository.findCountry(request.getName()));
return response;
}
正如您所看到的,我将MessageContext作为端点的handle方法中的参数,我执行以下操作以尝试读取来自te请求的SOAP标头:
SaajSoapMessage soapRequest = (SaajSoapMessage) messageContext.getRequest();
SoapHeader reqheader = soapRequest.getSoapHeader();
while (itr.hasNext()) {
SoapHeaderElement ele = itr.next();
}
显然我正在访问SOAP标头,但此时我并不确定如何读取任何SOAP标头元素的值,我尝试了不同的方法但没有成功。
例如,如果以下SOAP请求来自soapUI,我想从networkCode元素中读取值123456:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<ns1:RequestHeader
soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"
soapenv:mustUnderstand="0"
xmlns:ns1="https://www.google.com/apis/ads/publisher/v201508">
<ns1:networkCode>123456</ns1:networkCode>
<ns1:applicationName>DfpApi-Java-2.1.0-dfp_test</ns1:applicationName>
</ns1:RequestHeader>
</soapenv:Header>
<soapenv:Body>
<getAdUnitsByStatement xmlns="https://www.google.com/apis/ads/publisher/v201508">
<filterStatement>
<query>WHERE parentId IS NULL LIMIT 500</query>
</filterStatement>
</getAdUnitsByStatement>
</soapenv:Body>
</soapenv:Envelope>
提前致谢和最好的评价。
答案 0 :(得分:0)
在使用脚本断言的SoapUI中,我们可以这样做:
由于您的请求本身包含Header Details,我们可以使用xpath读取Request xml的任何元素。
将 TeststepName 替换为您的TestStepName 。
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(“TeststepName #Request”)
holder.namespaces [“ns1”] =“https://www.google.com/apis/ads/publisher/v201508”
def y = holder [“(// ns1:networkCode)”]
log.info“networkCode的值”+ y
或
断言持有人[“(// ns1:networkCode)”] =='123456'
答案 1 :(得分:0)
请尝试从您的请求中获取所有Header元素,如:
SaajSoapMessage soapRequest = (SaajSoapMessage) messageContext.getRequest();
Iterator HeaderList = soapRequest.getEnvelope()。getHeader()。examineAllHeaderElements();
while(HeaderList.hasNext()){
SoapHeaderElement HeaderElements = HeaderList.next();
println("\n"+HeaderElements.getName().getLocalPart()+ " - "+HeaderElements.getText());
}
}
答案 2 :(得分:0)
Yoy你可以QName使用必要的标签
来提取数据SaajSoapMessage soapRequest = (SaajSoapMessage) messageContext
.getRequest();
SoapHeader reqheader = soapRequest.getSoapHeader();
Iterator<SoapHeaderElement> itr = reqheader.examineAllHeaderElements();
while (itr.hasNext()) {
SoapHeaderElement testedElement = itr.next();
if (testedElement.getName()
.equals(new QName("https://www.google.com/apis/ads/publisher/v201508", "networkCode", "ns1"))) {
this.messageId = testedElement.getText();
break;
}
}