|
223 | 223 | <section id="message-context">
|
224 | 224 | <title><interfacename>MessageContext</interfacename></title>
|
225 | 225 | <para>
|
226 |
| - Typically, messages come in pairs: a request and a response. A request |
227 |
| - is created on the client-side, which is sent over some transport to the |
228 |
| - server-side, where a response is generated. This response gets |
| 226 | + Typically, messages come in pairs: a request and a response. A request is created on the client-side, |
| 227 | + which is sent over some transport to the server-side, where a response is generated. This response gets |
229 | 228 | sent back to the client, where it is read.
|
230 | 229 | </para>
|
231 | 230 | <para>
|
|
235 | 234 | On the client-side, the message context is created by the <link linkend="client-web-service-template">
|
236 | 235 | <classname>WebServiceTemplate</classname></link>.
|
237 | 236 | On the server-side, the message context is read from the transport-specific input stream.
|
238 |
| - For example, in HTTP, it is read from the <interfacename>HttpServletRequest</interfacename> and the response is written back |
239 |
| - to the <interfacename>HttpServletResponse</interfacename>. |
| 237 | + For example, in HTTP, it is read from the <interfacename>HttpServletRequest</interfacename> and the |
| 238 | + response is written back to the <interfacename>HttpServletResponse</interfacename>. |
240 | 239 | </para>
|
241 | 240 | </section>
|
242 | 241 | </section>
|
| 242 | + <section id="transport-context"> |
| 243 | + <title><interfacename>TransportContext</interfacename></title> |
| 244 | + <para> |
| 245 | + One of the key properties of the SOAP protocol is that it tries to be transport-agnostic. This is why, for |
| 246 | + instance, Spring-WS does not support mapping messages to endpoints by HTTP request URL, but |
| 247 | + rather by mesage content. |
| 248 | + </para> |
| 249 | + <para> |
| 250 | + However, sometimes it is necessary to get access to the underlying transport, either on the client or server |
| 251 | + side. For this, Spring Web Services has the <interfacename>TransportContext</interfacename>. The transport |
| 252 | + context allows access to the underlying <interfacename>WebServiceConnection</interfacename>, which typically |
| 253 | + is a <classname>HttpServletConnection</classname> on the server side; or a |
| 254 | + <classname>HttpUrlConnection</classname> or <classname>CommonsHttpConnection</classname> on the client side. |
| 255 | + For example, you can obtain the IP address of the current request in a server-side endpoint or |
| 256 | + interceptor like so: |
| 257 | + </para> |
| 258 | + <programlisting><![CDATA[ |
| 259 | +TransportContext context = TransportContextHolder.getTransportContext(); |
| 260 | +HttpServletConnection connection = (HttpServletConnection )context.getConnection(); |
| 261 | +HttpServletRequest request = connection.getHttpServletRequest(); |
| 262 | +String ipAddress = request.getRemoteAddr();]]></programlisting> |
| 263 | + </section> |
243 | 264 | <section id="xpath">
|
244 | 265 | <title>Handling XML With XPath</title>
|
245 | 266 | <para>
|
|
0 commit comments