Renamed QueryParam to Pair class in Java templates.

This commit is contained in:
Raghav Sidhanti 2015-06-22 15:16:45 -07:00
parent 7a9a41fe01
commit ecddfb7ccf
19 changed files with 78 additions and 78 deletions

View File

@ -116,7 +116,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
supportingFiles.add(new SupportingFile("Configuration.mustache", invokerFolder, "Configuration.java"));
supportingFiles.add(new SupportingFile("JsonUtil.mustache", invokerFolder, "JsonUtil.java"));
supportingFiles.add(new SupportingFile("StringUtil.mustache", invokerFolder, "StringUtil.java"));
supportingFiles.add(new SupportingFile("QueryParam.mustache", invokerFolder, "QueryParam.java"));
supportingFiles.add(new SupportingFile("Pair.mustache", invokerFolder, "Pair.java"));
final String authFolder = (sourceFolder + File.separator + invokerPackage + ".auth").replace(".", File.separator);
supportingFiles.add(new SupportingFile("auth/Authentication.mustache", authFolder, "Authentication.java"));

View File

@ -241,10 +241,10 @@ public class ApiClient {
}
/*
Format to {@code QueryParam} objects.
Format to {@code Pair} objects.
*/
public Set<QueryParam> parameterToQueryParams(String collectionFormat, String name, Object value){
Set<QueryParam> params = new HashSet<QueryParam>();
public Set<Pair> parameterToQueryParams(String collectionFormat, String name, Object value){
Set<Pair> params = new HashSet<Pair>();
// preconditions
if (name == null || name.isEmpty() || value == null) return params;
@ -255,7 +255,7 @@ public class ApiClient {
}
if (valueCollection == null) {
params.add(new QueryParam(name, String.valueOf(value)));
params.add(new Pair(name, String.valueOf(value)));
return params;
} else if (valueCollection.isEmpty()) {
return params;
@ -264,10 +264,10 @@ public class ApiClient {
collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv
if (collectionFormat.equals("csv")) {
params.add(new QueryParam(name, parameterToString(value)));
params.add(new Pair(name, parameterToString(value)));
} else if (collectionFormat.equals("multi")) {
for (String item : valueCollection) {
params.add(new QueryParam(name, item));
params.add(new Pair(name, item));
}
} else if (collectionFormat.equals("ssv")) {
StringBuilder sb = new StringBuilder() ;
@ -275,21 +275,21 @@ public class ApiClient {
sb.append(" ");
sb.append(item);
}
params.add(new QueryParam(name, sb.substring(1)));
params.add(new Pair(name, sb.substring(1)));
} else if (collectionFormat.equals("tsv")) {
StringBuilder sb = new StringBuilder() ;
for (String item : valueCollection) {
sb.append("\t");
sb.append(item);
}
params.add(new QueryParam(name, sb.substring(1)));
params.add(new Pair(name, sb.substring(1)));
} else if (collectionFormat.equals("pipes")) {
StringBuilder sb = new StringBuilder() ;
for (String item : valueCollection) {
sb.append("|");
sb.append(item);
}
params.add(new QueryParam(name, sb.substring(1)));
params.add(new Pair(name, sb.substring(1)));
}
return params;
@ -398,7 +398,7 @@ public class ApiClient {
* @param authNames The authentications to apply
* @return The response body in type of string
*/
public String invokeAPI(String path, String method, Set<QueryParam> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String accept, String contentType, String[] authNames) throws ApiException {
public String invokeAPI(String path, String method, Set<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String accept, String contentType, String[] authNames) throws ApiException {
updateParamsForAuth(authNames, queryParams, headerParams);
Client client = getClient();
@ -406,7 +406,7 @@ public class ApiClient {
StringBuilder b = new StringBuilder();
b.append("?");
if (queryParams != null){
for (QueryParam queryParam : queryParams){
for (Pair queryParam : queryParams){
if (!queryParam.getName().isEmpty()) {
b.append(escapeString(queryParam.getName()));
b.append("=");
@ -516,7 +516,7 @@ public class ApiClient {
*
* @param authNames The authentications to apply
*/
private void updateParamsForAuth(String[] authNames, Set<QueryParam> queryParams, Map<String, String> headerParams) {
private void updateParamsForAuth(String[] authNames, Set<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

@ -1,10 +1,10 @@
package {{invokerPackage}};
public class QueryParam {
public class Pair {
private String name = "";
private String value = "";
public QueryParam(String name, String value) {
public Pair (String name, String value) {
setName(name);
setValue(value);
}

View File

@ -3,7 +3,7 @@ package {{package}};
import {{invokerPackage}}.ApiException;
import {{invokerPackage}}.ApiClient;
import {{invokerPackage}}.Configuration;
import {{invokerPackage}}.QueryParam;
import {{invokerPackage}}.Pair;
import {{modelPackage}}.*;
@ -62,7 +62,7 @@ public class {{classname}} {
.replaceAll("\\{" + "{{paramName}}" + "\\}", apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}};
// query params
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();

View File

@ -1,6 +1,6 @@
package {{invokerPackage}}.auth;
import {{invokerPackage}}.QueryParam;
import {{invokerPackage}}.Pair;
import java.util.Map;
import java.util.Set;
@ -42,7 +42,7 @@ public class ApiKeyAuth implements Authentication {
}
@Override
public void applyToParams(Set<QueryParam> queryParams, Map<String, String> headerParams) {
public void applyToParams(Set<Pair> queryParams, Map<String, String> headerParams) {
String value;
if (apiKeyPrefix != null) {
value = apiKeyPrefix + " " + apiKey;
@ -50,7 +50,7 @@ public class ApiKeyAuth implements Authentication {
value = apiKey;
}
if (location == "query") {
queryParams.add(new QueryParam(paramName, value));
queryParams.add(new Pair(paramName, value));
} else if (location == "header") {
headerParams.put(paramName, value);
}

View File

@ -1,11 +1,11 @@
package {{invokerPackage}}.auth;
import {{invokerPackage}}.QueryParam;
import {{invokerPackage}}.Pair;
import java.util.Map;
import java.util.Set;
public interface Authentication {
/** Apply authentication settings to header and query params. */
void applyToParams(Set<QueryParam> queryParams, Map<String, String> headerParams);
void applyToParams(Set<Pair> queryParams, Map<String, String> headerParams);
}

View File

@ -1,6 +1,6 @@
package {{invokerPackage}}.auth;
import {{invokerPackage}}.QueryParam;
import {{invokerPackage}}.Pair;
import java.util.Map;
import java.util.Set;
@ -29,7 +29,7 @@ public class HttpBasicAuth implements Authentication {
}
@Override
public void applyToParams(Set<QueryParam> queryParams, Map<String, String> headerParams) {
public void applyToParams(Set<Pair> queryParams, Map<String, String> headerParams) {
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
try {
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8")));

View File

@ -1,13 +1,13 @@
package {{invokerPackage}}.auth;
import {{invokerPackage}}.QueryParam;
import {{invokerPackage}}.Pair;
import java.util.Map;
import java.util.Set;
public class OAuth implements Authentication {
@Override
public void applyToParams(Set<QueryParam> queryParams, Map<String, String> headerParams) {
public void applyToParams(Set<Pair> queryParams, Map<String, String> headerParams) {
// TODO: support oauth
}
}

View File

@ -240,10 +240,10 @@ public class ApiClient {
}
/*
Format to {@code QueryParam} objects.
Format to {@code Pair} objects.
*/
public Set<QueryParam> parameterToQueryParams(String collectionFormat, String name, Object value){
Set<QueryParam> params = new HashSet<QueryParam>();
public Set<Pair> parameterToQueryParams(String collectionFormat, String name, Object value){
Set<Pair> params = new HashSet<Pair>();
// preconditions
if (name == null || name.isEmpty() || value == null) return params;
@ -254,7 +254,7 @@ public class ApiClient {
}
if (valueCollection == null) {
params.add(new QueryParam(name, String.valueOf(value)));
params.add(new Pair(name, String.valueOf(value)));
return params;
} else if (valueCollection.isEmpty()) {
return params;
@ -263,10 +263,10 @@ public class ApiClient {
collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv
if (collectionFormat.equals("csv")) {
params.add(new QueryParam(name, parameterToString(value)));
params.add(new Pair(name, parameterToString(value)));
} else if (collectionFormat.equals("multi")) {
for (String item : valueCollection) {
params.add(new QueryParam(name, item));
params.add(new Pair(name, item));
}
} else if (collectionFormat.equals("ssv")) {
StringBuilder sb = new StringBuilder() ;
@ -274,21 +274,21 @@ public class ApiClient {
sb.append(" ");
sb.append(item);
}
params.add(new QueryParam(name, sb.substring(1)));
params.add(new Pair(name, sb.substring(1)));
} else if (collectionFormat.equals("tsv")) {
StringBuilder sb = new StringBuilder() ;
for (String item : valueCollection) {
sb.append("\t");
sb.append(item);
}
params.add(new QueryParam(name, sb.substring(1)));
params.add(new Pair(name, sb.substring(1)));
} else if (collectionFormat.equals("pipes")) {
StringBuilder sb = new StringBuilder() ;
for (String item : valueCollection) {
sb.append("|");
sb.append(item);
}
params.add(new QueryParam(name, sb.substring(1)));
params.add(new Pair(name, sb.substring(1)));
}
return params;
@ -397,7 +397,7 @@ public class ApiClient {
* @param authNames The authentications to apply
* @return The response body in type of string
*/
public String invokeAPI(String path, String method, Set<QueryParam> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String accept, String contentType, String[] authNames) throws ApiException {
public String invokeAPI(String path, String method, Set<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String accept, String contentType, String[] authNames) throws ApiException {
updateParamsForAuth(authNames, queryParams, headerParams);
Client client = getClient();
@ -405,7 +405,7 @@ public class ApiClient {
StringBuilder b = new StringBuilder();
b.append("?");
if (queryParams != null){
for (QueryParam queryParam : queryParams){
for (Pair queryParam : queryParams){
if (!queryParam.getName().isEmpty()) {
b.append(escapeString(queryParam.getName()));
b.append("=");
@ -515,7 +515,7 @@ public class ApiClient {
*
* @param authNames The authentications to apply
*/
private void updateParamsForAuth(String[] authNames, Set<QueryParam> queryParams, Map<String, String> headerParams) {
private void updateParamsForAuth(String[] authNames, Set<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

@ -1,10 +1,10 @@
package io.swagger.client;
public class QueryParam {
public class Pair {
private String name = "";
private String value = "";
public QueryParam(String name, String value) {
public Pair (String name, String value) {
setName(name);
setValue(value);
}

View File

@ -3,7 +3,7 @@ package io.swagger.client.api;
import io.swagger.client.ApiException;
import io.swagger.client.ApiClient;
import io.swagger.client.Configuration;
import io.swagger.client.QueryParam;
import io.swagger.client.Pair;
import io.swagger.client.model.*;
@ -55,7 +55,7 @@ public class PetApi {
String path = "/pet".replaceAll("\\{format\\}","json");
// query params
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
@ -112,7 +112,7 @@ public class PetApi {
String path = "/pet".replaceAll("\\{format\\}","json");
// query params
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
@ -169,7 +169,7 @@ public class PetApi {
String path = "/pet/findByStatus".replaceAll("\\{format\\}","json");
// query params
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
@ -228,7 +228,7 @@ public class PetApi {
String path = "/pet/findByTags".replaceAll("\\{format\\}","json");
// query params
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
@ -293,7 +293,7 @@ public class PetApi {
.replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString()));
// query params
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
@ -358,7 +358,7 @@ public class PetApi {
.replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString()));
// query params
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
@ -436,7 +436,7 @@ public class PetApi {
.replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString()));
// query params
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
@ -503,7 +503,7 @@ public class PetApi {
.replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString()));
// query params
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();

View File

@ -3,7 +3,7 @@ package io.swagger.client.api;
import io.swagger.client.ApiException;
import io.swagger.client.ApiClient;
import io.swagger.client.Configuration;
import io.swagger.client.QueryParam;
import io.swagger.client.Pair;
import io.swagger.client.model.*;
@ -54,7 +54,7 @@ public class StoreApi {
String path = "/store/inventory".replaceAll("\\{format\\}","json");
// query params
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
@ -111,7 +111,7 @@ public class StoreApi {
String path = "/store/order".replaceAll("\\{format\\}","json");
// query params
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
@ -174,7 +174,7 @@ public class StoreApi {
.replaceAll("\\{" + "orderId" + "\\}", apiClient.escapeString(orderId.toString()));
// query params
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
@ -237,7 +237,7 @@ public class StoreApi {
.replaceAll("\\{" + "orderId" + "\\}", apiClient.escapeString(orderId.toString()));
// query params
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();

View File

@ -3,7 +3,7 @@ package io.swagger.client.api;
import io.swagger.client.ApiException;
import io.swagger.client.ApiClient;
import io.swagger.client.Configuration;
import io.swagger.client.QueryParam;
import io.swagger.client.Pair;
import io.swagger.client.model.*;
@ -55,7 +55,7 @@ public class UserApi {
String path = "/user".replaceAll("\\{format\\}","json");
// query params
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
@ -112,7 +112,7 @@ public class UserApi {
String path = "/user/createWithArray".replaceAll("\\{format\\}","json");
// query params
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
@ -169,7 +169,7 @@ public class UserApi {
String path = "/user/createWithList".replaceAll("\\{format\\}","json");
// query params
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
@ -227,7 +227,7 @@ public class UserApi {
String path = "/user/login".replaceAll("\\{format\\}","json");
// query params
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
@ -287,7 +287,7 @@ public class UserApi {
String path = "/user/logout".replaceAll("\\{format\\}","json");
// query params
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
@ -350,7 +350,7 @@ public class UserApi {
.replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(username.toString()));
// query params
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
@ -414,7 +414,7 @@ public class UserApi {
.replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(username.toString()));
// query params
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
@ -477,7 +477,7 @@ public class UserApi {
.replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(username.toString()));
// query params
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();

View File

@ -1,6 +1,6 @@
package io.swagger.client.auth;
import io.swagger.client.QueryParam;
import io.swagger.client.Pair;
import java.util.Map;
import java.util.Set;
@ -42,7 +42,7 @@ public class ApiKeyAuth implements Authentication {
}
@Override
public void applyToParams(Set<QueryParam> queryParams, Map<String, String> headerParams) {
public void applyToParams(Set<Pair> queryParams, Map<String, String> headerParams) {
String value;
if (apiKeyPrefix != null) {
value = apiKeyPrefix + " " + apiKey;
@ -50,7 +50,7 @@ public class ApiKeyAuth implements Authentication {
value = apiKey;
}
if (location == "query") {
queryParams.add(new QueryParam(paramName, value));
queryParams.add(new Pair(paramName, value));
} else if (location == "header") {
headerParams.put(paramName, value);
}

View File

@ -1,11 +1,11 @@
package io.swagger.client.auth;
import io.swagger.client.QueryParam;
import io.swagger.client.Pair;
import java.util.Map;
import java.util.Set;
public interface Authentication {
/** Apply authentication settings to header and query params. */
void applyToParams(Set<QueryParam> queryParams, Map<String, String> headerParams);
void applyToParams(Set<Pair> queryParams, Map<String, String> headerParams);
}

View File

@ -1,6 +1,6 @@
package io.swagger.client.auth;
import io.swagger.client.QueryParam;
import io.swagger.client.Pair;
import java.util.Map;
import java.util.Set;
@ -29,7 +29,7 @@ public class HttpBasicAuth implements Authentication {
}
@Override
public void applyToParams(Set<QueryParam> queryParams, Map<String, String> headerParams) {
public void applyToParams(Set<Pair> queryParams, Map<String, String> headerParams) {
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
try {
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8")));

View File

@ -1,13 +1,13 @@
package io.swagger.client.auth;
import io.swagger.client.QueryParam;
import io.swagger.client.Pair;
import java.util.Map;
import java.util.Set;
public class OAuth implements Authentication {
@Override
public void applyToParams(Set<QueryParam> queryParams, Map<String, String> headerParams) {
public void applyToParams(Set<Pair> queryParams, Map<String, String> headerParams) {
// TODO: support oauth
}
}

View File

@ -5,7 +5,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import io.swagger.client.QueryParam;
import io.swagger.client.Pair;
import org.junit.*;
import static org.junit.Assert.*;
@ -13,7 +13,7 @@ import static org.junit.Assert.*;
public class ApiKeyAuthTest {
@Test
public void testApplyToParamsInQuery() {
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
ApiKeyAuth auth = new ApiKeyAuth("query", "api_key");
@ -21,7 +21,7 @@ public class ApiKeyAuthTest {
auth.applyToParams(queryParams, headerParams);
assertEquals(1, queryParams.size());
for (QueryParam queryParam : queryParams) {
for (Pair queryParam : queryParams) {
assertEquals("my-api-key", queryParam.getValue());
}
@ -31,7 +31,7 @@ public class ApiKeyAuthTest {
@Test
public void testApplyToParamsInHeaderWithPrefix() {
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
ApiKeyAuth auth = new ApiKeyAuth("header", "X-API-TOKEN");

View File

@ -5,7 +5,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import io.swagger.client.QueryParam;
import io.swagger.client.Pair;
import org.junit.*;
import static org.junit.Assert.*;
@ -20,7 +20,7 @@ public class HttpBasicAuthTest {
@Test
public void testApplyToParams() {
Set<QueryParam> queryParams = new HashSet<QueryParam>();
Set<Pair> queryParams = new HashSet<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
auth.setUsername("my-username");