Java Code Examples for org.apache.http.client.methods.HttpDelete#setHeader()
The following examples show how to use
org.apache.http.client.methods.HttpDelete#setHeader() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrocadeVcsApi.java From cloudstack with Apache License 2.0 | 6 votes |
protected void executeDeleteObject(String uri) throws BrocadeVcsApiException { if (_host == null || _host.isEmpty() || _adminuser == null || _adminuser.isEmpty() || _adminpass == null || _adminpass.isEmpty()) { throw new BrocadeVcsApiException("Hostname/credentials are null or empty"); } final HttpDelete dm = (HttpDelete)createMethod("delete", uri); dm.setHeader("Accept", "application/vnd.configuration.resource+xml"); final HttpResponse response = executeMethod(dm); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_NO_CONTENT) { String errorMessage; try { errorMessage = responseToErrorMessage(response); } catch (final IOException e) { s_logger.error("Failed to delete object : " + e.getMessage()); throw new BrocadeVcsApiException("Failed to delete object : " + e.getMessage()); } dm.releaseConnection(); s_logger.error("Failed to delete object : " + errorMessage); throw new BrocadeVcsApiException("Failed to delete object : " + errorMessage); } dm.releaseConnection(); }
Example 2
Source File: Session.java From openvidu with Apache License 2.0 | 6 votes |
/** * Gracefully closes the Session: unpublishes all streams and evicts every * participant * * @throws OpenViduJavaClientException * @throws OpenViduHttpException */ public void close() throws OpenViduJavaClientException, OpenViduHttpException { HttpDelete request = new HttpDelete(this.openVidu.hostname + OpenVidu.API_SESSIONS + "/" + this.sessionId); request.setHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded"); HttpResponse response; try { response = this.openVidu.httpClient.execute(request); } catch (IOException e) { throw new OpenViduJavaClientException(e.getMessage(), e.getCause()); } try { int statusCode = response.getStatusLine().getStatusCode(); if ((statusCode == org.apache.http.HttpStatus.SC_NO_CONTENT)) { this.openVidu.activeSessions.remove(this.sessionId); log.info("Session {} closed", this.sessionId); } else { throw new OpenViduHttpException(statusCode); } } finally { EntityUtils.consumeQuietly(response.getEntity()); } }
Example 3
Source File: CMODataAbapClient.java From devops-cm-client with Apache License 2.0 | 5 votes |
public void deleteTransport(String id) throws EntityProviderException, IOException, UnexpectedHttpResponseException { try (CloseableHttpClient client = clientFactory.createClient()) { HttpDelete delete = requestBuilder.deleteTransport(id); delete.setHeader("x-csrf-token", getCSRFToken()); try(CloseableHttpResponse response = client.execute(delete)) { hasStatusOrFail(response, HttpStatus.SC_NO_CONTENT); } } }
Example 4
Source File: RabbitManager.java From NFVO with Apache License 2.0 | 5 votes |
/** * Removes a user from RabbitMQ. This function does <em>not</em> throw exceptions even if the * removal of the user fails. * * @param rabbitUsername the user who shall execute the remove operation * @param rabbitPassword the password of the RabbitMQ instance * @param brokerIp the IP where RabbitMQ is running * @param managementPort the port used by RabbitMQ * @param userToRemove the user to remove */ public static void removeRabbitMqUserQuietly( String rabbitUsername, String rabbitPassword, String brokerIp, String managementPort, String userToRemove) { try { String uri = "http://" + brokerIp + ":" + managementPort + "/api/users/" + userToRemove; HttpDelete delete = new HttpDelete(uri); String authStr = rabbitUsername + ":" + rabbitPassword; String encoding = Base64.encodeBase64String(authStr.getBytes()); delete.setHeader("Authorization", "Basic " + encoding); delete.setHeader(new BasicHeader("Accept", "application/json")); // delete.setHeader(new BasicHeader("Content-type", "application/json")); log.trace("Executing request: " + delete.getMethod() + " on " + uri); // TODO switch to SSL if possible try (CloseableHttpClient httpClient = HttpClients.createDefault()) { CloseableHttpResponse response = httpClient.execute(delete); log.trace(String.valueOf("Status: " + response.getStatusLine().getStatusCode())); if (response.getStatusLine().getStatusCode() == 404) { log.warn("User not found in RabbitMQ. Assuming that it is removed."); } else if (response.getStatusLine().getStatusCode() != 204) { log.warn( "Error removing RabbitMQ user " + userToRemove + ": " + response.getStatusLine()); } } } catch (Exception e) { log.warn( "Ignoring exception while removing RabbitMQ user " + userToRemove + ": " + e.getMessage()); } }
Example 5
Source File: SiteToSiteRestApiClient.java From nifi with Apache License 2.0 | 5 votes |
public TransactionResultEntity commitTransferFlowFiles(final String transactionUrl, final ResponseCode clientResponse) throws IOException { final String requestUrl = transactionUrl + "?responseCode=" + clientResponse.getCode(); logger.debug("Sending commitTransferFlowFiles request to transactionUrl: {}", requestUrl); final HttpDelete delete = createDelete(requestUrl); delete.setHeader("Accept", "application/json"); delete.setHeader(HttpHeaders.PROTOCOL_VERSION, String.valueOf(transportProtocolVersionNegotiator.getVersion())); setHandshakeProperties(delete); try (CloseableHttpResponse response = getHttpClient().execute(delete)) { final int responseCode = response.getStatusLine().getStatusCode(); logger.debug("commitTransferFlowFiles responseCode={}", responseCode); try (InputStream content = response.getEntity().getContent()) { switch (responseCode) { case RESPONSE_CODE_OK: return readResponse(content); case RESPONSE_CODE_BAD_REQUEST: return readResponse(content); default: throw handleErrResponse(responseCode, content); } } } }
Example 6
Source File: SwiftManager.java From sync-service with Apache License 2.0 | 5 votes |
@Override public void deleteChunk(Workspace workspace, String chunkName) throws Exception { if (!isTokenActive()) { login(); } HttpClient httpClient = new DefaultHttpClient(); String url = this.storageUrl + "/" + workspace.getSwiftContainer() + "/" + chunkName; try { HttpDelete request = new HttpDelete(url); request.setHeader(SwiftResponse.X_AUTH_TOKEN, authToken); HttpResponse response = httpClient.execute(request); SwiftResponse swiftResponse = new SwiftResponse(response); if (swiftResponse.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { throw new UnauthorizedException("401 User unauthorized"); } if (swiftResponse.getStatusCode() == HttpStatus.SC_NOT_FOUND) { throw new ObjectNotFoundException("404 Not Found"); } if (swiftResponse.getStatusCode() < 200 || swiftResponse.getStatusCode() >= 300) { throw new UnexpectedStatusCodeException("Unexpected status code: " + swiftResponse.getStatusCode()); } } finally { httpClient.getConnectionManager().shutdown(); } }
Example 7
Source File: ODataTestUtils.java From product-ei with Apache License 2.0 | 5 votes |
public static int sendDELETE(String endpoint, Map<String, String> headers) throws IOException { HttpClient httpClient = new DefaultHttpClient(); HttpDelete httpDelete = new HttpDelete(endpoint); for (String headerType : headers.keySet()) { httpDelete.setHeader(headerType, headers.get(headerType)); } HttpResponse httpResponse = httpClient.execute(httpDelete); return httpResponse.getStatusLine().getStatusCode(); }
Example 8
Source File: Session.java From openvidu with Apache License 2.0 | 5 votes |
/** * Forces some user to unpublish a Stream. OpenVidu Browser will trigger the * proper events on the client-side (<code>streamDestroyed</code>) with reason * set to "forceUnpublishByServer". <br> * * You can get <code>streamId</code> parameter with * {@link io.openvidu.java.client.Session#getActiveConnections()} and then for * each Connection you can call * {@link io.openvidu.java.client.Connection#getPublishers()}. Finally * {@link io.openvidu.java.client.Publisher#getStreamId()}) will give you the * <code>streamId</code>. Remember to call * {@link io.openvidu.java.client.Session#fetch()} before to fetch the current * actual properties of the Session from OpenVidu Server * * @throws OpenViduJavaClientException * @throws OpenViduHttpException */ public void forceUnpublish(String streamId) throws OpenViduJavaClientException, OpenViduHttpException { HttpDelete request = new HttpDelete( this.openVidu.hostname + OpenVidu.API_SESSIONS + "/" + this.sessionId + "/stream/" + streamId); request.setHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded"); HttpResponse response; try { response = this.openVidu.httpClient.execute(request); } catch (IOException e) { throw new OpenViduJavaClientException(e.getMessage(), e.getCause()); } try { int statusCode = response.getStatusLine().getStatusCode(); if ((statusCode == org.apache.http.HttpStatus.SC_NO_CONTENT)) { for (Connection connection : this.activeConnections.values()) { // Try to remove the Publisher from the Connection publishers collection if (connection.publishers.remove(streamId) != null) { continue; } // Try to remove the Publisher from the Connection subscribers collection connection.subscribers.remove(streamId); } log.info("Stream {} unpublished", streamId); } else { throw new OpenViduHttpException(statusCode); } } finally { EntityUtils.consumeQuietly(response.getEntity()); } }
Example 9
Source File: SiteToSiteRestApiClient.java From nifi with Apache License 2.0 | 5 votes |
public TransactionResultEntity commitReceivingFlowFiles(final String transactionUrl, final ResponseCode clientResponse, final String checksum) throws IOException { logger.debug("Sending commitReceivingFlowFiles request to transactionUrl: {}, clientResponse={}, checksum={}", transactionUrl, clientResponse, checksum); stopExtendingTtl(); final StringBuilder urlBuilder = new StringBuilder(transactionUrl).append("?responseCode=").append(clientResponse.getCode()); if (ResponseCode.CONFIRM_TRANSACTION.equals(clientResponse)) { urlBuilder.append("&checksum=").append(checksum); } final HttpDelete delete = createDelete(urlBuilder.toString()); delete.setHeader("Accept", "application/json"); delete.setHeader(HttpHeaders.PROTOCOL_VERSION, String.valueOf(transportProtocolVersionNegotiator.getVersion())); setHandshakeProperties(delete); try (CloseableHttpResponse response = getHttpClient().execute(delete)) { final int responseCode = response.getStatusLine().getStatusCode(); logger.debug("commitReceivingFlowFiles responseCode={}", responseCode); try (InputStream content = response.getEntity().getContent()) { switch (responseCode) { case RESPONSE_CODE_OK: return readResponse(content); case RESPONSE_CODE_BAD_REQUEST: return readResponse(content); default: throw handleErrResponse(responseCode, content); } } } }
Example 10
Source File: ODataTestUtils.java From micro-integrator with Apache License 2.0 | 5 votes |
public static int sendDELETE(String endpoint, Map<String, String> headers) throws IOException { HttpClient httpClient = new DefaultHttpClient(); HttpDelete httpDelete = new HttpDelete(endpoint); for (String headerType : headers.keySet()) { httpDelete.setHeader(headerType, headers.get(headerType)); } HttpResponse httpResponse = httpClient.execute(httpDelete); return httpResponse.getStatusLine().getStatusCode(); }
Example 11
Source File: SwiftManagerHTTPS.java From sync-service with Apache License 2.0 | 5 votes |
@Override public void deleteChunk(Workspace workspace, String chunkName) throws Exception { if (!isTokenActive()) { login(); } HttpClient httpClient = new DefaultHttpClient(); String url = this.storageUrl + "/" + workspace.getSwiftContainer() + "/" + chunkName; try { HttpDelete request = new HttpDelete(url); request.setHeader(SwiftResponse.X_AUTH_TOKEN, authToken); HttpResponse response = httpClient.execute(request); SwiftResponse swiftResponse = new SwiftResponse(response); if (swiftResponse.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { throw new UnauthorizedException("401 User unauthorized"); } if (swiftResponse.getStatusCode() == HttpStatus.SC_NOT_FOUND) { throw new ObjectNotFoundException("404 Not Found"); } if (swiftResponse.getStatusCode() < 200 || swiftResponse.getStatusCode() >= 300) { throw new UnexpectedStatusCodeException("Unexpected status code: " + swiftResponse.getStatusCode()); } } finally { httpClient.getConnectionManager().shutdown(); } }
Example 12
Source File: SiteToSiteRestApiClient.java From localization_nifi with Apache License 2.0 | 5 votes |
public TransactionResultEntity commitTransferFlowFiles(final String transactionUrl, final ResponseCode clientResponse) throws IOException { final String requestUrl = transactionUrl + "?responseCode=" + clientResponse.getCode(); logger.debug("Sending commitTransferFlowFiles request to transactionUrl: {}", requestUrl); final HttpDelete delete = createDelete(requestUrl); delete.setHeader("Accept", "application/json"); delete.setHeader(HttpHeaders.PROTOCOL_VERSION, String.valueOf(transportProtocolVersionNegotiator.getVersion())); setHandshakeProperties(delete); try (CloseableHttpResponse response = getHttpClient().execute(delete)) { final int responseCode = response.getStatusLine().getStatusCode(); logger.debug("commitTransferFlowFiles responseCode={}", responseCode); try (InputStream content = response.getEntity().getContent()) { switch (responseCode) { case RESPONSE_CODE_OK: return readResponse(content); case RESPONSE_CODE_BAD_REQUEST: return readResponse(content); default: throw handleErrResponse(responseCode, content); } } } }
Example 13
Source File: SiteToSiteRestApiClient.java From localization_nifi with Apache License 2.0 | 5 votes |
public TransactionResultEntity commitReceivingFlowFiles(final String transactionUrl, final ResponseCode clientResponse, final String checksum) throws IOException { logger.debug("Sending commitReceivingFlowFiles request to transactionUrl: {}, clientResponse={}, checksum={}", transactionUrl, clientResponse, checksum); stopExtendingTtl(); final StringBuilder urlBuilder = new StringBuilder(transactionUrl).append("?responseCode=").append(clientResponse.getCode()); if (ResponseCode.CONFIRM_TRANSACTION.equals(clientResponse)) { urlBuilder.append("&checksum=").append(checksum); } final HttpDelete delete = createDelete(urlBuilder.toString()); delete.setHeader("Accept", "application/json"); delete.setHeader(HttpHeaders.PROTOCOL_VERSION, String.valueOf(transportProtocolVersionNegotiator.getVersion())); setHandshakeProperties(delete); try (CloseableHttpResponse response = getHttpClient().execute(delete)) { final int responseCode = response.getStatusLine().getStatusCode(); logger.debug("commitReceivingFlowFiles responseCode={}", responseCode); try (InputStream content = response.getEntity().getContent()) { switch (responseCode) { case RESPONSE_CODE_OK: return readResponse(content); case RESPONSE_CODE_BAD_REQUEST: return readResponse(content); default: throw handleErrResponse(responseCode, content); } } } }
Example 14
Source File: AbstractDatabricksRestClientImpl.java From databricks-rest-client with Apache License 2.0 | 5 votes |
protected HttpDelete makeDeleteMethod(String path) { HttpDelete method = new HttpDelete(url + path); logger.info(method.toString()); method.setHeader("Accept", "application/json"); method.setHeader("Content-type", "application/json"); return method; }
Example 15
Source File: DcRestAdapter.java From io with Apache License 2.0 | 5 votes |
/** * DELETEメソッド. * @param url リクエスト対象URL * @param headers リクエストヘッダのハッシュマップ * @return DcResponse型 * @throws DcException DAO例外 */ public final DcResponse del(final String url, final HashMap<String, String> headers) throws DcException { HttpDelete req = new HttpDelete(url); for (Map.Entry<String, String> entry : headers.entrySet()) { req.setHeader(entry.getKey(), entry.getValue()); } req.addHeader("X-Dc-Version", DcCoreTestConfig.getCoreVersion()); debugHttpRequest(req, ""); return this.request(req); }
Example 16
Source File: ODataTenantUserTestCase.java From micro-integrator with Apache License 2.0 | 5 votes |
private static int sendDELETE(String endpoint, String acceptType) throws IOException { HttpClient httpClient = new DefaultHttpClient(); HttpDelete httpDelete = new HttpDelete(endpoint); httpDelete.setHeader("Accept", acceptType); HttpResponse httpResponse = httpClient.execute(httpDelete); return httpResponse.getStatusLine().getStatusCode(); }
Example 17
Source File: ODataSuperTenantUserTestCase.java From micro-integrator with Apache License 2.0 | 5 votes |
private static int sendDELETE(String endpoint, String acceptType) throws IOException { HttpClient httpClient = new DefaultHttpClient(); HttpDelete httpDelete = new HttpDelete(endpoint); httpDelete.setHeader("Accept", acceptType); HttpResponse httpResponse = httpClient.execute(httpDelete); return httpResponse.getStatusLine().getStatusCode(); }
Example 18
Source File: Client.java From geoportal-server-harvester with Apache License 2.0 | 4 votes |
private PublishResponse delete(URI uri) throws URISyntaxException, IOException { HttpDelete del = new HttpDelete(uri); del.setConfig(DEFAULT_REQUEST_CONFIG); del.setHeader("User-Agent", HttpConstants.getUserAgent()); return execute(del, PublishResponse.class); }
Example 19
Source File: ITApolloConfigurationTest.java From skywalking with Apache License 2.0 | 4 votes |
@SuppressWarnings("StatementWithEmptyBody") @Ignore // due to instability @Test(timeout = 10000) public void shouldReadUpdated() { try { assertNull(provider.watcher.value()); final HttpPost createConfigPost = new HttpPost(baseUrl + "/openapi/v1/envs/DEV" + "/apps/SampleApp" + "/clusters/default" + "/namespaces/application" + "/items"); createConfigPost.setHeader("Authorization", token); createConfigPost.setHeader("Content-Type", "application/json;charset=UTF-8"); final StringEntity entity = new StringEntity("{\n" + " \"key\":\"test-module.default.testKey\",\n" + " \"value\":\"3000\",\n" + " \"comment\":\"test key\",\n" + " \"dataChangeCreatedBy\":\"apollo\"\n" + "}"); createConfigPost.setEntity(entity); final String createResponse = (String) httpClient.execute(createConfigPost, responseHandler); LOGGER.info("createResponse: {}", createResponse); final HttpPost releaseConfigRequest = new HttpPost(baseUrl + "/openapi/v1/envs/DEV" + "/apps/SampleApp" + "/clusters/default" + "/namespaces/application/releases"); releaseConfigRequest.setEntity(new StringEntity("{\n" + " \"releaseTitle\":\"2019-06-07\",\n" + " \"releaseComment\":\"test\",\n" + " \"releasedBy\":\"apollo\"\n" + "}")); releaseConfigRequest.setHeader("Authorization", token); releaseConfigRequest.setHeader("Content-Type", "application/json;charset=UTF-8"); final String releaseCreateResponse = (String) httpClient.execute(releaseConfigRequest, responseHandler); LOGGER.info("releaseCreateResponse: {}", releaseCreateResponse); for (String v = provider.watcher.value(); v == null; v = provider.watcher.value()) { } assertEquals("3000", provider.watcher.value()); final HttpDelete deleteConfigRequest = new HttpDelete(baseUrl + "/openapi/v1" + "/envs/DEV" + "/apps/SampleApp" + "/clusters/default" + "/namespaces/application" + "/items/test-module.default.testKey" + "?operator=apollo"); deleteConfigRequest.setHeader("Authorization", token); deleteConfigRequest.setHeader("Content-Type", "application/json;charset=UTF-8"); httpClient.execute(deleteConfigRequest); final String releaseDeleteResponse = (String) httpClient.execute(releaseConfigRequest, responseHandler); LOGGER.info("releaseDeleteResponse: {}", releaseDeleteResponse); for (String v = provider.watcher.value(); v != null; v = provider.watcher.value()) { } assertNull(provider.watcher.value()); } catch (IOException e) { LOGGER.error(e.getMessage(), e); fail(e.getMessage()); } }
Example 20
Source File: SwiftManagerHTTPS.java From sync-service with Apache License 2.0 | 4 votes |
@Override public void deleteWorkspace(Workspace workspace) throws Exception { if (!isTokenActive()) { login(); } TrustStrategy acceptingTrustStrategy = new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] certificate, String authType) { return true; } }; SSLSocketFactory sf = new SSLSocketFactory(acceptingTrustStrategy, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("https", 5000, sf)); ClientConnectionManager ccm = new SingleClientConnManager(registry); HttpClient httpClient = new DefaultHttpClient(ccm); String url = this.storageUrl + "/" + workspace.getSwiftContainer(); try { HttpDelete request = new HttpDelete(url); request.setHeader(SwiftResponse.X_AUTH_TOKEN, authToken); HttpResponse response = httpClient.execute(request); SwiftResponse swiftResponse = new SwiftResponse(response); if (swiftResponse.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { throw new UnauthorizedException("401 User unauthorized"); } if (swiftResponse.getStatusCode() < 200 || swiftResponse.getStatusCode() >= 300) { throw new UnexpectedStatusCodeException("Unexpected status code: " + swiftResponse.getStatusCode()); } } finally { httpClient.getConnectionManager().shutdown(); } }