Skip to content

Commit d99c701

Browse files
Release 3.0.1 - Jacoco Report Aggregator
* tankIcon for tools * async clients for metrics * remove empty module * reduce dependency * Fix ArrayOutOfBoundsException * Use InBuilt HttpServer * async httpclient5 * jacoco-report-aggregator
1 parent 0cad65f commit d99c701

File tree

147 files changed

+1042
-1160
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+1042
-1160
lines changed

agent/agent_common/pom.xml

+1-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.intuit.tank</groupId>
77
<artifactId>agent-parent</artifactId>
8-
<version>3.0.0</version>
8+
<version>3.0.1</version>
99
</parent>
1010

1111
<artifactId>agent-common</artifactId>
@@ -27,11 +27,6 @@
2727
<artifactId>commons-fileupload</artifactId>
2828
</dependency>
2929

30-
<dependency>
31-
<groupId>com.googlecode.json-simple</groupId>
32-
<artifactId>json-simple</artifactId>
33-
</dependency>
34-
3530
<dependency>
3631
<groupId>org.jdom</groupId>
3732
<artifactId>jdom</artifactId>

agent/agent_common/src/main/java/com/intuit/tank/http/BaseRequest.java

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.intuit.tank.http;
22

3+
import java.nio.charset.StandardCharsets;
34
import java.util.Date;
45
import java.util.HashMap;
56
import java.util.List;
67
import java.util.Map;
78

89
import javax.net.ssl.SSLContext;
910

11+
import org.apache.commons.lang3.StringUtils;
1012
import org.apache.logging.log4j.LogManager;
1113
import org.apache.logging.log4j.Logger;
1214

@@ -26,8 +28,9 @@ public abstract class BaseRequest {
2628
protected int port = -1;
2729
protected String path = "/";
2830
protected String contentType = "application/x-www-form-urlencoded";
29-
protected String contentTypeCharSet = "UTF-8";
31+
protected String contentTypeCharSet = StandardCharsets.UTF_8.toString();
3032
protected String requestUrl;
33+
private boolean async = false;
3134

3235
protected HashMap<String, String> headerInformation = null;
3336
protected HashMap<String, String> urlVariables = null;
@@ -95,8 +98,6 @@ public void setContentType(String contentType) {
9598
this.contentType = contentType;
9699
}
97100

98-
99-
100101
public TankHttpClient getHttpclient() {
101102
return httpclient;
102103
}
@@ -288,11 +289,11 @@ public void logRequest(String url, String body, String method, Map<String, Strin
288289
}
289290
// Cookies Information
290291
if (cookies != null) {
291-
for (String c : cookies) {
292-
sb.append(c).append(NEWLINE);
292+
for (String cookie : cookies) {
293+
sb.append(cookie).append(NEWLINE);
293294
}
294295
}
295-
if (null != body) {
296+
if (StringUtils.isNotEmpty(body)) {
296297
sb.append("REQUEST SIZE: " + body.getBytes().length).append(NEWLINE);
297298
sb.append("REQUEST BODY: " + body).append(NEWLINE);
298299
}
@@ -313,4 +314,11 @@ public String getContentTypeCharSet() {
313314
return contentTypeCharSet;
314315
}
315316

317+
public void setAsync(boolean async) {
318+
this.async = async;
319+
}
320+
public boolean getAsync() {
321+
return async;
322+
}
323+
316324
}

agent/agent_common/src/main/java/com/intuit/tank/http/BaseResponse.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public void logResponse() {
201201
sb.append("RESPONSE HTTP CODE: " + this.httpCode).append(NEWLINE);
202202
sb.append("RESPONSE HTTP MSG: " + this.rspMessage).append(NEWLINE);
203203
sb.append("RESPONSE TIME: " + responseTime).append(NEWLINE);
204-
sb.append("RESPONSE SIZE: " + responseByteArray.length).append(NEWLINE);
204+
sb.append("RESPONSE SIZE: " + getResponseSize()).append(NEWLINE);
205205
for (Entry<String, String> mapEntry : headers.entrySet()) {
206206
sb.append("RESPONSE HEADER: " + (String) mapEntry.getKey() + " = " + (String) mapEntry.getValue()).append(NEWLINE);
207207
}

agent/agent_common/src/main/java/com/intuit/tank/http/json/JsonResponse.java

+7-28
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,19 @@
1313
* #L%
1414
*/
1515

16+
import java.io.IOException;
1617
import java.net.URLDecoder;
18+
import java.nio.charset.StandardCharsets;
1719
import java.util.HashMap;
18-
import java.util.LinkedHashMap;
19-
import java.util.LinkedList;
20-
import java.util.List;
2120
import java.util.Map;
2221

22+
import com.fasterxml.jackson.databind.ObjectMapper;
2323
import org.apache.commons.jxpath.JXPathContext;
2424
import org.apache.commons.lang3.StringUtils;
2525
import org.apache.commons.lang3.math.NumberUtils;
2626
import org.apache.logging.log4j.LogManager;
2727
import org.apache.logging.log4j.Logger;
2828
import org.json.JSONObject;
29-
import org.json.simple.parser.ContainerFactory;
30-
import org.json.simple.parser.JSONParser;
3129

3230
import com.intuit.tank.http.BaseResponse;
3331

@@ -65,16 +63,15 @@ public String getValue(String key) {
6563
JSONObject jsonResponse = new JSONObject(this.response);
6664
return (String) jsonResponse.get(key);
6765
}
68-
} catch (Exception e) {
69-
}
66+
} catch (Exception e) { }
7067
try {
7168
if (this.jsonMap == null) {
7269
initialize();
7370
}
7471
String keyTrans = key.replace("@", "");
7572
// note that indexing is 1 based not zero based
7673
JXPathContext context = JXPathContext.newContext(this.jsonMap);
77-
String output = URLDecoder.decode(String.valueOf(context.getValue(keyTrans)), "UTF-8");
74+
String output = URLDecoder.decode(String.valueOf(context.getValue(keyTrans)), StandardCharsets.UTF_8);
7875
if (output.equalsIgnoreCase("null"))
7976
return "";
8077
return output;
@@ -92,32 +89,14 @@ private String cleanString(String input) {
9289
}
9390
}
9491

95-
@SuppressWarnings({ "rawtypes", "unchecked" })
9692
private void initialize() {
97-
9893
try {
99-
JSONParser parser = new JSONParser();
100-
ContainerFactory containerFactory = new ContainerFactory() {
101-
public List creatArrayContainer() {
102-
return new LinkedList();
103-
}
104-
105-
public Map createObjectContainer() {
106-
return new LinkedHashMap();
107-
}
108-
};
10994
if (!StringUtils.isEmpty(this.response)) {
110-
Object parse = parser.parse(this.response, containerFactory);
111-
if (parse instanceof List) {
112-
this.jsonMap = new LinkedHashMap();
113-
} else {
114-
this.jsonMap = (Map) parse;
115-
}
116-
this.jsonMap.put("root", parse);
95+
this.jsonMap = new ObjectMapper().readValue(this.response, HashMap.class);
11796
} else {
11897
this.jsonMap = new HashMap();
11998
}
120-
} catch (Exception ex) {
99+
} catch (IOException ex) {
121100
logger.warn("Unable to parse the response string as a JSON object: " + this.response, ex);
122101
}
123102
}

agent/agent_standalone/pom.xml

+1-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.intuit.tank</groupId>
77
<artifactId>agent-parent</artifactId>
8-
<version>3.0.0</version>
8+
<version>3.0.1</version>
99
</parent>
1010

1111
<artifactId>agent-standalone</artifactId>
@@ -25,18 +25,6 @@
2525
<artifactId>api</artifactId>
2626
<version>${project.version}</version>
2727
</dependency>
28-
29-
<dependency>
30-
<groupId>org.simpleframework</groupId>
31-
<artifactId>simple-http</artifactId>
32-
</dependency>
33-
34-
<dependency>
35-
<groupId>javax.mail</groupId>
36-
<artifactId>mail</artifactId>
37-
<scope>provided</scope>
38-
</dependency>
39-
4028
</dependencies>
4129

4230
</project>

agent/agent_standalone/src/main/java/com/intuit/tank/standalone/agent/CommandListener.java

+29-38
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515

1616
import java.io.IOException;
1717
import java.io.InputStream;
18-
import java.io.PrintStream;
18+
import java.io.OutputStream;
1919
import java.net.InetSocketAddress;
20-
import java.net.SocketAddress;
2120

2221
import javax.xml.bind.JAXBContext;
2322
import javax.xml.bind.JAXBException;
@@ -26,22 +25,20 @@
2625
import javax.xml.transform.Source;
2726
import javax.xml.transform.sax.SAXSource;
2827

28+
import com.sun.net.httpserver.Headers;
29+
import com.sun.net.httpserver.HttpContext;
30+
import com.sun.net.httpserver.HttpExchange;
31+
import com.sun.net.httpserver.HttpServer;
32+
import org.apache.http.protocol.HTTP;
2933
import org.apache.logging.log4j.LogManager;
3034
import org.apache.logging.log4j.Logger;
31-
import org.simpleframework.http.Request;
32-
import org.simpleframework.http.Response;
33-
import org.simpleframework.http.core.Container;
34-
import org.simpleframework.http.core.ContainerSocketProcessor;
35-
import org.simpleframework.transport.SocketProcessor;
36-
import org.simpleframework.transport.connect.Connection;
37-
import org.simpleframework.transport.connect.SocketConnection;
3835
import org.xml.sax.InputSource;
3936
import org.xml.sax.SAXException;
4037

4138
import com.intuit.tank.vm.agent.messages.StandaloneAgentRequest;
42-
import com.intuit.tank.vm.api.enumerated.WatsAgentCommand;
39+
import com.intuit.tank.vm.api.enumerated.AgentCommand;
4340

44-
public class CommandListener implements Container {
41+
public class CommandListener {
4542

4643
private static Logger LOG = LogManager.getLogger(CommandListener.class);
4744

@@ -54,12 +51,11 @@ public synchronized static void startHttpServer(int port, StandaloneAgentStartup
5451
if (!started) {
5552
agentStarter = standaloneAgentStartup;
5653
try {
57-
Container container = new CommandListener();
58-
SocketProcessor processor = new ContainerSocketProcessor(container);
59-
Connection connection = new SocketConnection(processor);
60-
SocketAddress address = new InetSocketAddress(port);
54+
HttpServer server = HttpServer.create(new InetSocketAddress(PORT), 0);
55+
HttpContext context = server.createContext("/");
56+
context.setHandler(CommandListener::handleRequest);
57+
server.start();
6158
System.out.println("Starting httpserver on port " + port);
62-
connection.connect(address);
6359
started = true;
6460
} catch (IOException e) {
6561
LOG.error("Error starting httpServer: " + e, e);
@@ -68,43 +64,38 @@ public synchronized static void startHttpServer(int port, StandaloneAgentStartup
6864
}
6965
}
7066

71-
@Override
72-
public void handle(Request req, Response response) {
67+
private static void handleRequest(HttpExchange exchange) {
7368
try {
74-
String msg = "unknown path";
69+
String response = "unknown path";
7570
int code = 200;
76-
String path = req.getPath().getPath();
77-
if (path.equals(WatsAgentCommand.request.getPath())) {
78-
msg = "Requesting users ";
79-
StandaloneAgentRequest agentRequest = getRequest(req.getInputStream());
71+
String path = exchange.getRequestURI().getPath();
72+
if (path.equals(AgentCommand.request.getPath())) {
73+
response = "Requesting users ";
74+
StandaloneAgentRequest agentRequest = getRequest(exchange.getRequestBody());
8075
if (agentRequest == null) {
81-
msg = "Invalid StandaloneAgentRequest.";
76+
response = "Invalid StandaloneAgentRequest.";
8277
code = 406;
8378
} else if (agentRequest.getJobId() != null && agentRequest.getUsers() > 0) {
8479
// launch the harness with the specified details.
8580
agentStarter.startTest(agentRequest);
8681
} else {
87-
msg = "invalid request.";
82+
response = "invalid request.";
8883
code = 400;
8984
}
9085
}
91-
long time = System.currentTimeMillis();
92-
response.setCode(code);
93-
response.setContentType("text/plain");
94-
response.setDescription("Intuit Tank Agent/2.3.0");
95-
response.setDate("Date", time);
96-
response.setDate("Last-Modified", time);
97-
98-
PrintStream body = response.getPrintStream();
99-
body.println(msg);
100-
body.close();
101-
} catch (Exception e) {
86+
exchange.getResponseHeaders().set(HTTP.CONTENT_TYPE, "text/plain");
87+
exchange.getResponseHeaders().set(HTTP.SERVER_HEADER,"Intuit Tank Agent/3.0.1");
88+
exchange.sendResponseHeaders(code, response.length());
89+
OutputStream os = exchange.getResponseBody();
90+
os.write(response.getBytes());
91+
os.close();
92+
exchange.close();
93+
} catch (SAXException| ParserConfigurationException | IOException e) {
10294
LOG.error("error sending response");
103-
response.setCode(500);
10495
}
10596
}
10697

107-
private StandaloneAgentRequest getRequest(InputStream inputStream) throws SAXException, ParserConfigurationException {
98+
private static StandaloneAgentRequest getRequest(InputStream inputStream) throws SAXException, ParserConfigurationException {
10899
try {
109100
//Source: https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Prevention_Cheat_Sheet#Unmarshaller
110101
SAXParserFactory spf = SAXParserFactory.newInstance();

agent/agent_standalone_pkg/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.intuit.tank</groupId>
77
<artifactId>agent-parent</artifactId>
8-
<version>3.0.0</version>
8+
<version>3.0.1</version>
99
</parent>
1010

1111
<artifactId>agent-standalone-pkg</artifactId>

agent/agent_startup/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.intuit.tank</groupId>
77
<artifactId>agent-parent</artifactId>
8-
<version>3.0.0</version>
8+
<version>3.0.1</version>
99
</parent>
1010

1111
<artifactId>agent-startup</artifactId>

agent/agent_startup/src/main/java/com/intuit/tank/agent/AgentStartup.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void run() {
8383
logger.error("Error unzipping support files : retryCount="
8484
+ retryCount + " : " + e.getMessage());
8585
if (retryCount < FIBONACCI.length) {
86-
Thread.sleep( FIBONACCI[++retryCount] * 1000 );
86+
Thread.sleep( FIBONACCI[retryCount++] * 1000 );
8787
} else throw e;
8888
}
8989
}

agent/agent_startup_pkg/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.intuit.tank</groupId>
77
<artifactId>agent-parent</artifactId>
8-
<version>3.0.0</version>
8+
<version>3.0.1</version>
99
</parent>
1010

1111
<artifactId>agent-startup-pkg</artifactId>

agent/apiharness/pom.xml

+4-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.intuit.tank</groupId>
77
<artifactId>agent-parent</artifactId>
8-
<version>3.0.0</version>
8+
<version>3.0.1</version>
99
</parent>
1010

1111
<artifactId>agent</artifactId>
@@ -65,19 +65,19 @@
6565

6666
<dependency>
6767
<groupId>${project.groupId}</groupId>
68-
<artifactId>http_client_commons_3</artifactId>
68+
<artifactId>http_client_apache_3</artifactId>
6969
<version>${project.version}</version>
7070
</dependency>
7171

7272
<dependency>
7373
<groupId>${project.groupId}</groupId>
74-
<artifactId>http_client_commons_4</artifactId>
74+
<artifactId>http_client_apache_4</artifactId>
7575
<version>${project.version}</version>
7676
</dependency>
7777

7878
<dependency>
7979
<groupId>${project.groupId}</groupId>
80-
<artifactId>http_client_commons_5</artifactId>
80+
<artifactId>http_client_apache_5</artifactId>
8181
<version>${project.version}</version>
8282
</dependency>
8383

@@ -86,10 +86,6 @@
8686
<artifactId>jaxb-impl</artifactId>
8787
<scope>runtime</scope>
8888
</dependency>
89-
<dependency>
90-
<groupId>org.simpleframework</groupId>
91-
<artifactId>simple-http</artifactId>
92-
</dependency>
9389
</dependencies>
9490

9591
</project>

0 commit comments

Comments
 (0)