2020年3月26日 星期四

Jenkins curl 出現 unable to get local issuer certificate

平常在跑的排程因為SSL簽章過期更新後出現unable to get local issuer certificate這樣的錯誤訊息 參考這篇blog無法解決,不過也是個研究方向,應急不行。

這篇 curl 略過檢查自簽 SSL 憑證有效性 就不錯用了,加上-k 或 --insecure 去重跑排程就不會再報錯!! 當然一般寫code加上CURLOPT_SSL_VERIFYPEER去排除狀態,不過這是透過Shell Script來執行的初次碰到就註記下。


#!/bin/sh
system=('www1' 'www2' 'www3')
for i in "${system[@]}"
do
   curl -k --request GET 'https://'$i'.domain.net/method.php'
done


<?php
$url = "https://www1.domain.net/method.php/";
$post_data['var'] = "xxx";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
$result = curl_exec($ch);
curl_close($ch);
?>

jQuery autocomplete example memo

最近用到又忘了怎麼做,在Model顯示卡了些關~寫個文章記錄下!!

//Head 需要Include的Resource
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">

//補充顯示的CSS設定
<style type="text/css">
.ui-autocomplete { 
position: absolute; 
cursor: default;
z-index:99999 !important;   //有時候(使用Model)會顯示不在最前面,故設定大些
display:block;
}  
</style>

//Body
<form action="#" role="form" method="post" id="ListForm" >  
  <input type="text" class="form-control inputFieldClass" id="inValue" name="inValue" ></input>
  <input type="hidden" id="tx_value" name="tx_value" />  
   <input type="hidden" id="tx_lable" name="tx_lable" /> 
</form>

//如果回傳是一個Class,其中一個變數才是要用的jQuery.parseJSON(data)這樣處理
<script>
$(function (){
    $(".inputFieldClass").on("focus", function(){
        $(this).autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: "API_URL", 
                    dataType: "json",
                    type: "POST",
                    data: {
                        key: request.term     
                      },
                    success: function (data) {
                    if (data.isSuccess){
                    response($.map(jQuery.parseJSON(data.jsondata), function (item) {
                            return {
                            value: item.in_value,      
                            lable: item.in_lable
                            }
                        }));
                    }
                    }
                });
            },
            minLength: 2,   //輸入多少字元觸發
            select : function(event, ui) {  
                //候選項選擇帶入
    $("#tx_value").val(ui.item.value);  
                $("#tx_lable").val(ui.item.lable);  
                return false;
            }
        });
    });
});
</script>

2020年3月6日 星期五

Maven Call SOAP sample

At pos.xml add

<dependency>
    <groupId>com.mashape.unirest</groupId>
    <artifactId>unirest-java</artifactId>
    <version>1.4.9</version>
</dependency>

At controller add method

import com.mashape.unirest.http.Unirest;

String soap_postdata = "{\"DATA1\":\"XXX\",\"DATA2\":\"XXX\"}";
HttpResponse<JsonNode> jsonResponse = Unirest.post(soap_url)
  .header("cache-control", "no-cache")
  .header("accept", "application/json")
  .body(soap_postdata)
  .asJson();
if (jsonResponse != null) {
 if (jsonResponse.getStatus() == 200) {
    JSONObject json = jsonResponse.getBody().getObject();
       if (json.has("error")) {
   //SOAP Fail. json.has error
} else {
           //do it
        }
  }
}

補充說明:
呼叫後會有一堆這類的紀錄,貌似關不掉可以透過log關閉方式排除
[Thread-46] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Closing expired connections
[Thread-46] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Closing connections idle longer than 30 SECONDS

At logback.xml add
<logger name="com.mashape.unirest" level="ERROR" />