MCPcopy Create free account
hub / github.com/BaseXdb/basex / send

Method send

basex-api/src/test/java/org/basex/http/HTTPTest.java:201–227  ·  view source on GitHub ↗

Executes the specified PUT request. @param status status code to check @param method HTTP method @param is input stream (can be null) @param type media type (optional, may be null) @param path path of request @param params query parameters (keys and values) @return string result @thr

(final int status, final String method, final InputStream is,
      final MediaType type, final String path, final Object... params)

Source from the content-addressed store, hash-verified

199 * @throws IOException I/O exception
200 */
201 protected static String send(final int status, final String method, final InputStream is,
202 final MediaType type, final String path, final Object... params) throws IOException {
203
204 final BodyPublisher pub = is != null ? HttpRequest.BodyPublishers.ofInputStream(() -> is) :
205 HttpRequest.BodyPublishers.noBody();
206
207 final StringBuilder sb = new StringBuilder(rootUrl + path);
208 final int pl = params.length;
209 for(int p = 0; p < pl; p += 2) {
210 sb.append(p == 0 ? '?' : '&').append(params[p]).append('=').
211 append(URLEncoder.encode(params[p + 1].toString(), StandardCharsets.UTF_8));
212 }
213 final URI uri = URI.create(sb.toString());
214 final HttpRequest.Builder builder = HttpRequest.newBuilder(uri).method(method, pub);
215 if(type != null) builder.setHeader("Content-Type", type.toString());
216
217 try {
218 final HttpClient client = IOUrl.client(true);
219 final HttpResponse<String> response = client.send(builder.build(),
220 HttpResponse.BodyHandlers.ofString());
221 final String body = response.body();
222 assertEquals(status, response.statusCode(), method + ' ' + path + "\nResponse: " + body);
223 return body;
224 } catch(final InterruptedException ex) {
225 throw new IOException(ex);
226 }
227 }
228}

Callers 6

getMethod · 0.95
deleteMethod · 0.95
headMethod · 0.95
optionsMethod · 0.95
postMethod · 0.95
putMethod · 0.95

Calls 10

clientMethod · 0.95
assertEqualsMethod · 0.80
statusCodeMethod · 0.80
appendMethod · 0.65
toStringMethod · 0.65
encodeMethod · 0.45
createMethod · 0.45
methodMethod · 0.45
buildMethod · 0.45
bodyMethod · 0.45

Tested by

no test coverage detected