I have developed soap request using spring boot where my soap request contain custom herders inside "" section of "soapenv:Header". I am facing issue to retrieve details passed inside "" section. There are no Exception but what I am receiving are all empty properties value of RequestHeader object at backend
My soap request looks like below:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://com/schema/OrderRequest" xmlns:ns="http://com/schema/RequestHeader">
<soapenv:Header>
<ns:RequestHeader>
<ns:name>Name1</ns:name>
</ns:RequestHeader>>
</soapenv:Header>
<soapenv:Body>
.... no issue to retrieve body information
</soapenv:Body>
</soapenv:Envelope>
I an tring to retrieve header section using below code
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "OrderRequest")
@ResponsePayload
public JAXBElement<OrderResponse> createOrder(@RequestPayload JAXBElement<OrderRequest>
createWorkOrderRequestCplxType, @SoapHeader("{http://com/schema/RequestHeader/2/0}RequestHeader")SoapHeaderElement requestHeader) {
log.info("Start createWorkOrder :");
try{
Source bodySource = requestHeader.getSource();
DOMSource bodyDomSource = (DOMSource) bodySource;
JAXBContext context = JAXBContext.newInstance(RequestHeader.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
RequestHeader requestH = (RequestHeader) unmarshaller.unmarshal(bodyDomSource);
log.info("activity name from request header : {}",requestH.getName); //This value is getting empty
}catch (JAXBException e){
e.printStackTrace();
}
}
Can you please help me to understand what I am doing wrong?
I was tried multiple ways but didn't find direct solution to get Java object of RequesHeader directly in PayloadRoot method. Hence able to manage with below alternate approach: