本文整理汇总了Java中org.springframework.util.MultiValueMap.setAll方法的典型用法代码示例。如果您正苦于以下问题:Java MultiValueMap.setAll方法的具体用法?Java MultiValueMap.setAll怎么用?Java MultiValueMap.setAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.util.MultiValueMap
的用法示例。
在下文中一共展示了MultiValueMap.setAll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendPostForUpload
import org.springframework.util.MultiValueMap; //导入方法依赖的package包/类
/**
*
* /** sendPostCommand
*
* @param url
* @param parameters
* @return
* @throws ClientProtocolException
*/
public Map<String, Object> sendPostForUpload(String url, Map<String, Object> parameters) {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setBufferRequestBody(false);
RestTemplate restTemplate = new RestTemplate(requestFactory);
List<HttpMessageConverter<?>> mc = restTemplate.getMessageConverters();
mc.add(new MappingJackson2HttpMessageConverter());
restTemplate.setMessageConverters(mc);
MultiValueMap<String, Object> postParams = new LinkedMultiValueMap<String, Object>();
postParams.setAll(parameters);
Map<String, Object> response = new HashMap<String, Object>();
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "multipart/form-data");
headers.set("Accept", "application/json");
headers.add("Cookie", "JSESSIONID=" + localContext.getCookieStore().getCookies().get(0).getValue());
HttpEntity<Object> request = new HttpEntity<Object>(postParams, headers);
ResponseEntity<?> result = restTemplate.exchange(url, HttpMethod.POST, request, String.class);
String body = result.getBody().toString();
MediaType contentType = result.getHeaders().getContentType();
HttpStatus statusCode = result.getStatusCode();
response.put(CONTENT_TYPE, contentType);
response.put(STATUS_CODE, statusCode);
response.put(BODY, body);
return response;
}
示例2: sendPostForUpload
import org.springframework.util.MultiValueMap; //导入方法依赖的package包/类
public Map<String, Object> sendPostForUpload( String url, String path, Log log )
throws IOException
{
File file = new File( path );
FileInputStream fileInputStream = new FileInputStream( file );
fileInputStream.available();
fileInputStream.close();
FileSystemResource resource = new FileSystemResource( file );
Map<String, Object> params = new HashMap<>();
params.put( "file", resource );
RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, Object> postParams = new LinkedMultiValueMap<String, Object>();
postParams.setAll( params );
Map<String, Object> response = new HashMap<String, Object>();
HttpHeaders headers = new HttpHeaders();
headers.set( "Content-Type", "multipart/form-data" );
headers.set( "Accept", "application/json" );
headers.add( "Cookie", "JSESSIONID=" + localContext.getCookieStore().getCookies().get( 0 ).getValue() );
org.springframework.http.HttpEntity<Object> request =
new org.springframework.http.HttpEntity<Object>( postParams, headers );
ResponseEntity<?> result = restTemplate.exchange( url, HttpMethod.POST, request, String.class );
String body = result.getBody().toString();
MediaType contentType = result.getHeaders().getContentType();
HttpStatus statusCode = result.getStatusCode();
response.put( "content-type", contentType );
response.put( "statusCode", statusCode );
response.put( "body", body );
return response;
}