Skip to content

Commit

Permalink
Release 3.0.1 - Jacoco Report Aggregator
Browse files Browse the repository at this point in the history
* tankIcon for tools
* async clients for metrics
* remove empty module
* reduce dependency
* Fix ArrayOutOfBoundsException
* Use InBuilt HttpServer
* async httpclient5
* jacoco-report-aggregator
  • Loading branch information
kevin-mcgoldrick authored Apr 13, 2021
1 parent 0cad65f commit d99c701
Show file tree
Hide file tree
Showing 147 changed files with 1,042 additions and 1,160 deletions.
7 changes: 1 addition & 6 deletions agent/agent_common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.intuit.tank</groupId>
<artifactId>agent-parent</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
</parent>

<artifactId>agent-common</artifactId>
Expand All @@ -27,11 +27,6 @@
<artifactId>commons-fileupload</artifactId>
</dependency>

<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
</dependency>

<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.intuit.tank.http;

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

import javax.net.ssl.SSLContext;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

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

protected HashMap<String, String> headerInformation = null;
protected HashMap<String, String> urlVariables = null;
Expand Down Expand Up @@ -95,8 +98,6 @@ public void setContentType(String contentType) {
this.contentType = contentType;
}



public TankHttpClient getHttpclient() {
return httpclient;
}
Expand Down Expand Up @@ -288,11 +289,11 @@ public void logRequest(String url, String body, String method, Map<String, Strin
}
// Cookies Information
if (cookies != null) {
for (String c : cookies) {
sb.append(c).append(NEWLINE);
for (String cookie : cookies) {
sb.append(cookie).append(NEWLINE);
}
}
if (null != body) {
if (StringUtils.isNotEmpty(body)) {
sb.append("REQUEST SIZE: " + body.getBytes().length).append(NEWLINE);
sb.append("REQUEST BODY: " + body).append(NEWLINE);
}
Expand All @@ -313,4 +314,11 @@ public String getContentTypeCharSet() {
return contentTypeCharSet;
}

public void setAsync(boolean async) {
this.async = async;
}
public boolean getAsync() {
return async;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void logResponse() {
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: " + responseByteArray.length).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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,19 @@
* #L%
*/

import java.io.IOException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.jxpath.JXPathContext;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.JSONObject;
import org.json.simple.parser.ContainerFactory;
import org.json.simple.parser.JSONParser;

import com.intuit.tank.http.BaseResponse;

Expand Down Expand Up @@ -65,16 +63,15 @@ public String getValue(String key) {
JSONObject jsonResponse = new JSONObject(this.response);
return (String) jsonResponse.get(key);
}
} catch (Exception e) {
}
} catch (Exception e) { }
try {
if (this.jsonMap == null) {
initialize();
}
String keyTrans = key.replace("@", "");
// note that indexing is 1 based not zero based
JXPathContext context = JXPathContext.newContext(this.jsonMap);
String output = URLDecoder.decode(String.valueOf(context.getValue(keyTrans)), "UTF-8");
String output = URLDecoder.decode(String.valueOf(context.getValue(keyTrans)), StandardCharsets.UTF_8);
if (output.equalsIgnoreCase("null"))
return "";
return output;
Expand All @@ -92,32 +89,14 @@ private String cleanString(String input) {
}
}

@SuppressWarnings({ "rawtypes", "unchecked" })
private void initialize() {

try {
JSONParser parser = new JSONParser();
ContainerFactory containerFactory = new ContainerFactory() {
public List creatArrayContainer() {
return new LinkedList();
}

public Map createObjectContainer() {
return new LinkedHashMap();
}
};
if (!StringUtils.isEmpty(this.response)) {
Object parse = parser.parse(this.response, containerFactory);
if (parse instanceof List) {
this.jsonMap = new LinkedHashMap();
} else {
this.jsonMap = (Map) parse;
}
this.jsonMap.put("root", parse);
this.jsonMap = new ObjectMapper().readValue(this.response, HashMap.class);
} else {
this.jsonMap = new HashMap();
}
} catch (Exception ex) {
} catch (IOException ex) {
logger.warn("Unable to parse the response string as a JSON object: " + this.response, ex);
}
}
Expand Down
14 changes: 1 addition & 13 deletions agent/agent_standalone/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.intuit.tank</groupId>
<artifactId>agent-parent</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
</parent>

<artifactId>agent-standalone</artifactId>
Expand All @@ -25,18 +25,6 @@
<artifactId>api</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-http</artifactId>
</dependency>

<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<scope>provided</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.SocketAddress;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
Expand All @@ -26,22 +25,20 @@
import javax.xml.transform.Source;
import javax.xml.transform.sax.SAXSource;

import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpContext;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpServer;
import org.apache.http.protocol.HTTP;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.simpleframework.http.Request;
import org.simpleframework.http.Response;
import org.simpleframework.http.core.Container;
import org.simpleframework.http.core.ContainerSocketProcessor;
import org.simpleframework.transport.SocketProcessor;
import org.simpleframework.transport.connect.Connection;
import org.simpleframework.transport.connect.SocketConnection;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import com.intuit.tank.vm.agent.messages.StandaloneAgentRequest;
import com.intuit.tank.vm.api.enumerated.WatsAgentCommand;
import com.intuit.tank.vm.api.enumerated.AgentCommand;

public class CommandListener implements Container {
public class CommandListener {

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

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

@Override
public void handle(Request req, Response response) {
private static void handleRequest(HttpExchange exchange) {
try {
String msg = "unknown path";
String response = "unknown path";
int code = 200;
String path = req.getPath().getPath();
if (path.equals(WatsAgentCommand.request.getPath())) {
msg = "Requesting users ";
StandaloneAgentRequest agentRequest = getRequest(req.getInputStream());
String path = exchange.getRequestURI().getPath();
if (path.equals(AgentCommand.request.getPath())) {
response = "Requesting users ";
StandaloneAgentRequest agentRequest = getRequest(exchange.getRequestBody());
if (agentRequest == null) {
msg = "Invalid StandaloneAgentRequest.";
response = "Invalid StandaloneAgentRequest.";
code = 406;
} else if (agentRequest.getJobId() != null && agentRequest.getUsers() > 0) {
// launch the harness with the specified details.
agentStarter.startTest(agentRequest);
} else {
msg = "invalid request.";
response = "invalid request.";
code = 400;
}
}
long time = System.currentTimeMillis();
response.setCode(code);
response.setContentType("text/plain");
response.setDescription("Intuit Tank Agent/2.3.0");
response.setDate("Date", time);
response.setDate("Last-Modified", time);

PrintStream body = response.getPrintStream();
body.println(msg);
body.close();
} catch (Exception e) {
exchange.getResponseHeaders().set(HTTP.CONTENT_TYPE, "text/plain");
exchange.getResponseHeaders().set(HTTP.SERVER_HEADER,"Intuit Tank Agent/3.0.1");
exchange.sendResponseHeaders(code, response.length());
OutputStream os = exchange.getResponseBody();
os.write(response.getBytes());
os.close();
exchange.close();
} catch (SAXException| ParserConfigurationException | IOException e) {
LOG.error("error sending response");
response.setCode(500);
}
}

private StandaloneAgentRequest getRequest(InputStream inputStream) throws SAXException, ParserConfigurationException {
private static StandaloneAgentRequest getRequest(InputStream inputStream) throws SAXException, ParserConfigurationException {
try {
//Source: https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Prevention_Cheat_Sheet#Unmarshaller
SAXParserFactory spf = SAXParserFactory.newInstance();
Expand Down
2 changes: 1 addition & 1 deletion agent/agent_standalone_pkg/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.intuit.tank</groupId>
<artifactId>agent-parent</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
</parent>

<artifactId>agent-standalone-pkg</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion agent/agent_startup/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.intuit.tank</groupId>
<artifactId>agent-parent</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
</parent>

<artifactId>agent-startup</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void run() {
logger.error("Error unzipping support files : retryCount="
+ retryCount + " : " + e.getMessage());
if (retryCount < FIBONACCI.length) {
Thread.sleep( FIBONACCI[++retryCount] * 1000 );
Thread.sleep( FIBONACCI[retryCount++] * 1000 );
} else throw e;
}
}
Expand Down
2 changes: 1 addition & 1 deletion agent/agent_startup_pkg/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.intuit.tank</groupId>
<artifactId>agent-parent</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
</parent>

<artifactId>agent-startup-pkg</artifactId>
Expand Down
12 changes: 4 additions & 8 deletions agent/apiharness/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.intuit.tank</groupId>
<artifactId>agent-parent</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
</parent>

<artifactId>agent</artifactId>
Expand Down Expand Up @@ -65,19 +65,19 @@

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

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

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

Expand All @@ -86,10 +86,6 @@
<artifactId>jaxb-impl</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-http</artifactId>
</dependency>
</dependencies>

</project>
Loading

0 comments on commit d99c701

Please sign in to comment.