[Java] MIME type "*/*" default to JSON (#6188)

* update java petstore

* minor fix to docstring

* roll back resttemplate with xml petstore due to errors

* minor fix to resttemplate isjson check
This commit is contained in:
wing328
2017-07-27 11:36:29 +08:00
committed by GitHub
parent 44e7b5dd3f
commit 927055a681
54 changed files with 89 additions and 55 deletions

View File

@@ -13,8 +13,8 @@ import javax.ws.rs.core.Response.Status;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.filter.LoggingFilter;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.logging.LoggingFeature;
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.MultiPart;
@@ -51,21 +51,21 @@ import io.swagger.client.auth.OAuth;
public class ApiClient {
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
private String basePath = "http://petstore.swagger.io:80/v2";
private boolean debugging = false;
private int connectionTimeout = 0;
protected Map<String, String> defaultHeaderMap = new HashMap<String, String>();
protected String basePath = "http://petstore.swagger.io:80/v2";
protected boolean debugging = false;
protected int connectionTimeout = 0;
private Client httpClient;
private JSON json;
private String tempFolderPath = null;
protected Client httpClient;
protected JSON json;
protected String tempFolderPath = null;
private Map<String, Authentication> authentications;
protected Map<String, Authentication> authentications;
private int statusCode;
private Map<String, List<String>> responseHeaders;
protected int statusCode;
protected Map<String, List<String>> responseHeaders;
private DateFormat dateFormat;
protected DateFormat dateFormat;
public ApiClient() {
json = new JSON();
@@ -433,12 +433,13 @@ public class ApiClient {
* application/json; charset=UTF8
* APPLICATION/JSON
* application/vnd.company+json
* "* / *" is also default to JSON
* @param mime MIME
* @return True if the MIME type is JSON
*/
public boolean isJsonMime(String mime) {
String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$";
return mime != null && (mime.matches(jsonMime) || mime.equalsIgnoreCase("application/json-patch+json"));
return mime != null && (mime.matches(jsonMime) || mime.equals("*/*"));
}
/**
@@ -729,18 +730,26 @@ public class ApiClient {
* @param debugging Debug setting
* @return Client
*/
private Client buildHttpClient(boolean debugging) {
protected Client buildHttpClient(boolean debugging) {
final ClientConfig clientConfig = new ClientConfig();
clientConfig.register(MultiPartFeature.class);
clientConfig.register(json);
clientConfig.register(JacksonFeature.class);
if (debugging) {
clientConfig.register(new LoggingFilter(java.util.logging.Logger.getLogger(LoggingFilter.class.getName()), true));
clientConfig.register(new LoggingFeature(java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), java.util.logging.Level.INFO, LoggingFeature.Verbosity.PAYLOAD_ANY, 1024*50 /* Log payloads up to 50K */));
clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);
// Set logger to ALL
java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME).setLevel(java.util.logging.Level.ALL);
}
performAdditionalClientConfiguration(clientConfig);
return ClientBuilder.newClient(clientConfig);
}
private Map<String, List<String>> buildResponseHeaders(Response response) {
protected void performAdditionalClientConfiguration(ClientConfig clientConfig) {
// No-op extension point
}
protected Map<String, List<String>> buildResponseHeaders(Response response) {
Map<String, List<String>> responseHeaders = new HashMap<String, List<String>>();
for (Entry<String, List<Object>> entry: response.getHeaders().entrySet()) {
List<Object> values = entry.getValue();
@@ -758,7 +767,7 @@ public class ApiClient {
*
* @param authNames The authentications to apply
*/
private void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams) {
protected void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams) {
for (String authName : authNames) {
Authentication auth = authentications.get(authName);
if (auth == null) throw new RuntimeException("Authentication undefined: " + authName);

View File

@@ -168,6 +168,7 @@ public class PetApi {
* @param tags Tags to filter by (required)
* @return List&lt;Pet&gt;
* @throws ApiException if fails to make API call
* @Deprecated
*/
public List<Pet> findPetsByTags(List<String> tags) throws ApiException {
Object localVarPostBody = null;

View File

@@ -39,7 +39,7 @@ public class Cat extends Animal {
* @return declawed
**/
@ApiModelProperty(value = "")
public Boolean getDeclawed() {
public Boolean isDeclawed() {
return declawed;
}

View File

@@ -181,7 +181,7 @@ public class Order {
* @return complete
**/
@ApiModelProperty(value = "")
public Boolean getComplete() {
public Boolean isComplete() {
return complete;
}