Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions common/src/main/java/com/genexus/internet/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Location
private String proxyAuthenticationUser = "";
private String proxyAuthenticationRealm = "";
private String proxyAuthenticationPassword = "";
private String accessToken = "";
private IGXWSAddressing wsAddressing;
private IGXWSSecurity wsSecurity;
private String certificate = "";
Expand Down Expand Up @@ -120,7 +121,10 @@ public String getProxyAuthenticationPassword()
{
return proxyAuthenticationPassword;
}

public String getAccessToken()
{
return accessToken;
}
public IGXWSAddressing getWSAddressing()
{
return wsAddressing;
Expand Down Expand Up @@ -220,7 +224,9 @@ public void setProxyAuthenticationPassword(String authenticationPassword)
{
this.proxyAuthenticationPassword = authenticationPassword;
}


public void setAccessToken(String token) { this.accessToken = token; }

public void setWSAddressing(IGXWSAddressing wsAddressing)
{
this.wsAddressing = wsAddressing;
Expand Down
50 changes: 33 additions & 17 deletions java/src/main/java/com/genexus/internet/GXRestAPIClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public < T extends IGxJSONSerializable> T getBodyGeospatial(String varName, Clas
catch (Exception e) {
errorCode = DESERIALIZING_ERROR_CODE;
errorMessage = DESERIALIZING_ERROR_MSG;
logger.error(DESERIALIZING_ERROR_MSG + " " + sdtClass, e);
logError(DESERIALIZING_ERROR_CODE, DESERIALIZING_ERROR_MSG + " " + sdtClass, e);
return null;
}
}
Expand Down Expand Up @@ -342,13 +342,13 @@ else if (jsonResponse.length() == 1 && jsonResponse.has(""))
else {
errorCode = RESPONSE_ERROR_CODE;
errorMessage = RESPONSE_ERROR_MSG;
logger.error(RESPONSE_ERROR_MSG );
logError(RESPONSE_ERROR_CODE, RESPONSE_ERROR_MSG);
}
}
catch( JSONException e) {
errorCode = PARSING_ERROR_CODE;
errorMessage = PARSING_ERROR_MSG;
logger.error(PARSING_ERROR_MSG, e);
logError(PARSING_ERROR_CODE, PARSING_ERROR_MSG, e);
}
return jsonstr;
}
Expand Down Expand Up @@ -381,21 +381,21 @@ else if (jsonResponse.length()>= 1) {
{
errorCode = RESPONSE_ERROR_CODE;
errorMessage = RESPONSE_ERROR_MSG;
logger.error(RESPONSE_ERROR_MSG + " " + sdtClass);
logError( RESPONSE_ERROR_CODE, RESPONSE_ERROR_MSG + " " + sdtClass);
return null;
}
}
else {
errorCode = RESPONSE_ERROR_CODE;
errorMessage = RESPONSE_ERROR_MSG;
logger.error(RESPONSE_ERROR_MSG + " " + sdtClass);
logError( RESPONSE_ERROR_CODE,RESPONSE_ERROR_MSG + " " + sdtClass);
return null;
}
}
catch (json.org.json.JSONException e) {
errorCode = PARSING_ERROR_CODE;
errorMessage = PARSING_ERROR_MSG;
logger.error(PARSING_ERROR_MSG + " " + sdtClass, e);
logError(PARSING_ERROR_CODE, PARSING_ERROR_MSG + " " + sdtClass, e);
return null;
}
return sdt;
Expand Down Expand Up @@ -431,18 +431,18 @@ else if (jsonResponse.length() == 1 && jsonResponse.has(""))
else {
errorCode = RESPONSE_ERROR_CODE;
errorMessage = RESPONSE_ERROR_MSG;
logger.error(RESPONSE_ERROR_MSG + " " + elementClass);
logError(RESPONSE_ERROR_CODE,RESPONSE_ERROR_MSG + " " + elementClass);
}
}
catch (json.org.json.JSONException e) {
errorCode = PARSING_ERROR_CODE;
errorMessage = PARSING_ERROR_MSG;
logger.error(PARSING_ERROR_MSG + " " + elementClass ,e );
logError(PARSING_ERROR_CODE,PARSING_ERROR_MSG + " " + elementClass ,e );
}
catch (Exception e) {
errorCode = DESERIALIZING_ERROR_CODE;
errorMessage = DESERIALIZING_ERROR_MSG;
logger.error(DESERIALIZING_ERROR_MSG + " " + elementClass, e);
logError(DESERIALIZING_ERROR_CODE, DESERIALIZING_ERROR_MSG + " " + elementClass, e);
}
}

Expand All @@ -465,7 +465,7 @@ else if (jsonResponse.length() == 1 && jsonResponse.has("")) {
catch (json.org.json.JSONException e) {
errorCode = PARSING_ERROR_CODE;
errorMessage = PARSING_ERROR_MSG;
logger.error(PARSING_ERROR_MSG + " " + elementClasss, e);
logError(PARSING_ERROR_CODE,PARSING_ERROR_MSG + " " + elementClasss, e);
}
return coll;
}
Expand Down Expand Up @@ -500,17 +500,20 @@ public void RestExecute() {
httpClient.addHeader( "Content-Type", contentType);
}
else {
if (this.httpMethod == "POST" || this.httpMethod == "PUT") {
if (httpMethod == "POST" || httpMethod == "PUT") {
bodyString = "{}";
httpClient.addString(bodyString);
httpClient.addHeader("Content-Type", contentType);
}
}
String serviceuri = ((this.location.getSecure() > 0) ? "https" : "http") + "://" + this.location.getHost();
serviceuri += (this.location.getPort() != 80) ? ":" + Integer.toString(this.location.getPort()): "";
serviceuri += "/" + this.location.getBaseURL() + "/" + this.location.getResourceName();
if (location.getAuthenticationMethod() == 4 && location.getAccessToken() != null && ! location.getAccessToken().trim().isEmpty()) {
httpClient.addHeader("Authorization", location.getAccessToken());
}
String serviceuri = ((location.getSecure() > 0) ? "https" : "http") + "://" + location.getHost();
serviceuri += (location.getPort() != 80) ? ":" + Integer.toString(location.getPort()): "";
serviceuri += "/" + location.getBaseURL() + "/" + location.getResourceName();
serviceuri += queryString;
httpClient.execute( this.httpMethod, serviceuri);
httpClient.execute( httpMethod, serviceuri);

if (httpClient.getStatusCode() >= 300 || httpClient.getErrCode() > 0) {
errorCode = (httpClient.getErrCode() == 0)? 1 : httpClient.getErrCode();
Expand All @@ -520,14 +523,27 @@ public void RestExecute() {
else {
statusCode = httpClient.getStatusCode();
try {
jsonResponse = new JSONObject(httpClient.getString());
String response = httpClient.getString();
if (response.trim().startsWith("["))
{
// unwrapped list response
response = "{\"\":" + response + "}";
}
jsonResponse = new JSONObject(response);
}
catch( JSONException e) {
errorCode = PARSING_ERROR_CODE;
errorMessage = PARSING_ERROR_MSG;
logger.error(PARSING_ERROR_MSG, e);
logError(PARSING_ERROR_CODE, PARSING_ERROR_MSG, e);
jsonResponse = new JSONObject();
}
}
}

private void logError(int code, String msg) {
logger.error("Error: " + Integer.toString(code) + " " + msg);
}
private void logError(int code, String msg, Exception e) {
logger.error("Error: " + Integer.toString(code) + " " + msg, e);
}
}