Book Image

Mastering Spring Application Development

By : Anjana Mankale
Book Image

Mastering Spring Application Development

By: Anjana Mankale

Overview of this book

Table of Contents (19 chapters)
Mastering Spring Application Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Sending multipart HTTP requests using Spring's RestTemplate


Most of the time, we have implemented file upload functionality in our application. Files are sent over HTTP as a multipart request.

In this section, let us see how we can configure the inbound channel adapter using RestTemplate to send a file over HTTP request.

Let us configure the server with the inbound channel adapter and then write a client for it:

<int-http:inbound-channel-adapter id="httpInboundAdapter"
  channel="receiveChannel"
  name="/inboundAdapter.htm"
  supported-methods="GET, POST"/>
<int:channel id="receiveChannel"/>
<int:service-activator input-channel="receiveChannel">
  <bean class="org.springframework.integration.samples.multipart.MultipartReceiver"/>
</int:service-activator>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>

The httpInboundAdapter will receive the request and convert it to a message with a payload LinkedMultiValueMap...