# MultipleHeadersControl.jcx Sample

This topic inludes the source code for the MultipleHeadersControl.jcx Sample.

## Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/SamplesApp/WebServices/soapHeaders/

## Sample Source Code

`001 package soapHeaders; 002 003 /** 004 * @jc:location http-url="multipleHeaders.jws" jms-url="multipleHeaders.jws" 005 * @jc:wsdl file="#multipleHeadersWsdl" 006 * @editor-info:link autogen-style="java" source="multipleHeaders.jws" autogen="true" 007 */ 008 public interface multipleHeadersControl extends com.bea.control.ControlExtension, com.bea.control.ServiceControl 009 { 010 011 /** 012 * In this method, headers are created using HeaderDocument.Factory.Parse. The FirstChild is extracted into header, which is type Element. Each header is put into an array that is passed to the JwsContext service method, setOutputHeaders, which puts the headers in place. The format of the Element header is: firstChild localName = "Header" name = "SOAP-ENV:Header" namespaceURI= "http://schemas-xmlsoap.org/soap/envelope/" firstChild localName = "content<header#>" name = "my:content<header#>" namespaceURI= "http://my.com/uri/" firstChild data = "Header<header#>" 013 */ 014 public void myMethod (); 015 016 /** 017 * The header can be obtained by using the JwsContext interface getInputHeaders(), which is the compliment to setOutputHeaders() that was used in myMethod to add the header. The result is formated exactly the same way. Note that, while myMethod created multiple elements in headerElement[], the getInputHeaders method created a single array element. What you get back with getInputHeaders is that single array element that contains all of the headers arranged in a tree of nodes. You can extract the header names by traversing the tree that. To do this use the getFirstChild and getNextSibling methods that are part of the Element interface. 018 */ 019 public java.lang.String[] GetHeaders1 (); 020 021 /** 022 * This method gets just the header names, not the envelope name. It's a somewhat simpler method that relys on getting a list of Child Nodes, where each child is one of the headers. The getChildNodes method also gives the number of nodes in the list. This way all you have to do is index into the list instead of keeping track of the child nodes and siblings. To do this, use the getInputHeaders method to get the single array element with all the headers in it. Then use the Element interface method, getChildNodes to get a list of nodes in a NodeList type object. You then use the NodeList interface methods, getLength and item, to get the number of nodes and header node, respectively. getNodeName then supplies the name of the node. 023 */ 024 public java.lang.String[] GetHeaders2 (); 025 026 static final long serialVersionUID = 1L; 027 } 028 029 /** @common:define name="multipleHeadersWsdl" value:: 030 <?xml version="1.0" encoding="utf-8"?> 031 <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:conv="http://www.openuri.org/2002/04/soap/conversation/" xmlns:cw="http://www.openuri.org/2002/04/wsdl/conversation/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:jms="http://www.openuri.org/2002/04/wsdl/jms/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:s0="http://www.openuri.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="http://www.openuri.org/"> 032 <types> 033 <s:schema elementFormDefault="qualified" targetNamespace="http://www.openuri.org/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:ope="http://www.openuri.org/"> 034 <s:element name="myMethod"> 035 <s:complexType> 036 <s:sequence/> 037 </s:complexType> 038 </s:element> 039 <s:element name="myMethodResponse"> 040 <s:complexType> 041 <s:sequence/> 042 </s:complexType> 043 </s:element> 044 <s:element name="GetHeaders1"> 045 <s:complexType> 046 <s:sequence/> 047 </s:complexType> 048 </s:element> 049 <s:element name="GetHeaders1Response"> 050 <s:complexType> 051 <s:sequence> 052 <s:element name="GetHeaders1Result" type="ope:ArrayOfString" minOccurs="0"/> 053 </s:sequence> 054 </s:complexType> 055 </s:element> 056 <s:element name="ArrayOfString" nillable="true" type="ope:ArrayOfString"/> 057 <s:element name="GetHeaders2"> 058 <s:complexType> 059 <s:sequence/> 060 </s:complexType> 061 </s:element> 062 <s:element name="GetHeaders2Response"> 063 <s:complexType> 064 <s:sequence> 065 <s:element name="GetHeaders2Result" type="ope:ArrayOfString" minOccurs="0"/> 066 </s:sequence> 067 </s:complexType> 068 </s:element> 069 <s:complexType name="ArrayOfString"> 070 <s:sequence> 071 <s:element name="String" type="s:string" nillable="true" minOccurs="0" maxOccurs="unbounded"/> 072 </s:sequence> 073 </s:complexType> 074 </s:schema> 075 076 </types> 077 <message name="myMethodSoapIn"> 078 <part name="parameters" element="s0:myMethod"/> 079 </message> 080 <message name="myMethodSoapOut"> 081 <part name="parameters" element="s0:myMethodResponse"/> 082 </message> 083 <message name="GetHeaders1SoapIn"> 084 <part name="parameters" element="s0:GetHeaders1"/> 085 </message> 086 <message name="GetHeaders1SoapOut"> 087 <part name="parameters" element="s0:GetHeaders1Response"/> 088 </message> 089 <message name="GetHeaders2SoapIn"> 090 <part name="parameters" element="s0:GetHeaders2"/> 091 </message> 092 <message name="GetHeaders2SoapOut"> 093 <part name="parameters" element="s0:GetHeaders2Response"/> 094 </message> 095 <message name="myMethodHttpGetIn"/> 096 <message name="myMethodHttpGetOut"/> 097 <message name="GetHeaders1HttpGetIn"/> 098 <message name="GetHeaders1HttpGetOut"> 099 <part name="Body" element="s0:ArrayOfString"/> 100 </message> 101 <message name="GetHeaders2HttpGetIn"/> 102 <message name="GetHeaders2HttpGetOut"> 103 <part name="Body" element="s0:ArrayOfString"/> 104 </message> 105 <message name="myMethodHttpPostIn"/> 106 <message name="myMethodHttpPostOut"/> 107 <message name="GetHeaders1HttpPostIn"/> 108 <message name="GetHeaders1HttpPostOut"> 109 <part name="Body" element="s0:ArrayOfString"/> 110 </message> 111 <message name="GetHeaders2HttpPostIn"/> 112 <message name="GetHeaders2HttpPostOut"> 113 <part name="Body" element="s0:ArrayOfString"/> 114 </message> 115 <portType name="multipleHeadersSoap"> 116 <operation name="myMethod"> 117 <documentation>In this method, headers are created using HeaderDocument.Factory.Parse. The FirstChild is extracted into header, which is type Element. Each header is put into an array that is passed to the JwsContext service method, setOutputHeaders, which puts the headers in place. The format of the Element header is: firstChild localName = "Header" name = "SOAP-ENV:Header" namespaceURI= "http://schemas-xmlsoap.org/soap/envelope/" firstChild localName = "content&lt;header#&gt;" name = "my:content&lt;header#&gt;" namespaceURI= "http://my.com/uri/" firstChild data = "Header&lt;header#&gt;"</documentation> 118 <input message="s0:myMethodSoapIn"/> 119 <output message="s0:myMethodSoapOut"/> 120 </operation> 121 <operation name="GetHeaders1"> 122 <documentation>The header can be obtained by using the JwsContext interface getInputHeaders(), which is the compliment to setOutputHeaders() that was used in myMethod to add the header. The result is formated exactly the same way. Note that, while myMethod created multiple elements in headerElement[], the getInputHeaders method created a single array element. What you get back with getInputHeaders is that single array element that contains all of the headers arranged in a tree of nodes. You can extract the header names by traversing the tree that. To do this use the getFirstChild and getNextSibling methods that are part of the Element interface.</documentation> 123 <input message="s0:GetHeaders1SoapIn"/> 124 <output message="s0:GetHeaders1SoapOut"/> 125 </operation> 126 <operation name="GetHeaders2"> 127 <documentation>This method gets just the header names, not the envelope name. It's a somewhat simpler method that relys on getting a list of Child Nodes, where each child is one of the headers. The getChildNodes method also gives the number of nodes in the list. This way all you have to do is index into the list instead of keeping track of the child nodes and siblings. To do this, use the getInputHeaders method to get the single array element with all the headers in it. Then use the Element interface method, getChildNodes to get a list of nodes in a NodeList type object. You then use the NodeList interface methods, getLength and item, to get the number of nodes and header node, respectively. getNodeName then supplies the name of the node.</documentation> 128 <input message="s0:GetHeaders2SoapIn"/> 129 <output message="s0:GetHeaders2SoapOut"/> 130 </operation> 131 </portType> 132 <portType name="multipleHeadersHttpGet"> 133 <operation name="myMethod"> 134 <documentation>In this method, headers are created using HeaderDocument.Factory.Parse. The FirstChild is extracted into header, which is type Element. Each header is put into an array that is passed to the JwsContext service method, setOutputHeaders, which puts the headers in place. The format of the Element header is: firstChild localName = "Header" name = "SOAP-ENV:Header" namespaceURI= "http://schemas-xmlsoap.org/soap/envelope/" firstChild localName = "content&lt;header#&gt;" name = "my:content&lt;header#&gt;" namespaceURI= "http://my.com/uri/" firstChild data = "Header&lt;header#&gt;"</documentation> 135 <input message="s0:myMethodHttpGetIn"/> 136 <output message="s0:myMethodHttpGetOut"/> 137 </operation> 138 <operation name="GetHeaders1"> 139 <documentation>The header can be obtained by using the JwsContext interface getInputHeaders(), which is the compliment to setOutputHeaders() that was used in myMethod to add the header. The result is formated exactly the same way. Note that, while myMethod created multiple elements in headerElement[], the getInputHeaders method created a single array element. What you get back with getInputHeaders is that single array element that contains all of the headers arranged in a tree of nodes. You can extract the header names by traversing the tree that. To do this use the getFirstChild and getNextSibling methods that are part of the Element interface.</documentation> 140 <input message="s0:GetHeaders1HttpGetIn"/> 141 <output message="s0:GetHeaders1HttpGetOut"/> 142 </operation> 143 <operation name="GetHeaders2"> 144 <documentation>This method gets just the header names, not the envelope name. It's a somewhat simpler method that relys on getting a list of Child Nodes, where each child is one of the headers. The getChildNodes method also gives the number of nodes in the list. This way all you have to do is index into the list instead of keeping track of the child nodes and siblings. To do this, use the getInputHeaders method to get the single array element with all the headers in it. Then use the Element interface method, getChildNodes to get a list of nodes in a NodeList type object. You then use the NodeList interface methods, getLength and item, to get the number of nodes and header node, respectively. getNodeName then supplies the name of the node.</documentation> 145 <input message="s0:GetHeaders2HttpGetIn"/> 146 <output message="s0:GetHeaders2HttpGetOut"/> 147 </operation> 148 </portType> 149 <portType name="multipleHeadersHttpPost"> 150 <operation name="myMethod"> 151 <documentation>In this method, headers are created using HeaderDocument.Factory.Parse. The FirstChild is extracted into header, which is type Element. Each header is put into an array that is passed to the JwsContext service method, setOutputHeaders, which puts the headers in place. The format of the Element header is: firstChild localName = "Header" name = "SOAP-ENV:Header" namespaceURI= "http://schemas-xmlsoap.org/soap/envelope/" firstChild localName = "content&lt;header#&gt;" name = "my:content&lt;header#&gt;" namespaceURI= "http://my.com/uri/" firstChild data = "Header&lt;header#&gt;"</documentation> 152 <input message="s0:myMethodHttpPostIn"/> 153 <output message="s0:myMethodHttpPostOut"/> 154 </operation> 155 <operation name="GetHeaders1"> 156 <documentation>The header can be obtained by using the JwsContext interface getInputHeaders(), which is the compliment to setOutputHeaders() that was used in myMethod to add the header. The result is formated exactly the same way. Note that, while myMethod created multiple elements in headerElement[], the getInputHeaders method created a single array element. What you get back with getInputHeaders is that single array element that contains all of the headers arranged in a tree of nodes. You can extract the header names by traversing the tree that. To do this use the getFirstChild and getNextSibling methods that are part of the Element interface.</documentation> 157 <input message="s0:GetHeaders1HttpPostIn"/> 158 <output message="s0:GetHeaders1HttpPostOut"/> 159 </operation> 160 <operation name="GetHeaders2"> 161 <documentation>This method gets just the header names, not the envelope name. It's a somewhat simpler method that relys on getting a list of Child Nodes, where each child is one of the headers. The getChildNodes method also gives the number of nodes in the list. This way all you have to do is index into the list instead of keeping track of the child nodes and siblings. To do this, use the getInputHeaders method to get the single array element with all the headers in it. Then use the Element interface method, getChildNodes to get a list of nodes in a NodeList type object. You then use the NodeList interface methods, getLength and item, to get the number of nodes and header node, respectively. getNodeName then supplies the name of the node.</documentation> 162 <input message="s0:GetHeaders2HttpPostIn"/> 163 <output message="s0:GetHeaders2HttpPostOut"/> 164 </operation> 165 </portType> 166 <binding name="multipleHeadersSoap" type="s0:multipleHeadersSoap"> 167 <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> 168 <operation name="myMethod"> 169 <soap:operation soapAction="http://www.openuri.org/myMethod" style="document"/> 170 <input> 171 <soap:body use="literal"/> 172 </input> 173 <output> 174 <soap:body use="literal"/> 175 </output> 176 </operation> 177 <operation name="GetHeaders1"> 178 <soap:operation soapAction="http://www.openuri.org/GetHeaders1" style="document"/> 179 <input> 180 <soap:body use="literal"/> 181 </input> 182 <output> 183 <soap:body use="literal"/> 184 </output> 185 </operation> 186 <operation name="GetHeaders2"> 187 <soap:operation soapAction="http://www.openuri.org/GetHeaders2" style="document"/> 188 <input> 189 <soap:body use="literal"/> 190 </input> 191 <output> 192 <soap:body use="literal"/> 193 </output> 194 </operation> 195 </binding> 196 <binding name="multipleHeadersHttpGet" type="s0:multipleHeadersHttpGet"> 197 <http:binding verb="GET"/> 198 <operation name="myMethod"> 199 <http:operation location="/myMethod"/> 200 <input> 201 <http:urlEncoded/> 202 </input> 203 <output/> 204 </operation> 205 <operation name="GetHeaders1"> 206 <http:operation location="/GetHeaders1"/> 207 <input> 208 <http:urlEncoded/> 209 </input> 210 <output> 211 <mime:mimeXml part="Body"/> 212 </output> 213 </operation> 214 <operation name="GetHeaders2"> 215 <http:operation location="/GetHeaders2"/> 216 <input> 217 <http:urlEncoded/> 218 </input> 219 <output> 220 <mime:mimeXml part="Body"/> 221 </output> 222 </operation> 223 </binding> 224 <binding name="multipleHeadersHttpPost" type="s0:multipleHeadersHttpPost"> 225 <http:binding verb="POST"/> 226 <operation name="myMethod"> 227 <http:operation location="/myMethod"/> 228 <input> 229 <mime:content type="application/x-www-form-urlencoded"/> 230 </input> 231 <output/> 232 </operation> 233 <operation name="GetHeaders1"> 234 <http:operation location="/GetHeaders1"/> 235 <input> 236 <mime:content type="application/x-www-form-urlencoded"/> 237 </input> 238 <output> 239 <mime:mimeXml part="Body"/> 240 </output> 241 </operation> 242 <operation name="GetHeaders2"> 243 <http:operation location="/GetHeaders2"/> 244 <input> 245 <mime:content type="application/x-www-form-urlencoded"/> 246 </input> 247 <output> 248 <mime:mimeXml part="Body"/> 249 </output> 250 </operation> 251 </binding> 252 <service name="multipleHeaders"> 253 <port name="multipleHeadersSoap" binding="s0:multipleHeadersSoap"> 254 <soap:address location="http://localhost:7001/soapHeaders/multipleHeaders.jws"/> 255 </port> 256 <port name="multipleHeadersHttpGet" binding="s0:multipleHeadersHttpGet"> 257 <http:address location="http://localhost:7001/soapHeaders/multipleHeaders.jws"/> 258 </port> 259 <port name="multipleHeadersHttpPost" binding="s0:multipleHeadersHttpPost"> 260 <http:address location="http://localhost:7001/soapHeaders/multipleHeaders.jws"/> 261 </port> 262 </service> 263 </definitions> 264 * :: 265 */`