當前位置: 首頁>>代碼示例>>Java>>正文


Java MultiValueMap.setAll方法代碼示例

本文整理匯總了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;

}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:38,代碼來源:RestUtils.java

示例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;
}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:31,代碼來源:RestUtils.java


注:本文中的org.springframework.util.MultiValueMap.setAll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。