首页 文章

从camel cxf组件向客户端发送响应

提问于
浏览
2

我是骆驼的新手,我正在尝试使用camel cxf组件来创建一个soap webservice . 我从骆驼的样本开始 . 我使用cxf组件配置了一个路由,并添加了一个处理器来处理请求 . 我收到了用于处理服务的bean中的请求,但我无法将响应发送回客户端 . 提前致谢

这是我使用的路线:

<route>
<from uri="cxf:bean:orderEndpoint" />
<setExchangePattern pattern="InOut"/>
<to uri="bean:productService" />
</route>

这是我配置的cxf endpoints ,

<cxf:cxfEndpoint id="orderEndpoint"
                   address="/"
                   serviceClass="camelws.ws.ProductService"/>

这是我使用的bean:

@Service("productService")
public class ProductServiceImpl {
    public Product getProducts(){
        System.out.println("Inside webservices method....");
        Product product = new Product();
        product.setName("test product");
        product.setPrice("3242");
        return product;
    }

}

Sysout语句打印在控制台上,但我得到一个空体的肥皂响应 .

下面是我从浏览器点击http://localhost:9080/ /时的回复:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body/>
</soap:Envelope>

2 回答

  • 2

    您应该使用以下内容实现Processor,拦截并处理您的消息:

    public class MyProcessor implements Processor {
      public void process(Exchange exchange) throws Exception {
        ...
        // Set your response here
        exchange.getOut().setBody(product);
      }
    }
    

    然后在您的路线中引用您的处理器 .

  • 0

    您的回复就是在您的死记硬币结束后您的路线体内的响应,因此您必须在路线结束前创建您的massege响应对象 .

相关问题