Citrus框架:graphql请求给出了400错误的请求响应

时间:2020-02-24 07:08:31

标签: citrus-framework

有人举过将graphql请求放入Citrus的示例吗?我有一个graphql请求,对我来说在Postman和JMeter中可以正常工作,但是我无法在Citrus中使用它。我已经将Postman / JMeter中的端点和设置与Citrus进行了比较。在Citrus日志中,端点显示的与我在Postman / JMeter中显示的相同。

From citrus-context.xml:
<citrus-http:client id="myRestAPIEndpoint" 
request-url="${endpoint}"
request-method="POST" 
content-type="application/graphql"
charset="UTF-8"
timeout="60000" />

From step definition:
designer.http()
        .client("myRestAPIEndpoint")
        .send()
        .post("/myrestapi")
        .payload(new ClassPathResource("citrus/payloads/graphqlRequest.txt"))
        .header("Authorization", "Bearer ${BEARER_TOKEN}");

Here's what I’ve tried in Citrus:
Within citrus-context.xml I’ve tried both content-type="application/graphql" and content-type="application/json" (Note: In Postman and JMeter I have application/graphql)
Within citrus-context I also tried adding default-accept-header="false" (don’t think this really matters, but tried it anyway)
Within step definitions I’ve tried specifying a messageType - both .messageType(MessageType.PLAINTEXT) and .messageType(MessageType.JSON)
For my actual file, tried both .json and .txt extensions (I don’t think this matters since it’s purely reading in contents of the file and it’s the same either way, but tried it anyway)

有人有想法吗?

1 个答案:

答案 0 :(得分:0)

我们知道了。在Postman中,它的代码链接为橙色(在Params,Auth,Headers,Body ...的右侧)。这将打开一个“生成代码段”窗口。如果单击Java代码段,它将显示一些Java生成的代码示例。它基本上在其开头添加了一个{\“ query \”:,然后将我的graphql请求作为查询的对值放在后面。更新此内容后,我的Citrus请求正常运行。 :)