2017-01-07 14 views
1

SOAP 본문에 pos:searchText과 같은 로컬 이름이 있는지 확인하고 싶습니다. 내가 EndpointInterceptorAdapter을 사용하고 있기 때문에 MessageContext을 사용해야합니다.Spring에서 SOAP의 모든 로컬 이름을 본문에 가져옵니다.

내 SOAP 요청은 다음과 같습니다.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
<soapenv:Body> 
    <pos:getSearchRequest> 
    <pos:searchText>some Text</pos:searchText> 
    <pos:anotherField>example</pos:anotherField> 
    </pos:getSearchRequest> 
</soapenv:Body> 
</soapenv:Envelope> 

모든 요청을 인터셉트하고 이에 대한 모델이 없기 때문에 비 정렬 화가 작동하지 않습니다.

pos:searchText과 같은 모든 로컬 이름을 얻으려면 어떻게해야합니까?

답변

0

SOAP 요청을 "언 마샬링 (unmarshall)"하는 방법과 오류 또는 어려움에 대한 자세한 내용을 확인하는 것이 유용 할 것입니다. 인터셉터의 추상화로 인해 SOAP 메시지를 언 마샬 할 수없는 최근의 경우 XML 문자열을 만들어야 만 XPath 표현식을 사용하여 필요한 요소를 쉽게 찾을 수있었습니다. 어쩌면이 너무 당신을 도울 것입니다 :

private String extractSearchText(MessageContext messageContext) throws IOException, XPathExpressionException { 
    ByteArrayOutputStream soapResponseOutputStream = new ByteArrayOutputStream(); 
    messageContext.getResponse().writeTo(soapResponseOutputStream); 
    InputSource soapResponseInputSource = new InputSource(new StringReader(new String(soapResponseOutputStream.toByteArray()))); 
    return (String) xpath.evaluate("//pos:searchText", soapResponseInputSource, XPathConstants.STRING); 
} 

PS를 : 당신이 당신의 요청을 비 직렬화 할 수없는 이유를 정말 볼 수 없습니다. 더 자세한 내용을 살펴보면, 당신을 도우려는 것이 더 쉬울 것이고, 필요한 작업을 올바르게 수행 할 수 있기 때문에 노력을 기울일 것입니다.