Skip to content

Commit

Permalink
Release XLT 6.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jowerner committed Mar 18, 2022
2 parents b61faae + 8ed5cc5 commit ebb666a
Show file tree
Hide file tree
Showing 12 changed files with 320 additions and 28 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.xceptance</groupId>
<artifactId>xlt</artifactId>
<version>6.0.0</version>
<version>6.1.0</version>
<packaging>jar</packaging>

<name>XLT</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,12 @@ private HttpUriRequest makeHttpMethod(final WebRequest webRequest, final HttpCli
setProxy(httpMethod, webRequest);

if (httpMethod instanceof HttpEntityEnclosingRequest) {
// start XC: GH#211
/*
// POST as well as PUT and PATCH
*/
// POST, PUT, PATCH, and DELETE
// end XC: GH#211
final HttpEntityEnclosingRequest method = (HttpEntityEnclosingRequest) httpMethod;

if (webRequest.getEncodingType() == FormEncodingType.URL_ENCODED && method instanceof HttpPost) {
Expand Down Expand Up @@ -362,15 +367,25 @@ else if (FormEncodingType.MULTIPART == webRequest.getEncodingType()) {
}
method.setEntity(builder.build());
}
// start XC: GH#211
/*
else { // for instance a PUT or PATCH request
*/
else { // PUT, PATCH, DELETE
// end XC: GH#211
final String body = webRequest.getRequestBody();
if (body != null) {
method.setEntity(new StringEntity(body, charset));
}
}
}
else {
// start XC: GH#211
/*
// this is the case for GET as well as TRACE, DELETE, OPTIONS and HEAD
*/
// GET, HEAD, OPTIONS, TRACE
// end XC: GH#211
if (!webRequest.getRequestParameters().isEmpty()) {
final List<NameValuePair> pairs = webRequest.getRequestParameters();
final String query = URLEncodedUtils.format(NameValuePair.toHttpClient(pairs), charset);
Expand Down Expand Up @@ -490,7 +505,7 @@ else if (pairWithFile.getFileName() == null) {
* @param uri the uri being used
* @return a new HttpClient HTTP method based on the specified parameters
*/
private static HttpRequestBase buildHttpMethod(final HttpMethod submitMethod, final URI uri) {
protected HttpRequestBase buildHttpMethod(final HttpMethod submitMethod, final URI uri) {
final HttpRequestBase method;
switch (submitMethod) {
case GET:
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,18 @@ public void setRequestBody(final String requestBody) throws RuntimeException {
+ "the two are mutually exclusive!";
throw new RuntimeException(msg);
}
// start XC: GH#211
/*
if (httpMethod_ != HttpMethod.POST && httpMethod_ != HttpMethod.PUT && httpMethod_ != HttpMethod.PATCH) {
final String msg = "The request body may only be set for POST, PUT or PATCH requests!";
throw new RuntimeException(msg);
}
*/
if (httpMethod_ != HttpMethod.POST && httpMethod_ != HttpMethod.PUT && httpMethod_ != HttpMethod.PATCH && httpMethod_ != HttpMethod.DELETE) {
final String msg = "The request body may only be set for POST, PUT, PATCH, or DELETE requests!";
throw new RuntimeException(msg);
}
// end XC: GH#211
requestBody_ = requestBody;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,12 @@ protected void doGet(final HttpServletRequest req, final HttpServletResponse res
final File file = new File(rootDirectory, fileName);
in = new FileInputStream(file);

resp.setContentLength((int) file.length());
// resp.setContentType("???");

resp.setStatus(HttpServletResponse.SC_OK);
resp.setContentLengthLong(file.length());
final OutputStream out = resp.getOutputStream();

IOUtils.copy(in, out);

resp.setStatus(HttpServletResponse.SC_OK);
}
}
catch (final Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private O makeRequest(final WebRequest webRequest) throws URISyntaxException
final O request;

// set parameters/body
if (!(method == HttpMethod.POST || method == HttpMethod.PUT || method == HttpMethod.PATCH))
if (!(method == HttpMethod.POST || method == HttpMethod.PUT || method == HttpMethod.PATCH || method == HttpMethod.DELETE))
{
if (!webRequest.getRequestParameters().isEmpty())
{
Expand Down Expand Up @@ -226,10 +226,17 @@ else if (FormEncodingType.MULTIPART == webRequest.getEncodingType())
}
else
{
// for instance a PUT or PATCH request
final String body = StringUtils.defaultString(webRequest.getRequestBody());
// PUT, PATCH, DELETE

request = createRequestWithStringBody(uri, webRequest, body, MimeType.TEXT_PLAIN, charset);
final String body = webRequest.getRequestBody();
if (body == null)
{
request = createRequestWithoutBody(uri, webRequest);
}
else
{
request = createRequestWithStringBody(uri, webRequest, body, MimeType.TEXT_PLAIN, charset);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2005-2022 Xceptance Software Technologies GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.xceptance.xlt.engine.htmlunit.apache;

import java.net.URI;

import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;

/**
* Allows sending a DELETE request with or without a request body.
*/
class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase
{
public HttpDeleteWithBody(final URI uri)
{
super();
setURI(uri);
}

@Override
public String getMethod()
{
return HttpDelete.METHOD_NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.xceptance.xlt.engine.htmlunit.apache;

import java.io.IOException;
import java.net.URI;
import java.util.LinkedHashMap;
import java.util.Map;

Expand All @@ -26,12 +27,14 @@
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.config.SocketConfig;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpRequestExecutor;

import com.gargoylesoftware.htmlunit.DownloadedContent;
import com.gargoylesoftware.htmlunit.HttpMethod;
import com.gargoylesoftware.htmlunit.HttpWebConnection;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebRequest;
Expand Down Expand Up @@ -196,4 +199,25 @@ protected WebResponse makeWebResponse(final HttpResponse httpResponse, final Web

return webResponse;
}

/**
* {@inheritDoc}
*/
@Override
protected HttpRequestBase buildHttpMethod(final HttpMethod submitMethod, final URI uri)
{
final HttpRequestBase method;

switch (submitMethod)
{
case DELETE:
method = new HttpDeleteWithBody(uri);
break;

default:
method = super.buildHttpMethod(submitMethod, uri);
}

return method;
}
}
22 changes: 11 additions & 11 deletions src/main/java/com/xceptance/xlt/engine/httprequest/HttpRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -617,13 +617,13 @@ public HttpRequest clone()
*/
protected WebRequest buildWebRequest() throws MalformedURLException, URISyntaxException
{
final boolean isPostOrPutOrPatch = (httpMethod == HttpMethod.POST || httpMethod == HttpMethod.PUT ||
httpMethod == HttpMethod.PATCH);
final boolean methodSupportsBody = (httpMethod == HttpMethod.POST || httpMethod == HttpMethod.PUT ||
httpMethod == HttpMethod.PATCH || httpMethod == HttpMethod.DELETE);

// basic parameter validation
Assert.assertTrue("Base URL must not be null or blank", StringUtils.isNotBlank(baseUrl));
Assert.assertTrue("Can not use request parameters in conjunction with request body in POST, PUT or PATCH request",
!isPostOrPutOrPatch || (body == null || parameters.isEmpty()));
Assert.assertTrue("Can not use request parameters in conjunction with request body in POST, PUT, PATCH, or DELETE requests",
!methodSupportsBody || (body == null && bytesBody == null) || parameters.isEmpty());

// Evaluate URL and create web request
final URL url;
Expand All @@ -650,7 +650,7 @@ protected WebRequest buildWebRequest() throws MalformedURLException, URISyntaxEx
webRequest.setCharset(contentCharset);
}

if (isPostOrPutOrPatch && encodingType != null)
if (methodSupportsBody && encodingType != null)
{
webRequest.setEncodingType(encodingType);
}
Expand All @@ -661,10 +661,10 @@ protected WebRequest buildWebRequest() throws MalformedURLException, URISyntaxEx
}

// Handle parameters
handleParameters(webRequest, parameters, isPostOrPutOrPatch);
handleParameters(webRequest, parameters, methodSupportsBody);

// Handle body
if (isPostOrPutOrPatch)
if (methodSupportsBody)
{
// Assumes no parameters have been specified

Expand Down Expand Up @@ -701,15 +701,15 @@ else if (bytesBody != null)
* the web request
* @param parameters
* the custom request parameters
* @param isPostOrPutOrPatch
* whether the HTTP method is POST, PUT, or PATCH
* @param methodSupportsBody
* whether the HTTP method may have a request body
*/
private void handleParameters(final WebRequest webRequest, final List<NameValuePair> parameters, final boolean isPostOrPutOrPatch)
private void handleParameters(final WebRequest webRequest, final List<NameValuePair> parameters, final boolean methodSupportsBody)
throws URISyntaxException, MalformedURLException
{
if (!parameters.isEmpty())
{
if (isPostOrPutOrPatch)
if (methodSupportsBody)
{
// remove any parameter from the URL that is also part of the custom parameters
if (StringUtils.isNotEmpty(webRequest.getUrl().getQuery()))
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/xceptance/xlt/report/DataRecordReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.zip.GZIPInputStream;

import org.apache.commons.vfs2.FileObject;
Expand Down Expand Up @@ -70,7 +70,7 @@ class DataRecordReader implements Runnable
/**
* The global line counter.
*/
private final AtomicInteger totalLineCounter;
private final AtomicLong totalLineCounter;

/**
* The instance number of the test user.
Expand Down Expand Up @@ -99,7 +99,7 @@ class DataRecordReader implements Runnable
* the dispatcher that coordinates result processing
*/
public DataRecordReader(final FileObject directory, final String agentName, final String testCaseName, final String userNumber,
final AtomicInteger totalLineCounter, final Dispatcher dispatcher)
final AtomicLong totalLineCounter, final Dispatcher dispatcher)
{
this.directory = directory;
this.agentName = agentName;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/xceptance/xlt/report/LogReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileType;
Expand Down Expand Up @@ -82,7 +82,7 @@ public class LogReader
/**
* The total number of lines/data records read.
*/
private final AtomicInteger totalLinesCounter;
private final AtomicLong totalLinesCounter;

/**
* The filter to skip the results of certain test cases when reading.
Expand Down Expand Up @@ -130,7 +130,7 @@ public LogReader(final FileObject inputDir, final DataRecordFactory dataRecordFa
{
this.inputDir = inputDir;

totalLinesCounter = new AtomicInteger();
totalLinesCounter = new AtomicLong();

testCaseFilter = new StringMatcher(testCaseIncludePatternList, testCaseExcludePatternList, true);
agentFilter = new StringMatcher(agentIncludePatternList, agentExcludePatternList, true);
Expand Down
Loading

0 comments on commit ebb666a

Please sign in to comment.