以下是用于使用http消息的Http Camel SU的代码片段。你能告诉我SMSProcessor
组件有什么问题吗?
我得到:cannot cast apache.servicemix.jbi.jaxp.StringSource to apache.servicemix.jbi.jaxp.StringSource"
结合:
<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;
}
}
SMSProcessor:
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());
}
}
答案 0 :(得分:1)
使用Camel类型转换器,而不是Java类型转换
StringSource text = exchange.getIn()。getBody(StringSource.class);
或者如果你想要纯文本,那么
String text = exchange.getIn()。getBody(String.class);
如果你想要一个DOM
Document dom = exchange.getIn()。getBody(Document.class);
等等