forked from loafle/openapi-generator-original
Merge pull request #2174 from xhh/java-object-mapper-getter
[Java] Add getter/setter methods for objectMapper and httpClient in ApiClient
This commit is contained in:
commit
a14015c1c7
@ -49,7 +49,7 @@ public class ApiClient {
|
|||||||
private int connectionTimeout = 0;
|
private int connectionTimeout = 0;
|
||||||
|
|
||||||
private Client httpClient;
|
private Client httpClient;
|
||||||
private ObjectMapper mapper;
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
private Map<String, Authentication> authentications;
|
private Map<String, Authentication> authentications;
|
||||||
|
|
||||||
@ -59,24 +59,16 @@ public class ApiClient {
|
|||||||
private DateFormat dateFormat;
|
private DateFormat dateFormat;
|
||||||
|
|
||||||
public ApiClient() {
|
public ApiClient() {
|
||||||
mapper = new ObjectMapper();
|
objectMapper = new ObjectMapper();
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||||
mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
|
objectMapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
|
||||||
mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
|
objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
|
||||||
mapper.registerModule(new JodaModule());
|
objectMapper.registerModule(new JodaModule());
|
||||||
|
objectMapper.setDateFormat(ApiClient.buildDefaultDateFormat());
|
||||||
|
|
||||||
httpClient = buildHttpClient(debugging);
|
dateFormat = ApiClient.buildDefaultDateFormat();
|
||||||
|
|
||||||
// Use RFC3339 format for date and datetime.
|
|
||||||
// See http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14
|
|
||||||
this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
|
|
||||||
|
|
||||||
// Use UTC as the default time zone.
|
|
||||||
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
|
||||||
|
|
||||||
this.mapper.setDateFormat((DateFormat) dateFormat.clone());
|
|
||||||
|
|
||||||
// Set default User-Agent.
|
// Set default User-Agent.
|
||||||
setUserAgent("Java-Swagger");
|
setUserAgent("Java-Swagger");
|
||||||
@ -88,6 +80,62 @@ public class ApiClient {
|
|||||||
authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}}
|
authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}}
|
||||||
// Prevent the authentications from being modified.
|
// Prevent the authentications from being modified.
|
||||||
authentications = Collections.unmodifiableMap(authentications);
|
authentications = Collections.unmodifiableMap(authentications);
|
||||||
|
|
||||||
|
rebuildHttpClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DateFormat buildDefaultDateFormat() {
|
||||||
|
// Use RFC3339 format for date and datetime.
|
||||||
|
// See http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14
|
||||||
|
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
|
||||||
|
// Use UTC as the default time zone.
|
||||||
|
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
return dateFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the Client used to make HTTP requests with the latest settings,
|
||||||
|
* i.e. objectMapper and debugging.
|
||||||
|
* TODO: better to use the Builder Pattern?
|
||||||
|
*/
|
||||||
|
public ApiClient rebuildHttpClient() {
|
||||||
|
// Add the JSON serialization support to Jersey
|
||||||
|
JacksonJsonProvider jsonProvider = new JacksonJsonProvider(objectMapper);
|
||||||
|
DefaultClientConfig conf = new DefaultClientConfig();
|
||||||
|
conf.getSingletons().add(jsonProvider);
|
||||||
|
Client client = Client.create(conf);
|
||||||
|
if (debugging) {
|
||||||
|
client.addFilter(new LoggingFilter());
|
||||||
|
}
|
||||||
|
this.httpClient = client;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current object mapper used for JSON serialization/deserialization.
|
||||||
|
* <p>
|
||||||
|
* Note: If you make changes to the object mapper, remember to set it back via
|
||||||
|
* <code>setObjectMapper</code> in order to trigger HTTP client rebuilding.
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
public ObjectMapper getObjectMapper() {
|
||||||
|
return objectMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApiClient setObjectMapper(ObjectMapper objectMapper) {
|
||||||
|
this.objectMapper = objectMapper;
|
||||||
|
// Need to rebuild the Client as it depends on object mapper.
|
||||||
|
rebuildHttpClient();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Client getHttpClient() {
|
||||||
|
return httpClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApiClient setHttpClient(Client httpClient) {
|
||||||
|
this.httpClient = httpClient;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBasePath() {
|
public String getBasePath() {
|
||||||
@ -228,8 +276,8 @@ public class ApiClient {
|
|||||||
*/
|
*/
|
||||||
public ApiClient setDebugging(boolean debugging) {
|
public ApiClient setDebugging(boolean debugging) {
|
||||||
this.debugging = debugging;
|
this.debugging = debugging;
|
||||||
// Rebuild HTTP Client according to the new "debugging" value.
|
// Need to rebuild the Client as it depends on the value of debugging.
|
||||||
this.httpClient = buildHttpClient(debugging);
|
rebuildHttpClient();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,8 +311,10 @@ public class ApiClient {
|
|||||||
*/
|
*/
|
||||||
public ApiClient setDateFormat(DateFormat dateFormat) {
|
public ApiClient setDateFormat(DateFormat dateFormat) {
|
||||||
this.dateFormat = dateFormat;
|
this.dateFormat = dateFormat;
|
||||||
// also set the date format for model (de)serialization with Date properties
|
// Also set the date format for model (de)serialization with Date properties.
|
||||||
this.mapper.setDateFormat((DateFormat) dateFormat.clone());
|
this.objectMapper.setDateFormat((DateFormat) dateFormat.clone());
|
||||||
|
// Need to rebuild the Client as objectMapper changes.
|
||||||
|
rebuildHttpClient();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -611,19 +661,4 @@ public class ApiClient {
|
|||||||
|
|
||||||
return encodedFormParams;
|
return encodedFormParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Build the Client used to make HTTP requests.
|
|
||||||
*/
|
|
||||||
private Client buildHttpClient(boolean debugging) {
|
|
||||||
// Add the JSON serialization support to Jersey
|
|
||||||
JacksonJsonProvider jsonProvider = new JacksonJsonProvider(mapper);
|
|
||||||
DefaultClientConfig conf = new DefaultClientConfig();
|
|
||||||
conf.getSingletons().add(jsonProvider);
|
|
||||||
Client client = Client.create(conf);
|
|
||||||
if (debugging) {
|
|
||||||
client.addFilter(new LoggingFilter());
|
|
||||||
}
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
|
|
||||||
apply plugin: 'com.android.library'
|
apply plugin: 'com.android.library'
|
||||||
apply plugin: 'com.github.dcendents.android-maven'
|
apply plugin: 'com.github.dcendents.android-maven'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 22
|
compileSdkVersion 22
|
||||||
buildToolsVersion '22.0.0'
|
buildToolsVersion '22.0.0'
|
||||||
@ -35,7 +35,7 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
sourceCompatibility JavaVersion.VERSION_1_7
|
sourceCompatibility JavaVersion.VERSION_1_7
|
||||||
targetCompatibility JavaVersion.VERSION_1_7
|
targetCompatibility JavaVersion.VERSION_1_7
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rename the aar correctly
|
// Rename the aar correctly
|
||||||
libraryVariants.all { variant ->
|
libraryVariants.all { variant ->
|
||||||
variant.outputs.each { output ->
|
variant.outputs.each { output ->
|
||||||
@ -51,7 +51,7 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
provided 'javax.annotation:jsr250-api:1.0'
|
provided 'javax.annotation:jsr250-api:1.0'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
afterEvaluate {
|
afterEvaluate {
|
||||||
android.libraryVariants.all { variant ->
|
android.libraryVariants.all { variant ->
|
||||||
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
|
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
|
||||||
@ -63,12 +63,12 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
artifacts.add('archives', task);
|
artifacts.add('archives', task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task sourcesJar(type: Jar) {
|
task sourcesJar(type: Jar) {
|
||||||
from android.sourceSets.main.java.srcDirs
|
from android.sourceSets.main.java.srcDirs
|
||||||
classifier = 'sources'
|
classifier = 'sources'
|
||||||
}
|
}
|
||||||
|
|
||||||
artifacts {
|
artifacts {
|
||||||
archives sourcesJar
|
archives sourcesJar
|
||||||
}
|
}
|
||||||
@ -77,16 +77,16 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
|
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
apply plugin: 'maven'
|
apply plugin: 'maven'
|
||||||
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_7
|
sourceCompatibility = JavaVersion.VERSION_1_7
|
||||||
targetCompatibility = JavaVersion.VERSION_1_7
|
targetCompatibility = JavaVersion.VERSION_1_7
|
||||||
|
|
||||||
install {
|
install {
|
||||||
repositories.mavenInstaller {
|
repositories.mavenInstaller {
|
||||||
pom.artifactId = '{{artifactId}}'
|
pom.artifactId = '{{artifactId}}'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task execute(type:JavaExec) {
|
task execute(type:JavaExec) {
|
||||||
main = System.getProperty('mainClass')
|
main = System.getProperty('mainClass')
|
||||||
classpath = sourceSets.main.runtimeClasspath
|
classpath = sourceSets.main.runtimeClasspath
|
||||||
@ -96,19 +96,21 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
ext {
|
ext {
|
||||||
swagger_annotations_version = "1.5.0"
|
swagger_annotations_version = "1.5.0"
|
||||||
jackson_version = "2.4.2"
|
jackson_version = "2.4.2"
|
||||||
jersey_version = "2.6"
|
jersey_version = "2.22"
|
||||||
jodatime_version = "2.3"
|
jodatime_version = "2.3"
|
||||||
junit_version = "4.8.1"
|
junit_version = "4.12"
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
|
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
|
||||||
compile "org.glassfish.jersey.core:jersey-client:$jersey_version"
|
compile "org.glassfish.jersey.core:jersey-client:$jersey_version"
|
||||||
compile "org.glassfish.jersey.media:jersey-media-multipart:$jersey_version"
|
compile "org.glassfish.jersey.media:jersey-media-multipart:$jersey_version"
|
||||||
|
compile "org.glassfish.jersey.media:jersey-media-json-jackson:2.22.1"
|
||||||
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
|
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
|
||||||
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
|
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
|
||||||
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
|
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
|
||||||
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5"
|
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5"
|
||||||
compile "joda-time:joda-time:$jodatime_version"
|
compile "joda-time:joda-time:$jodatime_version"
|
||||||
|
compile "com.brsanthu:migbase64:2.2"
|
||||||
testCompile "junit:junit:$junit_version"
|
testCompile "junit:junit:$junit_version"
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,27 @@
|
|||||||
<target>1.6</target>
|
<target>1.6</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<!-- For testing build.gradle -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
<version>1.2.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>gradle-test</id>
|
||||||
|
<phase>integration-test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>exec</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<executable>gradle</executable>
|
||||||
|
<arguments>
|
||||||
|
<argument>check</argument>
|
||||||
|
</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -129,7 +150,7 @@
|
|||||||
<artifactId>jersey-media-json-jackson</artifactId>
|
<artifactId>jersey-media-json-jackson</artifactId>
|
||||||
<version>2.22.1</version>
|
<version>2.22.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- JSON processing: jackson -->
|
<!-- JSON processing: jackson -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
@ -174,10 +195,10 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
<properties>
|
<properties>
|
||||||
<swagger-annotations-version>1.5.0</swagger-annotations-version>
|
<swagger-annotations-version>1.5.0</swagger-annotations-version>
|
||||||
<jersey-version>2.12</jersey-version>
|
<jersey-version>2.22</jersey-version>
|
||||||
<jackson-version>2.4.2</jackson-version>
|
<jackson-version>2.4.2</jackson-version>
|
||||||
<jodatime-version>2.3</jodatime-version>
|
<jodatime-version>2.3</jodatime-version>
|
||||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||||
<junit-version>4.8.1</junit-version>
|
<junit-version>4.12</junit-version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
@ -108,7 +108,9 @@ dependencies {
|
|||||||
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
|
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
|
||||||
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
|
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
|
||||||
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
|
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
|
||||||
|
compile "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:$jackson_version"
|
||||||
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5"
|
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5"
|
||||||
compile "joda-time:joda-time:$jodatime_version"
|
compile "joda-time:joda-time:$jodatime_version"
|
||||||
|
compile "com.brsanthu:migbase64:2.2"
|
||||||
testCompile "junit:junit:$junit_version"
|
testCompile "junit:junit:$junit_version"
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ import io.swagger.client.auth.HttpBasicAuth;
|
|||||||
import io.swagger.client.auth.ApiKeyAuth;
|
import io.swagger.client.auth.ApiKeyAuth;
|
||||||
import io.swagger.client.auth.OAuth;
|
import io.swagger.client.auth.OAuth;
|
||||||
|
|
||||||
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-17T17:16:20.498+08:00")
|
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-18T20:04:40.386+08:00")
|
||||||
public class ApiClient {
|
public class ApiClient {
|
||||||
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
||||||
private String basePath = "http://petstore.swagger.io/v2";
|
private String basePath = "http://petstore.swagger.io/v2";
|
||||||
@ -49,7 +49,7 @@ public class ApiClient {
|
|||||||
private int connectionTimeout = 0;
|
private int connectionTimeout = 0;
|
||||||
|
|
||||||
private Client httpClient;
|
private Client httpClient;
|
||||||
private ObjectMapper mapper;
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
private Map<String, Authentication> authentications;
|
private Map<String, Authentication> authentications;
|
||||||
|
|
||||||
@ -59,24 +59,16 @@ public class ApiClient {
|
|||||||
private DateFormat dateFormat;
|
private DateFormat dateFormat;
|
||||||
|
|
||||||
public ApiClient() {
|
public ApiClient() {
|
||||||
mapper = new ObjectMapper();
|
objectMapper = new ObjectMapper();
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||||
mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
|
objectMapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
|
||||||
mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
|
objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
|
||||||
mapper.registerModule(new JodaModule());
|
objectMapper.registerModule(new JodaModule());
|
||||||
|
objectMapper.setDateFormat(ApiClient.buildDefaultDateFormat());
|
||||||
|
|
||||||
httpClient = buildHttpClient(debugging);
|
dateFormat = ApiClient.buildDefaultDateFormat();
|
||||||
|
|
||||||
// Use RFC3339 format for date and datetime.
|
|
||||||
// See http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14
|
|
||||||
this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
|
|
||||||
|
|
||||||
// Use UTC as the default time zone.
|
|
||||||
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
|
||||||
|
|
||||||
this.mapper.setDateFormat((DateFormat) dateFormat.clone());
|
|
||||||
|
|
||||||
// Set default User-Agent.
|
// Set default User-Agent.
|
||||||
setUserAgent("Java-Swagger");
|
setUserAgent("Java-Swagger");
|
||||||
@ -91,6 +83,62 @@ public class ApiClient {
|
|||||||
authentications.put("test_api_key_header", new ApiKeyAuth("header", "test_api_key_header"));
|
authentications.put("test_api_key_header", new ApiKeyAuth("header", "test_api_key_header"));
|
||||||
// Prevent the authentications from being modified.
|
// Prevent the authentications from being modified.
|
||||||
authentications = Collections.unmodifiableMap(authentications);
|
authentications = Collections.unmodifiableMap(authentications);
|
||||||
|
|
||||||
|
rebuildHttpClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DateFormat buildDefaultDateFormat() {
|
||||||
|
// Use RFC3339 format for date and datetime.
|
||||||
|
// See http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14
|
||||||
|
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
|
||||||
|
// Use UTC as the default time zone.
|
||||||
|
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
return dateFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the Client used to make HTTP requests with the latest settings,
|
||||||
|
* i.e. objectMapper and debugging.
|
||||||
|
* TODO: better to use the Builder Pattern?
|
||||||
|
*/
|
||||||
|
public ApiClient rebuildHttpClient() {
|
||||||
|
// Add the JSON serialization support to Jersey
|
||||||
|
JacksonJsonProvider jsonProvider = new JacksonJsonProvider(objectMapper);
|
||||||
|
DefaultClientConfig conf = new DefaultClientConfig();
|
||||||
|
conf.getSingletons().add(jsonProvider);
|
||||||
|
Client client = Client.create(conf);
|
||||||
|
if (debugging) {
|
||||||
|
client.addFilter(new LoggingFilter());
|
||||||
|
}
|
||||||
|
this.httpClient = client;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current object mapper used for JSON serialization/deserialization.
|
||||||
|
* <p>
|
||||||
|
* Note: If you make changes to the object mapper, remember to set it back via
|
||||||
|
* <code>setObjectMapper</code> in order to trigger HTTP client rebuilding.
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
public ObjectMapper getObjectMapper() {
|
||||||
|
return objectMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApiClient setObjectMapper(ObjectMapper objectMapper) {
|
||||||
|
this.objectMapper = objectMapper;
|
||||||
|
// Need to rebuild the Client as it depends on object mapper.
|
||||||
|
rebuildHttpClient();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Client getHttpClient() {
|
||||||
|
return httpClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApiClient setHttpClient(Client httpClient) {
|
||||||
|
this.httpClient = httpClient;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBasePath() {
|
public String getBasePath() {
|
||||||
@ -231,8 +279,8 @@ public class ApiClient {
|
|||||||
*/
|
*/
|
||||||
public ApiClient setDebugging(boolean debugging) {
|
public ApiClient setDebugging(boolean debugging) {
|
||||||
this.debugging = debugging;
|
this.debugging = debugging;
|
||||||
// Rebuild HTTP Client according to the new "debugging" value.
|
// Need to rebuild the Client as it depends on the value of debugging.
|
||||||
this.httpClient = buildHttpClient(debugging);
|
rebuildHttpClient();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,8 +314,10 @@ public class ApiClient {
|
|||||||
*/
|
*/
|
||||||
public ApiClient setDateFormat(DateFormat dateFormat) {
|
public ApiClient setDateFormat(DateFormat dateFormat) {
|
||||||
this.dateFormat = dateFormat;
|
this.dateFormat = dateFormat;
|
||||||
// also set the date format for model (de)serialization with Date properties
|
// Also set the date format for model (de)serialization with Date properties.
|
||||||
this.mapper.setDateFormat((DateFormat) dateFormat.clone());
|
this.objectMapper.setDateFormat((DateFormat) dateFormat.clone());
|
||||||
|
// Need to rebuild the Client as objectMapper changes.
|
||||||
|
rebuildHttpClient();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -614,19 +664,4 @@ public class ApiClient {
|
|||||||
|
|
||||||
return encodedFormParams;
|
return encodedFormParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Build the Client used to make HTTP requests.
|
|
||||||
*/
|
|
||||||
private Client buildHttpClient(boolean debugging) {
|
|
||||||
// Add the JSON serialization support to Jersey
|
|
||||||
JacksonJsonProvider jsonProvider = new JacksonJsonProvider(mapper);
|
|
||||||
DefaultClientConfig conf = new DefaultClientConfig();
|
|
||||||
conf.getSingletons().add(jsonProvider);
|
|
||||||
Client client = Client.create(conf);
|
|
||||||
if (debugging) {
|
|
||||||
client.addFilter(new LoggingFilter());
|
|
||||||
}
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ mvn deploy
|
|||||||
|
|
||||||
Refer to the [official documentation](https://maven.apache.org/plugins/maven-deploy-plugin/usage.html) for more information.
|
Refer to the [official documentation](https://maven.apache.org/plugins/maven-deploy-plugin/usage.html) for more information.
|
||||||
|
|
||||||
After the client libarary is installed/deployed, you can use it in your Maven project by adding the following to your *pom.xml*:
|
After the client library is installed/deployed, you can use it in your Maven project by adding the following to your *pom.xml*:
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -23,7 +23,7 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
|
|
||||||
apply plugin: 'com.android.library'
|
apply plugin: 'com.android.library'
|
||||||
apply plugin: 'com.github.dcendents.android-maven'
|
apply plugin: 'com.github.dcendents.android-maven'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 22
|
compileSdkVersion 22
|
||||||
buildToolsVersion '22.0.0'
|
buildToolsVersion '22.0.0'
|
||||||
@ -35,7 +35,7 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
sourceCompatibility JavaVersion.VERSION_1_7
|
sourceCompatibility JavaVersion.VERSION_1_7
|
||||||
targetCompatibility JavaVersion.VERSION_1_7
|
targetCompatibility JavaVersion.VERSION_1_7
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rename the aar correctly
|
// Rename the aar correctly
|
||||||
libraryVariants.all { variant ->
|
libraryVariants.all { variant ->
|
||||||
variant.outputs.each { output ->
|
variant.outputs.each { output ->
|
||||||
@ -51,7 +51,7 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
provided 'javax.annotation:jsr250-api:1.0'
|
provided 'javax.annotation:jsr250-api:1.0'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
afterEvaluate {
|
afterEvaluate {
|
||||||
android.libraryVariants.all { variant ->
|
android.libraryVariants.all { variant ->
|
||||||
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
|
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
|
||||||
@ -63,12 +63,12 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
artifacts.add('archives', task);
|
artifacts.add('archives', task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task sourcesJar(type: Jar) {
|
task sourcesJar(type: Jar) {
|
||||||
from android.sourceSets.main.java.srcDirs
|
from android.sourceSets.main.java.srcDirs
|
||||||
classifier = 'sources'
|
classifier = 'sources'
|
||||||
}
|
}
|
||||||
|
|
||||||
artifacts {
|
artifacts {
|
||||||
archives sourcesJar
|
archives sourcesJar
|
||||||
}
|
}
|
||||||
@ -77,16 +77,16 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
|
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
apply plugin: 'maven'
|
apply plugin: 'maven'
|
||||||
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_7
|
sourceCompatibility = JavaVersion.VERSION_1_7
|
||||||
targetCompatibility = JavaVersion.VERSION_1_7
|
targetCompatibility = JavaVersion.VERSION_1_7
|
||||||
|
|
||||||
install {
|
install {
|
||||||
repositories.mavenInstaller {
|
repositories.mavenInstaller {
|
||||||
pom.artifactId = 'swagger-petstore-jersey2'
|
pom.artifactId = 'swagger-petstore-jersey2'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task execute(type:JavaExec) {
|
task execute(type:JavaExec) {
|
||||||
main = System.getProperty('mainClass')
|
main = System.getProperty('mainClass')
|
||||||
classpath = sourceSets.main.runtimeClasspath
|
classpath = sourceSets.main.runtimeClasspath
|
||||||
@ -96,19 +96,21 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
ext {
|
ext {
|
||||||
swagger_annotations_version = "1.5.0"
|
swagger_annotations_version = "1.5.0"
|
||||||
jackson_version = "2.4.2"
|
jackson_version = "2.4.2"
|
||||||
jersey_version = "2.6"
|
jersey_version = "2.22"
|
||||||
jodatime_version = "2.3"
|
jodatime_version = "2.3"
|
||||||
junit_version = "4.8.1"
|
junit_version = "4.12"
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
|
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
|
||||||
compile "org.glassfish.jersey.core:jersey-client:$jersey_version"
|
compile "org.glassfish.jersey.core:jersey-client:$jersey_version"
|
||||||
compile "org.glassfish.jersey.media:jersey-media-multipart:$jersey_version"
|
compile "org.glassfish.jersey.media:jersey-media-multipart:$jersey_version"
|
||||||
|
compile "org.glassfish.jersey.media:jersey-media-json-jackson:2.22.1"
|
||||||
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
|
compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
|
||||||
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
|
compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
|
||||||
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
|
compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
|
||||||
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5"
|
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5"
|
||||||
compile "joda-time:joda-time:$jodatime_version"
|
compile "joda-time:joda-time:$jodatime_version"
|
||||||
|
compile "com.brsanthu:migbase64:2.2"
|
||||||
testCompile "junit:junit:$junit_version"
|
testCompile "junit:junit:$junit_version"
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,27 @@
|
|||||||
<target>1.6</target>
|
<target>1.6</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<!-- For testing build.gradle -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
<version>1.2.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>gradle-test</id>
|
||||||
|
<phase>integration-test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>exec</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<executable>gradle</executable>
|
||||||
|
<arguments>
|
||||||
|
<argument>check</argument>
|
||||||
|
</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -129,7 +150,7 @@
|
|||||||
<artifactId>jersey-media-json-jackson</artifactId>
|
<artifactId>jersey-media-json-jackson</artifactId>
|
||||||
<version>2.22.1</version>
|
<version>2.22.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- JSON processing: jackson -->
|
<!-- JSON processing: jackson -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
@ -174,10 +195,10 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
<properties>
|
<properties>
|
||||||
<swagger-annotations-version>1.5.0</swagger-annotations-version>
|
<swagger-annotations-version>1.5.0</swagger-annotations-version>
|
||||||
<jersey-version>2.12</jersey-version>
|
<jersey-version>2.22</jersey-version>
|
||||||
<jackson-version>2.4.2</jackson-version>
|
<jackson-version>2.4.2</jackson-version>
|
||||||
<jodatime-version>2.3</jodatime-version>
|
<jodatime-version>2.3</jodatime-version>
|
||||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||||
<junit-version>4.8.1</junit-version>
|
<junit-version>4.12</junit-version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user