List of usage examples for org.apache.commons.httpclient HttpStatus SC_NO_CONTENT
int SC_NO_CONTENT
To view the source code for org.apache.commons.httpclient HttpStatus SC_NO_CONTENT.
Click Source Link
From source file:com.zimbra.cs.dav.client.CalDavClient.java
public String sendCalendarData(Appointment appt) throws IOException, DavException { HttpInputStream resp = sendPut(appt.href, appt.data.getBytes("UTF-8"), MimeConstants.CT_TEXT_CALENDAR, appt.etag, null);/*from w ww .j a va 2 s . c om*/ String etag = resp.getHeader(DavProtocol.HEADER_ETAG); ZimbraLog.dav.debug("ETags: " + appt.etag + ", " + etag); int status = resp.getStatusCode(); if (status != HttpStatus.SC_OK && status != HttpStatus.SC_CREATED && status != HttpStatus.SC_NO_CONTENT) { throw new DavException("Can't send calendar data (status=" + status + ")", status); } if (mSchedulingEnabled) sendSchedulingMessage(appt); return etag; }
From source file:com.sun.faban.harness.util.CLI.java
private void makeRequest(HttpMethodBase method) throws IOException { HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); int status = client.executeMethod(method); String enc = method.getResponseCharSet(); InputStream response = method.getResponseBodyAsStream(); if (status == HttpStatus.SC_NOT_FOUND) { System.err.println("Not found!"); return;/*from w w w. j av a 2 s. c o m*/ } else if (status == HttpStatus.SC_NO_CONTENT) { System.err.println("Empty!"); return; } else if (response != null) { BufferedReader reader = new BufferedReader(new InputStreamReader(response, enc)); String line = null; while ((line = reader.readLine()) != null) System.out.println(line); } else if (status != HttpStatus.SC_OK) throw new IOException(HttpStatus.getStatusText(status)); }
From source file:com.cloud.utils.rest.RESTServiceConnector.java
public void executeDeleteObject(final String uri) throws CloudstackRESTException { final DeleteMethod dm = (DeleteMethod) createMethod(DELETE_METHOD_TYPE, uri); dm.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE); executeMethod(dm);/* ww w. jav a 2 s. co m*/ if (dm.getStatusCode() != HttpStatus.SC_NO_CONTENT) { final String errorMessage = responseToErrorMessage(dm); dm.releaseConnection(); s_logger.error("Failed to delete object : " + errorMessage); throw new CloudstackRESTException("Failed to delete object : " + errorMessage); } dm.releaseConnection(); }
From source file:com.cloud.network.nicira.NiciraNvpApiTest.java
@Test public void testDeleteSecurityProfile() throws NiciraNvpApiException, IOException { // Prepare//from w w w . j a va 2 s.co m method = mock(DeleteMethod.class); when(method.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT); // Execute api.deleteSecurityProfile(UUID); // Assert verify(method, times(1)).releaseConnection(); assertEquals("Wrong URI for SecurityProfile deletion REST service", UUID_SEC_PROFILE_URI, uri); assertEquals("Wrong HTTP method for SecurityProfile deletion REST service", NiciraNvpApi.DELETE_METHOD_TYPE, type); }
From source file:com.sun.faban.harness.util.CLI.java
private String makeStringRequest(HttpMethodBase method) throws IOException { HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); int status = client.executeMethod(method); String enc = method.getResponseCharSet(); InputStream response = method.getResponseBodyAsStream(); StringBuilder buffer = new StringBuilder(); if (status == HttpStatus.SC_NOT_FOUND) { System.err.println("Not found!"); return buffer.toString(); } else if (status == HttpStatus.SC_NO_CONTENT) { System.err.println("Empty!"); return buffer.toString(); } else if (response != null) { BufferedReader reader = new BufferedReader(new InputStreamReader(response, enc)); String line = null;/*from w w w . j a v a 2 s .c om*/ while ((line = reader.readLine()) != null) buffer.append(line).append('\n'); } else if (status != HttpStatus.SC_OK) throw new IOException(HttpStatus.getStatusText(status)); return buffer.toString(); }
From source file:com.intuit.wasabi.api.AssignmentsResourceTest.java
@Test public void flushMessages() throws Exception { when(authorization.getUser(AUTHHEADER)).thenReturn(USER); assertThat(resource.flushMessages(AUTHHEADER).getStatus(), is(HttpStatus.SC_NO_CONTENT)); }
From source file:com.cloud.network.brocade.BrocadeVcsApi.java
protected <T> boolean executeUpdateObject(T newObject, String uri) throws BrocadeVcsApiException { boolean result = true; if (_host == null || _host.isEmpty() || _adminuser == null || _adminuser.isEmpty() || _adminpass == null || _adminpass.isEmpty()) {//w w w. j a v a 2 s . c o m throw new BrocadeVcsApiException("Hostname/credentials are null or empty"); } HttpPatch pm = (HttpPatch) createMethod("patch", uri); pm.setHeader("Accept", "application/vnd.configuration.resource+xml"); pm.setEntity(new StringEntity(convertToString(newObject), ContentType.APPLICATION_XML)); HttpResponse response = executeMethod(pm); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_NO_CONTENT) { String errorMessage; try { errorMessage = responseToErrorMessage(response); } catch (IOException e) { s_logger.error("Failed to update object : " + e.getMessage()); throw new BrocadeVcsApiException("Failed to update object : " + e.getMessage()); } pm.releaseConnection(); s_logger.error("Failed to update object : " + errorMessage); throw new BrocadeVcsApiException("Failed to update object : " + errorMessage); } pm.releaseConnection(); return result; }
From source file:com.cloudbees.jenkins.plugins.gogs.server.client.GogsServerAPIClient.java
private String postRequest(PostMethod httppost) throws UnsupportedEncodingException { HttpClient client = getHttpClient(); client.getState().setCredentials(AuthScope.ANY, credentials); client.getParams().setAuthenticationPreemptive(true); String response = null;/*w w w . ja va 2 s. c om*/ InputStream responseBodyAsStream = null; try { client.executeMethod(httppost); if (httppost.getStatusCode() == HttpStatus.SC_NO_CONTENT) { // 204, no content return ""; } responseBodyAsStream = httppost.getResponseBodyAsStream(); if (responseBodyAsStream != null) { response = IOUtils.toString(responseBodyAsStream, "UTF-8"); } if (httppost.getStatusCode() != HttpStatus.SC_OK && httppost.getStatusCode() != HttpStatus.SC_CREATED) { throw new GogsRequestException(httppost.getStatusCode(), "HTTP request error. Status: " + httppost.getStatusCode() + ": " + httppost.getStatusText() + ".\n" + response); } } catch (HttpException e) { throw new GogsRequestException(0, "Communication error: " + e, e); } catch (IOException e) { throw new GogsRequestException(0, "Communication error: " + e, e); } finally { httppost.releaseConnection(); if (responseBodyAsStream != null) { IOUtils.closeQuietly(responseBodyAsStream); } } if (response == null) { throw new GogsRequestException(0, "HTTP request error"); } return response; }
From source file:com.cloud.network.nicira.NiciraNvpApi.java
private void executeDeleteObject(String uri) throws NiciraNvpApiException { String url;// w ww .j a v a 2 s . c o m try { url = new URL(_protocol, _host, uri).toString(); } catch (MalformedURLException e) { s_logger.error("Unable to build Nicira API URL", e); throw new NiciraNvpApiException("Unable to build Nicira API URL", e); } DeleteMethod dm = new DeleteMethod(url); dm.setRequestHeader("Content-Type", "application/json"); executeMethod(dm); if (dm.getStatusCode() != HttpStatus.SC_NO_CONTENT) { String errorMessage = responseToErrorMessage(dm); dm.releaseConnection(); s_logger.error("Failed to delete object : " + errorMessage); throw new NiciraNvpApiException("Failed to delete object : " + errorMessage); } dm.releaseConnection(); }
From source file:com.cloud.network.brocade.BrocadeVcsApi.java
protected void executeDeleteObject(String uri) throws BrocadeVcsApiException { if (_host == null || _host.isEmpty() || _adminuser == null || _adminuser.isEmpty() || _adminpass == null || _adminpass.isEmpty()) {//from www .j a v a 2 s. c o m throw new BrocadeVcsApiException("Hostname/credentials are null or empty"); } HttpDelete dm = (HttpDelete) createMethod("delete", uri); dm.setHeader("Accept", "application/vnd.configuration.resource+xml"); HttpResponse response = executeMethod(dm); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_NO_CONTENT) { String errorMessage; try { errorMessage = responseToErrorMessage(response); } catch (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(); }