Apache Camel和Web服务

4

我正在尝试理解如何将Apache Camel与任何提供WSDL的Web服务集成,以生成其类并随后调用其方法返回一些请求。

我已经学习了一些关于camel-spring-wscamel-cxf包的知识。据我所见,Spring Web Services组件不支持使用WSDL,但CXF支持,但它仅支持连接到托管在CXF中的JAX-WS服务。

如果我从客户那里收到一个WSDL,我可以使用CXF吗?还是需要创建一个自定义组件来使用他的方法?

据我所见,实现它最简单的方法是创建一个进程或一个Bean来调用远程web服务。

我尝试实现一个生产者来调用远程Web服务。我的 beans.xml :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xmlns:cxf="http://camel.apache.org/schema/cxf"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd 
       http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd">

    <import resource="classpath:META-INF/cxf/cxf.xml"/> 

    <cxf:cxfEndpoint 
        id="osvEndpoint" 
        address="http://10.193.1.90:8767/" 
        serviceClass="siemens_hiq8000.SiemensHiq8000PortType"/> 

    <bean id="osvWebServiceProcessor" class="br.com.willianantunes.processor.OsvWebServiceProcessor" />

</beans>

我的路由

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

    <routeContext id="osvWebServiceInvoke" xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="quartz2://test?cron=0/10+*+*+*+*+?"/>
            <process ref="osvWebServiceProcessor" />
            <to uri="cxf:bean:osvEndpoint"/>
            <to uri="log:live?level=INFO" />
        </route>
    </routeContext>

</beans>

而我的处理器

public class OsvWebServiceProcessor implements Processor
{
    @Override
    public void process(Exchange exchange) throws Exception
    {
        Message inMessage = exchange.getIn();

        // The method to be called
        inMessage.setHeader(CxfConstants.OPERATION_NAME, "getVersion");

        // Parameters to be passed into the web service
        List<Object> params = new ArrayList<Object>();
        ResultCodeStructHolder resultCodeStructHolder = new ResultCodeStructHolder();
        VersionDataHolder versionDataHolder = new VersionDataHolder();
        params.add(resultCodeStructHolder);
        params.add(versionDataHolder);
        inMessage.setBody(params);
    }
}

方法getVersion需要以下参数:
public void getVersion(siemens_hiq8000.holders.ResultCodeStructHolder result, 
siemens_hiq8000.holders.VersionDataHolder versionData) throws java.rmi.RemoteException;

我该如何通过它们呢?这些持有者必须用Web服务的响应填充。运行我的项目时,我收到以下错误:

[main] INFO org.apache.cxf.service.factory.ReflectionServiceFactoryBean - Creating Service {http://siemens_hiq8000/}SiemensHiq8000PortType from class siemens_hiq8000.SiemensHiq8000PortType
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.cxf.wsdl11.WSDLEndpointFactory.createEndpointInfo(Lorg/apache/cxf/service/model/ServiceInfo;Lorg/apache/cxf/service/model/BindingInfo;Ljava/util/List;)Lorg/apache/cxf/service/model/EndpointInfo;
    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpointInfo(AbstractWSDLBasedEndpointFactory.java:287)
    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:144)
    at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:91)
    at org.apache.camel.component.cxf.CxfSpringEndpoint.createClient(CxfSpringEndpoint.java:116)
    at org.apache.camel.component.cxf.CxfProducer.doStart(CxfProducer.java:76)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
    at org.apache.camel.impl.DefaultCamelContext.startService(DefaultCamelContext.java:2869)
    at org.apache.camel.impl.DefaultCamelContext.doAddService(DefaultCamelContext.java:1097)
    at org.apache.camel.impl.DefaultCamelContext.addService(DefaultCamelContext.java:1058)
    at org.apache.camel.impl.ProducerCache.doGetProducer(ProducerCache.java:405)
    at org.apache.camel.impl.ProducerCache.acquireProducer(ProducerCache.java:123)
    at org.apache.camel.processor.SendProcessor.doStart(SendProcessor.java:219)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:74)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:59)
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:103)
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:89)
    at org.apache.camel.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:79)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:74)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:59)
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:103)
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:89)
    at org.apache.camel.processor.RedeliveryErrorHandler.doStart(RedeliveryErrorHandler.java:1272)
    at org.apache.camel.support.ChildServiceSupport.start(ChildServiceSupport.java:44)
    at org.apache.camel.support.ChildServiceSupport.start(ChildServiceSupport.java:31)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:74)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:59)
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:103)
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:89)
    at org.apache.camel.processor.interceptor.DefaultChannel.doStart(DefaultChannel.java:153)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:74)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:59)
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:103)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:61)
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:103)
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:89)
    at org.apache.camel.processor.MulticastProcessor.doStart(MulticastProcessor.java:1060)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:74)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:59)
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:103)
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:89)
    at org.apache.camel.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:79)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:74)
    at org.apache.camel.impl.RouteService.startChildService(RouteService.java:340)
    at org.apache.camel.impl.RouteService.warmUp(RouteService.java:182)
    at org.apache.camel.impl.DefaultCamelContext.doWarmUpRoutes(DefaultCamelContext.java:3090)
    at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:3020)
    at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:2797)
    at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:2653)
    at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:167)
    at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2467)
    at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2463)
    at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:2486)
    at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:2463)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
    at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:2432)
    at org.apache.camel.spring.SpringCamelContext.maybeStart(SpringCamelContext.java:255)
    at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:121)
    at org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:332)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:151)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:128)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:331)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:773)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:483)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
    at org.apache.camel.spring.Main.createDefaultApplicationContext(Main.java:216)
    at org.apache.camel.spring.Main.doStart(Main.java:156)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
    at org.apache.camel.main.MainSupport.run(MainSupport.java:150)
    at br.com.willianantunes.test.Program.main(Program.java:12)

解决方案

对于想让camel-cxf充当生产者的人,只需按照以下步骤进行操作:

  1. 首先,我下载了OpenScape Voice的最新WSDL文件here,该链接在developer page中提供。
  2. 客户端代码需要在选项serviceClass中通知SEI(服务端点接口)。您可以通过发出以下命令来生成:

wsdl2java -client -d "TargetFolderHere" -autoNameResolution "OpenScape-Voice_V8.00.28.01.wsdl"

  1. Insert the generated client classes in your project. The same applies to the WSDL file.
  2. In your beans.xml inform the cxfEndpoint configuration.

    <import resource="classpath:META-INF/cxf/cxf.xml" />    
    
    <cxf:cxfEndpoint xmlns:urn="urn:openscape-voice"
        id="osvEndpoint" 
        address="http://10.193.1.90:8767/" 
        serviceClass="voice.openscape.OpenscapeVoicePortType"
        wsdlURL="OpenScape-Voice_V8.00.28.01.wsdl"
        serviceName="urn:openscape_voice">  
    </cxf:cxfEndpoint>
    
    <bean id="osvWebServiceProcessor" class="br.com.willianantunes.processor.OsvWebServiceProcessor" />
    
  3. Before the web service call, configure a processor to inform the parameters and the method to execute.

    Message inMessage = exchange.getIn();
    
    // The method to be called
    inMessage.setHeader(CxfConstants.OPERATION_NAME, "GetVersion");
    
    // Parameters to be passed into the web service
    List<Object> params = new ArrayList<Object>();
    
    Holder<ResultCodeStruct> result = new Holder<>();
    Holder<VersionData> versionData = new Holder<>();
    
    params.add(result);
    params.add(versionData);
    inMessage.setBody(params);
    
  4. Now you can configure the route and insert in your camelContext as a ref to accomplish the task.

    <routeContext id="osvWebServiceInvoke" xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="quartz2://test?cron=0/10+*+*+*+*+?"/>
            <process ref="osvWebServiceProcessor"/>
            <to uri="cxf:bean:osvEndpoint"/>
            <to uri="log:live?level=INFO"/>
        </route>
    </routeContext>
    

而日志打印了以下内容:

- Quartz scheduler 'DefaultQuartzScheduler-main-application' initialized from an externally provided properties instance.
- Quartz scheduler version: 2.2.1
- Job Camel_main-application.test (triggerType=CronTriggerImpl, jobClass=CamelJob) is scheduled. Next fire date is Tue Mar 31 09:12:00 BRT 2015
- AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.
- StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
- Creating Service {urn:openscape-voice}openscape_voice from WSDL: OpenScape-Voice_V8.00.28.01.wsdl
- Could not find endpoint/port for {urn:openscape-voice}openscape_voicePortTypePort in wsdl. Using {urn:openscape-voice}openscape_voice.
- Route: route1 started and consuming from: Endpoint[quartz2://test?cron=0%2F10+*+*+*+*+%3F]
- Starting scheduler.
- Scheduler DefaultQuartzScheduler-main-application_$_NON_CLUSTERED started.
- Total 1 routes, of which 1 is started.
- Apache Camel 2.15.0 (CamelContext: main-application) started in 10.759 seconds
- Exchange[ExchangePattern: InOnly, BodyType: org.apache.cxf.message.MessageContentsList, Body: [null, javax.xml.ws.Holder@508696f5, javax.xml.ws.Holder@333cf1ba]]

我在使用CXF时遇到了一些依赖问题,以下是我的pom.xml文件:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-cxf</artifactId>
    <version>${camel-version}</version>
</dependency>
<!-- Apache CXF -->
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-frontend-jaxws</artifactId>
    <version>${cxf.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-frontend-jaxrs</artifactId>
    <version>${cxf.version}</version>
</dependency>   
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http</artifactId>
    <version>${cxf.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http-jetty</artifactId>
    <version>${cxf.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-bindings-soap</artifactId>
    <version>${cxf.version}</version>
</dependency>   
<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>jsr311-api</artifactId>
    <version>1.1.1</version>
</dependency>
<!-- End of Apache CXF -->

你可以设计一个新的处理器或bean来获取来自Web服务的响应体消息(而不是纯SOAP消息,而是之前使用的POJO)。@Namphibian提供的答案很好,也可以满足我的目的。
2个回答

2
你指的是Web服务的契约优先或自上而下的开发方式。在这种方法中,你从WSDL定义生成存根代码并在开发中使用这些类等。我经常这样做,并使用过来自 .Net、Java、PHP 甚至 Delphi(尽管 Delphi 违反了 WSI 合规性,请不要尝试)创建的服务的 WSDL。
CXF 可以从几乎任何你可以指向库的 WSDL 生成类。首先,你需要向 Maven POM 文件添加一个条目,告诉 Maven 为你从 WSDL 生成类。
请将以下内容添加到你的 POM 文件中:
<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>get the latest version or the version you want</version>
    <executions>
        <execution>
        <id>generate-sources</id>
        <phase>generate-sources</phase>
        <configuration>

            <sourceRoot>
            ${basedir}/target/generated/src/main/java
            </sourceRoot>
            <wsdlOptions>
                <wsdlOption>
                <wsdl>
                URI/FILE PATH OF WSDL HERE
                </wsdl>
                <extraargs>
                <extraarg>-impl</extraarg> <-- use this if you want to implement the service i.e. create it
                <extraarg>-client</extraarg> <-- us this if you want to generate a client for the service.
                </extraargs>
                </wsdlOption>
            </wsdlOptions>
        </configuration>
        <goals>
        <goal>wsdl2java</goal>
        </goals>
        </execution>
    </executions>
</plugin>

现在可以运行maven目标mvn generate-source来生成需要的桩类来使用这个文件。

通常我会进入处理器/bean来执行实际实现,因为我生产和消费的大多数 web-service 都有相当复杂的数据结构。不过这确实取决于服务。

所以简而言之,你可以使用 CXF 为几乎(Delphi 的人们你们在听吗?)所有 web-service 生成桩类,然后在处理器中使用这些生成的类来实现客户端和/或服务器。

更新:

基于您上面的示例,您走在了正确的轨道上。首先我想讨论一下在 Camel 中使用 CXF 的一个重要概念。CXF bean 和其他 bean 有点不同,例如当你看到以下代码时:

<from uri="file://....."/>
<to uri="mock"/>

文件组件是一种生产者,它生成文件;而模拟组件是一种消费者,它接收由文件组件生成的数据并用于执行其任务。
Web服务在这个概念上略有不同。例如你有一个路由如下: 被称为生产者,因为它调用了一个Web服务。当你将用作消费者或在路由的部分中使用时,它会变得更加有趣。
以下是一个Web服务消费者的示例:
<from uri="cxf:bean:someService" />

CXF Bean会消费Web服务调用,然后将消息发送到各个其他部分。这使您能够暴露非常复杂的内容,例如从FTP服务器下载文件,使用JDBC调用来丰富内容,然后针对SAP系统作为Web服务处理丰富的数据。在<from>中,您的路由将CXF Bean公开为服务,其余的路由可以进行所有集成,但它作为Web服务公开。这是一个非常强大的概念。
在您的情况下,您的Web服务Bean是生产者或客户端。通常,我不使用CXF Bean作为客户端,因为我所使用的服务可能相当复杂,我需要Java的全部功能来处理这些情况。因此,我将向您展示如何以这种方式完成任务。
因此,在我的世界中,我会按照以下Camel路线进行操作:
<routeContext id="osvWebServiceInvoke" xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="quartz2://test?cron=0/10+*+*+*+*+?"/>
        <process ref="osvWebServiceProcessor" />
        <to uri="log:live?level=INFO" />
    </route>
</routeContext>

我的处理器bean将会变成这样:
public class OsvWebServiceProcessor implements Processor
{
    @Override
    public void process(Exchange exchange) throws Exception
    {
        Message inMessage = exchange.getIn();



       /*
              SInce i dont have access to the WSDL and XSD I cant say how the following code will look but essentially you would need to call the web-service here in Java code and get the result back.

       */
      outSOAPMsg=  siemens_hiq8000.SiemensHiq8000PortType.OperationName(inSOAPMsg)
      //set the reply into the inbody and send onto other components for processing.
      inMessage.setBody(outSOAPMsg);

  }
}

看了你的代码,我发现你的存根类似乎没有正确生成。我强烈建议您将我的帖子中描述的项目添加到您的POM文件中。如果您能发布一些WSDL和XSD文件,我可以给您更详细的答案。


实际上,我的问题是关于如何在Apache Camel的上下文中编写代码来调用Web服务(使用CXF组件的生产者方法)。生成存根类对我来说没问题,但还是谢谢。 - Willian Antunes
就像我说的,使用处理器或bean。您需要向调用添加值,最简单的方法是使用处理器路线。 - Namphibian
太好了,我可以帮你解决这个问题。只需要稍微耐心一下,我要和客户开几个小时的会议。 - Namphibian
只是为了添加更多信息,我没有设置选项wsdlURL,因为我在使用自己的定制解决方案之前已经生成了存根类(通常的方式),所以我不再需要WSDL文件。现在我正在尝试使用像Apache Camel这样的集成框架向前发展。 - Willian Antunes
谢谢您的解释!我正想着您在答案中更新的内容,问题在于实现的方法,这与我通常在开发中不使用集成框架的方式相同。如果是这种情况,我可以获取WSDL文件并仅使用CXF组件。如果您想查看WSDL文件,可以在此处获取一个:http://wiki.unify.com/images/f/f9/OpenScape_Voice_V8%2C_WSDL_file.zip。 - Willian Antunes
你可能可以按照最初的想法去做,但由于涉及到SOAP调用,用JAVA代码处理会更容易一些。请记住,真正的威力在于使用CXF创建服务,即编写服务本身而不是客户端。我会花点时间研究一下,并将其放入我的博客中。我的博客上的待办事项越来越多了…… - Namphibian

1
我的主要职责之一是使用camel作为客户端消耗不同的Web服务。这是我通常使用的方法,从未遇到任何问题,每次都能完美运行。
1)在camel-config.xml文件中定义端点:
<bean id="service_name_CXFEndpoint" class="org.apache.camel.component.cxf.CxfEndpoint" />
2)在路由中使用配置文件中定义的端点进行Web服务消费: private String CXF_SERVICE_ENDPOINT = "cxf:bean:service_name_CXFEndpoint?address=wsdl_uri_location&serviceClass=service_name_from_the_stubs&loggingFeatureEnabled=true";
对于服务名称,您需要复制wsdl的内容,将其粘贴到.wsdl文件中并生成Web服务客户端。要做到这一点,您需要右键单击wsdl文件>webservices>Generate Client。然后,您需要选择JbossWS作为运行时(您必须先在首选项中设置它)。一旦存根已经生成,请查找主要服务类。然后复制其整个位置。(例如,对于名为WebServiceClass的类,位于com.test中,serviceClass=com.test.WebService.class)

3)定义消费的路由:

from("direct:web_service")
.routeId("service_name")
.bean(ServiceWSProcessor,"processRequest")
.to(CXF_SERVICE_ENDPOINT)
.bean(ServiceWSProcessor,"processResponse")
.end();

现在,您发送一个请求到该处理器,它将转到Web服务端点并给您一个响应。
4)编写一个用于请求响应的处理器(在这种情况下是serviceWS处理器)。
@Component(value="serviceWSProcessor")
public class ServiceWSProcessor {

  private static final Logger LOGGER = LoggerFactory.getLogger(ServiceWSProcessor.class);

  public void processRequest(Exchange exchange) throws Exception {

    Message in = exchange.getIn();
    Message out = exchange.getOut();

    try {

      LOGGER.info("Service - START");

      Request Request = in.getBody(Request.class);

      //This depends on your WSDL File. Test the process in SOAP UI and see how the request looks like and code
      //accordingly.

      List<Object> list = new ArrayList<Object>();
      list.add(header);
      list.add(body);
      //for this, you need to check the service for what are the parameters for that method and what response its expecting.

      out.setHeader(CxfConstants.OPERATION_NAME, "method_name");
      out.setBody(list);

    } 
    catch (Exception e) {
      e.printStackTrace();
    }

  }

  public void processResponse(Exchange exchange) throws Exception {

    Message in = exchange.getIn();
    Message out = exchange.getOut();

    try {
      Response response = null; //Code this based on what response you should set to the final body. check the message
      //contents list in debug mode to see what response you are getting.

      try {
        MessageContentsList result = (MessageContentsList) in.getBody();
        if (result != null) {
          response = (Response)result.get(0);

          out.setHeader(Constants.HEADER_SERVICE_RESPONSE_SUCCESS, Constants.SERVICE_RESPONSE_SUCCESS_Y);
        } else {
          out.setHeader(Constants.HEADER_SERVICE_RESPONSE_SUCCESS, Constants.SERVICE_RESPONSE_SUCCESS_N);
        }

      } catch (Exception e) {
        e.printStackTrace();
        out.setHeader(Constants.HEADER_SERVICE_RESPONSE_SUCCESS, Constants.SERVICE_RESPONSE_SUCCESS_N);
      }
      LOGGER.info("Service - END");
      out.setBody(response));
    } 
    catch (Exception e) {
      LOGGER.error("Service - ERROR");
      out.setBody(e.getMessage());
    } 

  }

}

要查看camel和spring-ws所需的依赖项列表,请查看此页面。

https://github.com/gauthamhs/Java/blob/master/JavaEE/Dependencies-Important-Camel-Spring.xml

如果您需要额外的帮助或有任何疑虑,请告诉我。

祝好, Gautham


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接