Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
a28fc13161 | |||
52c7e3cf6d | |||
bd7413bb48 | |||
75c518801f | |||
b3bc04467b | |||
88c8657a34 | |||
28b2478a08 | |||
dc63abc272 | |||
dd5d0f504a | |||
34d03a91e5 | |||
2584b8d668 | |||
a756b05f6c | |||
853b4e66cf | |||
f2032df0f3 | |||
8d3f4559bd | |||
3f476bba5c | |||
6292dde23b | |||
659f71c72c | |||
52f77dddbb |
7
pom.xml
7
pom.xml
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.inteligr8</groupId>
|
||||
<artifactId>common-rest-api</artifactId>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
<version>1.1.5</version>
|
||||
<name>ReST API Client for Java</name>
|
||||
|
||||
<properties>
|
||||
@@ -39,11 +39,6 @@
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
<version>2.12.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-multipart</artifactId>
|
||||
<version>${jersey.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
|
@@ -26,7 +26,7 @@ public abstract class Client {
|
||||
public final javax.ws.rs.client.Client getClient() {
|
||||
synchronized (this.sync) {
|
||||
if (this.client == null)
|
||||
this.client = this.buildClient((AuthorizationFilter)null);
|
||||
this.client = this.buildClient(null);
|
||||
}
|
||||
|
||||
return this.client;
|
||||
@@ -48,7 +48,7 @@ public abstract class Client {
|
||||
* @param authFilter A dynamic authorization filter.
|
||||
* @return A pre-configured JAX-RS client (no URL) with the specified authorization.
|
||||
*/
|
||||
public final javax.ws.rs.client.Client buildClient(AuthorizationFilter authFilter) {
|
||||
public javax.ws.rs.client.Client buildClient(AuthorizationFilter authFilter) {
|
||||
JacksonJsonProvider provider = new JacksonJaxbJsonProvider();
|
||||
|
||||
if (this.getConfig().isWrapRootValueEnabled())
|
||||
@@ -64,14 +64,9 @@ public abstract class Client {
|
||||
authFilter = this.getConfig().createAuthorizationFilter();
|
||||
if (authFilter != null)
|
||||
clientBuilder.register(authFilter);
|
||||
this.buildClient(clientBuilder);
|
||||
|
||||
return clientBuilder.build();
|
||||
}
|
||||
|
||||
public void buildClient(ClientBuilder clientBuilder) {
|
||||
// for extension purposes
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A pre-configured JAX-RS target (client w/ base URL) with configured authorization.
|
||||
|
@@ -9,6 +9,7 @@ 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.apache.cxf.jaxrs.provider.MultipartProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@@ -67,14 +68,12 @@ public abstract class ClientCxfImpl extends Client implements InitializingBean {
|
||||
List<Object> providersAndFilters = new LinkedList<Object>();
|
||||
providersAndFilters.add(new JacksonJaxbJsonProvider());
|
||||
providersAndFilters.add(new CxfLoggingFilter());
|
||||
providersAndFilters.add(new CxfMultipartProvider());
|
||||
providersAndFilters.add(new MultipartProvider());
|
||||
|
||||
if (authFilter == null)
|
||||
authFilter = this.getConfig().createAuthorizationFilter();
|
||||
if (authFilter != null)
|
||||
providersAndFilters.add(authFilter);
|
||||
|
||||
this.addProvidersAndFilters(providersAndFilters);
|
||||
|
||||
// we can't use JAXRSClientFactory with a JAXRS client (duh!)
|
||||
// so we need to create a CXF client
|
||||
@@ -90,10 +89,6 @@ public abstract class ClientCxfImpl extends Client implements InitializingBean {
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
public void addProvidersAndFilters(List<Object> providersAndFilters) {
|
||||
// for extension purposes
|
||||
}
|
||||
|
||||
/**
|
||||
* This method retrieves a JAX-RS implementation of the specified API with
|
||||
|
@@ -1,12 +1,10 @@
|
||||
package com.inteligr8.rs;
|
||||
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
import javax.ws.rs.ext.RuntimeDelegate;
|
||||
|
||||
import org.glassfish.jersey.client.ClientProperties;
|
||||
import org.glassfish.jersey.client.proxy.WebResourceFactory;
|
||||
import org.glassfish.jersey.internal.RuntimeDelegateImpl;
|
||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@@ -48,14 +46,20 @@ public abstract class ClientJerseyImpl extends Client implements InitializingBea
|
||||
this.logger.info("API Base URL: " + this.getConfig().getBaseUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param authFilter A post-configuration authorization filter.
|
||||
* @return A JAX-RS client.
|
||||
*/
|
||||
@Override
|
||||
public void buildClient(ClientBuilder clientBuilder) {
|
||||
clientBuilder.register(MultiPartFeature.class);
|
||||
|
||||
public javax.ws.rs.client.Client getClient(AuthorizationFilter authFilter) {
|
||||
javax.ws.rs.client.Client client = super.getClient(authFilter);
|
||||
|
||||
if (!this.getConfig().isPutBodyRequired()) {
|
||||
// allow PUT operations without body data
|
||||
clientBuilder.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
|
||||
client.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
|
||||
}
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,29 +0,0 @@
|
||||
package com.inteligr8.rs;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
|
||||
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
|
||||
import org.apache.cxf.jaxrs.provider.MultipartProvider;
|
||||
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@Produces(MediaType.MULTIPART_FORM_DATA)
|
||||
@Provider
|
||||
public class CxfMultipartProvider extends MultipartProvider {
|
||||
|
||||
@Override
|
||||
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
|
||||
return MultipartBody.class.isAssignableFrom(type) || this.isReadable(type, genericType, annotations, mediaType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
|
||||
return MultipartBody.class.isAssignableFrom(type) || this.isWriteable(type, genericType, annotations, mediaType);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user