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

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

Introduction

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

Prototype

int SC_NOT_FOUND

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

Click Source Link

Document

<tt>404 Not Found</tt> (HTTP/1.0 - RFC 1945)

Usage

From source file:org.alfresco.dataprep.SitePagesService.java

/**
 * Create a new blog post//from   w  w  w  . ja v  a  2s  .c o  m
 * @param userName String user name
 * @param password String password
 * @param siteName String site name
 * @param blogTitle String blog title
 * @param content String blog content
 * @param draft boolean create blog as draft. If not it will be published
 * @param tags List of tags
 * @return true if blog post is created (200 Status)
 */
@SuppressWarnings("unchecked")
public boolean createBlogPost(final String userName, final String password, final String siteName,
        final String blogTitle, final String content, final boolean draft, final List<String> tags) {
    if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password) || StringUtils.isEmpty(siteName)
            || StringUtils.isEmpty(blogTitle)) {
        throw new IllegalArgumentException("Null Parameters: Please correct");
    }
    AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
    String url = client.getApiUrl() + "blog/site/" + siteName + "/blog/posts";
    HttpPost post = new HttpPost(url);
    JSONObject body = new JSONObject();
    body.put("title", blogTitle);
    body.put("content", content);
    body.put("draft", draft);
    body.put("tags", createTagsArray(tags));
    HttpResponse response = client.executeRequest(userName, password, body, post);
    switch (response.getStatusLine().getStatusCode()) {
    case HttpStatus.SC_OK:
        if (logger.isTraceEnabled()) {
            logger.trace("Blog " + blogTitle + " is created successfuly");
        }
        return true;
    case HttpStatus.SC_NOT_FOUND:
        throw new RuntimeException("Invalid site " + siteName);
    default:
        logger.error("Unable to create blog page: " + response.toString());
        break;
    }
    return false;
}

From source file:org.alfresco.dataprep.SitePagesService.java

/**
 * Update blog post//from  w w  w .ja  v  a2 s  . c om
 * @param userName String user name
 * @param password String password
 * @param siteName String site name
 * @param blogTitle String blog title to be updated
 * @param newBlogTitle String new blog title
 * @param newBlogText String new blog text
 * @param isDraft boolean is draft
 * @return true if blog is updated (200 Status)
 */
@SuppressWarnings("unchecked")
public boolean updateBlogPost(final String userName, final String password, final String siteName,
        final String blogTitle, final String newBlogTitle, final String newBlogText, final boolean isDraft) {
    String blogName = getBlogName(userName, password, siteName, blogTitle, isDraft);
    AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
    String url = client.getApiUrl() + "blog/post/site/" + siteName + "/blog/" + blogName
            + "?page=blog-postlist";
    HttpPut put = new HttpPut(url);
    JSONObject body = new JSONObject();
    body.put("title", newBlogTitle);
    body.put("content", newBlogText);
    HttpResponse response = client.executeRequest(userName, password, body, put);
    switch (response.getStatusLine().getStatusCode()) {
    case HttpStatus.SC_OK:
        return true;
    case HttpStatus.SC_NOT_FOUND:
        throw new RuntimeException("Blog doesn't exists " + blogTitle);
    default:
        logger.error("Unable to update blog post: " + response.toString());
        break;
    }
    return false;
}

From source file:org.alfresco.dataprep.SitePagesService.java

/**
 * Delete blog post/*w  w  w .java 2s .  c  o  m*/
 * @param userName String user name
 * @param password String password
 * @param siteName String site name
 * @param blogTitle String blog title
 * @param isDraft boolean is draft
 * @return true if blog is removed (200 Status)
 * @throws RuntimeException if blog is not found
 */
public boolean deleteBlogPost(final String userName, final String password, final String siteName,
        final String blogTitle, final boolean isDraft) {
    String blogName = getBlogName(userName, password, siteName, blogTitle, isDraft);
    AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
    String url = client.getApiUrl() + "blog/post/site/" + siteName + "/blog/" + blogName
            + "?page=blog-postlist";
    HttpDelete delete = new HttpDelete(url);
    HttpResponse response = client.executeRequest(userName, password, delete);
    switch (response.getStatusLine().getStatusCode()) {
    case HttpStatus.SC_OK:
        return true;
    case HttpStatus.SC_NOT_FOUND:
        throw new RuntimeException("Blog doesn't exists " + blogTitle);
    default:
        logger.error("Unable to delete blog post: " + response.toString());
        break;
    }
    return false;
}

From source file:org.alfresco.dataprep.SitePagesService.java

/**
 * Create a new blog post/* ww w.j av  a 2 s.c o  m*/
 * @param userName String user name
 * @param password String password
 * @param siteName String site name
 * @param linkTitle String link title
 * @param url String link url
 * @param description String link description
 * @param internal boolean internal
 * @param tags List of tags
 * @return true if link is created (200 Status)
 * @throws RuntimeException if site is not found
 */
@SuppressWarnings("unchecked")
public boolean createLink(final String userName, final String password, final String siteName,
        final String linkTitle, final String url, final String description, final boolean internal,
        final List<String> tags) {
    if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password) || StringUtils.isEmpty(siteName)
            || StringUtils.isEmpty(linkTitle)) {
        throw new IllegalArgumentException("Null Parameters: Please correct");
    }
    AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
    String reqUrl = client.getApiUrl() + "links/site/" + siteName + "/links/posts";
    HttpPost post = new HttpPost(reqUrl);
    JSONObject body = new JSONObject();
    body.put("title", linkTitle);
    body.put("url", url);
    body.put("description", description);
    if (internal) {
        body.put("internal", internal);
    }
    body.put("tags", createTagsArray(tags));
    HttpResponse response = client.executeRequest(userName, password, body, post);
    switch (response.getStatusLine().getStatusCode()) {
    case HttpStatus.SC_OK:
        if (logger.isTraceEnabled()) {
            logger.trace("Link " + linkTitle + " is created successfuly");
        }
        return true;
    case HttpStatus.SC_NOT_FOUND:
        throw new RuntimeException("Invalid site " + siteName);
    default:
        logger.error("Unable to create link: " + response.toString());
        break;
    }
    return false;
}

From source file:org.alfresco.dataprep.SitePagesService.java

/**
 * Get the name (id) for blog post, link, discussion
 * @param userName String user name//  w ww  . j  av  a2  s  .  co  m
 * @param password String password
 * @param siteName String site name
 * @param title String blog title
 * @param draftBlog boolean is blog draft
 * @return Map<String, String> name, nodeRef and replyUrl
 * @throws RuntimeException if site is not found
 */
@SuppressWarnings("unchecked")
private Map<String, String> getIds(final String userName, final String password, final String siteName,
        final String title, final Page page) {
    String url = "";
    Map<String, String> ids = new HashMap<String, String>();
    AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
    switch (page) {
    case LINKS:
        url = client.getApiUrl() + "links/site/" + siteName
                + "/links?filter=all&contentLength=512&page=1&pageSize=10&startIndex=0";
        break;
    case BLOG:
        url = client.getApiUrl() + "blog/site/" + siteName + "/blog/posts";
        break;
    case DISCUSSIONS:
        url = client.getApiUrl() + "forum/site/" + siteName + "/discussions/posts";
        break;
    default:
        break;
    }
    HttpGet get = new HttpGet(url);
    try {
        HttpResponse response = client.execute(userName, password, get);
        switch (response.getStatusLine().getStatusCode()) {
        case HttpStatus.SC_OK:
            JSONArray jArray = client.getJSONArray(response, "", "items");
            Iterator<JSONObject> iterator = ((List<JSONObject>) jArray).iterator();
            while (iterator.hasNext() && jArray.size() > 0) {
                JSONObject factObj = (JSONObject) iterator.next();
                String theTitle = (String) factObj.get("title");
                if (title.toString().equalsIgnoreCase(theTitle)) {
                    ids.put("name", (String) factObj.get("name"));
                    ids.put("nodeRef", (String) factObj.get("nodeRef"));
                    if (page.pageId.equals("discussions-topiclist")) {
                        ids.put("repliesUrl", (String) factObj.get("repliesUrl"));
                    } else if (page.pageId.equals("blog-postlist") || page.pageId.equals("links")) {
                        ids.put("commentsUrl", (String) factObj.get("commentsUrl"));
                    }
                    return ids;
                }
            }
            return ids;
        case HttpStatus.SC_NOT_FOUND:
            throw new RuntimeException("Invalid site " + siteName);
        case HttpStatus.SC_UNAUTHORIZED:
            throw new RuntimeException("Invalid credentials");
        default:
            logger.error("Unable to find: " + title + " " + response.toString());
            break;
        }
    } catch (Exception e) {
        throw new RuntimeException("Failed to execute request:" + get, e);
    } finally {
        get.releaseConnection();
        client.close();
    }
    return ids;
}

From source file:org.alfresco.dataprep.SitePagesService.java

/**
 * Delete link//w  w  w .  j  av  a 2s .c  om
 * @param userName String user name
 * @param password String password
 * @param siteName String site name
 * @param linkTitle String blog title
 * @return true if link is removed (200 Status)
 */
@SuppressWarnings("unchecked")
public boolean deleteLink(final String userName, final String password, final String siteName,
        final String linkTitle) {
    String linkName = getLinkName(userName, password, siteName, linkTitle);
    AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
    String url = client.getApiUrl() + "links/delete/site/" + siteName + "/links";
    HttpPost post = new HttpPost(url);
    JSONObject body = new JSONObject();
    JSONArray array = new JSONArray();
    array.add(linkName);
    body.put("items", array);
    HttpResponse response = client.executeRequest(userName, password, body, post);
    switch (response.getStatusLine().getStatusCode()) {
    case HttpStatus.SC_OK:
        return true;
    case HttpStatus.SC_NOT_FOUND:
        throw new RuntimeException("Link doesn't exists " + linkTitle);
    default:
        logger.error("Unable to delete link: " + response.toString());
        break;
    }
    return false;
}

From source file:org.alfresco.dataprep.SitePagesService.java

/**
 * Update link//from w w w .  j  av  a  2s  .  c  o  m
 * @param userName String user name
 * @param password String password
 * @param siteName String site name
 * @param linkTitle String link title to be updated
 * @param newLinkTitle String new link title
 * @param newUrl String link new url
 * @param newDescription String new link description
 * @param newInternal boolean new internal
 * @param newTags new List of tags
 * @return true if link is updated (200 Status)
 */
@SuppressWarnings("unchecked")
public boolean updateLink(final String userName, final String password, final String siteName,
        final String linkTitle, final String newLinkTitle, final String newUrl, final String newDescription,
        final boolean newInternal, final List<String> newTags) {
    String linkName = getLinkName(userName, password, siteName, linkTitle);
    AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
    String url = client.getApiUrl() + "links/site/" + siteName + "/links/" + linkName;
    HttpPut put = new HttpPut(url);
    JSONObject body = new JSONObject();
    body.put("title", newLinkTitle);
    body.put("url", newUrl);
    body.put("description", newDescription);
    if (newInternal) {
        body.put("internal", newInternal);
    }
    body.put("tags", createTagsArray(newTags));
    HttpResponse response = client.executeRequest(userName, password, body, put);
    switch (response.getStatusLine().getStatusCode()) {
    case HttpStatus.SC_OK:
        return true;
    case HttpStatus.SC_NOT_FOUND:
        throw new RuntimeException("Link doesn't exists " + linkTitle);
    default:
        logger.error("Unable to update link: " + response.toString());
        break;
    }
    return false;
}

From source file:org.alfresco.dataprep.SitePagesService.java

/**
 * Create discussion topic/*  www .j  a  va2 s.  c  o m*/
 * @param userName String user name
 * @param password String password
 * @param siteName String site name
 * @param discussionTitle String topic title
 * @param text String topic content
 * @param tags List<String> tags
 * @return true if topic is created
 * @throws RuntimeException if site is not found
 */
@SuppressWarnings("unchecked")
public boolean createDiscussion(final String userName, final String password, final String siteName,
        final String discussionTitle, final String text, final List<String> tags) {
    if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password) || StringUtils.isEmpty(siteName)
            || StringUtils.isEmpty(discussionTitle)) {
        throw new IllegalArgumentException("Null Parameters: Please correct");
    }
    AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
    String reqUrl = client.getApiUrl() + "forum/site/" + siteName + "/discussions/posts";
    HttpPost post = new HttpPost(reqUrl);
    JSONObject body = new JSONObject();
    body.put("title", discussionTitle);
    body.put("content", text);
    body.put("tags", createTagsArray(tags));
    HttpResponse response = client.executeRequest(userName, password, body, post);
    switch (response.getStatusLine().getStatusCode()) {
    case HttpStatus.SC_OK:
        if (logger.isTraceEnabled()) {
            logger.trace("Discussion " + discussionTitle + " is created successfuly");
        }
        return true;
    case HttpStatus.SC_NOT_FOUND:
        throw new RuntimeException("Invalid site " + siteName);
    default:
        logger.error("Unable to create link: " + response.toString());
        break;
    }
    return false;
}

From source file:org.alfresco.dataprep.SitePagesService.java

/**
 * Update a discussion topic/*  ww w . ja v a 2  s  .c o m*/
 * @param userName String user name
 * @param password String password
 * @param siteName String site name
 * @param discussionTitle String discussion title to be updated
 * @param newDiscussionTitle String new title
 * @param newText String new text
 * @param newTags List<String> new tags
 * @return true if updated
 */
@SuppressWarnings("unchecked")
public boolean updateDiscussion(final String userName, final String password, final String siteName,
        final String discussionTitle, final String newDiscussionTitle, final String newText,
        final List<String> newTags) {
    String discussionName = getDiscussionName(userName, password, siteName, discussionTitle);
    AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
    String url = client.getApiUrl() + "forum/post/site/" + siteName + "/discussions/" + discussionName
            + "?page=discussions-topicview";
    HttpPut put = new HttpPut(url);
    JSONObject body = new JSONObject();
    body.put("title", newDiscussionTitle);
    body.put("content", newText);
    body.put("tags", createTagsArray(newTags));
    HttpResponse response = client.executeRequest(userName, password, body, put);
    switch (response.getStatusLine().getStatusCode()) {
    case HttpStatus.SC_OK:
        return true;
    case HttpStatus.SC_NOT_FOUND:
        throw new RuntimeException("Topic doesn't exists " + discussionTitle);
    default:
        logger.error("Unable to updated topic post: " + response.toString());
        break;
    }
    return false;
}

From source file:org.alfresco.dataprep.SitePagesService.java

/**
 * Delete a discussion topic/*from  w  ww  .ja  v a 2  s . c  o  m*/
 * @param userName String user name
 * @param password String password
 * @param siteName String site name
 * @param discussionTitle String discussion title
 * @return true if deleted
 */
public boolean deleteDiscussion(final String userName, final String password, final String siteName,
        final String discussionTitle) {
    String discussionName = getDiscussionName(userName, password, siteName, discussionTitle);
    AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject();
    String url = client.getApiUrl() + "forum/post/site/" + siteName + "/discussions/" + discussionName
            + "?page=discussions-topicview";
    HttpDelete delete = new HttpDelete(url);
    HttpResponse response = client.executeRequest(userName, password, delete);
    switch (response.getStatusLine().getStatusCode()) {
    case HttpStatus.SC_OK:
        return true;
    case HttpStatus.SC_NOT_FOUND:
        throw new RuntimeException("Topic doesn't exists " + discussionTitle);
    default:
        logger.error("Unable to delete topic post: " + response.toString());
        break;
    }
    return false;
}