gpt4 book ai didi

java - org.apache.camel.InvalidPayloadException:没有可用类型为java.io.InputStream的主体,但具有值:在解码绑定(bind)bean时抛出

转载 作者:行者123 更新时间:2023-12-01 18:51:07 24 4
gpt4 key购买 nike

我正在尝试进行api调用并获取有效载荷,并在将bean对象解组后丰富内容。我可以看到已经解组了bindy对象,但是在进行api调用后,它抛出了以下异常。

Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId ProcessorId Processor Elapsed (ms)
[route1 ] [route1 ] [file://inbox?fileName=3100.txt ] [ 4]
[route1 ] [unmarshal1 ] [unmarshal[org.apache.camel.model.DataFormatDefinition@6e255e77] ] [ 0]
[route1 ] [enrich1 ] [enrich[constant{direct:getUN}] ] [ 0]
[route2 ] [setHeader1 ] [setHeader[CamelHttpMethod] ] [ 0]
[route2 ] [setHeader2 ] [setHeader[Content-Type] ] [ 0]
[route2 ] [to2 ] [http://localhost:8084/get/45718 ] [ 1]

Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------

org.apache.camel.InvalidPayloadException: No body available of type: java.io.InputStream but has value: PART_INB_IFD(ctrl_seg=CTRL_SEG(TRNNAM=PART_TRAN, TRNVER=9.0, WHSE_ID=----, PART_SEG=PART_SEG(SEGNAM=PART, TRNTYP=R, PRT_CLIENT_ID=----, PRTNUM=598, HAZMAT_FLG=1, VC_TOSG_HAZ_UN_NUM=null))) of type: com.model.PART_INB_IFD on: Message[]. Caused by: No type converter available to convert from type:


ConverterRoute.java

@Override
public void addRoutesToCamelContext(CamelContext context) throws Exception {

context.addRoutes(new RouteBuilder() {
public void configure() {
try {

XmlFriendlyNameCoder nameCoder = new XmlFriendlyNameCoder("_-", "_");
Dom4JDriver dom4JDriver = new Dom4JDriver(nameCoder);

xStreamDataFormat.setAliases(Collections.singletonMap("PART_INB_IFD", PART_INB_IFD.class.getCanonicalName()));
xStreamDataFormat.setXstreamDriver(dom4JDriver);

from(SOURCE_INPUT_PATH).
log("Received input from file and body is ${body}").
split().tokenize(System.lineSeparator()).
unmarshal(bindyBeanConfig.bindyCsvDataFormat()).
enrich("direct:getUN", new MyProcessor()).
marshal(xStreamDataFormat).
log("After Marshalling and body is ${body}").
to(SOURCE_OUTPUT_PATH).log("Finished Transformation").
end();

from("direct:getUN")
.setHeader(Exchange.HTTP_METHOD,constant("GET"))
.setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
.to("http://localhost:8084/get/45718")
.log("HTTP response status: ${header.CamelHttpResponseCode}")
.log(LoggingLevel.DEBUG, "HTTP response body:\n${body}");

} catch (Exception e) {
e.printStackTrace();
}
}
});
context.suspend();
context.stop();
}


下面我实现了聚合策略。在解组newExchange api返回的有效负载后,它将获得oldExchange。

MyProcessor.java

   public class MyProcessor implements AggregationStrategy {

private static final Logger logger = LoggerFactory.getLogger(MyProcessor.class);

@Override
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {

PART_INB_IFD originalBody = oldExchange.getIn().getBody(PART_INB_IFD.class);

String resourceResponse = newExchange.getIn().getBody(String.class);

logger.info("After Unmarshalling Original Body {}", originalBody);

logger.info("ResourceResponse {}", resourceResponse);

return oldExchange;
}
}

最佳答案

我猜想Camel尝试序列化PART_INB_IFD.class类型的消息正文以将其发送到http://localhost:8084/get/45718

PART_INB_IFD.class是否实现Serializable?如果没有,这可能是您遇到问题的原因。

关于java - org.apache.camel.InvalidPayloadException:没有可用类型为java.io.InputStream的主体,但具有值:在解码绑定(bind)bean时抛出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59738409/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com