「Kintone ⇒ Javaアプリ ⇒ Kintone REST API」のようにJavaアプリ内から
Kintone REST APIを呼び出すプログラムを実装しており(SDK未使用)、
実装したプログラムの動作確認を行ったところ、
ローカル実行(spring bootの内蔵tomcat)ではKintone REST APIの「レコードの一括取得(records.json)」を
実行し、想定した値が取得できているのですが、jarに固めてコマンドプロンプトから
「java -jar {jarのパス}」で起動後に実行するとエラーが返って来てしまいました。
デバッグやログ出力で原因を探してみましたが、
原因を突き詰めることができませんでした。
実装、またはjarの起動方法等に問題があるでしょうか?
下記、詳細です。
【エラー】
ステータス: 400
コード: CB_IJ01
メッセージ: 不正なJSON文字列です。
【リクエストJSON】
{
“app”: {アプリID},
“query”: “コード="code001" and ステータス="承認済" order by $id asc limit 500 offset 0”,
“totalCount”: “true”
}
【実装】
{
// URL
URL url = new URL(“https://{ドメイン}.cybozu.com/k/v1/records.json”);
// オブジェクト生成(HTTPリクエスト用)
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setAllowUserInteraction(false);
connection.setDoOutput(true);
// リクエストヘッダ
connection.setRequestMethod(“POST”);
connection.setRequestProperty(“X-Cybozu-API-Token”, {トークン});
connection.setRequestProperty(“Content-Type”, “application/json”);
connection.setRequestProperty(“X-HTTP-Method-Override”, “GET”);
// リクエストボディ
OutputStreamWriter body = new OutputStreamWriter(connection.getOutputStream());
body.write({リクエストJSON});
body.flush();
body.close();
connection.connect();
// ステータス取得
int status = connection.getResponseCode();
// 失敗した場合
if (status != 200) {
return null;
}
// レスポンス取得
InputStream inputStream = connection.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, “UTF-8”);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String readLine;
StringBuffer str = new StringBuffer();
while ((readLine = bufferedReader.readLine()) != null) {
str.append(readLine);
}
bufferedReader.close();
inputStreamReader.close();
inputStream.close();
String jsonStr = str.toString();
return jsonStr;
}
※補足です。
リクエストJSONの「“query”: “コード="code001" and ステータス="承認済" order by $id asc limit 500 offset 0”,」が
「“query”: “test="test" order by $id asc limit 500 offset 0”,」だとうまく実行できます。
全角文字が入ることが原因?