Rdebu opened a new issue #62:
URL: https://github.com/apache/apisix-java-plugin-runner/issues/62
### Issue description
My current requirement is: I want to update the filter in
Apisix-java-plugin-runner when Apisix is not down
【我现在的需求是:想在apisix不停机的时候更新apisix-java-plugin-runner中的filter】
### Environment
apisix2.7 apisix-java-plugin-runner0.1
* your apisix-java-plugin-runner version
At present, I can obtain the token created for the first time on the runner
side during the test run, so as to replace Cache<token, A6Conf> and Map<String,
PluginFilter> in A6ConfigHandler with my filter. In the final test, some of
the requests go through the updated filter. You said in the QQ group that the
update on the runner side is not supported, may I ask how to solve it?
【目前我能在runner测运行的时候获取到runner侧第一次创建的token,从而将自己的filter替换A6ConfigHandler中的Cache<token,
A6Conf>与Map<String,
PluginFilter>。最后测试的时候,有些请求是经过我们更新的filter,有些请求却经过原先的filter,还有可能会得到”503 Service
Temporarily Unavailable”。您在QQ群里说在runner侧更新不支持,那请问如何解决呢。】
Configured routes:
【配置的路由:】
`{
"uri": "/get",
"name": "TokenValidator",
"desc": "TokenValidator",
"methods": [
"GET"
],
"plugins": {
"ext-plugin-pre-req": {
"conf": [
{
"name": "TokenValidator",
"value":
"{\"validate_header\":\"token\",\"validate_url\":\"vU\",\"rejected_code\":\"444\"}"
}
]
}
},
"upstream": {
"nodes": [
{
"host": "httpbin.org",
"port": 80,
"weight": 1
}
],
"type": "roundrobin",
"hash_on": "vars",
"scheme": "http",
"pass_host": "pass"
},
"labels": {
"API_VERSION": "V1"
},
"status": 1
}`
Test the curl:
【测试的curl:】
curl -H 'token: 123456' 127.0.0.1:9080/get -i
The original filter: (note: this will return true and false, subsequent
filter changes will only return false)
【原先的filter:(注意:此时会进行判断返回true与false,后续更改的filter只会返回false)】
`package org.apache.apisix.plugin.runner.filter;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.apache.apisix.plugin.runner.HttpRequest;
import org.apache.apisix.plugin.runner.HttpResponse;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
import java.util.HashMap;
import java.util.Map;
@Slf4j
@Component
public class TokenValidator implements PluginFilter {
@Override
public String name() {
return "TokenValidator";
}
@Override
public Mono<Void> filter(HttpRequest request, HttpResponse response,
PluginFilterChain chain) {
// parse `conf` to json
String configStr = request.getConfig(this);
Gson gson = new Gson();
Map<String, Object> conf = new HashMap<>();
conf = gson.fromJson(configStr, conf.getClass());
// get configuration parameters
String token = request.getHeader((String) conf.get("validate_header"));
log.info("token: {}", token);
String validateUrl = (String) conf.get("validate_url");
log.info("validateUrl: {}", validateUrl);
boolean flag = validate(token, validateUrl);
log.info(
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
log.info(
"???????????????????????????????????????????????????????????????????????");
log.info(
"8888888888888888888888888****************************ssssssssss********");
// token verification results
if (!flag) {
log.info("test------------------failed");
String rejectedCode = (String) conf.get("rejected_code");
response.setStatusCode(Integer.parseInt(rejectedCode));
return chain.filter(request, response);
}
log.info("test------------------success");
return chain.filter(request, response);
}
private Boolean validate(String token, String validateUrl) {
if ("123456".equals(token) && "vU".equals(validateUrl)) {
return true;
}
return false;
}
}`
Changed filter:
【更改的filter:】
`package org.apache.apisix.plugin.runner.filter;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.apache.apisix.plugin.runner.HttpRequest;
import org.apache.apisix.plugin.runner.HttpResponse;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
import java.util.HashMap;
import java.util.Map;
@Slf4j
@Component
public class TokenValidator implements PluginFilter {
@Override
public String name() {
return "TokenValidator";
}
@Override
public Mono<Void> filter(HttpRequest request, HttpResponse response,
PluginFilterChain chain) {
// parse `conf` to json
String configStr = request.getConfig(this);
Gson gson = new Gson();
Map<String, Object> conf = new HashMap<>();
conf = gson.fromJson(configStr, conf.getClass());
// get configuration parameters
String token = request.getHeader((String) conf.get("validate_header"));
log.info("token: {}", token);
String validateUrl = (String) conf.get("validate_url");
log.info("validateUrl: {}", validateUrl);
boolean flag = validate(token, validateUrl);
log.info(
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
log.info(
"???????????????????????????????????????????????????????????????????????");
log.info(
"8888888888888888888888888****************************ssssssssss********");
// token verification results
if (!flag) {
log.info("test------------------failed");
String rejectedCode = (String) conf.get("rejected_code");
response.setStatusCode(Integer.parseInt(rejectedCode));
return chain.filter(request, response);
}
log.info("test------------------success");
return chain.filter(request, response);
}
private Boolean validate(String token, String validateUrl) {
if ("123456".equals(token) && "vU".equals(validateUrl)) {
return false;
}
return false;
}
}`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]