diff --git a/README.md b/README.md
index 3c80237..3df68b3 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# Common ReST Client Library
-This project provides a library for Spring and POJO-based REST client instantiation.
+This project provides a library for Spring and POJO-based REST client instantiation. It includes special classes with classifiers for two popular JAXRS-based client frameworks: Apache CXF and Jersey.
## Usage
@@ -15,6 +15,7 @@ First, you will need to include the library in your project.
com.inteligr8common-rest-client
+ ......
...
@@ -23,4 +24,69 @@ First, you will need to include the library in your project.
```
-See the `cxf` and `jersey` branches for examples and more documentation.
+Valid `classifier` values are `cxf` or `jersey`.
+
+### Spring Framework
+
+#### Single Client
+
+If you will only be declaring a single client in your Spring context, this is easy. You will just need two things. First, inject the single client into any of your Spring beans. You may do inject it into more than one. An example is below:
+
+```java
+@Component
+public class ... {
+ @Autowired
+ @Qualifier("client.cxf") // may be optional
+ private Client client;
+}
+```
+
+Next, you need to configure that client. You can do that by providing a single implementation of the `ClientConfiguration` (or `ClientCxfConfiguration`) interface.
+
+```java
+@Configuration
+public class ... implements ClientCxfConfiguration {
+ ...
+}
+```
+
+For Jersey implementations, just use `client.jersey` and `ClientJerseyConfiguration`. If you want to provide one of each, then follow the instructions for multiple clients below.
+
+#### Multiple Clients
+
+If you will or may have multiple clients in your Spring context, there is an extra step. You will still need to define a `ClientConfiguration` for each. On top of that, you will need to create specialized implementations of each client. That special implementation will reference the configuration directly. An example is below.
+
+```java
+@Component("my.client")
+public class MyClient extends ClientCxfImpl {
+ @Autowired
+ public MyClient(MyClientConfiguration config) {
+ super(config);
+ }
+}
+```
+
+You can then inject your client(s) into your Spring beans. Like the example below:
+
+```java
+@Component
+public class ... {
+ @Autowired
+ private MyClient client;
+
+ @PostConstruct
+ public void init() {
+ MyJaxRsApi api = this.client.getApi(MyJaxRsApi.class);
+ }
+}
+
+### POJO
+
+You do not have to use the Spring framework to use these classes. You can instantiate them directly. But you wil still need to create a `ClientConfiguration` as mentioned above.
+
+```java
+MyClientConfiguration config = new MyClientConfiguration();
+...
+ClientCxfImpl client = new ClientCxfImpl(config);
+MyJaxRsApi api = client.getApi(MyJaxRsApi.class);
+```
diff --git a/pom.xml b/pom.xml
index f514d94..a8acd22 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,11 +6,11 @@
com.inteligr8common-rest-client
- 2.0-SNAPSHOT
+ 2.0-SNAPSHOT-cxfjarReST API Client for Java
- A common library for building REST API clients
+ A common library for building CXF REST API clientshttps://bitbucket.org/inteligr8/common-rest-client
@@ -45,7 +45,6 @@
5.7.25.2.14.RELEASE
- 2.353.3.2
@@ -98,10 +97,42 @@
4.5.9test
+
+
+
+ org.apache.cxf
+ cxf-rt-rs-client
+ ${cxf.version}
+
+
+ org.codehaus.mojo
+ build-helper-maven-plugin
+ 3.2.0
+
+
+ add-jaxrs-src
+ add-source
+
+
+ src/main/cxf
+
+
+
+
+ add-test-src
+ add-test-source
+
+
+ src/test/cxf
+
+
+
+
+ maven-surefire-plugin3.0.0-M5
diff --git a/src/main/cxf/com/inteligr8/rs/ClientCxfConfiguration.java b/src/main/cxf/com/inteligr8/rs/ClientCxfConfiguration.java
new file mode 100644
index 0000000..b354593
--- /dev/null
+++ b/src/main/cxf/com/inteligr8/rs/ClientCxfConfiguration.java
@@ -0,0 +1,38 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see .
+ */
+package com.inteligr8.rs;
+
+/**
+ * This interface defines additional configurations specific to the Apache CXF
+ * JAX-RS library and its nuances.
+ *
+ * @author brian@inteligr8.com
+ */
+public interface ClientCxfConfiguration extends ClientConfiguration {
+
+ /**
+ * Apache CXF uses a global bus configuration where interceptors could
+ * wreck havoc on your implementation. This method allows you to
+ * explicitly by-pass the default bus.
+ *
+ * See https://cxf.apache.org/docs/bus-configuration.html.
+ *
+ * @return true to use the default bus; false otherwise.
+ */
+ default boolean isDefaultBusEnabled() {
+ return true;
+ }
+
+}
diff --git a/src/main/cxf/com/inteligr8/rs/ClientCxfImpl.java b/src/main/cxf/com/inteligr8/rs/ClientCxfImpl.java
new file mode 100644
index 0000000..ae8583b
--- /dev/null
+++ b/src/main/cxf/com/inteligr8/rs/ClientCxfImpl.java
@@ -0,0 +1,142 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see .
+ */
+package com.inteligr8.rs;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+import javax.ws.rs.ext.RuntimeDelegate;
+
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.jaxrs.impl.RuntimeDelegateImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
+
+/**
+ * A class that provides pre-configured JAX-RS Client & WebTarget &
+ * CXF WebClient objects.
+ *
+ * @author brian@inteligr8.com
+ */
+@Component("client.cxf")
+public class ClientCxfImpl extends Client {
+
+ private final Logger logger = LoggerFactory.getLogger(ClientCxfImpl.class);
+
+ private ClientCxfConfiguration config;
+
+ /**
+ * This constructor is for Spring or POJO use.
+ * @param config The client configuration.
+ */
+ @Autowired
+ public ClientCxfImpl(ClientCxfConfiguration config) {
+ this.config = config;
+ }
+
+ /**
+ * This method registers the Apache CXF library as the default provider for
+ * the JAX-RS specification.
+ */
+ @PostConstruct
+ public void register() {
+ if (RuntimeDelegate.getInstance() == null) {
+ this.logger.info("Setting JAX-RS runtime delegate to the CXF library");
+ RuntimeDelegate.setInstance(new RuntimeDelegateImpl());
+ } else if (RuntimeDelegate.getInstance() instanceof RuntimeDelegateImpl) {
+ this.logger.info("JAX-RS runtime delegate already the CXF library");
+ } else {
+ this.logger.warn("Setting JAX-RS runtime delegate to the CXF library; was: " + RuntimeDelegate.getInstance().getClass().getName());
+ RuntimeDelegate.setInstance(new RuntimeDelegateImpl());
+ }
+
+ if (this.logger.isInfoEnabled())
+ this.logger.info("API Base URL: " + this.getConfig().getBaseUrl());
+ }
+
+ /**
+ * @return A CXF client (not JAX-RS).
+ */
+ public WebClient getCxfClient() {
+ return this.getCxfClient(null);
+ }
+
+ /**
+ * @param authFilter A post-configuration authorization filter.
+ * @return A CXF client (not JAX-RS).
+ */
+ public WebClient getCxfClient(AuthorizationFilter authFilter) {
+ List