INTSAMPLES-2 added http-outbound-gateway sample to multipart-http

This commit is contained in:
Oleg Zhurakousky
2010-09-27 16:33:06 -04:00
parent e980888249
commit 87bbb1b50f
14 changed files with 129 additions and 24 deletions

View File

@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
@@ -11,5 +10,10 @@
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@@ -30,14 +30,8 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>

View File

@@ -1,3 +1,4 @@
#Thu Sep 16 09:13:09 EDT 2010
#Sun Sep 26 22:00:17 EDT 2010
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/multipart-http/src/main/resources/META-INF/spring/integration/http-outbound-config.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="GatewayModelElement" type\="gateway">\n<structure end\="1054" endstart\="1040" start\="696" startend\="893"/>\n<bounds height\="112" width\="116" x\="19" y\="17"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="1092" endstart\="1092" start\="1058" startend\="1092"/>\n<bounds height\="112" width\="116" x\="155" y\="17"/>\n</element>\n<element clazz\="OutboundGatewayModelElement" type\="outbound-gateway">\n<structure end\="1317" endstart\="1317" start\="1095" startend\="1317"/>\n<bounds height\="112" width\="116" x\="291" y\="17"/>\n</element>\n</graph>
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/multipart-http/src/main/webapp/WEB-INF/servlet-config.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="InboundChannelAdapterModelElement" type\="inbound-channel-adapter">\n<structure end\="1093" endstart\="1093" start\="915" startend\="1093"/>\n<bounds height\="112" width\="116" x\="19" y\="17"/>\n</element>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="1131" endstart\="1131" start\="1097" startend\="1131"/>\n<bounds height\="112" width\="116" x\="155" y\="17"/>\n</element>\n<element clazz\="ServiceActivatorModelElement" type\="service-activator">\n<structure end\="1325" endstart\="1301" start\="1135" startend\="1212"/>\n<bounds height\="112" width\="116" x\="291" y\="17"/>\n</element>\n</graph>
eclipse.preferences.version=1

View File

@@ -1,12 +1,13 @@
#Thu Sep 16 09:11:51 EDT 2010
#Sun Sep 26 22:12:18 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.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.compliance=1.5
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
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5

View File

@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="multipart-http">
<wb-resource deploy-path="/" source-path="/src/main/webapp"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/java"/>
<property name="context-root" value="multipart-http"/>
<property name="java-output-path" value="/multipart-http/target/classes"/>
</wb-module>

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.6"/>
<installed facet="jst.web" version="2.5"/>
<installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="java" version="1.5"/>
</faceted-project>

View File

@@ -1,4 +1,4 @@
#Tue Aug 31 23:37:04 EDT 2010
#Sun Sep 26 21:33:25 EDT 2010
activeProfiles=
eclipse.preferences.version=1
fullBuildGoals=process-test-resources

View File

@@ -7,6 +7,7 @@
</configSuffixes>
<enableImports><![CDATA[false]]></enableImports>
<configs>
<config>src/main/resources/META-INF/spring/integration/http-outbound-config.xml</config>
</configs>
<configSets>
</configSets>

View File

@@ -7,7 +7,7 @@
<name>Spring Integration HTTP Multipart Demo</name>
<packaging>war</packaging>
<properties>
<spring.integration.version>2.0.0.M7</spring.integration.version>
<spring.integration.version>2.0.0.BUILD-SNAPSHOT</spring.integration.version>
<spring.version>3.0.4.RELEASE</spring.version>
<commons-fileupload>1.2</commons-fileupload>
<commons-io>1.3.2</commons-io>

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.integration.samples.multipart;
import java.util.LinkedList;
import org.apache.log4j.Logger;
import org.springframework.integration.http.UploadedMultipartFile;
import org.springframework.util.LinkedMultiValueMap;
@@ -23,13 +25,18 @@ import org.springframework.util.LinkedMultiValueMap;
*
*/
public class MultipartReceiever {
private static Logger logger = Logger.getLogger(MultipartClient.class);
private static Logger logger = Logger.getLogger(MultipartReceiever.class);
@SuppressWarnings("rawtypes")
public void recieve(LinkedMultiValueMap<String, Object> 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]);
LinkedList value = (LinkedList)multipartRequest.get("company");
String[] multiValues = (String[]) value.get(0);
for (String companyName : multiValues) {
logger.info(elementName + " - " + companyName);
}
} else if (elementName.equals("company-logo")){
logger.info(elementName + " - as UploadedMultipartFile: "
+ ((UploadedMultipartFile) multipartRequest.getFirst("company-logo")).getOriginalFilename());

View File

@@ -0,0 +1,17 @@
/**
*
*/
package org.springframework.integration.samples.multipart;
import java.util.Map;
import org.springframework.http.HttpStatus;
/**
* @author ozhurakousky
*
*/
public interface MultipartRequestGateway {
public HttpStatus postMultipartRequest(Map<String, Object> multipartRequest);
}

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-http="http://www.springframework.org/schema/integration/http"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http-2.0.xsd">
<int:gateway id="requestGateway"
service-interface="org.springframework.integration.samples.multipart.MultipartRequestGateway"
default-request-channel="requestChannel">
<!-- <int:method name="postMultipartRequest">-->
<!-- <int:header name="Content-Type" value="multipart/form-data"/>-->
<!-- </int:method>-->
</int:gateway>
<int:channel id="requestChannel"/>
<int-http:outbound-gateway request-channel="requestChannel"
url="http://localhost:8080/multipart-http/inboundAdapter.htm"
http-method="POST"
extract-request-payload="true"/>
<bean id="headerMapper" class="org.springframework.integration.http.DefaultHttpHeaderMapper">
<property name="outboundHeaderNames" value="Content-Type"/>
</bean>
</beans>

View File

@@ -0,0 +1,52 @@
/*
* 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 java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
/**
* @author Oleg Zhurakousky
*
*/
public class MultipartClientForHttpOutboundClient {
private static Logger logger = Logger.getLogger(MultipartClientForHttpOutboundClient.class);
private static String resourcePath = "org/springframework/integration/samples/multipart/spring09_logo.png";
/**
* @param args
*/
public static void main(String[] args) throws Exception{
ApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/integration/http-outbound-config.xml");
Resource s2logo = new ClassPathResource(resourcePath);
Map<String, Object> multipartMap = new HashMap<String, Object>();
multipartMap.put("company", new String[]{"SpringSource", "VMWare"});
multipartMap.put("company-logo", s2logo);
logger.info("Created multipart request: " + multipartMap);
MultipartRequestGateway requestGateway = context.getBean("requestGateway", MultipartRequestGateway.class);
HttpStatus reply = requestGateway.postMultipartRequest(multipartMap);
System.out.println("Replied with HttpStatus code: " + reply);
}
}

View File

@@ -31,9 +31,9 @@ import org.springframework.web.client.RestTemplate;
* @author Oleg Zhurakousky
*
*/
public class MultipartClient {
public class MultipartRestClient {
private static Logger logger = Logger.getLogger(MultipartClient.class);
private static Logger logger = Logger.getLogger(MultipartRestClient.class);
private static String uri = "http://localhost:8080/multipart-http/inboundAdapter.htm";
private static String resourcePath = "org/springframework/integration/samples/multipart/spring09_logo.png";