Compare commits
3 Commits
v2.0.4-cxf
...
v2.0.5-cxf
Author | SHA1 | Date | |
---|---|---|---|
458cdad213 | |||
8b03d251e8 | |||
a1acb3f9d9 |
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.inteligr8</groupId>
|
<groupId>com.inteligr8</groupId>
|
||||||
<artifactId>common-rest-client</artifactId>
|
<artifactId>common-rest-client</artifactId>
|
||||||
<version>2.0.4-cxf</version>
|
<version>2.0.5-cxf</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>ReST API Client for Java</name>
|
<name>ReST API Client for Java</name>
|
||||||
|
@@ -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