gpt4 book ai didi

java - HTTP请求参数消耗: Camel SU issue

转载 作者:太空宇宙 更新时间:2023-11-04 08:43:48 26 4
gpt4 key购买 nike

下面是 Http Camel SU 用于消费 http 消息的代码片段。您能否告知 SMSProcessor 组件出了什么问题?

我得到:无法将 apache.servicemix.jbi.jaxp.StringSource 转换为 apache.servicemix.jbi.jaxp.StringSource”

绑定(bind):

<beans xmlns:http="http://servicemix.apache.org/http/1.0"
xmlns:b="http://rhinopay.com/bridge">

<http:consumer service="b:http"
endpoint="endpoint"
targetService="b:pipeline"
locationURI="http://localhost:8192/rhinopay/"
defaultMep="http://www.w3.org/2004/08/wsdl/in-out"
marshaler="#myMarshaler"
/>

<bean id="myMarshaler" class="marshaller.HttpMarshaller"/>
</beans>

HttpMarshaller:

import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.NormalizedMessage;
import javax.servlet.http.HttpServletRequest;

import org.apache.servicemix.common.EndpointComponentContext;
import org.apache.servicemix.http.endpoints.DefaultHttpConsumerMarshaler;
import org.apache.servicemix.jbi.jaxp.StringSource;

public class HttpMarshaller extends DefaultHttpConsumerMarshaler {

public MessageExchange createExchange(HttpServletRequest request,
javax.jbi.component.ComponentContext context) throws Exception {
// TODO Auto-generated method stub

String mobile = request.getParameter("mobile");
String smsTxt = request.getParameter("smsTxt");
// String message = request.getParameter("msg");
MessageExchange exchange = ((EndpointComponentContext) context).getDeliveryChannel().createExchangeFactory().createExchange(getDefaultMep());
NormalizedMessage in = exchange.createMessage();
String xmlContext = mobile+","+smsTxt;
System.out.println("xmlContext---"+xmlContext);
in.setContent(new StringSource(xmlContext));
exchange.setMessage(in,"in");
return exchange;
}
}

短信处理器:

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.servicemix.jbi.jaxp.StringSource;

public class SMSProcessor implements Processor {

/*
* @see org.apache.camel.Processor#process(org.apache.camel.Exchange)
*/
public void process(Exchange exchange) throws Exception {
System.out.println("SMSProcessor");
StringSource text = ((StringSource)exchange.getIn().getBody());
System.out.println("text"+text.getText());
}
}

最佳答案

使用Camel类型转换器,而不是Java类型转换

StringSource text = Exchange.getIn().getBody(StringSource.class);

或者如果您想要纯文本,那么就这样做

字符串文本 = Exchange.getIn().getBody(String.class);

如果你想要一个 DOM

文档dom = Exchange.getIn().getBody(Document.class);

等等

关于java - HTTP请求参数消耗: Camel SU issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4749406/

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