moved CXF/Jersey config to common
This commit is contained in:
parent
5564513134
commit
41b7ee255a
@ -4,31 +4,31 @@ import java.net.URI;
|
|||||||
|
|
||||||
import javax.ws.rs.client.ClientRequestFilter;
|
import javax.ws.rs.client.ClientRequestFilter;
|
||||||
|
|
||||||
public abstract class ClientConfiguration {
|
public interface ClientConfiguration {
|
||||||
|
|
||||||
public abstract String getBaseUrl();
|
String getBaseUrl();
|
||||||
|
|
||||||
public abstract String getBasicAuthUsername();
|
String getBasicAuthUsername();
|
||||||
|
|
||||||
public abstract String getBasicAuthPassword();
|
String getBasicAuthPassword();
|
||||||
|
|
||||||
public abstract String getAccessToken();
|
String getAccessToken();
|
||||||
|
|
||||||
public abstract String getOAuthTokenUrl();
|
String getOAuthTokenUrl();
|
||||||
|
|
||||||
public abstract String getOAuthClientId();
|
String getOAuthClientId();
|
||||||
|
|
||||||
public abstract String getOAuthClientSecret();
|
String getOAuthClientSecret();
|
||||||
|
|
||||||
public abstract String getOAuthAuthCode();
|
String getOAuthAuthCode();
|
||||||
|
|
||||||
public abstract String getOAuthAuthRedirectUri();
|
String getOAuthAuthRedirectUri();
|
||||||
|
|
||||||
public abstract String getOAuthUsername();
|
String getOAuthUsername();
|
||||||
|
|
||||||
public abstract String getOAuthPassword();
|
String getOAuthPassword();
|
||||||
|
|
||||||
public ClientRequestFilter getAuthorizationFilter() {
|
default ClientRequestFilter getAuthorizationFilter() {
|
||||||
if (this.getAccessToken() != null) {
|
if (this.getAccessToken() != null) {
|
||||||
return new AccessTokenRequestFilter(this.getAccessToken());
|
return new AccessTokenRequestFilter(this.getAccessToken());
|
||||||
} else if (this.getOAuthTokenUrl() != null) {
|
} else if (this.getOAuthTokenUrl() != null) {
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.inteligr8.rs;
|
||||||
|
|
||||||
|
public interface ClientCxfConfiguration extends ClientConfiguration {
|
||||||
|
|
||||||
|
default boolean isDefaultBusEnabled() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -6,6 +6,7 @@ import java.util.List;
|
|||||||
import javax.ws.rs.client.ClientRequestFilter;
|
import javax.ws.rs.client.ClientRequestFilter;
|
||||||
import javax.ws.rs.ext.RuntimeDelegate;
|
import javax.ws.rs.ext.RuntimeDelegate;
|
||||||
|
|
||||||
|
import org.apache.cxf.BusFactory;
|
||||||
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
|
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
|
||||||
import org.apache.cxf.jaxrs.client.WebClient;
|
import org.apache.cxf.jaxrs.client.WebClient;
|
||||||
import org.apache.cxf.jaxrs.impl.RuntimeDelegateImpl;
|
import org.apache.cxf.jaxrs.impl.RuntimeDelegateImpl;
|
||||||
@ -22,6 +23,9 @@ public abstract class ClientCxfImpl extends Client implements InitializingBean {
|
|||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(ClientCxfImpl.class);
|
private final Logger logger = LoggerFactory.getLogger(ClientCxfImpl.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected abstract ClientCxfConfiguration getConfig();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet() {
|
||||||
if (RuntimeDelegate.getInstance() == null) {
|
if (RuntimeDelegate.getInstance() == null) {
|
||||||
@ -49,6 +53,14 @@ public abstract class ClientCxfImpl extends Client implements InitializingBean {
|
|||||||
// we can't use JAXRSClientFactory with a JAXRS client (duh!)
|
// we can't use JAXRSClientFactory with a JAXRS client (duh!)
|
||||||
// so we need to create a CXF client
|
// so we need to create a CXF client
|
||||||
WebClient client = WebClient.create(this.getConfig().getBaseUrl(), providersAndFilters);
|
WebClient client = WebClient.create(this.getConfig().getBaseUrl(), providersAndFilters);
|
||||||
|
|
||||||
|
if (!this.getConfig().isDefaultBusEnabled()) {
|
||||||
|
// Some applications (like ACS) add interceptors to the default bus
|
||||||
|
// those interceptors may treat all messages as SOAP messages (like ACS), resulting in ClassCastExceptions
|
||||||
|
// we need to ignore the default bus
|
||||||
|
org.apache.cxf.jaxrs.client.ClientConfiguration config = WebClient.getConfig(client);
|
||||||
|
config.setBus(BusFactory.newInstance().createBus());
|
||||||
|
}
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.inteligr8.rs;
|
||||||
|
|
||||||
|
public interface ClientJerseyConfiguration extends ClientConfiguration {
|
||||||
|
|
||||||
|
default boolean isPutBodyRequired() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -16,6 +16,9 @@ public abstract class ClientJerseyImpl extends Client implements InitializingBea
|
|||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(ClientJerseyImpl.class);
|
private final Logger logger = LoggerFactory.getLogger(ClientJerseyImpl.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected abstract ClientJerseyConfiguration getConfig();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet() {
|
||||||
if (RuntimeDelegate.getInstance() == null) {
|
if (RuntimeDelegate.getInstance() == null) {
|
||||||
@ -34,9 +37,14 @@ public abstract class ClientJerseyImpl extends Client implements InitializingBea
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public javax.ws.rs.client.Client getClient() {
|
public javax.ws.rs.client.Client getClient() {
|
||||||
return super.getClient()
|
javax.ws.rs.client.Client client = super.getClient();
|
||||||
// allow PUT operations without body data
|
|
||||||
.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
|
if (!this.getConfig().isPutBodyRequired()) {
|
||||||
|
// allow PUT operations without body data
|
||||||
|
client.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user