Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: intuit/Tank
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3.3.0
Choose a base ref
...
head repository: intuit/Tank
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
Showing 739 changed files with 17,714 additions and 56,748 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ agent/apiharness/settings.xml
data_model/settings.xml
data_access/settings.xml
rest-mvc/settings.xml
rest-mvc/impl/settings.xml
wats_common/settings.xml
wats_vmManager/settings.xml
web/web_support/settings.xml
@@ -41,7 +42,7 @@ tank_vmManager/settings.xml
tank.mwb
agent/http_client_3/settings.xml
agent/http_client_4/settings.xml
agent/ok_http_client/settings.xml
agent/http_client_jdk/settings.xml

# Byte-compiled / optimized / DLL files
__pycache__/
14 changes: 5 additions & 9 deletions agent/agent_common/pom.xml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
<parent>
<groupId>com.intuit.tank</groupId>
<artifactId>agent-parent</artifactId>
<version>3.3.0</version>
<version>4.1.1-SNAPSHOT</version>
</parent>

<artifactId>agent-common</artifactId>
@@ -15,23 +15,19 @@


<dependencies>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>api</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>

<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
<artifactId>jdom2</artifactId>
</dependency>

<dependency>
<groupId>jakarta.xml.ws</groupId>
<artifactId>jakarta.xml.ws-api</artifactId>
Original file line number Diff line number Diff line change
@@ -171,6 +171,16 @@ public void doPost(BaseResponse response) {

}

/**
* Execute the PATCH.
*/
public void doPatch(BaseResponse response) {
this.response = response;
requestUrl = TankHttpUtil.buildUrl(protocol, host, port, path, urlVariables).toString();
httpclient.doPatch(this);

}

/**
* Set as value in the request
*
@@ -215,11 +225,11 @@ public void addURLVariable(String name, String value) {
}

public void addHeader(String key, String value) {
this.headerInformation.put(key, value);
this.headerInformation.put(key.toLowerCase(), value);
}

public void removeHeader(String key) {
this.headerInformation.remove(key);
this.headerInformation.remove(key.toLowerCase());
}

/**
@@ -310,6 +320,9 @@ public void setTimestamp(Date date) {
this.timestamp = date;
}

public void setContentTypeCharSet(String contentTypeCharSet) {
this.contentTypeCharSet = contentTypeCharSet;
}
public String getContentTypeCharSet() {
return contentTypeCharSet;
}
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ public abstract class BaseResponse {

protected String response;
protected long responseTime = -1;
protected long proxyResponseTime = -1;
protected int httpCode = -1;
protected String rspMessage = "";
protected HashMap<String, String> headers = new HashMap<String, String>();
@@ -47,9 +48,51 @@ public abstract class BaseResponse {
* @return the responseLogMsg
*/
public String getLogMsg() {
try {
StringBuilder sb = new StringBuilder();
sb.append("RESPONSE HTTP CODE: ").append(this.httpCode).append(NEWLINE)
.append("RESPONSE HTTP MSG: ").append(this.rspMessage).append(NEWLINE)
.append("RESPONSE TIME: ").append(responseTime).append(NEWLINE)
.append("PROXY RESPONSE TIME: ").append(proxyResponseTime).append(NEWLINE)
.append("RESPONSE SIZE: ").append(getResponseSize()).append(NEWLINE);
for (Entry<String, String> mapEntry : headers.entrySet()) {
sb.append("RESPONSE HEADER: ")
.append(mapEntry.getKey()).append(" = ")
.append(mapEntry.getValue()).append(NEWLINE);
}
for (Entry<String, String> entry : cookies.entrySet()) {
sb.append("RESPONSE COOKIE: ")
.append(entry.getKey()).append(" = ")
.append(entry.getValue()).append(NEWLINE);
}
if (response != null) {
String contentType = this.headers.get("content-type");
if (isDataType(contentType)) {
sb.append("RESPONSE BODY: ").append(this.response).append(NEWLINE);
} else {
sb.append("RESPONSE BODY: not logged because ")
.append(contentType).append(" is not a content-type.").append(NEWLINE);
}
}
this.responseLogMsg = sb.toString();
} catch (Exception ex) {
LOG.error("Error processing response: {}", ex.getMessage(), ex);
}
return responseLogMsg;
}

public String convertToCSV() {
StringBuilder sb = new StringBuilder();
sb.append(this.httpCode).append(",");
sb.append(this.rspMessage).append(",");
sb.append(responseTime).append(",");
sb.append(proxyResponseTime).append(",");
sb.append(getResponseSize()).append(",");
headers.forEach((key, value) -> sb.append(key).append(" = ").append(value.replace(",", "")).append(","));
cookies.forEach((key, value) -> sb.append(key).append(" = ").append(value).append(","));
return sb.toString();
}

/**
* Common codes are 200 OK, 202 accepted, 204 no content, 400 bad request,
* 404 not found, 500 internal server error, 503 Service Unavailable
@@ -70,7 +113,7 @@ public void setHttpMessage(String msg) {
}

public void setHeader(String key, String value) {
this.headers.put(key, value);
this.headers.put(key.toLowerCase(), value);
}

/**
@@ -89,7 +132,7 @@ public String getHttpMsg() {
* @return The value associated with the key, or null if it doesn't exist.
*/
public String getHttpHeader(String header) {
return this.headers.get(header);
return this.headers.get(header.toLowerCase());
}

/**
@@ -131,6 +174,14 @@ public void setResponseBody(String body) {
this.response = body;
}

public long getProxyResponseTime() {
return this.proxyResponseTime;
}

public void setProxyResponseTime(long proxyResponseTime) {
this.proxyResponseTime = proxyResponseTime;
}

/**
*
* @param byteArray
@@ -180,51 +231,17 @@ public int getResponseSize() {
* header
*/
public String getCookie(String key) {
return cookies.get(key);
return cookies.get(key.toLowerCase());
}

public void setCookie(String key, String value) {
this.cookies.put(key, value);
this.cookies.put(key.toLowerCase(), value);
}

public Map<String, String> getCookies() {
return cookies;
}

/**
* Log the response object
*/
public void logResponse() {
try {
StringBuilder sb = new StringBuilder();
// System.out.println("******** RESPONSE ***********");
sb.append("RESPONSE HTTP CODE: " + this.httpCode).append(NEWLINE);
sb.append("RESPONSE HTTP MSG: " + this.rspMessage).append(NEWLINE);
sb.append("RESPONSE TIME: " + responseTime).append(NEWLINE);
sb.append("RESPONSE SIZE: " + getResponseSize()).append(NEWLINE);
for (Entry<String, String> mapEntry : headers.entrySet()) {
sb.append("RESPONSE HEADER: " + (String) mapEntry.getKey() + " = " + (String) mapEntry.getValue()).append(NEWLINE);
}
for (Entry<String, String> entry : cookies.entrySet()) {
sb.append("RESPONSE COOKIE: " + entry.getKey() + " = " + entry.getValue()).append(NEWLINE);
}
if (response != null) {
String contentType = this.headers.get("Content-Type");
if (isDataType(contentType)) {
sb.append("RESPONSE BODY: " + this.response).append(NEWLINE);
} else {
sb.append("RESPONSE BODY: not logged because " + contentType + " is not a data type.").append(NEWLINE);
}
}
this.responseLogMsg = sb.toString();
LOG.debug("******** RESPONSE ***********");
LOG.debug(this.responseLogMsg);

} catch (Exception ex) {
LOG.error("Error processing response: " + ex.getMessage(), ex);
}
}

public static final boolean isDataType(String contentType) {
if (!StringUtils.isBlank(contentType)) {
contentType = contentType.toLowerCase();
Original file line number Diff line number Diff line change
@@ -38,6 +38,13 @@ public interface TankHttpClient {
*/
public void doPost(BaseRequest request);

/**
* Execute the PATCH.
*
* @param request
*/
public void doPatch(BaseRequest request);

/**
* Adds the authentication
*
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
@@ -52,18 +51,13 @@ public static String getQueryString(Map<String, String> urlVariables) {
if (urlVariables != null && !urlVariables.isEmpty()) {
return "?" + urlVariables.entrySet().stream()
.map(entry -> {
try {
if (StringUtils.isBlank(entry.getValue())) {
return URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8.name());
} else {
return URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8.name())
+ "="
+ URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.name());
}
} catch (UnsupportedEncodingException ex) {
LOG.warn("Unable to set query string value: " + ex.getMessage());
if (StringUtils.isBlank(entry.getValue())) {
return URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8);
} else {
return URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8)
+ "="
+ URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8);
}
return "";
})
.collect(joining("&"));
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.intuit.tank.http.soap;

import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import jakarta.xml.soap.MessageFactory;
import jakarta.xml.soap.SOAPBody;
import jakarta.xml.soap.SOAPEnvelope;
import jakarta.xml.soap.SOAPMessage;
import jakarta.xml.soap.SOAPPart;

/*
* #%L
Original file line number Diff line number Diff line change
@@ -2,7 +2,10 @@

import org.junit.jupiter.api.Test;

import java.util.*;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;

@@ -65,8 +68,7 @@ public void testGetNullHttpclient() {
public void testGetHeaderInformation() {
BaseRequest fixture = new MockBaseRequest(null);
Map<String, String> headerInformation = fixture.getHeaderInformation();
Map<String, String> expected = new HashMap<String, String>();
assertEquals(expected, headerInformation);
assertEquals(Map.of(), headerInformation);
}

@Test
@@ -138,36 +140,32 @@ public void testDoPost() {
public void testAddURLVariable() {
BaseRequest fixture = new MockBaseRequest(null);
fixture.addURLVariable("testKey", "testValue");
Map<String, String> urlVariable = new HashMap<String, String>();
urlVariable.put("testKey", "testValue");
Map<String, String> urlVariable = Map.of("testKey", "testValue");
assertEquals(urlVariable, fixture.urlVariables);
}

@Test
public void testRemoveURLVariable() {
BaseRequest fixture = new MockBaseRequest(null);
fixture.addURLVariable("testKey", "testValue");
Map<String, String> urlVariable = new HashMap<String, String>();
fixture.removeURLVariable("testKey");
assertEquals(urlVariable, fixture.urlVariables);
assertEquals(Map.of(), fixture.urlVariables);
}

@Test
public void testAddHeader() {
BaseRequest fixture = new MockBaseRequest(null);
fixture.addHeader("testKey", "testValue");
Map<String, String> header = new HashMap<String, String>();
header.put("testKey", "testValue");
Map<String, String> header = Map.of("testKey".toLowerCase(), "testValue");
assertEquals(header, fixture.headerInformation);
}

@Test
public void testRemoveHeader() {
BaseRequest fixture = new MockBaseRequest(null);
fixture.addHeader("testKey", "testValue");
Map<String, String> header = new HashMap<String, String>();
fixture.removeHeader("testKey");
assertEquals(header, fixture.headerInformation);
assertEquals(Map.of(), fixture.headerInformation);
}

@Test
@@ -243,10 +241,8 @@ public void testGetReqQueryString() {
@Test
public void testLogRequest() {
BaseRequest fixture = new MockBaseRequest(null);
Map <String, String> headerInformation = new HashMap<>();
headerInformation.put("testHeaderKey", "testHeaderValue");
List <String> cookies = new ArrayList<>();
cookies.add("testCookie");
Map <String, String> headerInformation = Map.of("testHeaderKey", "testHeaderValue");
List<String> cookies = List.of("testCookie");
fixture.logRequest("testUrl", "testBody", "testMethod", headerInformation,
cookies, false);
assertEquals("REQUEST URL: testMethod testUrl\n" +
@@ -262,6 +258,10 @@ public void testGetContentTypeCharSet() {
BaseRequest fixture = new MockBaseRequest(null);
String contentTypeCharSet = fixture.getContentTypeCharSet();
assertEquals("UTF-8", contentTypeCharSet);

fixture.setContentTypeCharSet(StandardCharsets.UTF_16.toString());
contentTypeCharSet = fixture.getContentTypeCharSet();
assertEquals("UTF-16", contentTypeCharSet);
}

@Test
Loading