<?xml version="1.0" encoding="UTF-8"?>
<!--
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->

<!-- START SNIPPET: e1 -->
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xmlns:cxf="http://camel.apache.org/schema/cxf"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.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"/>

  <!-- spring property placeholder, ignore resource not found as the file resource is for unit testing -->
  <context:property-placeholder location="classpath:incident.properties,file:target/custom.properties"
                                ignore-resource-not-found="true"/>

  <!-- Use a bean to start and stop the real web service (is not Camel specific) -->
  <!-- In a real use-case the real web service would be probably located on another server
       but we simulate this in the same JVM -->
  <bean id="realWebService" class="org.apache.camel.example.cxf.proxy.RealWebServiceBean"
        init-method="start" destroy-method="stop">
    <!-- url of the real web service we have proxied -->
    <property name="url" value="http://localhost:${real.port}/real-webservice"/>
  </bean>

  <!-- bean that enriches the SOAP request -->
  <bean id="enrichBean" class="org.apache.camel.example.cxf.proxy.EnrichBean"/>

  <!-- this is the CXF web service we use as the front end -->
  <cxf:cxfEndpoint id="reportIncident"
                   address="http://localhost:${proxy.port}/camel-example-cxf-proxy/webservices/incident"
                   endpointName="s:ReportIncidentEndpoint"
                   serviceName="s:ReportIncidentEndpointService"
                   wsdlURL="etc/report_incident.wsdl"
                   xmlns:s="http://reportincident.example.camel.apache.org"/>

  <!-- this is the Camel route which proxies the real web service and forwards SOAP requests to it -->
  <camelContext xmlns="http://camel.apache.org/schema/spring">

    <!-- property which contains port number -->
    <propertyPlaceholder id="properties" location="classpath:incident.properties,file:target/custom.properties"/>

    <endpoint id="callRealWebService" uri="http://localhost:${real.port}/real-webservice?throwExceptionOnFailure=false"/>

    <route>
      <!-- CXF consumer using MESSAGE format -->
      <from uri="cxf:bean:reportIncident?dataFormat=MESSAGE"/>
      <!-- log input received -->
      <to uri="log:input"/>
      <!-- enrich the input by ensure the incidentId parameter is set -->
      <to uri="bean:enrichBean"/>
      <!-- send proxied request to real web service -->
      <to ref="callRealWebService"/>
      <!-- log answer from real web service -->
      <to uri="log:output"/>
    </route>

  </camelContext>

</beans>
<!-- END SNIPPET: e1 -->
