Total Pageviews

2016/08/30

[Travel] Osaka (大阪)

Osaka Castle 大阪城





大阪歷史博物館







大阪 道頓崛








2016/08/09

[Git] Frequently Used Command

1. how to show file change list?
 
 
 
 
 
 
 
 
 
albert@albert-PC MINGW64 /d/git/issue-webapp (master)
$ git status
On branch master
Your branch is behind 'origin/master' by 6 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   src/app/journal/journal.list.component.ts
        modified:   src/app/journal/journal.list.html


2. How to create a branch from master? (given your branch name after -b)

albert@albert-PC MINGW64 /d/git/issue-webapp (master)
$ git checkout -b fix#165468
       src/app/journal/journal.list.component.ts
       src/app/journal/journal.list.html
Switched to a new branch 'fix#165468'


3. How to discard changes? (assign the file path after git checkout)

albert@albert-PC MINGW64 /d/git/issue-webapp (fix#165468)
$ git checkout  src/app/journal/journal.list.component.ts


4. How to change from my local branch to master?


albert@albert-PC MINGW64 /d/git/issue-webapp (fix#165468)
$ git checkout master


5. How to add all changed files and commit to local? (remember to add comments as you do commit)
albert@albert-PC MINGW64 /d/git/issue-webapp (fix#165468)
$ git add --all

albert@albert-PC MINGW64 /d/git/issue-webapp (fix#165468)
$ git commit -m 'fix #165468'
[fix#165468 dbec729] fix #165468
 2 files changed, 25 insertions(+), 5 deletions(-)


6. How to push commits made on your local branch to a remote repository? (assign your branch name after origin)
 albert@albert-PC MINGW64 /d/git/issue-webapp (fix#165468)
$ git push origin fix#165468


7. How to synchronize my local repository with remote repository?
albert@albert-PC MINGW64 /d/git/issue-webapp (master)
$ git pull --rebase upstream master
From https://github.com/ChunghwaTelecom/issue-webapp
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> upstream/master
First, rewinding head to replay your work on top of it...
Fast-forwarded master to b393bd26111dbe2335bf1fb5d9cf3cb110c278ca.


8. How to list values of all configuration? 

albert@albert-PC MINGW64 /d/git/issue-webapp (master)
$ git config --list
core.symlinks=false
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
rebase.autosquash=true


9. 
How to configure remote.upstream.url to https://gitlab.com/ChunghwaTelecom/rakr-chrome-extension.git ?
albert@albert-PC MINGW64 /d/git/issue-webapp (master)
$ git config remote.upstream.url https://gitlab.com/ChunghwaTelecom/rakr-chrome-extension.git



2016/08/08

How to send SMS via 三竹簡訊

Requirement
Our web application has SMS (short message service) requirement. Our customer asks to send short message by 三竹簡訊.

Based on its documentation, it provide 8 ways to send short message, and we choose approach 4th.


Here has an diagram to describe 三竹資訊's architecture:


We will use Http Get method to send user name, password, phone number and short message to SmGateway:


And it will return response to your source code:


The status code and its description are as follows:



How-to
Here has the sample code.
This enumeration contains the status code and its description:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package albert.practice.sms;

import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
public enum SmsStatusCodeEnum {

    STATUS_STAR("*", "系統發生錯誤,請聯絡三竹資訊窗口人員"),
    STATUS_a("a", "簡訊發送功能暫時停止服務,請稍候再試"),
    STATUS_b("b", "簡訊發送功能暫時停止服務,請稍候再試"),
    STATUS_c("c", "請輸入帳號"),
    STATUS_d("d", "請輸入密碼"),
    STATUS_e("e", "帳號、密碼錯誤"),
    STATUS_f("f", "帳號已過期"),
    STATUS_h("h", "帳號已被停用"),
    STATUS_k("k", "無效的連線位址"),
    STATUS_m("m", "必須變更密碼,在變更密碼前,無法使用簡訊發送服務"),
    STATUS_n("n", "密碼已逾期,在變更密碼前,將無法使用簡訊發送服務"),
    STATUS_p("p", "沒有權限使用外部Http程式"),
    STATUS_r("r", "系統暫停服務,請稍後再試"),
    STATUS_s("s", "帳務處理失敗,無法發送簡訊"),
    STATUS_t("t", "簡訊已過期"),
    STATUS_u("u", "簡訊內容不得為空白"),
    STATUS_v("v", "無效的手機號碼"),
    STATUS_0("0", "預約傳送中"),
    STATUS_1("1", "已送達業者"),
    STATUS_2("2", "已送達業者"),
    STATUS_3("3", "已送達業者"),
    STATUS_4("4", "已送達手機"),
    STATUS_5("5", "內容有錯誤"),
    STATUS_6("6", "門號有錯誤"),
    STATUS_7("7", "簡訊已停用"),
    STATUS_8("8", "逾時無送達"),
    STATUS_9("9", "預約已取消");

    @Getter
    private String code;

    @Getter
    private String description;

}

This utility class is used to send short message:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package albert.practice.sms;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.List;

import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang.StringUtils;

import com.google.common.collect.Lists;

/**
 * username = 使用者帳號。SmGateway資料庫表格SMUser中需有此使用者,且狀態為啟用。 <br>
 * password = 使用者密碼 <br>
 * dstaddr = 受訊方手機號碼 <br>
 * DestName = 收訊人名稱。若其他系統需要與簡訊資料進行系統整合,此欄位可填入來源系統所產生的Key值,以對應回來源資料庫 <br>
 * dlvtime = 簡訊預約時間。格式為YYYY-MM-DD HH:NN:SS或YYYYMMDDHHNNSS,或是整數值代表幾秒後傳送。<br>
 * vldtime = 簡訊有效期限。格式為YYYY-MM-DD HH:NN:SS或YYYYMMDDHHNNSS,或是整數值代表傳送後幾秒後內有效。 <br>
 * smbody = 簡訊內容。必須為BIG-5編碼,長度70個中文字或是160個英數字。若有換行的需求,請填入ASCII Code 6代表換行。 <br>
 */
@Slf4j
public class SmsUtils {

    private final static String USER_AGENT = "Mozilla/5.0";

    private final String SMS_URL = "http://xxx/SmSendGet.asp?";
    private final String USER_NAME = "Test001";
    private final String PASSWORD = "TestPwd";

    public static void main(String[] args) throws Exception {
        String phone = "09";
        String smBody = "您的網路申請驗證碼為○○○○○○,僅限會員申請使用,請於收到簡訊10分鐘內完成驗證。";
        new SmsUtils().sendSms(phone, smBody);
    }

    public void sendSms(String phoneNumber, String body) throws Exception {
        body = URLEncoder.encode(body, "Big5");
        sendGet(phoneNumber, body);
    }

    private void sendGet(String phoneNumber, String body) throws IOException {

        StringBuilder url = new StringBuilder();
        url.append(SMS_URL);
        url.append("username=").append(USER_NAME);
        url.append("&password=").append(PASSWORD);
        url.append("&dstaddr=").append(phoneNumber);
        url.append("&smbody=").append(body);

        URL obj = null;
        BufferedReader bufferedReader = null;
        try {
            obj = new URL(url.toString());
            HttpURLConnection con = (HttpURLConnection) obj.openConnection();

            // optional default is GET
            con.setRequestMethod("GET");

            // add request header
            con.setRequestProperty("User-Agent", USER_AGENT);

            int responseCode = con.getResponseCode();

            log.debug("\nSending 'GET' request to URL : " + url);
            log.debug("Response Code : " + responseCode);

            bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String inputLine = "";
            StringBuffer response = new StringBuffer();

            while ((inputLine = bufferedReader.readLine()) != null) {
                response.append(inputLine);
            }

            // print result
            String responseStr = response.toString();
            log.debug(responseStr);

            int from = responseStr.indexOf("statuscode=");
            int to = responseStr.indexOf("AccountPoint=");
            String tmpStr = StringUtils.substring(responseStr, from, to);

            // 取得status code
            String statusCode = StringUtils.substring(tmpStr, tmpStr.length() - 1, tmpStr.length());
            log.info("statusCode = " + statusCode);

            // 將status code 轉成 中文訊息
            String executionResult = getDescription(statusCode);
            log.info("executionResult = " + executionResult);

            List<String> successList = Lists.newArrayList("0", "1", "2", "3", "4"); // 成功的SATUSCODE
            if (!successList.contains(statusCode)) {
                throw new RuntimeException(executionResult);
            }

        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (bufferedReader != null) {
                bufferedReader.close();
            }
        }
    }

    /**
     * 將status code 轉成 中文訊息
     * 
     * @param statusCode
     * @return 中文訊息
     */
    private String getDescription(String statusCode) {
        String description = "";
        for (SmsStatusCodeEnum smsStatusCode : SmsStatusCodeEnum.values()) {
            if (smsStatusCode.getCode().equals(statusCode)) {
                description = smsStatusCode.getDescription();
            }
        }
        return description;
    }
}









2016/08/07

[Visual Studio Code] How to Change Visual Studio Code Display Language

Problem
After I installed Visual Studio Code, its display language show Transitional Chinese. How do I change it to English?


How-To
Step1. Press F1


Step2. type config in Command Palette and choose Configure Language


Step3. Update locale from zh-tw to en-US




Step4. restart Visual Studio Code



Reference
[1] https://code.visualstudio.com/docs/customization/locales

2016/08/06

[Websphere] WTRN0006W: Transaction has timed out after 120 seconds

Problem
I am deploying WAR in WAS 7. 
I got this error message as I do test:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
[2016-05-16 15:28:23][INFO][Non-deferrable Alarm : 1][Line:1709][com.ibm.ws.tx.jta.TimeoutManager.logToJSR47Logger]WTRN0006W: Transaction 00000154B8756C5F00000003618D9380FB564FCFE7EE45F38E06607A9BFB0CE57778367B00000154B8756C5F00000003618D9380FB564FCFE7EE45F38E06607A9BFB0CE57778367B00000001 has timed out after 120 seconds.
[2016-05-16 15:28:23][INFO][Non-deferrable Alarm : 1][Line:1709][com.ibm.ws.tx.jta.TimeoutManager.logToJSR47Logger]WTRN0124I: When the timeout occurred the thread with which the transaction is, or was most recently, associated was Thread[SimpleAsyncTaskExecutor-1,5,main]. The stack trace of this thread when the timeout occurred was: 
 java.io.RandomAccessFile.readBytes(Native Method)
 java.io.RandomAccessFile.read(RandomAccessFile.java:368)
 org.apache.fontbox.ttf.BufferedRandomAccessFile.fillBuffer(BufferedRandomAccessFile.java:122)
 org.apache.fontbox.ttf.BufferedRandomAccessFile.read(BufferedRandomAccessFile.java:160)
 org.apache.fontbox.ttf.RAFDataStream.read(RAFDataStream.java:162)
 org.apache.fontbox.ttf.TTFDataStream.read(TTFDataStream.java:263)
 org.apache.fontbox.ttf.TTFDataStream.readString(TTFDataStream.java:91)
 org.apache.fontbox.ttf.TTFDataStream.readString(TTFDataStream.java:64)
 org.apache.fontbox.ttf.TTFParser.readTableDirectory(TTFParser.java:232)
 org.apache.fontbox.ttf.TTFParser.parse(TTFParser.java:139)
 org.apache.fontbox.ttf.TTFParser.parse(TTFParser.java:87)
 org.apache.pdfbox.pdmodel.font.FileSystemFontProvider.addTrueTypeFont(FileSystemFontProvider.java:502)
 org.apache.pdfbox.pdmodel.font.FileSystemFontProvider.scanFonts(FileSystemFontProvider.java:246)
 org.apache.pdfbox.pdmodel.font.FileSystemFontProvider.<init>(FileSystemFontProvider.java:225)
 org.apache.pdfbox.pdmodel.font.FontMapperImpl$DefaultFontProvider.<clinit>(FontMapperImpl.java:132)
 java.lang.J9VMInternals.initializeImpl(Native Method)
 java.lang.J9VMInternals.initialize(J9VMInternals.java:236)
 org.apache.pdfbox.pdmodel.font.FontMapperImpl.getProvider(FontMapperImpl.java:151)
 org.apache.pdfbox.pdmodel.font.FontMapperImpl.findFont(FontMapperImpl.java:415)
 org.apache.pdfbox.pdmodel.font.FontMapperImpl.findFontBoxFont(FontMapperImpl.java:378)
 org.apache.pdfbox.pdmodel.font.FontMapperImpl.getFontBoxFont(FontMapperImpl.java:352)
 org.apache.pdfbox.pdmodel.font.PDType1Font.<init>(PDType1Font.java:115)
 org.apache.pdfbox.pdmodel.font.PDType1Font.<clinit>(PDType1Font.java:76)
 java.lang.J9VMInternals.initializeImpl(Native Method)
 java.lang.J9VMInternals.initialize(J9VMInternals.java:236)
 org.apache.pdfbox.pdmodel.font.PDFontFactory.createFont(PDFontFactory.java:62)
 org.apache.pdfbox.pdmodel.PDResources.getFont(PDResources.java:123)
 org.apache.pdfbox.contentstream.operator.text.SetFontAndSize.process(SetFontAndSize.java:60)
 org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:815)
 org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:472)
 org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:446)
 org.apache.pdfbox.contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:149)
 org.apache.pdfbox.rendering.PageDrawer.drawPage(PageDrawer.java:189)
 org.apache.pdfbox.rendering.PDFRenderer.renderPage(PDFRenderer.java:208)
 org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:139)
 org.apache.pdfbox.rendering.PDFRenderer.renderImageWithDPI(PDFRenderer.java:94)


How To
Here has a workaround approach, but you need to figure out the reason why your program had spent just a long time to execute. If your program really need more time to execute, you should log into WAS administration console to modify the value of Total transaction lifetime timeout and Maximum transaction timeout.

The configuration steps are as follows:

  • Step1. Log in to administration console
  • Step2. WebSphere Application Server 7.0: Click Servers > Server Types > WebSphere application servers > server_name > Container Services > Transaction Service.
  • Step3. Increase the Total transaction lifetime timeout. The default value is 120.
  • Step4. Increase the Maximum transaction timeout. The default value is 300 seconds.



  • Step5. Save your changes and restart WAS


Reference
[1] https://stackoverflow.com/questions/23004900/how-to-resolve-this-timeout-exception-in-was-7