Most of the web services use soap headers to pass various kinds of information and it is required to manipulate those headers within a BPEL process when we are creating a complex business logic. Sometimes we have to deal with soap headers which aren't declared in the WSDL abstract message. These kind of headers are called Dynamic headers and both Apache ODE and WSO2 BPS can handle these type of soap headers.
For more information about header handling in Apache ODE, follow this article.
This post will show you how to handle soap headers, covering following scenarios,
- Reading a soap header in request message.
- Create a new soap header in a variable and assign a value to it.
- Copying soap header from one variable to another.
To demonstrate above scenarios let's consider this simple BPEL process. These are process's default request and response messages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" | |
xmlns:sam="http://wso2.org/bps/sample"> | |
<soapenv:Header> | |
<eh:echo xmlns:eh="http://example.com/">hello</eh:echo> | |
</soapenv:Header> | |
<soapenv:Body> | |
<sam:soapHeaderTestProcessRequest> | |
<sam:input>inputValue</sam:input> | |
</sam:soapHeaderTestProcessRequest> | |
</soapenv:Body> | |
</soapenv:Envelope> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> | |
<soapenv:Body> | |
<soapHeaderTestProcessResponse xmlns="http://wso2.org/bps/sample"> | |
<tns:result xmlns:tns="http://wso2.org/bps/sample">result</tns:result> | |
</soapHeaderTestProcessResponse> | |
</soapenv:Body> | |
</soapenv:Envelope> |
1. Reading SOAP Header in Request Message.
Let's read "echo" header from the input message and set its value into the process output message (to result element). To do this, add another copy into the Assign activity like this. Note that we are using "header" attribute to refer a soap header. (Resultant process's response is shown in response.xml)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<bpel:copy> | |
<bpel:from variable="input" header="echo"></bpel:from> | |
<bpel:to part="payload" variable="output"> | |
<bpel:query queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath1.0"><![CDATA[tns:result]]></bpel:query> | |
</bpel:to> | |
</bpel:copy> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> | |
<soapenv:Body> | |
<soapHeaderTestProcessResponse xmlns="http://wso2.org/bps/sample"> | |
<tns:result xmlns:tns="http://wso2.org/bps/sample">hello</tns:result> | |
</soapHeaderTestProcessResponse> | |
</soapenv:Body> | |
</soapenv:Envelope> |
2. Create a new soap Header in a variable and assign a value to it
Let's add new soap header called "echo2" in the output variable and assign request message text (input) value as new header value. First copy will create the echo2 header and second copy will do the value assigning. (Resultant response is shown in response.xml)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<bpel:copy> | |
<bpel:from> | |
<bpel:literal> | |
<eh2:echo2 xmlns:eh2="http://anotherexample.com">noValueDefined</eh2:echo2> | |
</bpel:literal> | |
</bpel:from> | |
<bpel:to header="echo2" variable="output"></bpel:to> | |
</bpel:copy> | |
<bpel:copy> | |
<bpel:from part="payload" variable="input"> | |
<bpel:query queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath1.0"> | |
<![CDATA[tns:input]]> | |
</bpel:query> | |
</bpel:from> | |
<bpel:to header="echo2" variable="output"></bpel:to> | |
</bpel:copy> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> | |
<soapenv:Header> | |
<eh2:echo2 xmlns:eh2="http://anotherexample.com">inputValue</eh2:echo2> | |
</soapenv:Header> | |
<soapenv:Body> | |
<soapHeaderTestProcessResponse xmlns="http://wso2.org/bps/sample"> | |
<tns:result xmlns:tns="http://wso2.org/bps/sample">result</tns:result> | |
</soapHeaderTestProcessResponse> | |
</soapenv:Body> | |
</soapenv:Envelope> |
3. Copying soap header from one variable to another.
Let's copy request message's echo header to output message. In the Assign activity define a copy as follow. (Resultant response is shown in response.xml)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<bpel:copy> | |
<bpel:from header="echo" variable="input"></bpel:from> | |
<bpel:to header="echo" variable="output"></bpel:to> | |
</bpel:copy> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> | |
<soapenv:Header> | |
<echo xmlns="http://example.com/" xmlns:eh="http://example.com/" xmlns:sam="http://wso2.org/bps/sample">hello</echo> | |
</soapenv:Header> | |
<soapenv:Body> | |
<soapHeaderTestProcessResponse xmlns="http://wso2.org/bps/sample"> | |
<tns:result xmlns:tns="http://wso2.org/bps/sample">result</tns:result> | |
</soapHeaderTestProcessResponse> | |
</soapenv:Body> | |
</soapenv:Envelope> |
No comments:
Post a Comment