From ed5de9afc876a4206a93169417e36c31077e2919 Mon Sep 17 00:00:00 2001 From: cxxxr Date: Wed, 22 May 2024 12:31:40 +0900 Subject: [PATCH] =?UTF-8?q?accept-language=E3=82=92=E3=83=97=E3=83=AD?= =?UTF-8?q?=E3=83=91=E3=83=86=E3=82=A3=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=81=A7=E6=8C=87=E5=AE=9A=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/jp/pokepay/partnerapi/Config.java | 2 ++ src/main/java/jp/pokepay/partnerapi/HttpClient.java | 4 ++-- src/main/java/jp/pokepay/partnerapi/PartnerAPI.java | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/jp/pokepay/partnerapi/Config.java b/src/main/java/jp/pokepay/partnerapi/Config.java index 9b41796..6281397 100644 --- a/src/main/java/jp/pokepay/partnerapi/Config.java +++ b/src/main/java/jp/pokepay/partnerapi/Config.java @@ -9,6 +9,7 @@ class Config { public String baseUrl; public String p12File; public String p12Password; + public String acceptLanguage; public Config(File file) throws ConfigFileNotFoundException, ProcessingError { Properties properties = new Properties(); @@ -29,5 +30,6 @@ public Config(File file) throws ConfigFileNotFoundException, ProcessingError { this.baseUrl = properties.getProperty("API_BASE_URL"); this.p12File = file.toPath().getParent().resolve(properties.getProperty("PKCS12_FILE")).toString(); this.p12Password = properties.getProperty("PKCS12_PASSWORD"); + this.acceptLanguage = properties.getProperty("ACCEPT-LANGUAGE", "jp"); } } diff --git a/src/main/java/jp/pokepay/partnerapi/HttpClient.java b/src/main/java/jp/pokepay/partnerapi/HttpClient.java index 285df9c..68ffed0 100644 --- a/src/main/java/jp/pokepay/partnerapi/HttpClient.java +++ b/src/main/java/jp/pokepay/partnerapi/HttpClient.java @@ -128,7 +128,7 @@ public Response get(String path, String body) throws ProcessingError, Connection } } - public Response post(String path, String body) throws ProcessingError, ConnectionError { + public Response post(String path, String body, String acceptLanguage) throws ProcessingError, ConnectionError { URL url = ensureURL(path); try { HttpURLConnection conn = openConnection(url); @@ -137,7 +137,7 @@ public Response post(String path, String body) throws ProcessingError, Connectio conn.setRequestProperty("accept", "*/*"); if (body != null) { conn.setDoOutput(true); - conn.setRequestProperty("Accept-Language", "jp"); + conn.setRequestProperty("Accept-Language", acceptLanguage); conn.setRequestProperty("Content-Type", "application/json; charset=utf-8"); conn.setRequestProperty("Content-Length", String.valueOf(body.length())); OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream()); diff --git a/src/main/java/jp/pokepay/partnerapi/PartnerAPI.java b/src/main/java/jp/pokepay/partnerapi/PartnerAPI.java index 8568a32..41a6324 100644 --- a/src/main/java/jp/pokepay/partnerapi/PartnerAPI.java +++ b/src/main/java/jp/pokepay/partnerapi/PartnerAPI.java @@ -68,7 +68,7 @@ public String encodeRequest(Request request) throws ProcessingError { } public Response send(Request request) throws ProcessingError, ConnectionError, PartnerRequestError { - HttpClient.Response response = httpClient.post(request.path(), encodeRequest(request)); + HttpClient.Response response = httpClient.post(request.path(), encodeRequest(request), config.acceptLanguage); JsonResponse json = gson.fromJson(response.getBody(), JsonResponse.class); if (json.responseData == null) { ErrorResponse errorResponse = gson.fromJson(response.getBody(), ErrorResponse.class);