HttpRequestBase httpRequest; String requestPath = "/" + artifactoryRequest.getApiUrl(); ContentType contentType = Util.getContentType(artifactoryRequest.getRequestType()); if (!artifactoryRequest.getQueryParams().isEmpty()) { queryPath = Util.getQueryPath("?", artifactoryRequest.getQueryParams()); switch (artifactoryRequest.getMethod()) { case GET: httpRequest = new HttpGet(); setEntity((HttpPost)httpRequest, artifactoryRequest.getBody(), contentType); setEntity((HttpPut)httpRequest, artifactoryRequest.getBody(), contentType); setEntity((HttpPatch)httpRequest, artifactoryRequest.getBody(), contentType); break; Map<String, String> headers = artifactoryRequest.getHeaders(); for (String key : headers.keySet()) { httpRequest.setHeader(key, headers.get(key));
@Test public void testPatchProxy() throws Exception { final String proxyName = "proxy1"; String yaml = "proxies:\n" + " " + proxyName + ":\n" + " host: hostproxy1\n" + " port: 0 \n" + " defaultProxy: false\n"; ArtifactoryRequest patchProxyRequest = new ArtifactoryRequestImpl() .method(ArtifactoryRequest.Method.PATCH) .apiUrl("api/system/configuration") .requestType(ArtifactoryRequest.ContentType.YAML) .requestBody(yaml); ArtifactoryResponse response = artifactory.restCall(patchProxyRequest); assertNotNull(response); assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode()); String updatedXml = artifactory.system().configuration(); assertTrue(updatedXml.contains(proxyName)); // Remove proxy patchProxyRequest.requestBody("proxies:\n " + proxyName + ": null\n"); artifactory.restCall(patchProxyRequest); }