Example usage for org.apache.commons.httpclient HttpStatus SC_NO_CONTENT

List of usage examples for org.apache.commons.httpclient HttpStatus SC_NO_CONTENT

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpStatus SC_NO_CONTENT.

Prototype

int SC_NO_CONTENT

To view the source code for org.apache.commons.httpclient HttpStatus SC_NO_CONTENT.

Click Source Link

Document

<tt>204 No Content</tt> (HTTP/1.0 - RFC 1945)

Usage

From source file:com.agile_coder.poker.server.stories.steps.ResetEstimatesSteps.java

@Given("that estimates have been revealed")
public void reveal() throws IOException {
    startServer();//from ww  w .  ja  v  a2 s .  c o  m
    sessionId = createSession();
    int result = submitEstimate(sessionId, "Jon", "3");
    assertEquals(HttpStatus.SC_NO_CONTENT, result);
}

From source file:com.agile_coder.poker.server.stories.steps.SubmitStoryPointEstimateSteps.java

@Then("the server records my estimate")
public void validateSubmit() {
    assertEquals(HttpStatus.SC_NO_CONTENT, result);
}

From source file:com.agile_coder.poker.server.stories.steps.ResetEstimatesSteps.java

@When("I reset the estimates")
public void reset() throws IOException {
    HttpClient client = new HttpClient();
    DeleteMethod delete = new DeleteMethod(BASE_URL + "/" + sessionId + "/status");
    client.executeMethod(delete);// w w  w.j a  v a  2  s.  c om
    assertEquals(HttpStatus.SC_NO_CONTENT, delete.getStatusCode());
}

From source file:com.mosso.client.cloudfiles.FilesResponse.java

/**
 * Checks to see if the user managed to login with their credentials.
 *
 * @return true is login succeeded false otherwise
 *//*from w  w  w.  ja va 2  s. c om*/
public boolean loginSuccess() {
    if (getStatusCode() == HttpStatus.SC_UNAUTHORIZED)
        return false;

    if (getStatusCode() == HttpStatus.SC_NO_CONTENT)
        return true;

    return false;
}

From source file:com.owncloud.android.operations.EmptyTrashbinFileOperation.java

private boolean isSuccess(int status) {
    return status == HttpStatus.SC_NO_CONTENT;
}

From source file:com.myGengo.alfresco.webscripts.NodeContentGet.java

public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException {
    ContentReader textReader = null;//from   w  w  w .ja v a 2  s  .c  o  m
    Exception transformException = null;

    String nodeRef = req.getParameter("nodeRef");
    if (nodeRef == null) {
        throw new WebScriptException("nodeRef parameter is required for GetNodeContent");
    }

    ContentReader reader = contentService.getReader(new NodeRef(nodeRef), ContentModel.PROP_CONTENT);
    if (reader == null) {
        res.setStatus(HttpStatus.SC_NO_CONTENT);
        return;
    }

    // Perform transformation catering for mimetype AND encoding
    ContentWriter writer = contentService.getTempWriter();
    writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
    writer.setEncoding("UTF-8"); // Expect transformers to produce UTF-8

    ContentTransformer transformer = contentService.getTransformer(reader.getMimetype(),
            MimetypeMap.MIMETYPE_TEXT_PLAIN);
    if (transformer == null) {
        res.setStatus(HttpStatus.SC_NO_CONTENT);
        return;
    }

    try {
        transformer.transform(reader, writer);
    } catch (ContentIOException e) {
        transformException = e;
    }

    if (transformException == null) {
        // point the reader to the new-written content
        textReader = writer.getReader();
        // Check that the reader is a view onto something concrete
        if (textReader == null || !textReader.exists()) {
            transformException = new ContentIOException("The transformation did not write any content, yet: \n"
                    + "   transformer:     " + transformer + "\n" + "   temp writer:     " + writer);
        }
    }

    if (transformException != null) {
        res.setStatus(HttpStatus.SC_NO_CONTENT);
    } else {
        res.setStatus(HttpStatus.SC_OK);
        Date modified = new Date();
        streamContentImpl(req, res, textReader, false, modified, String.valueOf(modified.getTime()), null);
    }
}

From source file:com.zimbra.cs.store.http.HttpStoreManager.java

@Override
public String writeStreamToStore(InputStream in, long actualSize, Mailbox mbox)
        throws IOException, ServiceException {
    MessageDigest digest;//w  w  w  .j a v  a 2 s . c  o  m
    try {
        digest = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e) {
        throw ServiceException.FAILURE("SHA-256 digest not found", e);
    }
    ByteUtil.PositionInputStream pin = new ByteUtil.PositionInputStream(new DigestInputStream(in, digest));

    HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
    PostMethod post = new PostMethod(getPostUrl(mbox));
    try {
        HttpClientUtil.addInputStreamToHttpMethod(post, pin, actualSize, "application/octet-stream");
        int statusCode = HttpClientUtil.executeMethod(client, post);
        if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED
                || statusCode == HttpStatus.SC_NO_CONTENT) {
            return getLocator(post, ByteUtil.encodeFSSafeBase64(digest.digest()), pin.getPosition(), mbox);
        } else {
            throw ServiceException.FAILURE("error POSTing blob: " + post.getStatusText(), null);
        }
    } finally {
        post.releaseConnection();
    }
}

From source file:com.owncloud.android.operations.RestoreFileVersionOperation.java

private boolean isSuccess(int status) {
    return status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT;
}

From source file:com.agile_coder.poker.server.stories.steps.BaseSteps.java

protected void reveal(int session) throws IOException {
    HttpClient client = new HttpClient();
    String revealUrl = BASE_URL + "/" + session + "/reveal";
    PutMethod put = new PutMethod(revealUrl);
    int result = executeMethod(client, put);
    assertEquals(HttpStatus.SC_NO_CONTENT, result);

}

From source file:edu.unc.lib.dl.admin.controller.AbstractSwordController.java

public String updateDatastream(String pid, String datastream, HttpServletRequest request,
        HttpServletResponse response) {//w w w .j a v  a  2  s  .  c  o m
    String responseString = null;
    String dataUrl = swordUrl + "object/" + pid;
    if (datastream != null)
        dataUrl += "/" + datastream;

    Abdera abdera = new Abdera();
    Entry entry = abdera.newEntry();
    Parser parser = abdera.getParser();
    Document<FOMExtensibleElement> doc;
    HttpClient client;
    PutMethod method;

    ParserOptions parserOptions = parser.getDefaultParserOptions();
    parserOptions.setCharset(request.getCharacterEncoding());

    try {

        doc = parser.parse(request.getInputStream(), parserOptions);
        entry.addExtension(doc.getRoot());

        client = HttpClientUtil.getAuthenticatedClient(dataUrl, swordUsername, swordPassword);
        client.getParams().setAuthenticationPreemptive(true);
        method = new PutMethod(dataUrl);
        // Pass the users groups along with the request
        method.addRequestHeader(HttpClientUtil.FORWARDED_GROUPS_HEADER, GroupsThreadStore.getGroupString());

        Header header = new Header("Content-Type", "application/atom+xml");
        method.setRequestHeader(header);
        StringWriter stringWriter = new StringWriter(2048);
        StringRequestEntity requestEntity;
        entry.writeTo(stringWriter);
        requestEntity = new StringRequestEntity(stringWriter.toString(), "application/atom+xml", "UTF-8");
        method.setRequestEntity(requestEntity);
    } catch (UnsupportedEncodingException e) {
        log.error("Encoding not supported", e);
        return null;
    } catch (IOException e) {
        log.error("IOException while writing entry", e);
        return null;
    }

    try {
        client.executeMethod(method);
        response.setStatus(method.getStatusCode());
        if (method.getStatusCode() == HttpStatus.SC_NO_CONTENT) {
            // success
            return "";
        } else if (method.getStatusCode() >= 400 && method.getStatusCode() <= 500) {
            if (method.getStatusCode() == 500)
                log.warn("Failed to upload " + datastream + " " + method.getURI().getURI());
            // probably a validation problem
            responseString = method.getResponseBodyAsString();
            return responseString;
        } else {
            response.setStatus(500);
            throw new Exception("Failure to update fedora content due to response of: "
                    + method.getStatusLine().toString() + "\nPath was: " + method.getURI().getURI());
        }
    } catch (Exception e) {
        log.error("Error while attempting to stream Fedora content for " + pid, e);
    } finally {
        if (method != null)
            method.releaseConnection();
    }
    return responseString;
}