19
js/common.js
19
js/common.js
@@ -5,7 +5,10 @@
|
|||||||
var common = {
|
var common = {
|
||||||
/* *********** private function begin *********** */
|
/* *********** private function begin *********** */
|
||||||
|
|
||||||
// 获取上下文中客户端请求对象
|
/**
|
||||||
|
* 获取上下文中客户端请求对象
|
||||||
|
* @param {*} ctx 上下文 【必填】
|
||||||
|
*/
|
||||||
getInputReq: function (ctx){
|
getInputReq: function (ctx){
|
||||||
if(!ctx || !ctx['input'] || !ctx['input']['request']){
|
if(!ctx || !ctx['input'] || !ctx['input']['request']){
|
||||||
return {};
|
return {};
|
||||||
@@ -13,7 +16,12 @@ var common = {
|
|||||||
return ctx['input']['request']
|
return ctx['input']['request']
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获取上下文步骤中请求接口的请求对象
|
/**
|
||||||
|
* 获取上下文步骤中请求接口的请求对象
|
||||||
|
* @param {*} ctx 上下文 【必填】
|
||||||
|
* @param {*} stepName 步骤名称 【必填】
|
||||||
|
* @param {*} requestName 请求名称 【必填】
|
||||||
|
*/
|
||||||
getStepReq: function (ctx, stepName, requestName){
|
getStepReq: function (ctx, stepName, requestName){
|
||||||
if(!ctx || !stepName || !requestName){
|
if(!ctx || !stepName || !requestName){
|
||||||
return {};
|
return {};
|
||||||
@@ -25,7 +33,12 @@ var common = {
|
|||||||
return ctx[stepName]['requests'][requestName]['request'];
|
return ctx[stepName]['requests'][requestName]['request'];
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获取上下文步骤中请求接口的响应对象
|
/**
|
||||||
|
* 获取上下文步骤中请求接口的响应对象
|
||||||
|
* @param {*} ctx 上下文 【必填】
|
||||||
|
* @param {*} stepName 步骤名称 【必填】
|
||||||
|
* @param {*} requestName 请求名称 【必填】
|
||||||
|
*/
|
||||||
getStepResp: function (ctx, stepName, requestName){
|
getStepResp: function (ctx, stepName, requestName){
|
||||||
if(!ctx || !stepName || !requestName){
|
if(!ctx || !stepName || !requestName){
|
||||||
return {};
|
return {};
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
@Component
|
@Component
|
||||||
public class ConfigLoader {
|
public class ConfigLoader {
|
||||||
@Autowired
|
@Autowired
|
||||||
public static ConfigurableApplicationContext appContext;
|
public ConfigurableApplicationContext appContext;
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigLoader.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigLoader.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -367,7 +367,7 @@ public class Pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setApplicationContext(ConfigurableApplicationContext appContext) {
|
public void setApplicationContext(ConfigurableApplicationContext appContext) {
|
||||||
this.applicationContext = applicationContext;
|
this.applicationContext = appContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigurableApplicationContext getApplicationContext() {
|
public ConfigurableApplicationContext getApplicationContext() {
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ public class RPCInput extends Input {
|
|||||||
protected static final Logger LOGGER = LoggerFactory.getLogger(RPCInput.class.getName());
|
protected static final Logger LOGGER = LoggerFactory.getLogger(RPCInput.class.getName());
|
||||||
protected static final String FALLBACK_MODE_STOP = "stop";
|
protected static final String FALLBACK_MODE_STOP = "stop";
|
||||||
protected static final String FALLBACK_MODE_CONTINUE = "continue";
|
protected static final String FALLBACK_MODE_CONTINUE = "continue";
|
||||||
|
|
||||||
protected Map<String, Object> request = new HashMap<>();
|
protected Map<String, Object> request = new HashMap<>();
|
||||||
protected Map<String, Object> response = new HashMap<>();
|
protected Map<String, Object> response = new HashMap<>();
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ public class RequestInput extends RPCInput implements IInput{
|
|||||||
private InputType type;
|
private InputType type;
|
||||||
protected Map<String, Object> dataMapping;
|
protected Map<String, Object> dataMapping;
|
||||||
|
|
||||||
|
|
||||||
private static final String CONTENT_TYPE_JSON = "application/json";
|
private static final String CONTENT_TYPE_JSON = "application/json";
|
||||||
private static final String CONTENT_TYPE_XML = "application/xml";
|
private static final String CONTENT_TYPE_XML = "application/xml";
|
||||||
private static final String CONTENT_TYPE_JS = "application/javascript";
|
private static final String CONTENT_TYPE_JS = "application/javascript";
|
||||||
@@ -68,8 +67,8 @@ public class RequestInput extends RPCInput implements IInput{
|
|||||||
private static final String CONTENT_TYPE_TEXT = "text/plain";
|
private static final String CONTENT_TYPE_TEXT = "text/plain";
|
||||||
|
|
||||||
private static final String CONTENT_TYPE = "content-type";
|
private static final String CONTENT_TYPE = "content-type";
|
||||||
|
|
||||||
|
private String respContentType;
|
||||||
|
|
||||||
public InputType getType() {
|
public InputType getType() {
|
||||||
return type;
|
return type;
|
||||||
@@ -154,10 +153,11 @@ public class RequestInput extends RPCInput implements IInput{
|
|||||||
request.put("url", uriComponents.toUriString());
|
request.put("url", uriComponents.toUriString());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doResponseMapping(InputConfig aConfig, InputContext inputContext, Object responseBody) {
|
@Override
|
||||||
|
public void doResponseMapping(InputConfig aConfig, InputContext inputContext, String responseBody) {
|
||||||
|
|
||||||
RequestInputConfig config = (RequestInputConfig) aConfig;
|
RequestInputConfig config = (RequestInputConfig) aConfig;
|
||||||
response.put("body", responseBody);
|
response.put("body", this.parseBody(this.respContentType, responseBody));
|
||||||
|
|
||||||
// 数据转换
|
// 数据转换
|
||||||
if (inputContext != null && inputContext.getStepContext() != null) {
|
if (inputContext != null && inputContext.getStepContext() != null) {
|
||||||
@@ -255,8 +255,8 @@ public class RequestInput extends RPCInput implements IInput{
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doOnResponseSuccess(ClientResponse cr, long elapsedMillis) {
|
protected void doOnResponseSuccess(RPCResponse cr, long elapsedMillis) {
|
||||||
HttpHeaders httpHeaders = cr.headers().asHttpHeaders();
|
HttpHeaders httpHeaders = (HttpHeaders) cr.getHeaders();
|
||||||
Map<String, Object> headers = new HashMap<>();
|
Map<String, Object> headers = new HashMap<>();
|
||||||
httpHeaders.forEach((key, value) -> {
|
httpHeaders.forEach((key, value) -> {
|
||||||
if (value.size() > 1) {
|
if (value.size() > 1) {
|
||||||
@@ -267,6 +267,7 @@ public class RequestInput extends RPCInput implements IInput{
|
|||||||
});
|
});
|
||||||
headers.put("elapsedTime", elapsedMillis + "ms");
|
headers.put("elapsedTime", elapsedMillis + "ms");
|
||||||
this.response.put("headers", headers);
|
this.response.put("headers", headers);
|
||||||
|
this.respContentType = httpHeaders.getFirst(CONTENT_TYPE);
|
||||||
inputContext.getStepContext().addElapsedTime(prefix + request.get("url"),
|
inputContext.getStepContext().addElapsedTime(prefix + request.get("url"),
|
||||||
elapsedMillis);
|
elapsedMillis);
|
||||||
}
|
}
|
||||||
@@ -347,5 +348,4 @@ public class RequestInput extends RPCInput implements IInput{
|
|||||||
return RequestInputConfig.class;
|
return RequestInputConfig.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user