private CertPath buildCertPath(X509Certificate endCert) throws CertificatePathBuildingException {
  CertPathBuilder cpb=null;
  try {
    cpb=CertPathBuilder.getInstance("PKIX");
  }
 catch (  NoSuchAlgorithmException e) {
    throw new CertificatePathBuildingException("Error building CertPathBuilder:" + e.getMessage(),e);
  }
  PKIXBuilderParameters params=CreatePKIXBuilderParameters(endCert);
  CertPathBuilderResult cpbResult;
  try {
    cpbResult=cpb.build(params);
  }
 catch (  CertPathBuilderException e) {
    throw new CertificatePathBuildingException(e.getMessage(),e.getCause());
  }
catch (  InvalidAlgorithmParameterException e) {
    throw new CertificatePathBuildingException(e.getMessage(),e);
  }
  CertPath cp=cpbResult.getCertPath();
  return cp;
}

private CertPath buildCertPath ( X509Certificate endCert ) throws CertificatePathBuildingException { CertPathBuilder cpb = null ; try { cpb = CertPathBuilder . getInstance ( "PKIX" ) ; } catch ( NoSuchAlgorithmException e ) { throw new CertificatePathBuildingException ( "Error building CertPathBuilder:" + e . getMessage ( ) , e ) ; } PKIXBuilderParameters params = CreatePKIXBuilderParameters ( endCert ) ; CertPathBuilderResult cpbResult ; try { cpbResult = cpb . build ( params ) ; } catch ( CertPathBuilderException e ) { throw new CertificatePathBuildingException ( e . getMessage ( ) , e . getCause ( ) ) ; } catch ( InvalidAlgorithmParameterException e ) { throw new CertificatePathBuildingException ( e . getMessage ( ) , e ) ; } CertPath cp = cpbResult . getCertPath ( ) ; return cp ; }
build and validate cert path from end certificate . note : the certpath return seems only include intermediate ca unless there is none in which case the end cert is returned .
