我正在尝试对我的骆驼路线进行单元测试,并且在成功调用路由后从测试代码获取404,这意味着我无法从测试中读取响应,总是抛出404找不到
这是我的测试代码
@EnableAutoConfiguration exclude
我的路线定义如下
final Exchange send = template.send("cxfrs://http://localhost:9001/v1/core/handshake", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.setPattern(ExchangePattern.OutOnly);
Message inMessage = exchange.getIn();
// setupDestinationURL(inMessage);
final String uuid = UUID.randomUUID().toString().replace("-", "");
System.out.println("uuid = " + uuid);
final GenerateTestHeaders headerGenerator = new GenerateTestHeaders();
final Map<String, Object> outboundHeaderMap = headerGenerator.getOutboundHeaderMap(API_KEY, ACCESS_ID, PRIVATE_ACCESS_KEY, "utf-8", "POST", "2016-08-31T10:40:55.979-0400", uuid);
// set a customer header
inMessage.setHeaders(outboundHeaderMap);
// using the http central client API
inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.TRUE);
inMessage.setHeader("HOST", "localhost:9001");
// set the Http method
inMessage.setHeader(Exchange.HTTP_METHOD, "POST");
// set the operation name
inMessage.setHeader(CxfConstants.OPERATION_NAME, "handshake");
inMessage.setHeader(Exchange.ACCEPT_CONTENT_TYPE, "application/json");
// set the relative path
// inMessage.setHeader(Exchange.HTTP_PATH, "/IMP/v1/core/handshake");
// Specify the response class , cxfrs will use InputStream as the response object type
inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, HandshakeResponse.class);
// since we use the Get method, so we don't need to set the message body
inMessage.setBody(null);
}
});
因此我的路由被调用,日志记录拦截器记录200个有效负载的成功,但是当返回生成器模板时,它有404异常。
知道我做错了吗?。
答案 0 :(得分:0)
在进一步的调试实现它必须与Jetty Server在内部处理的方式有关。所以与Camel Apache Samples进行了交叉比较。修改它并且玩了一下,长话短的主要区别在于POM
我认为失败的原因是POM中的依赖关系。
<!-- http client tests -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-http</artifactId>
<scope>test</scope>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jetty</artifactId>
<version>${camel-version}</version>
<!-- use the same version as your Camel core version-->
</dependency>
<!-- Test Dependencies -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core-xml</artifactId>
<scope>test</scope>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test</artifactId>
<version>${camel-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring</artifactId>
<version>${camel-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-rm</artifactId>
<version>${cxf-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<scope>test</scope>
<version>4.5.2</version>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymockclassextension</artifactId>
<scope>test</scope>
<version>3.2</version>
</dependency>
我添加了这些并开始工作了。我必须看看哪一个 那个魔术,现在好了。