From 3a50c718bbb6cb627868c650ed610a40520e713b Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Wed, 1 Sep 2010 14:34:15 +0000 Subject: [PATCH] INT-1016 - added sample to HTTP documentation section --- .../samples/multipart/MultipartReceiever.java | 3 +- .../main/webapp/WEB-INF/servlet-config.xml | 5 +- src/docbkx/http.xml | 65 +++++++++++++++++++ 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/spring-integration-samples/multipart-http/src/main/java/org/springframework/integration/samples/multipart/MultipartReceiever.java b/spring-integration-samples/multipart-http/src/main/java/org/springframework/integration/samples/multipart/MultipartReceiever.java index 4d2b1696be..40e915fdcb 100644 --- a/spring-integration-samples/multipart-http/src/main/java/org/springframework/integration/samples/multipart/MultipartReceiever.java +++ b/spring-integration-samples/multipart-http/src/main/java/org/springframework/integration/samples/multipart/MultipartReceiever.java @@ -23,8 +23,7 @@ import org.springframework.util.LinkedMultiValueMap; */ public class MultipartReceiever { - public void recieve(LinkedMultiValueMap multipartRequest){ - + public void recieve(LinkedMultiValueMap multipartRequest){ System.out.println("### Successfully recieved multipart request ###"); for (String elementName : multipartRequest.keySet()) { if (elementName.equals("company")){ diff --git a/spring-integration-samples/multipart-http/src/main/webapp/WEB-INF/servlet-config.xml b/spring-integration-samples/multipart-http/src/main/webapp/WEB-INF/servlet-config.xml index 20b4c40779..3fe44b98d6 100644 --- a/spring-integration-samples/multipart-http/src/main/webapp/WEB-INF/servlet-config.xml +++ b/spring-integration-samples/multipart-http/src/main/webapp/WEB-INF/servlet-config.xml @@ -10,10 +10,11 @@ xmlns:int-http="http://www.springframework.org/schema/integration/http"> - + + - + diff --git a/src/docbkx/http.xml b/src/docbkx/http.xml index 511fffe24e..b16fc37ffb 100644 --- a/src/docbkx/http.xml +++ b/src/docbkx/http.xml @@ -140,4 +140,69 @@ By default the HTTP request will be generated using an instance of Si auto-startup="false"/>]]> +
+ HTTP Samples +
+ Multipart HTTP request - RestTemplate (client) and Http Inbound Gateway (server) + + This example demonstrates how simple it is to send a Multipart HTTP request via Spring's RestTemplate and receive it by Spring Integration HTTP Inbound Adapter. +All we are doing is creating MultiValueMap and populating it with multi-part data. RestTemplate will take care of the rest +by converting it to MultipartHttpServletRequest   +THis particular client will send a multipart Http Request which contains the name of the company as well as the image file with company logo. + httpResponse = template.exchange(uri, HttpMethod.POST, request, null);]]> + + +That is all for the client. + + +On the server side we have the following configuration: + + + + + + + + + +]]> + + +The 'httpInboundAdapter' will receive the request, convert it to a Message with a payload as LinkedMultiValueMap which +we are parsing in the 'multipartReceiver' service-activator; + multipartRequest){ + System.out.println("### Successfully recieved multipart request ###"); + for (String elementName : multipartRequest.keySet()) { + if (elementName.equals("company")){ + System.out.println("\t" + elementName + " - " + + ((String[]) multipartRequest.getFirst("company"))[0]); + } else if (elementName.equals("company-logo")){ + System.out.println("\t" + elementName + " - as UploadedMultipartFile: " + + ((UploadedMultipartFile) multipartRequest.getFirst("company-logo")).getOriginalFilename()); + } + } +} + +]]> +You should see the following output: + + +
+