开发者

HTTP request parameters consuming: Camel SU issue

Below is the code snippet for the Http Camel SU for consuming http messages. Can you please advise what is wrong with SMSProcessor component?

I am getting: cannot cast apache.servicemix.jbi.jaxp.StringSource to apache.servicemix.jbi.jaxp.StringSource"

Binding:

<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.getParamete开发者_运维技巧r("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());
    }
}


Use the Camel type converter's, instead of Java type casting

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

Or if you want plain text then do

String text = exchange.getIn().getBody(String.class);

If you want a DOM

Document dom = exchange.getIn().getBody(Document.class);

And so on

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜