diff --git a/samples/client/petstore/android-java/AndroidJavaPetstoreCodegen.scala b/samples/client/petstore/android-java/AndroidJavaPetstoreCodegen.scala
index bc441275a6f..63d475204c6 100644
--- a/samples/client/petstore/android-java/AndroidJavaPetstoreCodegen.scala
+++ b/samples/client/petstore/android-java/AndroidJavaPetstoreCodegen.scala
@@ -42,6 +42,7 @@ object AndroidJavaPetstoreCodegen extends BasicAndroidJavaGenerator {
// supporting classes
override def supportingFiles = List(
("apiInvoker.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "ApiInvoker.java"),
+ ("httpPatch.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "HttpPatch.java"),
("jsonUtil.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "JsonUtil.java"),
("apiException.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "ApiException.java"),
("pom.mustache", "samples/client/petstore/android-java", "pom.xml")
diff --git a/samples/client/petstore/android-java/pom.xml b/samples/client/petstore/android-java/pom.xml
index c1ec3e80b86..17001ba1cd1 100644
--- a/samples/client/petstore/android-java/pom.xml
+++ b/samples/client/petstore/android-java/pom.xml
@@ -207,7 +207,7 @@
1.0.0
4.8.1
1.6.1
- 4.2.3
+ 4.0
3.1.5
diff --git a/samples/client/petstore/android-java/src/main/java/com/wordnik/client/ApiInvoker.java b/samples/client/petstore/android-java/src/main/java/com/wordnik/client/ApiInvoker.java
index 86a7dccff6b..1536a1f1c58 100644
--- a/samples/client/petstore/android-java/src/main/java/com/wordnik/client/ApiInvoker.java
+++ b/samples/client/petstore/android-java/src/main/java/com/wordnik/client/ApiInvoker.java
@@ -9,11 +9,18 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.apache.http.*;
import org.apache.http.client.*;
import org.apache.http.client.methods.*;
+import org.apache.http.conn.*;
+import org.apache.http.conn.scheme.*;
+import org.apache.http.conn.ssl.*;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.*;
+import org.apache.http.impl.conn.*;
+import org.apache.http.params.*;
import org.apache.http.util.EntityUtils;
import java.io.File;
+import java.net.Socket;
+import java.net.UnknownHostException;
import java.net.URLEncoder;
import java.util.Map;
@@ -22,15 +29,50 @@ import java.util.List;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
+import java.security.GeneralSecurityException;
+import java.security.KeyManagementException;
+import java.security.KeyStore;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.security.cert.*;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+
+import java.util.Date;
+import java.util.Random;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+
public class ApiInvoker {
private static ApiInvoker INSTANCE = new ApiInvoker();
private Map defaultHeaderMap = new HashMap();
private HttpClient client = null;
+
+ private boolean ignoreSSLCertificates = false;
+
+ private ClientConnectionManager ignoreSSLConnectionManager;
+
+ public ApiInvoker() {
+ initConnectionManager();
+ }
+
public static ApiInvoker getInstance() {
return INSTANCE;
}
+ public void ignoreSSLCertificates(boolean ignoreSSLCertificates) {
+ this.ignoreSSLCertificates = ignoreSSLCertificates;
+ }
+
public void addDefaultHeader(String key, String value) {
defaultHeaderMap.put(key, value);
}
@@ -114,8 +156,11 @@ public class ApiInvoker {
}
else if ("POST".equals(method)) {
HttpPost post = new HttpPost(url);
- post.setHeader("Content-Type", contentType);
- post.setEntity(new StringEntity(serialize(body), "UTF-8"));
+
+ if (body != null) {
+ post.setHeader("Content-Type", contentType);
+ post.setEntity(new StringEntity(serialize(body), "UTF-8"));
+ }
for(String key : headers.keySet()) {
post.setHeader(key, headers.get(key));
}
@@ -139,6 +184,18 @@ public class ApiInvoker {
}
response = client.execute(delete);
}
+ else if ("PATCH".equals(method)) {
+ HttpPatch patch = new HttpPatch(url);
+
+ if (body != null) {
+ patch.setHeader("Content-Type", contentType);
+ patch.setEntity(new StringEntity(serialize(body), "UTF-8"));
+ }
+ for(String key : headers.keySet()) {
+ patch.setHeader(key, headers.get(key));
+ }
+ response = client.execute(patch);
+ }
int code = response.getStatusLine().getStatusCode();
String responseString = null;
@@ -167,8 +224,61 @@ public class ApiInvoker {
}
private HttpClient getClient(String host) {
- if(client == null)
- client = new DefaultHttpClient();
+ if (client == null) {
+ if (ignoreSSLCertificates && ignoreSSLConnectionManager != null) {
+ // Trust self signed certificates
+ client = new DefaultHttpClient(ignoreSSLConnectionManager, new BasicHttpParams());
+ } else {
+ client = new DefaultHttpClient();
+ }
+ }
return client;
}
+
+ private void initConnectionManager() {
+ try {
+ final SSLContext sslContext = SSLContext.getInstance("SSL");
+
+ // set up a TrustManager that trusts everything
+ TrustManager[] trustManagers = new TrustManager[] {
+ new X509TrustManager() {
+ public X509Certificate[] getAcceptedIssuers() {
+ return null;
+ }
+ public void checkClientTrusted(X509Certificate[] certs, String authType) {}
+ public void checkServerTrusted(X509Certificate[] certs, String authType) {}
+ }};
+
+ sslContext.init(null, trustManagers, new SecureRandom());
+
+ SSLSocketFactory sf = new SSLSocketFactory((KeyStore)null) {
+ private javax.net.ssl.SSLSocketFactory sslFactory = sslContext.getSocketFactory();
+
+ public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
+ throws IOException, UnknownHostException {
+ return sslFactory.createSocket(socket, host, port, autoClose);
+ }
+
+ public Socket createSocket() throws IOException {
+ return sslFactory.createSocket();
+ }
+ };
+
+ sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+ Scheme httpsScheme = new Scheme("https", sf, 443);
+ SchemeRegistry schemeRegistry = new SchemeRegistry();
+ schemeRegistry.register(httpsScheme);
+ schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
+
+ ignoreSSLConnectionManager = new SingleClientConnManager(new BasicHttpParams(), schemeRegistry);
+ } catch (NoSuchAlgorithmException e) {
+ // This will only be thrown if SSL isn't available for some reason.
+ } catch (KeyManagementException e) {
+ // This might be thrown when passing a key into init(), but no key is being passed.
+ } catch (GeneralSecurityException e) {
+ // This catches anything else that might go wrong.
+ // If anything goes wrong we default to the standard connection manager.
+ }
+ }
}
+
diff --git a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/PetApi.java b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/PetApi.java
index c9e33d53512..6aba213e762 100644
--- a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/PetApi.java
+++ b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/PetApi.java
@@ -2,9 +2,9 @@ package com.wordnik.petstore.api;
import com.wordnik.client.ApiException;
import com.wordnik.client.ApiInvoker;
-import java.io.File;
import com.wordnik.petstore.model.Pet;
import java.util.*;
+import java.io.File;
public class PetApi {
String basePath = "http://petstore.swagger.wordnik.com/api";
@@ -17,11 +17,11 @@ public class PetApi {
public ApiInvoker getInvoker() {
return apiInvoker;
}
-
+
public void setBasePath(String basePath) {
this.basePath = basePath;
}
-
+
public String getBasePath() {
return basePath;
}
diff --git a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/StoreApi.java b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/StoreApi.java
index 12076bf43dd..de44244f9b0 100644
--- a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/StoreApi.java
+++ b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/StoreApi.java
@@ -4,6 +4,7 @@ import com.wordnik.client.ApiException;
import com.wordnik.client.ApiInvoker;
import com.wordnik.petstore.model.Order;
import java.util.*;
+import java.io.File;
public class StoreApi {
String basePath = "http://petstore.swagger.wordnik.com/api";
@@ -16,11 +17,11 @@ public class StoreApi {
public ApiInvoker getInvoker() {
return apiInvoker;
}
-
+
public void setBasePath(String basePath) {
this.basePath = basePath;
}
-
+
public String getBasePath() {
return basePath;
}
diff --git a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/UserApi.java b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/UserApi.java
index 56ed2a8e038..098497a7007 100644
--- a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/UserApi.java
+++ b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/UserApi.java
@@ -4,6 +4,7 @@ import com.wordnik.client.ApiException;
import com.wordnik.client.ApiInvoker;
import com.wordnik.petstore.model.User;
import java.util.*;
+import java.io.File;
public class UserApi {
String basePath = "http://petstore.swagger.wordnik.com/api";
@@ -16,108 +17,15 @@ public class UserApi {
public ApiInvoker getInvoker() {
return apiInvoker;
}
-
+
public void setBasePath(String basePath) {
this.basePath = basePath;
}
-
+
public String getBasePath() {
return basePath;
}
- public void createUser (User body) throws ApiException {
- // verify required params are set
- if(body == null ) {
- throw new ApiException(400, "missing required params");
- }
- // create path and map variables
- String path = "/user".replaceAll("\\{format\\}","json");
-
- // query params
- Map queryParams = new HashMap();
- Map headerParams = new HashMap();
-
- String contentType = "application/json";
-
- try {
- String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType);
- if(response != null){
- return ;
- }
- else {
- return ;
- }
- } catch (ApiException ex) {
- if(ex.getCode() == 404) {
- return ;
- }
- else {
- throw ex;
- }
- }
- }
- public void createUsersWithArrayInput (List body) throws ApiException {
- // verify required params are set
- if(body == null ) {
- throw new ApiException(400, "missing required params");
- }
- // create path and map variables
- String path = "/user/createWithArray".replaceAll("\\{format\\}","json");
-
- // query params
- Map queryParams = new HashMap();
- Map headerParams = new HashMap();
-
- String contentType = "application/json";
-
- try {
- String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType);
- if(response != null){
- return ;
- }
- else {
- return ;
- }
- } catch (ApiException ex) {
- if(ex.getCode() == 404) {
- return ;
- }
- else {
- throw ex;
- }
- }
- }
- public void createUsersWithListInput (List body) throws ApiException {
- // verify required params are set
- if(body == null ) {
- throw new ApiException(400, "missing required params");
- }
- // create path and map variables
- String path = "/user/createWithList".replaceAll("\\{format\\}","json");
-
- // query params
- Map queryParams = new HashMap();
- Map headerParams = new HashMap();
-
- String contentType = "application/json";
-
- try {
- String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType);
- if(response != null){
- return ;
- }
- else {
- return ;
- }
- } catch (ApiException ex) {
- if(ex.getCode() == 404) {
- return ;
- }
- else {
- throw ex;
- }
- }
- }
public void updateUser (String username, User body) throws ApiException {
// verify required params are set
if(username == null || body == null ) {
@@ -273,5 +181,98 @@ public class UserApi {
}
}
}
+ public void createUser (User body) throws ApiException {
+ // verify required params are set
+ if(body == null ) {
+ throw new ApiException(400, "missing required params");
+ }
+ // create path and map variables
+ String path = "/user".replaceAll("\\{format\\}","json");
+
+ // query params
+ Map queryParams = new HashMap();
+ Map headerParams = new HashMap();
+
+ String contentType = "application/json";
+
+ try {
+ String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType);
+ if(response != null){
+ return ;
+ }
+ else {
+ return ;
+ }
+ } catch (ApiException ex) {
+ if(ex.getCode() == 404) {
+ return ;
+ }
+ else {
+ throw ex;
+ }
+ }
+ }
+ public void createUsersWithArrayInput (List body) throws ApiException {
+ // verify required params are set
+ if(body == null ) {
+ throw new ApiException(400, "missing required params");
+ }
+ // create path and map variables
+ String path = "/user/createWithArray".replaceAll("\\{format\\}","json");
+
+ // query params
+ Map queryParams = new HashMap();
+ Map headerParams = new HashMap();
+
+ String contentType = "application/json";
+
+ try {
+ String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType);
+ if(response != null){
+ return ;
+ }
+ else {
+ return ;
+ }
+ } catch (ApiException ex) {
+ if(ex.getCode() == 404) {
+ return ;
+ }
+ else {
+ throw ex;
+ }
+ }
+ }
+ public void createUsersWithListInput (List body) throws ApiException {
+ // verify required params are set
+ if(body == null ) {
+ throw new ApiException(400, "missing required params");
+ }
+ // create path and map variables
+ String path = "/user/createWithList".replaceAll("\\{format\\}","json");
+
+ // query params
+ Map queryParams = new HashMap();
+ Map headerParams = new HashMap();
+
+ String contentType = "application/json";
+
+ try {
+ String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType);
+ if(response != null){
+ return ;
+ }
+ else {
+ return ;
+ }
+ } catch (ApiException ex) {
+ if(ex.getCode() == 404) {
+ return ;
+ }
+ else {
+ throw ex;
+ }
+ }
+ }
}
diff --git a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/model/Category.java b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/model/Category.java
index 95cc380d095..a2dc94401c9 100644
--- a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/model/Category.java
+++ b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/model/Category.java
@@ -3,10 +3,8 @@ package com.wordnik.petstore.model;
import com.fasterxml.jackson.annotation.JsonProperty;
public class Category {
- /* Category unique identifier */
@JsonProperty("id")
private Long id = null;
- /* Name of the category */
@JsonProperty("name")
private String name = null;
public Long getId() {
diff --git a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/model/Order.java b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/model/Order.java
index 1466954b03e..28e1e74d27a 100644
--- a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/model/Order.java
+++ b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/model/Order.java
@@ -4,19 +4,15 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Date;
public class Order {
- /* Unique identifier for the order */
@JsonProperty("id")
private Long id = null;
- /* ID of pet being ordered */
@JsonProperty("petId")
private Long petId = null;
- /* Number of pets ordered */
@JsonProperty("quantity")
private Integer quantity = null;
- /* Status of the order */
+ /* Order Status */
@JsonProperty("status")
private String status = null;
- /* Date shipped, only if it has been */
@JsonProperty("shipDate")
private Date shipDate = null;
public Long getId() {
diff --git a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/model/Pet.java b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/model/Pet.java
index 8284abdc20c..5f68e4df203 100644
--- a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/model/Pet.java
+++ b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/model/Pet.java
@@ -6,19 +6,15 @@ import java.util.*;
import com.wordnik.petstore.model.Category;
import com.wordnik.petstore.model.Tag;
public class Pet {
- /* Unique identifier for the Pet */
+ /* unique identifier for the pet */
@JsonProperty("id")
private Long id = null;
- /* Category the pet is in */
@JsonProperty("category")
private Category category = null;
- /* Friendly name of the pet */
@JsonProperty("name")
private String name = null;
- /* Image URLs */
@JsonProperty("photoUrls")
private List photoUrls = new ArrayList();
- /* Tags assigned to this pet */
@JsonProperty("tags")
private List tags = new ArrayList();
/* pet status in the store */
diff --git a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/model/Tag.java b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/model/Tag.java
index e092d8fa6b5..52407da1267 100644
--- a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/model/Tag.java
+++ b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/model/Tag.java
@@ -3,10 +3,8 @@ package com.wordnik.petstore.model;
import com.fasterxml.jackson.annotation.JsonProperty;
public class Tag {
- /* Unique identifier for the tag */
@JsonProperty("id")
private Long id = null;
- /* Friendly name for the tag */
@JsonProperty("name")
private String name = null;
public Long getId() {
diff --git a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/model/User.java b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/model/User.java
index 6213bb6b7cd..117dd216308 100644
--- a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/model/User.java
+++ b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/model/User.java
@@ -3,25 +3,18 @@ package com.wordnik.petstore.model;
import com.fasterxml.jackson.annotation.JsonProperty;
public class User {
- /* Unique identifier for the user */
@JsonProperty("id")
private Long id = null;
- /* Unique username */
- @JsonProperty("username")
- private String username = null;
- /* First name of the user */
@JsonProperty("firstName")
private String firstName = null;
- /* Last name of the user */
+ @JsonProperty("username")
+ private String username = null;
@JsonProperty("lastName")
private String lastName = null;
- /* Email address of the user */
@JsonProperty("email")
private String email = null;
- /* Password name of the user */
@JsonProperty("password")
private String password = null;
- /* Phone number of the user */
@JsonProperty("phone")
private String phone = null;
/* User Status */
@@ -34,13 +27,6 @@ public class User {
this.id = id;
}
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
-
public String getFirstName() {
return firstName;
}
@@ -48,6 +34,13 @@ public class User {
this.firstName = firstName;
}
+ public String getUsername() {
+ return username;
+ }
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
public String getLastName() {
return lastName;
}
@@ -88,8 +81,8 @@ public class User {
StringBuilder sb = new StringBuilder();
sb.append("class User {\n");
sb.append(" id: ").append(id).append("\n");
- sb.append(" username: ").append(username).append("\n");
sb.append(" firstName: ").append(firstName).append("\n");
+ sb.append(" username: ").append(username).append("\n");
sb.append(" lastName: ").append(lastName).append("\n");
sb.append(" email: ").append(email).append("\n");
sb.append(" password: ").append(password).append("\n");