resttemplate

Is RestTemplate thread safe?

匿名 (未验证) 提交于 2019-12-03 02:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is a Spring RestTemplate thread-safe? That is Is a RestTemplate a Strategy object that multiple connections can safely share. or Is a RestTemplate a connection object (like a data-base connection), which can not be shared while in use, and requires creation afresh, or pooling, for each connection. 回答1: RestTemplate is thread safe (emphasis added): Conceptually, it is very similar to the JdbcTemplate , JmsTemplate , and the various other templates found in the Spring Framework and other portfolio projects. This means, for instance, that the

Spring RestTemplate postForObject with Header: webservice can't find my header parameters

匿名 (未验证) 提交于 2019-12-03 02:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm struggling with RestTemplate. I need to POST some authentication information to a rest webservice. I can send a request and I get a response. But according to the response my header parameters are not getting through. (Sending the same request with SOAPUI works fine) This is my code: HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); headers.add("companyId", companyId); headers.add("password", password); HttpEntity<String> request = new HttpEntity<String>(headers); RestTemplate

How to mock RestTemplet with MockRestServiceServer?

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: @RunWith(MockitoJUnitRunner.class) public class FeatureFlipperManagerTest { @Autowired RestTemplate restTemplate = new RestTemplate(); @Autowired Service service = new Service(); MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate); @Test public void test() throws Exception { mockServer.expect(requestTo(Mockito.anyString())) .andRespond(withSuccess("{\"enabled\":true}", MediaType.APPLICATION_JSON)); boolean res = service.isEnabled("xxx"); mockServer.verify(); Assert.assertEquals(true, res); } } I have

RestTemplate + Jackson

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to use Spring's RestTemplate plus Jackson to consume a WebService. I have followed several tutorials and have come to the point of creating the DAOs. This is the method where I get all of my domain objects: // Create a Rest template RestTemplate restTemplate = new RestTemplate(); // Create a list for the message converters List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>(); // Add the Jackson Message converter messageConverters.add(new MappingJacksonHttpMessageConverter()); // Add the message

Spring RestTemplate with Jackson as HttpMessageConverter and joda DateTime property fails to deserialize

匿名 (未验证) 提交于 2019-12-03 02:16:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: The scenario is as follows. I have an ObjectMapper (Jackson 2) that registers a JodaModule, capable of serializing and de-serializing Joda DateTime type. This ObjectMapper is tested with custom JSON strings and works as expected. ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new JodaModule()); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); objectMapper.setTimeZone(TimeZone.getTimeZone("GMT+1:00")); objectMapper.setDateFormat(new ISO8601DateFormat()); objectMapper.enable

Spring RestTemplate - Overriding ResponseErrorHandler

匿名 (未验证) 提交于 2019-12-03 02:15:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am calling Restservice through RestTemplate and trying to override ResponseErrorHandler in Spring 3.2 to handle custom error codes. CustomResponseErrroHandler public class MyResponseErrorHandler implements ResponseErrorHandler { @Override public boolean hasError(ClientHttpResponse response) throws IOException { boolean hasError = false; int rawStatusCode = response.getRawStatusCode(); if (rawStatusCode != 200){ hasError = true; } return hasError; } @Override public void handleError(ClientHttpResponse response) throws IOException { //String

How to disable SSL certificate checking with Spring RestTemplate?

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to write an integration test where our test launches an embedded HTTPS server using Simple . I created a self-signed certificate using keytool and am able to access the server using a browser (specifically Chrome, and I do get a warning about the self-signed certificate). However, when I try to connect using Spring RestTemplate , I get a ResourceAccessException : org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://localhost:8088":sun.security.validator.ValidatorException: PKIX path

Spring RestTemplate invoking webservice with errors and analyze status code

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I designed a webservice to perform a task if request parameters are OK, or return 401 Unauthorized HTTP status code if request parameters are wrong or empty. I'm using RestTemplate to perform a test and I'm able to verify the HTTP 200 OK status if the webservice replies with success. I am however unable to test for HTTP 401 error because RestTemplate itself throws an exception. My test method is @Test public void testUnauthorized() { Map<String, Object> params = new HashMap<String, Object>(); ResponseEntity response = restTemplate

How to set proxy on spring oauth2 OAuth2AccessToken request or How to override OAuth2AccessTokenSupport restTemplate variable?

匿名 (未验证) 提交于 2019-12-03 02:01:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have tried to set network proxy in the following ways, but none of the method is working 1: set jvm variables like -Dhttp.proxyHost= -Dhttp.proxyPort= ....... 2: Created the Bean. @Bean public RestTemplate restTemplate() { final String proxyHost = "######"; // host final int proxyPort = ####; // port SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); factory.setProxy(new Proxy(Type.HTTP, new InetSocketAddress(proxyHost, proxyPort))); return new RestTemplate(factory); } But this configuration is overridden by

Spring RestTemplate Behavior when handling responses with a status of NO_CONTENT

匿名 (未验证) 提交于 2019-12-03 01:55:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Okay, I have a class NamedSystems, that has as its only field a Set of NamedSystem. I have a method to find NamedSystems by certain criteria. That's not really important. When it gets results, everything works fine. However, when it can't find anything, and thus returns a null (or empty -- I've tried both ways) set, I get problems. Let me explain. I'm using the Spring RestTemplate class and I'm making a call like this in a unit test: ResponseEntity> responseEntity = template.exchange(BASE_SERVICE_URL + "? alias={aliasValue}&aliasAuthority=