Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ static int getMaxBytesToStorePerRequest() {
HTTPConstants.UNLOCK,
HTTPConstants.REPORT,
HTTPConstants.MKCALENDAR,
HTTPConstants.SEARCH
HTTPConstants.SEARCH,
HTTPConstants.QUERY
));
String userDefinedMethods = JMeterUtils.getPropDefault(
"httpsampler.user_defined_methods", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public interface HTTPConstantsInterface { // CHECKSTYLE IGNORE InterfaceIsType
String REPORT = "REPORT"; // $NON-NLS-1$
String MKCALENDAR = "MKCALENDAR"; // $NON-NLS-1$
String SEARCH = "SEARCH"; // $NON-NLS-1$
String QUERY = "QUERY"; // $NON-NLS-1$
String HEADER_AUTHORIZATION = "Authorization"; // $NON-NLS-1$
String HEADER_COOKIE = "Cookie"; // $NON-NLS-1$
String HEADER_COOKIE_IN_REQUEST = "Cookie:"; // $NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you 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 org.apache.jmeter.protocol.http.sampler;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicReference;

import org.apache.jmeter.junit.JMeterTestCase;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jorphan.test.JMeterSerialTest;
import org.junit.jupiter.api.Test;

import com.sun.net.httpserver.HttpServer;

public class HttpQueryTest extends JMeterTestCase implements JMeterSerialTest {

@Test
void querySendsRequestBody() throws Exception {
String expectedBody = "{\"name\":\"Ori\"}";
AtomicReference<String> receivedMethod = new AtomicReference<>();
AtomicReference<String> receivedBody = new AtomicReference<>();

// Port 0 lets the operating system select an available port.
HttpServer server = HttpServer.create(
new InetSocketAddress("127.0.0.1", 0), 0);

server.createContext("/search", exchange -> {
try {
receivedMethod.set(exchange.getRequestMethod());
receivedBody.set(new String(
exchange.getRequestBody().readAllBytes(),
StandardCharsets.UTF_8));

byte[] response = "OK".getBytes(StandardCharsets.UTF_8);
exchange.sendResponseHeaders(200, response.length);
try (var output = exchange.getResponseBody()) {
output.write(response);
}
} finally {
exchange.close();
}
});

server.start();
try {
HTTPSamplerProxy sampler =
new HTTPSamplerProxy(HTTPSamplerFactory.IMPL_HTTP_CLIENT4);
sampler.setProtocol("http");
sampler.setDomain("127.0.0.1");
sampler.setPort(server.getAddress().getPort());
sampler.setPath("/search");
sampler.setMethod("QUERY");
sampler.setConnectTimeout("5000");
sampler.setResponseTimeout("5000");
sampler.setPostBodyRaw(true);
sampler.addNonEncodedArgument("", expectedBody, "");

SampleResult result = sampler.sample();

assertTrue(result.isSuccessful(),
"Sampler failed: " + result.getResponseMessage());
assertEquals("200", result.getResponseCode());
assertEquals("QUERY", receivedMethod.get());
assertEquals(expectedBody, receivedBody.get());
} finally {
server.stop(0);
}
}
}
2 changes: 1 addition & 1 deletion xdocs/usermanual/component_reference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ https.default.protocol=SSLv3
<code>JAVA</code> implementation). With <code>HttpClient4</code> or <code>HttpClient5</code>, the following methods related to WebDav are
also allowed: <code>COPY</code>, <code>LOCK</code>, <code>MKCOL</code>, <code>MOVE</code>,
<code>PROPFIND</code>, <code>PROPPATCH</code>, <code>UNLOCK</code>, <code>REPORT</code>, <code>MKCALENDAR</code>,
<code>SEARCH</code>.
<code>SEARCH</code>, <code>QUERY</code>.
<p>More methods can be pre-defined for the HttpClient4 by using the JMeter property
<code>httpsampler.user_defined_methods</code>.</p>
</property>
Expand Down
Loading