updated CXF client to reflect the Jersey one
This commit is contained in:
@@ -14,6 +14,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.inteligr8.rs;
|
package com.inteligr8.rs;
|
||||||
|
|
||||||
|
import org.apache.cxf.jaxrs.client.WebClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface defines additional configurations specific to the Apache CXF
|
* This interface defines additional configurations specific to the Apache CXF
|
||||||
* JAX-RS library and its nuances.
|
* JAX-RS library and its nuances.
|
||||||
@@ -35,4 +37,12 @@ public interface ClientCxfConfiguration extends ClientConfiguration {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Jackson provider, logging filter, and authentication filter are already registered.
|
||||||
|
*
|
||||||
|
* @param client A CXF client to configure.
|
||||||
|
*/
|
||||||
|
default void configureClient(WebClient client) {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -29,6 +29,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
|
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,7 +44,9 @@ public class ClientCxfImpl extends Client {
|
|||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(ClientCxfImpl.class);
|
private final Logger logger = LoggerFactory.getLogger(ClientCxfImpl.class);
|
||||||
|
|
||||||
|
private final Object sync = new Object();
|
||||||
private ClientCxfConfiguration config;
|
private ClientCxfConfiguration config;
|
||||||
|
private WebClient client;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor is for Spring or POJO use.
|
* This constructor is for Spring or POJO use.
|
||||||
@@ -77,16 +81,40 @@ public class ClientCxfImpl extends Client {
|
|||||||
* @return A CXF client (not JAX-RS).
|
* @return A CXF client (not JAX-RS).
|
||||||
*/
|
*/
|
||||||
public WebClient getCxfClient() {
|
public WebClient getCxfClient() {
|
||||||
return this.getCxfClient(null);
|
synchronized (this.sync) {
|
||||||
|
if (this.client == null)
|
||||||
|
this.client = this.buildCxfClient(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param authFilter A dynamic authorization filter.
|
||||||
|
* @return A pre-configured CXF client (no URL) with the specified authorization.
|
||||||
|
*/
|
||||||
|
public WebClient getCxfClient(AuthorizationFilter authFilter) {
|
||||||
|
if (authFilter == null) {
|
||||||
|
return this.getCxfClient();
|
||||||
|
} else {
|
||||||
|
return this.buildCxfClient(authFilter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param authFilter A post-configuration authorization filter.
|
* @param authFilter A post-configuration authorization filter.
|
||||||
* @return A CXF client (not JAX-RS).
|
* @return A CXF client (not JAX-RS).
|
||||||
*/
|
*/
|
||||||
public WebClient getCxfClient(AuthorizationFilter authFilter) {
|
public WebClient buildCxfClient(AuthorizationFilter authFilter) {
|
||||||
|
ObjectMapper om = new ObjectMapper();
|
||||||
|
om.registerModules(new JavaTimeModule());
|
||||||
|
this.getConfig().configureJacksonMapper(om);
|
||||||
|
|
||||||
|
JacksonJaxbJsonProvider jacksonProvider = new JacksonJaxbJsonProvider(om, JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS);
|
||||||
|
this.getConfig().configureJacksonProvider(jacksonProvider);
|
||||||
|
|
||||||
List<Object> providersAndFilters = new LinkedList<Object>();
|
List<Object> providersAndFilters = new LinkedList<Object>();
|
||||||
providersAndFilters.add(new JacksonJaxbJsonProvider());
|
providersAndFilters.add(jacksonProvider);
|
||||||
providersAndFilters.add(new CxfLoggingFilter());
|
providersAndFilters.add(new CxfLoggingFilter());
|
||||||
providersAndFilters.add(new CxfMultipartProvider());
|
providersAndFilters.add(new CxfMultipartProvider());
|
||||||
|
|
||||||
@@ -109,6 +137,8 @@ public class ClientCxfImpl extends Client {
|
|||||||
config.setBus(BusFactory.newInstance().createBus());
|
config.setBus(BusFactory.newInstance().createBus());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.config.configureClient(client);
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user