title: Exception unable to validate certificate of the target in spring MVC
body: <p>i am trying to get issue details from jira server using my username and password but i am getting an ssl error saying unable to validate certificate</p>
  
  <p>so how to validate certificate</p>
  
  <p>url: http:local/8080/frr/hello</p>
  
  <p>Getting error:</p>
  
  <blockquote>
    <p>nested exception is
    org.springframework.web.client.ResourceAccessException: I/O error on
    GET request for </p>
    
    <p>"<a href="https://jira.example.com/rest/api/2/issue/id" rel="noreferrer">https://jira.example.com/rest/api/2/issue/id</a>":</p>
    
    <p>sun.security.validator.ValidatorException: PKIX path building failed:
    sun.security.provider.certpath.SunCertPathBuilderException: unable to
    find valid certification path to requested target; nested exception is
    javax.net.ssl.SSLHandshakeException:
    sun.security.validator.ValidatorException: PKIX path building failed:
    sun.security.provider.certpath.SunCertPathBuilderException: unable to
    find valid certification path to requested target] with root cause
    sun.security.provider.certpath.SunCertPathBuilderException: unable to
    find valid certification path to requested target</p>
  </blockquote>
  
  <p>my Service.class code</p>
  
  <pre><code>@Controller
  public class Service{
  
  
      @RequestMapping("/hello")
  
  
       public String Data(ModelMap model){
  
          RestTemplate restTemplate = new RestTemplate();
  
          ResponseEntity&lt;String&gt; result = restTemplate.exchange("https://jira.example.com/rest/api/2/issue/id",  HttpMethod.GET, new HttpEntity&lt;String&gt;(createHeaders("username", "password")), String.class);
  
          model.addAttribute("message", result);
  
  
          return "helloworld";
      }
  
      RestTemplate restTemplate = new RestTemplate();
      HttpHeaders createHeaders( String username, String password ){
          HttpHeaders header =  new HttpHeaders();
          String auth = username + ":" + password;
          byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("US-ASCII")) );
          String base64Creds = "Basic " + new String( encodedAuth );
          header.add("Authorization", "Basic " + base64Creds);
          return header;
      }   
  }
  </code></pre>