本文整理匯總了Java中org.springframework.http.converter.FormHttpMessageConverter類的典型用法代碼示例。如果您正苦於以下問題:Java FormHttpMessageConverter類的具體用法?Java FormHttpMessageConverter怎麽用?Java FormHttpMessageConverter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FormHttpMessageConverter類屬於org.springframework.http.converter包,在下文中一共展示了FormHttpMessageConverter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loginAndSaveJsessionIdCookie
import org.springframework.http.converter.FormHttpMessageConverter; //導入依賴的package包/類
private static void loginAndSaveJsessionIdCookie(final String user, final String password,
final HttpHeaders headersToUpdate) {
String url = "http://localhost:" + port + "/";
new RestTemplate().execute(url, HttpMethod.POST,
new RequestCallback() {
@Override
public void doWithRequest(ClientHttpRequest request) throws IOException {
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
map.add("username", user);
map.add("password", password);
new FormHttpMessageConverter().write(map, MediaType.APPLICATION_FORM_URLENCODED, request);
}
},
new ResponseExtractor<Object>() {
@Override
public Object extractData(ClientHttpResponse response) throws IOException {
headersToUpdate.add("Cookie", response.getHeaders().getFirst("Set-Cookie"));
return null;
}
});
}
示例2: EmailServiceImpl
import org.springframework.http.converter.FormHttpMessageConverter; //導入依賴的package包/類
EmailServiceImpl(Environment env,
TextService text) {
this.env = requireNonNull(env);
this.text = requireNonNull(text);
this.mailgun = new RestTemplate();
this.mailgun.setMessageConverters(asList(
new FormHttpMessageConverter(),
new StringHttpMessageConverter(),
new MappingJackson2HttpMessageConverter()
));
this.mailgun.getInterceptors().add(new BasicAuthorizationInterceptor(
"api", env.getProperty("mailgun.apiKey")
));
}
示例3: AbstractZg2proRestTemplate
import org.springframework.http.converter.FormHttpMessageConverter; //導入依賴的package包/類
protected AbstractZg2proRestTemplate(SimpleModule sm) {
super();
//converters
List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
messageConverters.add(new FormHttpMessageConverter());
messageConverters.add(new StringHttpMessageConverter());
messageConverters.add(new ByteArrayHttpMessageConverter());
messageConverters.add(new ResourceHttpMessageConverter());
ObjectMapper jsonMapper = camelToKebabObjectMapper(sm);
messageConverters.add(new MappingJackson2HttpMessageConverter(jsonMapper));
this.setMessageConverters(messageConverters);
//errors handling
setErrorHandler(new RestTemplateErrorHandler());
/*
//interceptors
LoggingRequestInterceptor lri = new LoggingRequestInterceptor();
this.setInterceptors(new ArrayList<>());
this.getInterceptors().add(lri);
this.setRequestFactory(LoggingRequestFactoryFactory.build(lri));
*/
}
示例4: doCall
import org.springframework.http.converter.FormHttpMessageConverter; //導入依賴的package包/類
public void doCall() {
RestTemplate restTemplate = new RestTemplate();
ClientHttpRequestInterceptor ri = new LoggingRequestInterceptor();
List<ClientHttpRequestInterceptor> ris = new ArrayList<ClientHttpRequestInterceptor>();
ris.add(ri);
restTemplate.setInterceptors(ris);
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
map.add("grant_type", "client_credentials");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.add("Authorization", "Basic " + credentialsBuilder.getCredentialsString());
headers.add("Accept", "*/*");
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(map, headers);
List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
messageConverters.add(new FormHttpMessageConverter());
messageConverters.add(new MappingJackson2HttpMessageConverter());
restTemplate.setMessageConverters(messageConverters);
AuthResponse authToken = restTemplate.postForObject(config.getRestProperty("environment") + "/v2/auth/token", requestEntity, AuthResponse.class);
tokenHolder.resetToken(authToken);
}
示例5: rebuildMessageConverter
import org.springframework.http.converter.FormHttpMessageConverter; //導入依賴的package包/類
private void rebuildMessageConverter(RequestMappingHandlerAdapter adapter) {
List<HttpMessageConverter<?>> messageConverters = adapter.getMessageConverters();
if (!CollectionUtils.isEmpty(messageConverters)) {
for (HttpMessageConverter<?> messageConverter : messageConverters) {
if (messageConverter instanceof MappingJackson2HttpMessageConverter) {
rebuildJacksonV2((MappingJackson2HttpMessageConverter) messageConverter);
}
// if (messageConverter instanceof MappingJacksonHttpMessageConverter) {
// rebuildJacksonV1((MappingJacksonHttpMessageConverter) messageConverter);
// }
}
}
/**
* 處理form表單
* form表單通過get方法請求,controller裏邊的方法中隻需設置一個接收的對象即可.
*/
adapter.getMessageConverters().add(new FormHttpMessageConverter());
}
示例6: doInBackground
import org.springframework.http.converter.FormHttpMessageConverter; //導入依賴的package包/類
@Override
protected AuthResponse doInBackground(Void... params) {
RestTemplate restTemplate = new RestTemplate();
ClientHttpRequestInterceptor ri = new LoggingRequestInterceptor();
List<ClientHttpRequestInterceptor> ris = new ArrayList<>();
ris.add(ri);
restTemplate.setInterceptors(ris);
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
map.add("grant_type", "client_credentials");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.add("Authorization", "Basic " + credentialsBuilder.getCredentialsString());
headers.add("Accept", "*/*");
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(map, headers);
List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
messageConverters.add(new FormHttpMessageConverter());
messageConverters.add(new MappingJackson2HttpMessageConverter());
restTemplate.setMessageConverters(messageConverters);
AuthResponse authToken = restTemplate.postForObject(config.getRestProperty("environment") + "/v2/auth/token", requestEntity, AuthResponse.class);
block.offer(authToken);
return authToken;
}
示例7: initRestTemplate
import org.springframework.http.converter.FormHttpMessageConverter; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
protected void initRestTemplate(RestTemplate restTemplate) {
super.initRestTemplate(restTemplate);
restTemplate.setErrorHandler(new DCTMJacksonErrorHandler(restTemplate.getMessageConverters()));
for(HttpMessageConverter<?> c : restTemplate.getMessageConverters()) {
if(c instanceof MappingJackson2HttpMessageConverter) {
((MappingJackson2HttpMessageConverter)c).getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
} else if(c instanceof FormHttpMessageConverter) {
try {
Field pcField = FormHttpMessageConverter.class.getDeclaredField("partConverters");
pcField.setAccessible(true);
List<HttpMessageConverter<?>> partConverters = ((List<HttpMessageConverter<?>>)pcField.get(c));
for(HttpMessageConverter<?> pc : partConverters) {
if(pc instanceof MappingJackson2HttpMessageConverter) {
((MappingJackson2HttpMessageConverter)pc).getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
break;
}
}
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
}
}
開發者ID:Enterprise-Content-Management,項目名稱:documentum-rest-client-java,代碼行數:26,代碼來源:DCTMJacksonClient.java
示例8: createRestTemplate
import org.springframework.http.converter.FormHttpMessageConverter; //導入依賴的package包/類
@Override
public RestTemplate createRestTemplate() {
RestTemplate rtp = new RestTemplate();
Charset utf8 = Charset.forName(CHARSET);
ByteArrayHttpMessageConverter byteConv = new ByteArrayHttpMessageConverter();
StringHttpMessageConverter stringConv = new StringHttpMessageConverter(utf8);
FormHttpMessageConverter formConv = new FormHttpMessageConverter();
formConv.setCharset(utf8);
List<HttpMessageConverter<?>> converters = rtp.getMessageConverters();
converters.add(byteConv);
converters.add(stringConv);
converters.add(formConv);
rtp.setMessageConverters(converters);
return rtp;
}
示例9: beforeMethod
import org.springframework.http.converter.FormHttpMessageConverter; //導入依賴的package包/類
@BeforeMethod
public void beforeMethod()
{
MockitoAnnotations.initMocks(this);
FreeMarkerViewResolver freeMarkerViewResolver = new FreeMarkerViewResolver();
freeMarkerViewResolver.setSuffix(".ftl");
Menu menu = mock(Menu.class);
when(menu.findMenuItemPath(MetadataManagerController.METADATA_MANAGER)).thenReturn("/test/path");
when(menuReaderService.getMenu()).thenReturn(menu);
when(appSettings.getLanguageCode()).thenReturn("nl");
User user = mock(User.class);
when(user.isSuperuser()).thenReturn(false);
when(userAccountService.getCurrentUser()).thenReturn(user);
MetadataManagerController metadataEditorController = new MetadataManagerController(menuReaderService,
appSettings, metadataManagerService, userAccountService);
mockMvc = MockMvcBuilders.standaloneSetup(metadataEditorController).setLocaleResolver(localeResolver)
.setMessageConverters(new FormHttpMessageConverter(), gsonHttpMessageConverter)
.build();
}
示例10: getTagsForText
import org.springframework.http.converter.FormHttpMessageConverter; //導入依賴的package包/類
private String getTagsForText(URI fragment,String text) throws TransformException {
RestTemplate rest = new RestTemplate();
CommonsClientHttpRequestFactory clientHttpRequestFactory = new CommonsClientHttpRequestFactory();
clientHttpRequestFactory.setReadTimeout(10000);
rest.setRequestFactory(clientHttpRequestFactory);
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
converters.add(new FormHttpMessageConverter());
converters.add(new StringHttpMessageConverter());
rest.setMessageConverters(converters);
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
map.add("prefix", fragment.stringValue()+"#");
map.add("text", text);
HttpEntity<?> httpEntity = new HttpEntity<Object>(map, getHttpHeaders());
try {
String annotation = rest.postForObject(config.getSpotlightUrl(), httpEntity, String.class);
return annotation;
}
catch (RestClientException e) {
throw new TransformException(e.getMessage(),e);
}
}
示例11: getTagsFor
import org.springframework.http.converter.FormHttpMessageConverter; //導入依賴的package包/類
private SpotlightAnnotation getTagsFor(URI fragment,String text) throws TransformException {
RestTemplate rest = new RestTemplate();
CommonsClientHttpRequestFactory clientHttpRequestFactory = new CommonsClientHttpRequestFactory();
clientHttpRequestFactory.setReadTimeout(10000);
rest.setRequestFactory(clientHttpRequestFactory);
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
converters.add(new MappingJacksonHttpMessageConverter());
converters.add(new FormHttpMessageConverter());
rest.setMessageConverters(converters);
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
map.add("prefix", fragment.toString()+"#");
map.add("text", text.toString());
HttpEntity<?> httpEntity = new HttpEntity<Object>(map, getHttpHeaders());
try {
SpotlightAnnotation annotation = rest.postForObject(config.getSpotlightUrl(), httpEntity, SpotlightAnnotation.class);
annotation.setFragmentURI(fragment);
return annotation;
}
catch (RestClientException e) {
log.warn("could not request tags for: " + text);
log.warn(e.getMessage());
return new SpotlightAnnotation();
}
}
示例12: csapEventsService
import org.springframework.http.converter.FormHttpMessageConverter; //導入依賴的package包/類
@Bean ( name = "csapEventsService" )
public RestTemplate csapEventsService ( CsapRestTemplateFactory factory ) {
RestTemplate restTemplate = factory.buildDefaultTemplate( "csapEvents", false, 10, 10, 5, 5, 300 );
restTemplate.getMessageConverters().clear();
restTemplate.getMessageConverters().add( new FormHttpMessageConverter() );
restTemplate.getMessageConverters().add( new StringHttpMessageConverter() );
restTemplate.getMessageConverters().add( new MappingJackson2HttpMessageConverter() );
return restTemplate;
}
示例13: initRestTemplate
import org.springframework.http.converter.FormHttpMessageConverter; //導入依賴的package包/類
/**
* springboot初始化restTemplate
*/
@Bean
public RestTemplate initRestTemplate() {
// 長連接保持30秒
PoolingHttpClientConnectionManager pollingConnectionManager = new PoolingHttpClientConnectionManager(30, TimeUnit.SECONDS);
// 總連接數
pollingConnectionManager.setMaxTotal(1000);
// 同路由的並發數
pollingConnectionManager.setDefaultMaxPerRoute(1000);
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
httpClientBuilder.setConnectionManager(pollingConnectionManager);
// 重試次數,默認是3次,沒有開啟
httpClientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(2, true));
// 保持長連接配置,需要在頭添加Keep-Alive
httpClientBuilder.setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy());
RequestConfig.Builder builder = RequestConfig.custom();
builder.setConnectionRequestTimeout(200);
builder.setConnectTimeout(5000);
builder.setSocketTimeout(5000);
RequestConfig requestConfig = builder.build();
httpClientBuilder.setDefaultRequestConfig(requestConfig);
List<Header> headers = new ArrayList<>();
headers.add(new BasicHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.16 Safari/537.36"));
headers.add(new BasicHeader("Accept-Encoding", "gzip,deflate"));
headers.add(new BasicHeader("Accept-Language", "zh-CN"));
headers.add(new BasicHeader("Connection", "Keep-Alive"));
httpClientBuilder.setDefaultHeaders(headers);
HttpClient httpClient = httpClientBuilder.build();
// httpClient連接配置,底層是配置RequestConfig
HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
// 連接超時
clientHttpRequestFactory.setConnectTimeout(5000);
// 數據讀取超時時間,即SocketTimeout
clientHttpRequestFactory.setReadTimeout(5000);
// 連接不夠用的等待時間,不宜過長,必須設置,比如連接不夠用時,時間過長將是災難性的
clientHttpRequestFactory.setConnectionRequestTimeout(200);
// 緩衝請求數據,默認值是true。通過POST或者PUT大量發送數據時,建議將此屬性更改為false,以免耗盡內存。
clientHttpRequestFactory.setBufferRequestBody(false);
// 添加內容轉換器
List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
messageConverters.add(initStringHttpMessageConverter());
messageConverters.add(new FormHttpMessageConverter());
messageConverters.add(new MappingJackson2XmlHttpMessageConverter());
messageConverters.add(new MappingJackson2HttpMessageConverter());
RestTemplate restTemplate = new RestTemplate(messageConverters);
restTemplate.setRequestFactory(clientHttpRequestFactory);
restTemplate.setErrorHandler(new DefaultResponseErrorHandler());
return restTemplate;
}
示例14: init
import org.springframework.http.converter.FormHttpMessageConverter; //導入依賴的package包/類
@PostConstruct
public void init() {
restTemplate = new RestTemplate();
SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
rf.setReadTimeout(portalConfig.readTimeout());
rf.setConnectTimeout(portalConfig.connectTimeout());
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setSupportedMediaTypes(
Arrays.asList(MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM));
restTemplate.setMessageConverters(Arrays.asList(converter, new FormHttpMessageConverter()));
}
示例15: createRestTemplate
import org.springframework.http.converter.FormHttpMessageConverter; //導入依賴的package包/類
private static RestTemplate createRestTemplate(ClientHttpRequestFactory requestFactory) {
// Request converter
final FormHttpMessageConverter requestConverter = new FormHttpMessageConverter();
requestConverter.setCharset(SMS_URL_CHARSET);
// Response converter
final StringHttpMessageConverter responseConverter = new StringHttpMessageConverter(SMS_URL_CHARSET);
final RestTemplate restTemplate = new RestTemplate(Arrays.asList(requestConverter, responseConverter));
restTemplate.setRequestFactory(requestFactory);
return restTemplate;
}