[[camel-integration]]
= Camel Quarkus Integration

It is fairly trivial to integrate Quarkus CXF services with https://camel.apache.org/camel-quarkus/2.7.x/index.html[Camel Quarkus] via https://camel.apache.org/camel-quarkus/2.7.x/user-guide/cdi.html[CDI integration].

There are no specific dependencies required for this integration other than the Camel Quarkus dependencies you will already have for your project.

Some sample Camel Quarkus dependencies are provided below.

[source,xml]
----
    <dependency>
        <groupId>org.apache.camel.quarkus</groupId>
        <artifactId>camel-quarkus-log</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.camel.quarkus</groupId>
        <artifactId>camel-quarkus-timer</artifactId>
    </dependency>
----

[[web-service-integration]]
== Web Service Integration

To invoke a Camel route from your `@WebService` or `@WebServiceProvider` class, you can implement it as shown in the example below.

Given a Camel `GreetingRoute` class defined as:

[source,java]
----
import org.apache.camel.builder.RouteBuilder;

import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class GreetingRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        fromF("direct:greeting")
                .setBody(exchange -> "Hello from Camel, " + exchange.getMessage().getBody(String.class))
                .to("log:greeting");
    }
}

----

Your web service can invoke the `GreetingRoute` as shown below.

[source,java]
----
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;

import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.ws.BindingType;

@WebService(endpointInterface = "org.acme.cdi.greeting.GreetingWebService", serviceName = "GreetingWebService")
@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
public class GreetingWebServiceImpl implements GreetingWebService {

    /**
     * Injects the Camel ProducerTemplate
     */
    @Produce("direct:greeting")
    ProducerTemplate producerTemplate;

    @Override
    public String ping(@WebParam(name = "text") String text) throws GreetingException {
        /**
         * Invokes the Camel "direct:greeting" endpoint defined in the
         * GreetingRoute
         */
        String response = producerTemplate.requestBody((Object) text, String.class);
        return response;
    }

}
----

NOTE: There are various other ways to inject and invoke a Camel route endpoint from your web service, that are covered https://camel.apache.org/camel-quarkus/2.7.x/user-guide/cdi.html#_endpointinject_and_produce[here].

[[client-integration]]
== Client Integration

To call a `@CXFClient` SOAP web service from your Camel route, you can implement it as shown in the example below.

[source,java]
----
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import io.quarkiverse.cxf.annotation.CXFClient;
import org.apache.camel.builder.RouteBuilder;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.tempuri.CalculatorSoap;

@ApplicationScoped
public class TimerRoute extends RouteBuilder {

    /**
     * {@code timer.period} is defined in {@code src/main/resources/application.properties}
     */
    @ConfigProperty(name = "timer.period", defaultValue = "1000")
    String period;

    /**
     * An injected bean
     */
    @Inject
    Counter counter;

    /**
    * An injected web service client
    */
    @Inject
    @CXFClient
    CalculatorSoap calculatorSoap;

    @Override
    public void configure() throws Exception {
        fromF("timer:foo?period=%s", period)
                .setProperty("counter", () -> counter.increment())
                .setBody(exchange ->
                        calculatorSoap.multiply(exchange.getProperty("counter", Integer.class),8))
                .to("log:example");
    }
}
----

NOTE: A similar injection pattern can be used in your Camel `Processor` https://camel.apache.org/manual/processor.html[implementation classes].