mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
fix: Set default request body to prevent NullPointerException
This commit is contained in:
parent
0f1d760dbe
commit
5834963fdd
@ -60,8 +60,13 @@ public class HttpProcessor extends CommonBasicProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set default mediaType
|
// set default mediaType
|
||||||
if (!"GET".equals(httpParams.method) && StringUtils.isEmpty(httpParams.mediaType)) {
|
if (!"GET".equals(httpParams.method)) {
|
||||||
if (JSONValidator.from(httpParams.body).validate()) {
|
// set default request body
|
||||||
|
if (StringUtils.isEmpty(httpParams.body)) {
|
||||||
|
httpParams.body = new JSONObject().toJSONString();
|
||||||
|
omsLogger.warn("try to use default request body:{}", httpParams.body);
|
||||||
|
}
|
||||||
|
if (JSONValidator.from(httpParams.body).validate() && StringUtils.isEmpty(httpParams.mediaType)) {
|
||||||
httpParams.mediaType = "application/json";
|
httpParams.mediaType = "application/json";
|
||||||
omsLogger.warn("try to use 'application/json' as media type");
|
omsLogger.warn("try to use 'application/json' as media type");
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,25 @@ class HttpProcessorTest {
|
|||||||
|
|
||||||
System.out.println(new HttpProcessor().process(TestUtils.genTaskContext(params.toJSONString())));
|
System.out.println(new HttpProcessor().process(TestUtils.genTaskContext(params.toJSONString())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testPostDefaultJson() throws Exception {
|
||||||
|
String url = "https://mock.uutool.cn/4f5qfgcdahj0?test=true";
|
||||||
|
JSONObject params = new JSONObject();
|
||||||
|
params.put("url", url);
|
||||||
|
params.put("method", "POST");
|
||||||
|
System.out.println(new HttpProcessor().process(TestUtils.genTaskContext(params.toJSONString())));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testPostDefaultWithMediaType() throws Exception {
|
||||||
|
String url = "https://mock.uutool.cn/4f5qfgcdahj0?test=true";
|
||||||
|
JSONObject params = new JSONObject();
|
||||||
|
params.put("url", url);
|
||||||
|
params.put("method", "POST");
|
||||||
|
params.put("mediaType", "application/json");
|
||||||
|
System.out.println(new HttpProcessor().process(TestUtils.genTaskContext(params.toJSONString())));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testTimeout() throws Exception {
|
void testTimeout() throws Exception {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user