Created
September 12, 2023 09:15
-
-
Save SinTeZWh1te/41858413d883216b013467ac9f58408a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ru.test.bgbilling.modules.inet.device.test; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import org.apache.logging.log4j.LogManager; | |
import org.apache.logging.log4j.Logger; | |
import org.json.JSONObject; | |
import ru.bitel.bgbilling.apps.inet.access.sa.ServiceActivator; | |
import ru.bitel.bgbilling.apps.inet.access.sa.ServiceActivatorAdapter; | |
import ru.bitel.bgbilling.apps.inet.access.sa.ServiceActivatorEvent; | |
import ru.bitel.bgbilling.common.BGException; | |
import ru.bitel.bgbilling.modules.inet.common.bean.InetDevice; | |
import ru.bitel.bgbilling.modules.inet.common.bean.InetDeviceType; | |
import ru.bitel.bgbilling.server.util.Setup; | |
import ru.bitel.common.ParameterMap; | |
import java.net.URI; | |
import java.net.http.HttpClient; | |
import java.net.http.HttpRequest; | |
import java.net.http.HttpResponse; | |
import java.time.Duration; | |
/** | |
* @author sintezwh1te | |
*/ | |
public class TestServiceActivator | |
extends ServiceActivatorAdapter | |
implements ServiceActivator { | |
private static final Logger logger = LogManager.getLogger(); | |
@Override | |
public Object init(Setup setup, int moduleId, InetDevice device, InetDeviceType deviceType, ParameterMap config) throws Exception { | |
return null; | |
} | |
@Override | |
public Object serviceModify(ServiceActivatorEvent event) throws Exception { | |
try { | |
ObjectMapper objectMapper = new ObjectMapper(); | |
HttpRequest request = HttpRequest.newBuilder() | |
.uri(new URI("https://host:port/bgbilling/executer/json/ru.bitel.bgbilling.kernel.contract.balance/PaymentService")) | |
.headers("Content-Type", "application/json") | |
.POST(HttpRequest.BodyPublishers.ofString("{\"method\": \"paymentUpdate\", \"user\": { \"user\": \"user\", \"pswd\": \"pswd\" }, \"params\": { \"payment\": { \"id\": null, \"userId\": 0, \"contractId\": " + event.getNewInetServ().getContractId() + ", \"typeId\": 1, \"date\": \"2023-09-12\", \"comment\": \"Редактирование сервиса\", \"sum\": 100.00 }, \"distribution\": \"\"}}")) | |
.build(); | |
HttpResponse<String> response = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5L)).build().send(request, HttpResponse.BodyHandlers.ofString()); | |
if (response.statusCode() == 200) { | |
JSONObject responseJson = new JSONObject(response.body()); | |
logger.info(responseJson); | |
} | |
} catch (Exception e) { | |
logger.error(e); | |
throw new BGException(e); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment