diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java index 43b446ed83b..eb9ccedb903 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java @@ -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", ""); diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPConstantsInterface.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPConstantsInterface.java index 5defe6aee12..061a1081d4a 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPConstantsInterface.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPConstantsInterface.java @@ -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$ diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/HttpQueryTest.java b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/HttpQueryTest.java new file mode 100644 index 00000000000..5ee5d55b033 --- /dev/null +++ b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/HttpQueryTest.java @@ -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 receivedMethod = new AtomicReference<>(); + AtomicReference 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); + } + } +} diff --git a/xdocs/usermanual/component_reference.xml b/xdocs/usermanual/component_reference.xml index 2e64ec36578..7cc0530995e 100644 --- a/xdocs/usermanual/component_reference.xml +++ b/xdocs/usermanual/component_reference.xml @@ -272,7 +272,7 @@ https.default.protocol=SSLv3 JAVA implementation). With HttpClient4 or HttpClient5, the following methods related to WebDav are also allowed: COPY, LOCK, MKCOL, MOVE, PROPFIND, PROPPATCH, UNLOCK, REPORT, MKCALENDAR, - SEARCH. + SEARCH, QUERY.

More methods can be pre-defined for the HttpClient4 by using the JMeter property httpsampler.user_defined_methods.