diff --git a/spring-integration-samples/multipart-http/.classpath b/spring-integration-samples/multipart-http/.classpath new file mode 100644 index 0000000000..060835db5e --- /dev/null +++ b/spring-integration-samples/multipart-http/.classpath @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/spring-integration-samples/multipart-http/.project b/spring-integration-samples/multipart-http/.project new file mode 100644 index 0000000000..1aa0542ba1 --- /dev/null +++ b/spring-integration-samples/multipart-http/.project @@ -0,0 +1,48 @@ + + + multipart-http + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + org.springframework.ide.eclipse.core.springbuilder + + + + + + org.springframework.ide.eclipse.core.springnature + org.maven.ide.eclipse.maven2Nature + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/spring-integration-samples/multipart-http/WebContent/META-INF/MANIFEST.MF b/spring-integration-samples/multipart-http/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..5e9495128c --- /dev/null +++ b/spring-integration-samples/multipart-http/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/spring-integration-samples/multipart-http/WebContent/WEB-INF/servlet-config.xml b/spring-integration-samples/multipart-http/WebContent/WEB-INF/servlet-config.xml new file mode 100644 index 0000000000..20b4c40779 --- /dev/null +++ b/spring-integration-samples/multipart-http/WebContent/WEB-INF/servlet-config.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + diff --git a/spring-integration-samples/multipart-http/WebContent/WEB-INF/web.xml b/spring-integration-samples/multipart-http/WebContent/WEB-INF/web.xml new file mode 100644 index 0000000000..43c0d51ac0 --- /dev/null +++ b/spring-integration-samples/multipart-http/WebContent/WEB-INF/web.xml @@ -0,0 +1,17 @@ + + + multipart-http + + Multipart + org.springframework.web.servlet.DispatcherServlet + + contextConfigLocation + /WEB-INF/servlet-config.xml + + 1 + + + Multipart + *.htm + + \ No newline at end of file diff --git a/spring-integration-samples/multipart-http/pom.xml b/spring-integration-samples/multipart-http/pom.xml new file mode 100644 index 0000000000..4d4f085a35 --- /dev/null +++ b/spring-integration-samples/multipart-http/pom.xml @@ -0,0 +1,33 @@ + + 4.0.0 + + org.springframework.integration.samples + spring-integration-samples + 2.0.0.BUILD-SNAPSHOT + + multipart-http + Spring Integration HTTP Multipart Demo + + + org.springframework.integration + spring-integration-http + 2.0.0.BUILD-SNAPSHOT + + + org.springframework + spring-webmvc + 3.0.3.RELEASE + + + commons-fileupload + commons-fileupload + 1.2 + + + org.apache.commons + commons-io + 1.3.2 + + + \ No newline at end of file diff --git a/spring-integration-samples/multipart-http/src/main/java/org/springframework/integration/samples/multipart/MultipartClient.java b/spring-integration-samples/multipart-http/src/main/java/org/springframework/integration/samples/multipart/MultipartClient.java new file mode 100644 index 0000000000..c468925476 --- /dev/null +++ b/spring-integration-samples/multipart-http/src/main/java/org/springframework/integration/samples/multipart/MultipartClient.java @@ -0,0 +1,45 @@ +package org.springframework.integration.samples.multipart; + +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.http.converter.BufferedImageHttpMessageConverter; +import org.springframework.http.converter.FormHttpMessageConverter; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; +/** + * @author Oleg Zhurakousky + * + */ +public class MultipartClient { + + /** + * @param args + */ + @SuppressWarnings("unchecked") + public static void main(String[] args) throws Exception{ + + RestTemplate template = new RestTemplate(); + for (HttpMessageConverter converter : template.getMessageConverters()) { + if (converter instanceof FormHttpMessageConverter){ + ((FormHttpMessageConverter)converter).addPartConverter(new BufferedImageHttpMessageConverter()); + } + } + String uri = "http://localhost:8080/multipart-http/inboundAdapter.htm"; + Resource s2logo = new ClassPathResource("org/springframework/integration/samples/multipart/spring09_logo.png"); + MultiValueMap map = new LinkedMultiValueMap(); + map.add("company", "SpringSource"); + map.add("company-logo", s2logo); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(new MediaType("multipart", "form-data")); + HttpEntity request = new HttpEntity(map, headers); + @SuppressWarnings("unused") + ResponseEntity httpResponse = template.exchange(uri, HttpMethod.POST, request, null); + } +} 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 new file mode 100644 index 0000000000..4d2b1696be --- /dev/null +++ b/spring-integration-samples/multipart-http/src/main/java/org/springframework/integration/samples/multipart/MultipartReceiever.java @@ -0,0 +1,37 @@ +/* + * Copyright 2002-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.integration.samples.multipart; + +import org.springframework.integration.http.UploadedMultipartFile; +import org.springframework.util.LinkedMultiValueMap; +/** + * @author Oleg Zhurakousky + * + */ +public class MultipartReceiever { + + public void recieve(LinkedMultiValueMap 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()); + } + } + } +} diff --git a/spring-integration-samples/multipart-http/src/main/java/org/springframework/integration/samples/multipart/spring09_logo.png b/spring-integration-samples/multipart-http/src/main/java/org/springframework/integration/samples/multipart/spring09_logo.png new file mode 100644 index 0000000000..36b42b0015 Binary files /dev/null and b/spring-integration-samples/multipart-http/src/main/java/org/springframework/integration/samples/multipart/spring09_logo.png differ