Merge pull request #7858 from AndriiLandiak/feature/rest-api-node
Rest API Call node - Add ability to remove quotes from Body
This commit is contained in:
commit
eb9cd79c7e
@ -35,7 +35,6 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory;
|
||||
import org.springframework.http.client.Netty4ClientHttpRequestFactory;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.util.concurrent.ListenableFutureCallback;
|
||||
import org.springframework.web.client.AsyncRestTemplate;
|
||||
@ -49,6 +48,7 @@ import org.thingsboard.rule.engine.api.util.TbNodeUtils;
|
||||
import org.thingsboard.rule.engine.credentials.BasicCredentials;
|
||||
import org.thingsboard.rule.engine.credentials.ClientCredentials;
|
||||
import org.thingsboard.rule.engine.credentials.CredentialsType;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
import org.thingsboard.server.common.msg.TbMsg;
|
||||
import org.thingsboard.server.common.msg.TbMsgMetaData;
|
||||
|
||||
@ -192,7 +192,7 @@ public class TbHttpClient {
|
||||
config.isIgnoreRequestBody()) {
|
||||
entity = new HttpEntity<>(headers);
|
||||
} else {
|
||||
entity = new HttpEntity<>(msg.getData(), headers);
|
||||
entity = new HttpEntity<>(getData(msg), headers);
|
||||
}
|
||||
|
||||
URI uri = buildEncodedUri(endpointUrl);
|
||||
@ -243,6 +243,18 @@ public class TbHttpClient {
|
||||
return uri;
|
||||
}
|
||||
|
||||
private String getData(TbMsg msg) {
|
||||
String data = msg.getData();
|
||||
|
||||
if (config.isTrimDoubleQuotes()) {
|
||||
final String dataBefore = data;
|
||||
data = data.replaceAll("^\"|\"$", "");;
|
||||
log.trace("Trimming double quotes. Before trim: [{}], after trim: [{}]", dataBefore, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private TbMsg processResponse(TbContext ctx, TbMsg origMsg, ResponseEntity<String> response) {
|
||||
TbMsgMetaData metaData = origMsg.getMetaData();
|
||||
metaData.putValue(STATUS, response.getStatusCode().name());
|
||||
|
||||
@ -37,8 +37,7 @@ public class TbRestApiCallNodeConfiguration implements NodeConfiguration<TbRestA
|
||||
private int readTimeoutMs;
|
||||
private int maxParallelRequestsCount;
|
||||
private boolean useRedisQueueForMsgPersistence;
|
||||
private boolean trimQueue;
|
||||
private int maxQueueSize;
|
||||
private boolean trimDoubleQuotes;
|
||||
private boolean enableProxy;
|
||||
private boolean useSystemProxyProperties;
|
||||
private String proxyHost;
|
||||
@ -59,7 +58,7 @@ public class TbRestApiCallNodeConfiguration implements NodeConfiguration<TbRestA
|
||||
configuration.setReadTimeoutMs(0);
|
||||
configuration.setMaxParallelRequestsCount(0);
|
||||
configuration.setUseRedisQueueForMsgPersistence(false);
|
||||
configuration.setTrimQueue(false);
|
||||
configuration.setTrimDoubleQuotes(false);
|
||||
configuration.setEnableProxy(false);
|
||||
configuration.setCredentials(new AnonymousCredentials());
|
||||
configuration.setIgnoreRequestBody(false);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user