diff --git a/cook-books/multipart-http/.classpath b/cook-books/multipart-http/.classpath new file mode 100644 index 00000000..dc2be4c4 --- /dev/null +++ b/cook-books/multipart-http/.classpath @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/cook-books/multipart-http/.project b/cook-books/multipart-http/.project new file mode 100644 index 00000000..1aa0542b --- /dev/null +++ b/cook-books/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/cook-books/multipart-http/.settings/.jsdtscope b/cook-books/multipart-http/.settings/.jsdtscope new file mode 100644 index 00000000..b46b9207 --- /dev/null +++ b/cook-books/multipart-http/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/cook-books/multipart-http/.settings/com.springsource.sts.config.flow.prefs b/cook-books/multipart-http/.settings/com.springsource.sts.config.flow.prefs new file mode 100644 index 00000000..a365e4ff --- /dev/null +++ b/cook-books/multipart-http/.settings/com.springsource.sts.config.flow.prefs @@ -0,0 +1,3 @@ +#Thu Sep 16 09:13:09 EDT 2010 +//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/multipart-http/src/main/webapp/WEB-INF/servlet-config.xml=\n\n\n\n\n\n\n\n\n\n\n\n\n\n +eclipse.preferences.version=1 diff --git a/cook-books/multipart-http/.settings/org.eclipse.jdt.core.prefs b/cook-books/multipart-http/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..316adb02 --- /dev/null +++ b/cook-books/multipart-http/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Thu Sep 16 09:11:51 EDT 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/cook-books/multipart-http/.settings/org.eclipse.wst.common.component b/cook-books/multipart-http/.settings/org.eclipse.wst.common.component new file mode 100644 index 00000000..84fb939a --- /dev/null +++ b/cook-books/multipart-http/.settings/org.eclipse.wst.common.component @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/cook-books/multipart-http/.settings/org.eclipse.wst.common.project.facet.core.xml b/cook-books/multipart-http/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 00000000..9f1491f6 --- /dev/null +++ b/cook-books/multipart-http/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/cook-books/multipart-http/.settings/org.eclipse.wst.jsdt.ui.superType.container b/cook-books/multipart-http/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 00000000..3bd5d0a4 --- /dev/null +++ b/cook-books/multipart-http/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/cook-books/multipart-http/.settings/org.eclipse.wst.jsdt.ui.superType.name b/cook-books/multipart-http/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 00000000..05bd71b6 --- /dev/null +++ b/cook-books/multipart-http/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/cook-books/multipart-http/.settings/org.maven.ide.eclipse.prefs b/cook-books/multipart-http/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 00000000..00480d5b --- /dev/null +++ b/cook-books/multipart-http/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,9 @@ +#Tue Aug 31 23:37:04 EDT 2010 +activeProfiles= +eclipse.preferences.version=1 +fullBuildGoals=process-test-resources +includeModules=false +resolveWorkspaceProjects=false +resourceFilterGoals=process-resources resources\:testResources +skipCompilerPlugin=true +version=1 diff --git a/cook-books/multipart-http/.settings/org.springframework.ide.eclipse.core.prefs b/cook-books/multipart-http/.settings/org.springframework.ide.eclipse.core.prefs new file mode 100644 index 00000000..2f28119e --- /dev/null +++ b/cook-books/multipart-http/.settings/org.springframework.ide.eclipse.core.prefs @@ -0,0 +1,68 @@ +#Thu Sep 16 09:14:16 EDT 2010 +eclipse.preferences.version=1 +org.springframework.ide.eclipse.core.builders.enable.aopreferencemodelbuilder=true +org.springframework.ide.eclipse.core.builders.enable.beanmetadatabuilder=true +org.springframework.ide.eclipse.core.builders.enable.osgibundleupdater=false +org.springframework.ide.eclipse.core.enable.project.preferences=true +org.springframework.ide.eclipse.core.validator.enable.com.springsource.server.ide.manifest.core.manifestvalidator=false +org.springframework.ide.eclipse.core.validator.enable.com.springsource.sts.bestpractices.beansvalidator=false +org.springframework.ide.eclipse.core.validator.enable.com.springsource.sts.server.quickfix.manifestvalidator=false +org.springframework.ide.eclipse.core.validator.enable.org.springframework.ide.eclipse.beans.core.beansvalidator=false +org.springframework.ide.eclipse.core.validator.enable.org.springframework.ide.eclipse.core.springvalidator=false +org.springframework.ide.eclipse.core.validator.enable.org.springframework.ide.eclipse.webflow.core.validator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.applicationSymbolicNameRule-com.springsource.server.ide.manifest.core.manifestvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.applicationVersionRule-com.springsource.server.ide.manifest.core.manifestvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.bundleActivationPolicyRule-com.springsource.server.ide.manifest.core.manifestvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.bundleActivatorRule-com.springsource.server.ide.manifest.core.manifestvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.bundleManifestVersionRule-com.springsource.server.ide.manifest.core.manifestvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.bundleSymbolicNameRule-com.springsource.server.ide.manifest.core.manifestvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.bundleVersionRule-com.springsource.server.ide.manifest.core.manifestvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.exportPackageRule-com.springsource.server.ide.manifest.core.manifestvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.importRule-com.springsource.server.ide.manifest.core.manifestvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.parsingProblemsRule-com.springsource.server.ide.manifest.core.manifestvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.server.ide.manifest.core.requireBundleRule-com.springsource.server.ide.manifest.core.manifestvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.AvoidDriverManagerDataSource-com.springsource.sts.bestpractices.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.ImportElementsAtTopRulee-com.springsource.sts.bestpractices.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.ParentBeanSpecifiesAbstractClassRule-com.springsource.sts.bestpractices.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.RefElementRule-com.springsource.sts.bestpractices.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.TooManyBeansInFileRule-com.springsource.sts.bestpractices.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.UnnecessaryValueElementRule-com.springsource.sts.bestpractices.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.com.springsource.sts.bestpractices.UseBeanInheritance-com.springsource.sts.bestpractices.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.bestpractices.legacyxmlusage.jndiobjectfactory-com.springsource.sts.bestpractices.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.server.quickfix.importBundleVersionRule-com.springsource.sts.server.quickfix.manifestvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.server.quickfix.importLibraryVersionRule-com.springsource.sts.server.quickfix.manifestvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.server.quickfix.importPackageVersionRule-com.springsource.sts.server.quickfix.manifestvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.com.springsource.sts.server.quickfix.requireBundleVersionRule-com.springsource.sts.server.quickfix.manifestvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.autowire.autowire-org.springframework.ide.eclipse.beans.core.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanAlias-org.springframework.ide.eclipse.beans.core.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanClass-org.springframework.ide.eclipse.beans.core.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanConstructorArgument-org.springframework.ide.eclipse.beans.core.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanDefinition-org.springframework.ide.eclipse.beans.core.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanDefinitionHolder-org.springframework.ide.eclipse.beans.core.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanFactory-org.springframework.ide.eclipse.beans.core.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanInitDestroyMethod-org.springframework.ide.eclipse.beans.core.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanProperty-org.springframework.ide.eclipse.beans.core.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.beanReference-org.springframework.ide.eclipse.beans.core.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.methodOverride-org.springframework.ide.eclipse.beans.core.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.parsingProblems-org.springframework.ide.eclipse.beans.core.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.requiredProperty-org.springframework.ide.eclipse.beans.core.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.beans.core.toolAnnotation-org.springframework.ide.eclipse.beans.core.beansvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.core.springClasspath-org.springframework.ide.eclipse.core.springvalidator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.action-org.springframework.ide.eclipse.webflow.core.validator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.actionstate-org.springframework.ide.eclipse.webflow.core.validator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.attribute-org.springframework.ide.eclipse.webflow.core.validator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.attributemapper-org.springframework.ide.eclipse.webflow.core.validator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.beanaction-org.springframework.ide.eclipse.webflow.core.validator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.evaluationaction-org.springframework.ide.eclipse.webflow.core.validator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.evaluationresult-org.springframework.ide.eclipse.webflow.core.validator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.exceptionhandler-org.springframework.ide.eclipse.webflow.core.validator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.import-org.springframework.ide.eclipse.webflow.core.validator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.inputattribute-org.springframework.ide.eclipse.webflow.core.validator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.mapping-org.springframework.ide.eclipse.webflow.core.validator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.outputattribute-org.springframework.ide.eclipse.webflow.core.validator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.set-org.springframework.ide.eclipse.webflow.core.validator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.state-org.springframework.ide.eclipse.webflow.core.validator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.subflowstate-org.springframework.ide.eclipse.webflow.core.validator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.transition-org.springframework.ide.eclipse.webflow.core.validator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.variable-org.springframework.ide.eclipse.webflow.core.validator=false +org.springframework.ide.eclipse.core.validator.rule.enable.org.springframework.ide.eclipse.webflow.core.validation.webflowstate-org.springframework.ide.eclipse.webflow.core.validator=false diff --git a/cook-books/multipart-http/.springBeans b/cook-books/multipart-http/.springBeans new file mode 100644 index 00000000..15608f30 --- /dev/null +++ b/cook-books/multipart-http/.springBeans @@ -0,0 +1,13 @@ + + + 1 + + + + + + + + + + diff --git a/cook-books/multipart-http/pom.xml b/cook-books/multipart-http/pom.xml new file mode 100644 index 00000000..636a9c62 --- /dev/null +++ b/cook-books/multipart-http/pom.xml @@ -0,0 +1,58 @@ + + 4.0.0 + org.springframework.integration.samples + multipart-http + 2.0.0 + Spring Integration HTTP Multipart Demo + war + + 2.0.0.M7 + 3.0.3.RELEASE + 1.2 + 1.3.2 + 1.2.15 + + + + org.springframework.integration + spring-integration-http + ${spring.integration.version} + + + org.springframework + spring-webmvc + ${spring.version} + + + commons-fileupload + commons-fileupload + ${commons-fileupload} + + + org.apache.commons + commons-io + 1.3.2 + + + log4j + log4j + ${log4j.version} + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + -Xlint:all + true + false + + + + + diff --git a/cook-books/multipart-http/readme.txt b/cook-books/multipart-http/readme.txt new file mode 100644 index 00000000..235eb5c4 --- /dev/null +++ b/cook-books/multipart-http/readme.txt @@ -0,0 +1,11 @@ +To run this sample + 1) deploy project + - If you are using STS and project is imported as Eclipse project in your workspace you can just execute 'Run on Server' + - You can also run 'mvn clean install' and generate the WAR file that you can deploy the conventional way + 2) run the simple test client program: org.springframework.integration.samples.multipart.MultipartClient + + You should see the following output from the server: + + ### Successfully recieved multipart request ### + company - SpringSource + company-logo - as UploadedMultipartFile: spring09_logo.png \ No newline at end of file diff --git a/cook-books/multipart-http/src/main/java/org/springframework/integration/samples/multipart/MultipartReceiever.java b/cook-books/multipart-http/src/main/java/org/springframework/integration/samples/multipart/MultipartReceiever.java new file mode 100644 index 00000000..419d9f8a --- /dev/null +++ b/cook-books/multipart-http/src/main/java/org/springframework/integration/samples/multipart/MultipartReceiever.java @@ -0,0 +1,39 @@ +/* + * 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.apache.log4j.Logger; +import org.springframework.integration.http.UploadedMultipartFile; +import org.springframework.util.LinkedMultiValueMap; +/** + * @author Oleg Zhurakousky + * + */ +public class MultipartReceiever { + private static Logger logger = Logger.getLogger(MultipartClient.class); + + public void recieve(LinkedMultiValueMap multipartRequest){ + logger.info("Successfully recieved multipart request: " + multipartRequest); + for (String elementName : multipartRequest.keySet()) { + if (elementName.equals("company")){ + logger.info(elementName + " - " + ((String[]) multipartRequest.getFirst("company"))[0]); + } else if (elementName.equals("company-logo")){ + logger.info(elementName + " - as UploadedMultipartFile: " + + ((UploadedMultipartFile) multipartRequest.getFirst("company-logo")).getOriginalFilename()); + } + } + } +} diff --git a/cook-books/multipart-http/src/main/java/org/springframework/integration/samples/multipart/spring09_logo.png b/cook-books/multipart-http/src/main/java/org/springframework/integration/samples/multipart/spring09_logo.png new file mode 100644 index 00000000..36b42b00 Binary files /dev/null and b/cook-books/multipart-http/src/main/java/org/springframework/integration/samples/multipart/spring09_logo.png differ diff --git a/cook-books/multipart-http/src/main/resources/log4j.xml b/cook-books/multipart-http/src/main/resources/log4j.xml new file mode 100644 index 00000000..b9d92d2c --- /dev/null +++ b/cook-books/multipart-http/src/main/resources/log4j.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cook-books/multipart-http/src/main/webapp/META-INF/MANIFEST.MF b/cook-books/multipart-http/src/main/webapp/META-INF/MANIFEST.MF new file mode 100644 index 00000000..5e949512 --- /dev/null +++ b/cook-books/multipart-http/src/main/webapp/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/cook-books/multipart-http/src/main/webapp/WEB-INF/servlet-config.xml b/cook-books/multipart-http/src/main/webapp/WEB-INF/servlet-config.xml new file mode 100644 index 00000000..b8e3b9e0 --- /dev/null +++ b/cook-books/multipart-http/src/main/webapp/WEB-INF/servlet-config.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + diff --git a/cook-books/multipart-http/src/main/webapp/WEB-INF/web.xml b/cook-books/multipart-http/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..43c0d51a --- /dev/null +++ b/cook-books/multipart-http/src/main/webapp/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/cook-books/multipart-http/src/main/webapp/index.html b/cook-books/multipart-http/src/main/webapp/index.html new file mode 100644 index 00000000..f60b3bbe --- /dev/null +++ b/cook-books/multipart-http/src/main/webapp/index.html @@ -0,0 +1,3 @@ +You have successfully deployed HTTP Multipart Sample. + +Now you ready to execute org.springframework.integration.samples.multipart.MultipartClient \ No newline at end of file diff --git a/cook-books/multipart-http/src/test/java/org/springframework/integration/samples/multipart/MultipartClient.java b/cook-books/multipart-http/src/test/java/org/springframework/integration/samples/multipart/MultipartClient.java new file mode 100644 index 00000000..4646e596 --- /dev/null +++ b/cook-books/multipart-http/src/test/java/org/springframework/integration/samples/multipart/MultipartClient.java @@ -0,0 +1,59 @@ +/* + * 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.apache.log4j.Logger; +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.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; +/** + * @author Oleg Zhurakousky + * + */ +public class MultipartClient { + + private static Logger logger = Logger.getLogger(MultipartClient.class); + private static String uri = "http://localhost:8080/multipart-http/inboundAdapter.htm"; + private static String resourcePath = "org/springframework/integration/samples/multipart/spring09_logo.png"; + + /** + * @param args + */ + public static void main(String[] args) throws Exception{ + RestTemplate template = new RestTemplate(); + Resource s2logo = new ClassPathResource(resourcePath); + MultiValueMap multipartMap = new LinkedMultiValueMap(); + multipartMap.add("company", "SpringSource"); + multipartMap.add("company-logo", s2logo); + logger.info("Created multipart request: " + multipartMap); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(new MediaType("multipart", "form-data")); + HttpEntity request = new HttpEntity(multipartMap, headers); + logger.info("Posting request to: " + uri); + ResponseEntity httpResponse = template.exchange(uri, HttpMethod.POST, request, null); + if (!httpResponse.getStatusCode().equals(HttpStatus.OK)){ + logger.error("Problems with the request. Http status: " + httpResponse.getStatusCode()); + } + } +}