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.ResponseEntity;
|
||||||
import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory;
|
import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory;
|
||||||
import org.springframework.http.client.Netty4ClientHttpRequestFactory;
|
import org.springframework.http.client.Netty4ClientHttpRequestFactory;
|
||||||
import org.thingsboard.server.common.data.StringUtils;
|
|
||||||
import org.springframework.util.concurrent.ListenableFuture;
|
import org.springframework.util.concurrent.ListenableFuture;
|
||||||
import org.springframework.util.concurrent.ListenableFutureCallback;
|
import org.springframework.util.concurrent.ListenableFutureCallback;
|
||||||
import org.springframework.web.client.AsyncRestTemplate;
|
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.BasicCredentials;
|
||||||
import org.thingsboard.rule.engine.credentials.ClientCredentials;
|
import org.thingsboard.rule.engine.credentials.ClientCredentials;
|
||||||
import org.thingsboard.rule.engine.credentials.CredentialsType;
|
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.TbMsg;
|
||||||
import org.thingsboard.server.common.msg.TbMsgMetaData;
|
import org.thingsboard.server.common.msg.TbMsgMetaData;
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ public class TbHttpClient {
|
|||||||
config.isIgnoreRequestBody()) {
|
config.isIgnoreRequestBody()) {
|
||||||
entity = new HttpEntity<>(headers);
|
entity = new HttpEntity<>(headers);
|
||||||
} else {
|
} else {
|
||||||
entity = new HttpEntity<>(msg.getData(), headers);
|
entity = new HttpEntity<>(getData(msg), headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
URI uri = buildEncodedUri(endpointUrl);
|
URI uri = buildEncodedUri(endpointUrl);
|
||||||
@ -243,6 +243,18 @@ public class TbHttpClient {
|
|||||||
return uri;
|
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) {
|
private TbMsg processResponse(TbContext ctx, TbMsg origMsg, ResponseEntity<String> response) {
|
||||||
TbMsgMetaData metaData = origMsg.getMetaData();
|
TbMsgMetaData metaData = origMsg.getMetaData();
|
||||||
metaData.putValue(STATUS, response.getStatusCode().name());
|
metaData.putValue(STATUS, response.getStatusCode().name());
|
||||||
|
|||||||
@ -37,8 +37,7 @@ public class TbRestApiCallNodeConfiguration implements NodeConfiguration<TbRestA
|
|||||||
private int readTimeoutMs;
|
private int readTimeoutMs;
|
||||||
private int maxParallelRequestsCount;
|
private int maxParallelRequestsCount;
|
||||||
private boolean useRedisQueueForMsgPersistence;
|
private boolean useRedisQueueForMsgPersistence;
|
||||||
private boolean trimQueue;
|
private boolean trimDoubleQuotes;
|
||||||
private int maxQueueSize;
|
|
||||||
private boolean enableProxy;
|
private boolean enableProxy;
|
||||||
private boolean useSystemProxyProperties;
|
private boolean useSystemProxyProperties;
|
||||||
private String proxyHost;
|
private String proxyHost;
|
||||||
@ -59,7 +58,7 @@ public class TbRestApiCallNodeConfiguration implements NodeConfiguration<TbRestA
|
|||||||
configuration.setReadTimeoutMs(0);
|
configuration.setReadTimeoutMs(0);
|
||||||
configuration.setMaxParallelRequestsCount(0);
|
configuration.setMaxParallelRequestsCount(0);
|
||||||
configuration.setUseRedisQueueForMsgPersistence(false);
|
configuration.setUseRedisQueueForMsgPersistence(false);
|
||||||
configuration.setTrimQueue(false);
|
configuration.setTrimDoubleQuotes(false);
|
||||||
configuration.setEnableProxy(false);
|
configuration.setEnableProxy(false);
|
||||||
configuration.setCredentials(new AnonymousCredentials());
|
configuration.setCredentials(new AnonymousCredentials());
|
||||||
configuration.setIgnoreRequestBody(false);
|
configuration.setIgnoreRequestBody(false);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user