INT-1477 restructuring samples repo to have basic, intermediate, advancedand applications directories
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.LinkedList;
|
||||
|
||||
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(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")){
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 6.6 KiB |
@@ -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>
|
||||
26
intermediate/multipart-http/src/main/resources/log4j.xml
Normal file
26
intermediate/multipart-http/src/main/resources/log4j.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||
|
||||
<!-- Appenders -->
|
||||
<appender name="console" class="org.apache.log4j.ConsoleAppender">
|
||||
<param name="Target" value="System.out" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-5p: %c - %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
<logger name="org.springframework.integration">
|
||||
<level value="warn" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework.integration.samples.multipart">
|
||||
<level value="debug" />
|
||||
</logger>
|
||||
|
||||
<!-- Root Logger -->
|
||||
<root>
|
||||
<priority value="warn" />
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
||||
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Class-Path:
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
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/file http://www.springframework.org/schema/integration/file/spring-integration-file-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http-2.0.xsd"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-file="http://www.springframework.org/schema/integration/file"
|
||||
xmlns:int-http="http://www.springframework.org/schema/integration/http">
|
||||
|
||||
|
||||
<int-http:inbound-channel-adapter id="httpInboundAdapter"
|
||||
channel="receiveChannel"
|
||||
name="/inboundAdapter.htm"
|
||||
supported-methods="GET, POST" />
|
||||
|
||||
<int:channel id="receiveChannel"/>
|
||||
|
||||
<int:service-activator id="multipartReceiver" input-channel="receiveChannel">
|
||||
<bean class="org.springframework.integration.samples.multipart.MultipartReceiever"/>
|
||||
</int:service-activator>
|
||||
|
||||
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
|
||||
</beans>
|
||||
17
intermediate/multipart-http/src/main/webapp/WEB-INF/web.xml
Normal file
17
intermediate/multipart-http/src/main/webapp/WEB-INF/web.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
|
||||
<display-name>multipart-http</display-name>
|
||||
<servlet>
|
||||
<servlet-name>Multipart</servlet-name>
|
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>/WEB-INF/servlet-config.xml</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>Multipart</servlet-name>
|
||||
<url-pattern>*.htm</url-pattern>
|
||||
</servlet-mapping>
|
||||
</web-app>
|
||||
3
intermediate/multipart-http/src/main/webapp/index.html
Normal file
3
intermediate/multipart-http/src/main/webapp/index.html
Normal file
@@ -0,0 +1,3 @@
|
||||
You have successfully deployed HTTP Multipart Sample.
|
||||
|
||||
Now you ready to execute org.springframework.integration.samples.multipart.MultipartClient
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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;
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
@@ -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 MultipartRestClient {
|
||||
|
||||
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";
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) throws Exception{
|
||||
RestTemplate template = new RestTemplate();
|
||||
Resource s2logo = new ClassPathResource(resourcePath);
|
||||
MultiValueMap<String, Object> multipartMap = new LinkedMultiValueMap<String, Object>();
|
||||
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<Object> request = new HttpEntity<Object>(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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user