使用Camel实现CXF Web服务

时间:2016-04-26 11:11:23

标签: apache-camel

我正在尝试使用Camel CXF组件公开Code First Web服务。通过汇总一些可用的例子,我得出以下路线定义:

@WebService(serviceName="customerService")
public interface CustomerService 
{
    public String getCustomerById(String customerId);

}

public class CustomerServiceImpl implements CustomerService
{


    @Override
    public String getCustomerById(String customerId)
    {
         System.out.println("Called with "+customerId);
        return "Hello " +customerId;
    }
}

我正在使用的SEI和实现类是微不足道的:

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

运行项目时,Web服务正确调用实现类,返回String“Hello [name]”,但SOAPUI返回的主体为空:

sprintf

你能帮我在Response中产生返回值吗? 谢谢

1 个答案:

答案 0 :(得分:1)

您应该返回一条SOAP消息:

        SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
        SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();

        QName payloadName = new QName("http://apache.org/hello_world_soap_http/types", "greetMeResponse", "ns1");

        SOAPBodyElement payload = body.addBodyElement(payloadName);

        SOAPElement message = payload.addChildElement("responseType");

        message.addTextNode("Your custom message");
        return soapMessage;

您还可以查看驼峰文档示例:http://camel.apache.org/cxf-example.html