วิธี bypass certificate https client และ Webservice client axis
เวลาเรา Call https ที่เป็น SSL จะเจอปัญหาว่า ไม่ผ่าน certificate
ได้ error ประมาณนี้
http://xml.apache.org/axis/}stackTrace: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
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1649)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:241)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:235)
ทางแก้ที่ถูกต้องคือการ trust cert ให้กับ client ของเรา
แต่ถ้าหากเราไม่อยากทำแบบนั้น คืออยกา bypass ไปเลย ก็สามารถทำได้
ถ้าเป็น webservice client ของ Axis ให้เพิ่มคำสั่งนี้
AxisProperties.setProperty("axis.socketSecureFactory","org.apache.axis.components.net.SunFakeTrustSocketFactory");
แต่ถ้าหากเป็น http client เช่นพวก REST แนะนำให้ download code จากที่นี่ครับ
http://schrepfler.blogspot.com.br/2009/06/relaxing-ssl-validation-for-jaxws.html
แล้วเพิ่ม static block ที่ code เราตามนี้
static {
SSLUtilities.trustAllHostnames();
SSLUtilities.trustAllHttpsCertificates();
}
**แต่อย่าลืมว่าการ bypass แบบนี้การรับส่งข้อมูลจะไม่ปลอดภัยนะครับ