- publicList parseJson() {
- logger.info("===========parseJson======start");
- List list =null;
- BufferedReader is =null;
- HttpsURLConnection httpsConn =null;
- try {
- String e =this.sysConfig.getValue("YG_HR_URL");
- URL url =new URL(e);
- if(e.startsWith("https")) {
- SSLContext sb = SSLContext.getInstance("SSL");
- sb.init((KeyManager[])null,newTrustManager[]{newYgHrService.TrustAnyTrustManager()},new SecureRandom());
- httpsConn = (HttpsURLConnection)url.openConnection();
- httpsConn.setSSLSocketFactory(sb.getSocketFactory());
- httpsConn.setHostnameVerifier(new YgHrService.TrustAnyHostnameVerifier());
- httpsConn.setDoOutput(true);
- httpsConn.connect();
- is =newBufferedReader(newInputStreamReader(httpsConn.getInputStream(), "UTF-8"));
- } else {
- is =newBufferedReader(newInputStreamReader(url.openStream(), "GBK"));
- }
- StringBuffer sb1 =new StringBuffer();
- String str = "";
- while((str = is.readLine()) !=null) {
- sb1.append(str);
- }
- String src = sb1.toString().replaceAll(" ", "");
- src = src.substring(src.indexOf("([") + 1, src.length() - 1);
- list = JSONArray.parseArray(src, HrOrgDTO.class);
- } catch (Exception var17) {
- logger.error("========json转dto error", var17);
- } finally {
- if(is !=null) {
- try {
- is.close();
- } catch (Exception var16) {
- ;
- }
- }
- if(httpsConn !=null) {
- httpsConn.disconnect();
- }
- }
- logger.info("===========parseJson======end");
- return list;
- }
- public void truncateYgORGTable() {
- this.dao.truncateYgORGTable();
- }
- private static classTrustAnyHostnameVerifierimplements HostnameVerifier {
- private TrustAnyHostnameVerifier() {
- }
- public boolean verify(String hostname, SSLSession session) {
- return true;
- }
- }
- private static classTrustAnyTrustManagerimplements X509TrustManager {
- private TrustAnyTrustManager() {
- }
- public voidcheckClientTrusted(X509Certificate[] chain, String authType)throws CertificateException {
- }
- public voidcheckServerTrusted(X509Certificate[] chain, String authType)throws CertificateException {
- }
- public voidcheckClientTrusted(java.security.cert.X509Certificate[] arg0, String arg1)throws java.security.cert.CertificateException {
- }
- public voidcheckServerTrusted(java.security.cert.X509Certificate[] arg0, String arg1)throws java.security.cert.CertificateException {
- }
- public java.security.cert.X509Certificate[] getAcceptedIssuers() {
- return null;
- }
- }
来源: http://www.bubuko.com/infodetail-2141801.html