Advertisement
Guest User

Untitled

a guest
Feb 25th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. public class CustomClientHttpRequestFactory extends SimpleClientHttpRequestFactory {
  2.  
  3. @Override
  4. protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
  5. super.prepareConnection(connection, httpMethod);
  6. connection.setInstanceFollowRedirects(true);
  7. }
  8.  
  9. @Autowired
  10. CustomClientHttpRequestFactory factory;
  11. @Bean
  12. public RestTemplate getRestSvc()
  13. {
  14. RestTemplate restTemplate = new RestTemplate();
  15. restTemplate.setRequestFactory(factory);
  16. return restTemplate;
  17. }
  18.  
  19. ResponseEntity<String> entity = restTemplate.postForEntity("http://localhost:9099/login?username=usernane&password=password", request, String.class);
  20. System.out.println("Status : " + entity.getStatusCode());
  21. assertTrue(entity.getStatusCode()==HttpStatus.OK);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement