Java 类org.springframework.http.converter.FormHttpMessageConverter 实例源码

项目:appverse-server    文件:IntegrationWebsocketTest.java   
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;
          }
         });
}
项目:users-service    文件:EmailServiceImpl.java   
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")
    ));
}
项目:spring-rest-basis    文件:AbstractZg2proRestTemplate.java   
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));
    */
}
项目:SACS-Java    文件:AuthenticationCall.java   
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);

}
项目:scaffold    文件:WebConfig.java   
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());

    }
项目:SACS-Android    文件:AuthenticationCall.java   
@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;
}
项目:documentum-rest-client-java    文件:DCTMJacksonClient.java   
@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);
            }
        }
    }
}
项目:intermine-android    文件:RoboSpiceService.java   
@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;
}
项目:molgenis    文件:MetadataManagerControllerTest.java   
@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();
}
项目:lodms-plugins    文件:WkdSpotlightNifTagger.java   
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);
    }

}
项目:lodms-plugins    文件:WkdSpotlightTagger.java   
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();
    }
}
项目:csap-core    文件:CsapCoreService.java   
@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;
}
项目:admin-shiro    文件:RestTemplateConfig.java   
/**
 * 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;

}
项目:apollo-custom    文件:CtripMQService.java   
@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()));

}
项目:oma-riista-web    文件:LabyrinttiSMSGatewayProvider.java   
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;
}
项目:apollo    文件:CtripMQService.java   
@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()));

}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:HttpMessageConverters.java   
@SuppressWarnings("unchecked")
private List<HttpMessageConverter<?>> extractPartConverters(
        FormHttpMessageConverter formConverter) {
    Field field = ReflectionUtils.findField(FormHttpMessageConverter.class,
            "partConverters");
    ReflectionUtils.makeAccessible(field);
    return (List<HttpMessageConverter<?>>) ReflectionUtils.getField(field,
            formConverter);
}
项目:SACS-Android    文件:GenericRestPostCall.java   
@Override
protected RS doInBackground(Class<RS>... params) {
    RestTemplate restTemplate = new RestTemplate();
    ClientHttpRequestInterceptor ri = new LoggingRequestInterceptor();
    List<ClientHttpRequestInterceptor> ris = new ArrayList<ClientHttpRequestInterceptor>();
    ris.add(ri);
    restTemplate.setInterceptors(ris);


    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.add("Authorization", "Bearer " + tokenHolder.getTokenString());
    headers.add("Accept", "*/*");

    HttpEntity<RQ> requestEntity = new HttpEntity<>(request,
            headers);

    List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
    messageConverters.add(new FormHttpMessageConverter());
    messageConverters.add(new MappingJackson2HttpMessageConverter());
    restTemplate.setMessageConverters(messageConverters);
    BaseDomainResponse<RS> result = new BaseDomainResponse<>();
    RS callResult = null;
    try {
        callResult = restTemplate.postForObject(url, requestEntity, params[0]);
    } catch (HttpClientErrorException e) {
        result.setStatus(e.getStatusCode().value());
        context.setFaulty(true);
    }
    result.setResult(callResult);
    block.offer(result);
    return null;
}
项目:CCDA-Score-CARD    文件:ScorecardProcessor.java   
public ValidationResultsDto callReferenceValidator(MultipartFile ccdaFile, String validationObjective, String referenceFileName,String referenceValidatorUrl)throws Exception
{
    LinkedMultiValueMap<String, Object> requestMap = new LinkedMultiValueMap<String, Object>();
    ValidationResultsDto referenceValidatorResults = null;
    File tempFile = File.createTempFile("ccda", "File");
    FileOutputStream out = new FileOutputStream(tempFile);
    IOUtils.copy(ccdaFile.getInputStream(), out);
    requestMap.add("ccdaFile", new FileSystemResource(tempFile));

    requestMap.add("validationObjective", validationObjective);
    requestMap.add("referenceFileName", referenceFileName);

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.MULTIPART_FORM_DATA);

    HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<LinkedMultiValueMap<String, Object>>(
                                                                                requestMap, headers);
    RestTemplate restTemplate = new RestTemplate();
    FormHttpMessageConverter formConverter = new FormHttpMessageConverter();
    formConverter.setCharset(Charset.forName("UTF8"));
    restTemplate.getMessageConverters().add(formConverter);
    restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
    referenceValidatorResults = restTemplate.postForObject(referenceValidatorUrl, requestEntity, ValidationResultsDto.class);
    tempFile.delete();

    return referenceValidatorResults;
}
项目:spring-boot-concourse    文件:HttpMessageConverters.java   
@SuppressWarnings("unchecked")
private List<HttpMessageConverter<?>> extractPartConverters(
        FormHttpMessageConverter formConverter) {
    Field field = ReflectionUtils.findField(FormHttpMessageConverter.class,
            "partConverters");
    ReflectionUtils.makeAccessible(field);
    return (List<HttpMessageConverter<?>>) ReflectionUtils.getField(field,
            formConverter);
}
项目:documentum-rest-client-java    文件:DCTMJaxbClient.java   
@Override
protected void initRestTemplate(RestTemplate restTemplate) {
    super.initRestTemplate(restTemplate);
    restTemplate.setErrorHandler(new DCTMJaxbErrorHandler(restTemplate.getMessageConverters()));
    for(HttpMessageConverter<?> c : restTemplate.getMessageConverters()) {
        if(c instanceof FormHttpMessageConverter) {
            ((FormHttpMessageConverter)c).addPartConverter(new Jaxb2RootElementHttpMessageConverter());
            break;
        }
    }
}
项目:contestparser    文件:HttpMessageConverters.java   
@SuppressWarnings("unchecked")
private List<HttpMessageConverter<?>> extractPartConverters(
        FormHttpMessageConverter formConverter) {
    Field field = ReflectionUtils.findField(FormHttpMessageConverter.class,
            "partConverters");
    ReflectionUtils.makeAccessible(field);
    return (List<HttpMessageConverter<?>>) ReflectionUtils.getField(field,
            formConverter);
}
项目:ShoppingMall    文件:RestTemplate.java   
public static void init(List<HttpMessageConverter<?>> messageConverters) {
    messageConverters.add(new ByteArrayHttpMessageConverter());
    messageConverters.add(new StringHttpMessageConverter());
    messageConverters.add(new ResourceHttpMessageConverter());

    // if javax.xml.transform is not available, fall back to standard Form message converter
    if (javaxXmlTransformPresent) {
        messageConverters.add(new SourceHttpMessageConverter<Source>());
        messageConverters.add(new XmlAwareFormHttpMessageConverter());
    } else {
        messageConverters.add(new FormHttpMessageConverter());
    }

    if (simpleXmlPresent) {
        messageConverters.add(new SimpleXmlHttpMessageConverter());
    }

    if (jackson2Present) {
        messageConverters.add(new MappingJackson2HttpMessageConverter());
    } else if (jacksonPresent) {
        messageConverters.add(new MappingJacksonHttpMessageConverter());
    }

    if (romePresent) {
        messageConverters.add(new SyndFeedHttpMessageConverter());
    }
}
项目:onboard    文件:NetServiceImpl.java   
@PostConstruct
public void init() {
    restTemplate = new RestTemplate();

    restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
    restTemplate.getMessageConverters().add(new FormHttpMessageConverter());
    restTemplate.getMessageConverters().add(new ResourceHttpMessageConverter());
    requestConfig = RequestConfig.custom().setSocketTimeout(TIME_OUT).setConnectTimeout(TIME_OUT).build();
}
项目:gmm-eclipse-plugins    文件:GMMAPIRestClient.java   
/**
 * Creates an OAuth2 rest template that provides facilities to deal with OAuth2 auth.
 * @param credential The user credential.
 * @return A new OAut2 Rest Template.
 */
protected RestTemplate createOAuthTemplate(GMMCredential credential) {
    ResourceOwnerPasswordResourceDetails details = new ResourceOwnerPasswordResourceDetails();
    details.setClientId(CLIENT_ID);
    details.setClientSecret(CLIENT_SECRET);
    details.setUsername(credential.getUsername());
    details.setPassword(credential.getPassword());
    details.setAccessTokenUri(OAUTH_TOK);

    OAuth2RestTemplate template = new OAuth2RestTemplate(details);
    template.getMessageConverters().add(new FormHttpMessageConverter());
    template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());

    return template;
}
项目:spring-cloud-netflix    文件:FormBodyWrapperFilter.java   
public FormBodyWrapperFilter(FormHttpMessageConverter formHttpMessageConverter) {
    this.formHttpMessageConverter = formHttpMessageConverter;
    this.requestField = ReflectionUtils.findField(HttpServletRequestWrapper.class,
            "req", HttpServletRequest.class);
    this.servletRequestField = ReflectionUtils.findField(ServletRequestWrapper.class,
            "request", ServletRequest.class);
    Assert.notNull(this.requestField,
            "HttpServletRequestWrapper.req field not found");
    Assert.notNull(this.servletRequestField,
            "ServletRequestWrapper.request field not found");
    this.requestField.setAccessible(true);
    this.servletRequestField.setAccessible(true);
}
项目:spring-cloud-netflix    文件:ZuulProxyTestBase.java   
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    FormHttpMessageConverter converter = new FormHttpMessageConverter();
    MediaType mediaType = new MediaType("application", "x-www-form-urlencoded",
            Charset.forName("UTF-8"));
    converter.setSupportedMediaTypes(Arrays.asList(mediaType));
    converters.add(converter);
    super.configureMessageConverters(converters);
}
项目:spring-cloud-netflix    文件:NoEncodingFormHttpMessageConverter.java   
@SuppressWarnings("unchecked")
@Override
public void write(MultiValueMap<String, ?> map, MediaType contentType, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    MultiValueMap<String, String> form = (MultiValueMap<String, String>) map;
    StringBuilder builder = new StringBuilder();
    for (Iterator<String> nameIterator = form.keySet().iterator(); nameIterator.hasNext();) {
        String name = nameIterator.next();
        for (Iterator<String> valueIterator = form.get(name).iterator(); valueIterator.hasNext();) {
            String value = valueIterator.next();
            builder.append(name);
            if (value != null) {
                builder.append('=');
                builder.append(value);
                if (valueIterator.hasNext()) {
                    builder.append('&');
                }
            }
        }
        if (nameIterator.hasNext()) {
            builder.append('&');
        }
    }
    final byte[] bytes = builder.toString().getBytes(FormHttpMessageConverter.DEFAULT_CHARSET);
    outputMessage.getHeaders().setContentLength(bytes.length);
    outputMessage.getHeaders().setContentType(MediaType.APPLICATION_FORM_URLENCODED);

    StreamUtils.copy(bytes, outputMessage.getBody());
}
项目:NickNack    文件:PushOverClientImpl.java   
public PushOverClientImpl() {
    final List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
    messageConverters.add(new FormHttpMessageConverter());
    final MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
    mapper = jsonConverter.getObjectMapper();
    messageConverters.add(new MappingJackson2HttpMessageConverter());

    restTemplate = new RestTemplate();
    restTemplate.setMessageConverters(messageConverters);
}
项目:bearchoke    文件:QuotesWebSocketIntegrationTest.java   
private static void loginAndSaveXAuthToken(final String user, final String password,
                                           final HttpHeaders headersToUpdate) {

    log.info("Authenticating user before subscribing to web socket");

    String url = "http://dev.bearchoke.com:" + port + "/api/authenticate";

    try {
        new RestTemplate().execute(url, HttpMethod.POST,

                request -> {
                    MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
                    map.add("username", user);
                    map.add("password", password);
                    new FormHttpMessageConverter().write(map, MediaType.APPLICATION_FORM_URLENCODED, request);
                },

                response -> {
                    String xAuthToken = response.getHeaders().getFirst(ServerConstants.X_AUTH_TOKEN);
                    log.info("Retrieved x-auth-token: " + xAuthToken);
                    headersToUpdate.add(ServerConstants.X_AUTH_TOKEN, xAuthToken);
                    return null;
                });
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
    }
}
项目:acceptance    文件:VCSRepositoryCRUDControllerTest.java   
private ExceptionHandlerExceptionResolver createExceptionResolver() {
  ExceptionHandlerExceptionResolver exceptionResolver = new ExceptionHandlerExceptionResolver() {
    protected ServletInvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handlerMethod, Exception exception) {
      Method method = new ExceptionHandlerMethodResolver(JsonErrorHandler.class).resolveMethod(exception);
      return new ServletInvocableHandlerMethod(jsonErrorHandler, method);
    }
  };
  List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
  messageConverters.add(new FormHttpMessageConverter());
  messageConverters.add(new StringHttpMessageConverter());
  messageConverters.add(new MappingJackson2HttpMessageConverter());
  exceptionResolver.setMessageConverters(messageConverters);
  exceptionResolver.afterPropertiesSet();
  return exceptionResolver;
}
项目:acceptance    文件:CredentialCRUDControllerTest.java   
private ExceptionHandlerExceptionResolver createExceptionResolver() {
  ExceptionHandlerExceptionResolver exceptionResolver = new ExceptionHandlerExceptionResolver() {
    protected ServletInvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handlerMethod, Exception exception) {
      Method method = new ExceptionHandlerMethodResolver(JsonErrorHandler.class).resolveMethod(exception);
      return new ServletInvocableHandlerMethod(jsonErrorHandler, method);
    }
  };
  List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
  messageConverters.add(new FormHttpMessageConverter());
  messageConverters.add(new StringHttpMessageConverter());
  messageConverters.add(new MappingJackson2HttpMessageConverter());
  exceptionResolver.setMessageConverters(messageConverters);
  exceptionResolver.afterPropertiesSet();
  return exceptionResolver;
}
项目:molgenis    文件:AccountControllerTest.java   
@BeforeMethod
public void setUp() throws CaptchaException
{
    FreeMarkerViewResolver freeMarkerViewResolver = new FreeMarkerViewResolver();
    freeMarkerViewResolver.setSuffix(".ftl");
    mockMvc = MockMvcBuilders.standaloneSetup(authenticationController)
                             .setMessageConverters(new FormHttpMessageConverter(),
                                     new MolgenisGsonHttpMessageConverter(new Gson()))
                             .build();

    reset(authenticationSettings);
    reset(captchaService);
    when(captchaService.validateCaptcha("validCaptcha")).thenReturn(true);
    reset(accountService); // mocks in the config class are not resetted after each test
}
项目:molgenis    文件:CaptchaControllerTest.java   
@BeforeMethod
public void setUp()
{
    mockMvc = MockMvcBuilders.standaloneSetup(captchaController)
                             .setMessageConverters(new BufferedImageHttpMessageConverter(),
                                     new FormHttpMessageConverter(), new MolgenisGsonHttpMessageConverter(new Gson()))
                             .build();
}
项目:molgenis    文件:FairControllerTest.java   
@BeforeMethod
public void beforeTest()
{
    dataService = mock(DataService.class);
    entityModelWriter = mock(EntityModelWriter.class);
    controller = new FairController(dataService, entityModelWriter);

    mockMvc = MockMvcBuilders.standaloneSetup(controller)
                             .setMessageConverters(new FormHttpMessageConverter(), gsonHttpMessageConverter,
                                     new RdfConverter())
                             .build();
}
项目:molgenis    文件:BeaconControllerTest.java   
@BeforeMethod
private void beforeMethod()
{
    initMocks(this);

    BeaconController beaconController = new BeaconController(beaconInfoService, beaconQueryService);
    mockMvc = MockMvcBuilders.standaloneSetup(beaconController)
                             .setMessageConverters(new FormHttpMessageConverter(), gsonHttpMessageConverter)
                             .build();
}
项目:ods-lodms-plugins    文件:RestFactory.java   
public static RestTemplate getRest() {
  RestTemplate rest = new RestTemplate();
  List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
  converters.add(new Jaxb2RootElementHttpMessageConverter());
  converters.add(new FormHttpMessageConverter());
  converters.add(new MappingJacksonHttpMessageConverter());
  rest.setMessageConverters(converters);
  return rest;
}
项目:xm-uaa    文件:TwitterTemplate.java   
@Override
protected FormHttpMessageConverter getFormMessageConverter() {
    return new TwitterEscapingFormHttpMessageConverter();
}
项目:cf-java-client-sap    文件:RestUtil.java   
private FormHttpMessageConverter getFormHttpMessageConverter() {
    FormHttpMessageConverter formPartsMessageConverter = new CloudFoundryFormHttpMessageConverter();
    formPartsMessageConverter.setPartConverters(getFormPartsMessageConverters());
    return formPartsMessageConverter;
}
项目:holon-core    文件:TestRestClientSecurity.java   
@Bean
public RestTemplate restTemplate() {
    RestTemplate rt = new RestTemplate();
    rt.getMessageConverters().add(new FormHttpMessageConverter());
    return rt;
}