Search in sources :

Example 6 with PostRequest

use of org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest in project ecf by eclipse.

the class Forum method postThread.

public boolean postThread(IThread thread) throws IllegalWriteException, BBException {
    if ((mode & READ_ONLY) == READ_ONLY) {
        throw new IllegalWriteException(E_READ_ONLY);
    }
    WebRequest request = new PostRequest(bb.getHttpClient(), bb.getURL(), "posting.php");
    NameValuePair[] params;
    params = new NameValuePair[] { new NameValuePair("subject", thread.getPrePostMessage().getName()), new NameValuePair("message", thread.getPrePostMessage().getMessage()), new NameValuePair("f", String.valueOf(id.getLongValue())), new NameValuePair("mode", "newtopic"), // checkbox : disabled new NameValuePair("notify", "on"),
    new NameValuePair("post", "Submit") };
    request.addParameters(params);
    // We seem to always have to get the response body.
    try {
        request.execute();
        request.getResponseBodyAsString();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    request.releaseConnection();
    return true;
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) PostRequest(org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest) WebRequest(org.eclipse.ecf.internal.bulletinboard.commons.webapp.WebRequest) IllegalWriteException(org.eclipse.ecf.bulletinboard.IllegalWriteException) IOException(java.io.IOException)

Example 7 with PostRequest

use of org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest in project ecf by eclipse.

the class ThreadBrowser2 method createRequest.

public WebRequest createRequest(int page) {
    /*
		 * String ppStr =
		 * bb.getActiveConfiguration().getProperties().getProperty(
		 * IBBConfiguration.P_POSTS_PER_PAGE);
		 */
    int pp = 15;
    int start = (page - 1) * pp;
    WebRequest req = new PostRequest(bb.getHttpClient(), bb.getURL(), "viewtopic.php?t=" + ((ThreadID) thread.getID()).getLongValue() + "&start=" + start);
    req.addParameter(new NameValuePair("postorder", "desc"));
    req.addParameter(new NameValuePair("postdays", "0"));
    req.addParameter(new NameValuePair("submit", "Go"));
    return req;
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) PostRequest(org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest) WebRequest(org.eclipse.ecf.internal.bulletinboard.commons.webapp.WebRequest) ThreadID(org.eclipse.ecf.internal.provider.phpbb.identity.ThreadID)

Example 8 with PostRequest

use of org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest in project ecf by eclipse.

the class Thread method postReply.

public ID postReply(IThreadMessage message) throws IllegalWriteException, BBException {
    if ((mode & READ_ONLY) == READ_ONLY) {
        throw new IllegalWriteException(E_READ_ONLY);
    }
    ThreadMessage msg = (ThreadMessage) message;
    // FIXME assert msg.bb == bb;
    assert msg.getThread() == this;
    PostRequest request = new PostRequest(bb.getHttpClient(), bb.getURL(), "newreply.php");
    NameValuePair[] params = new NameValuePair[] { new NameValuePair("emailupdate", "9999"), new NameValuePair("rating", "0") };
    request.addParameters(params);
    params = new NameValuePair[] { new NameValuePair("title", message.getName()), new NameValuePair("message", msg.getMessage()), new NameValuePair("iconid", "0"), new NameValuePair("s", ""), new NameValuePair("do", "postreply"), new NameValuePair("t", String.valueOf(id.getLongValue())) };
    request.addParameters(params);
    if (message.getReplyTo() != null) {
        params = new NameValuePair[] { new NameValuePair("p", String.valueOf(((ThreadMessageID) message.getReplyTo().getID()).getLongValue())) };
        request.addParameters(params);
    }
    params = new NameValuePair[] { new NameValuePair("posthash", ""), new NameValuePair("poststarttime", ""), new NameValuePair("sbutton", "Submit Reply"), new NameValuePair("parseurl", "1") // checkbox : disabled new NameValuePair("disablesmilies", "1"),
    };
    request.addParameters(params);
    try {
        request.execute();
        // TODO: do we have to do this?
        String resp = request.getResponseBodyAsString();
        Header newLocation = request.getMethod().getResponseHeader("Location");
        if (newLocation == null) {
            throw ((VBParser) bb.getParser()).createVBException("The message was not posted.", resp);
        }
        Matcher m = Pattern.compile("showthread.php\\?p=([0-9]+)").matcher(newLocation.getValue());
        if (m.find()) {
            synchronized (this) {
                lastReadMessageId = (ThreadMessageID) new ThreadMessageFactory().createBBObjectId(bb.getNamespace(), bb.getURL(), m.group(1));
                return lastReadMessageId;
            }
        } else {
            throw ((VBParser) bb.getParser()).createVBException("The message was not posted.", resp);
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NumberFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IDCreateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ThreadMessageFactory(org.eclipse.ecf.internal.provider.vbulletin.internal.ThreadMessageFactory) Matcher(java.util.regex.Matcher) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) IOException(java.io.IOException) PostRequest(org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest) Header(org.apache.commons.httpclient.Header) IllegalWriteException(org.eclipse.ecf.bulletinboard.IllegalWriteException) IThreadMessage(org.eclipse.ecf.bulletinboard.IThreadMessage)

Aggregations

PostRequest (org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest)8 IOException (java.io.IOException)7 NameValuePair (org.apache.commons.httpclient.NameValuePair)7 BBException (org.eclipse.ecf.bulletinboard.BBException)5 IllegalWriteException (org.eclipse.ecf.bulletinboard.IllegalWriteException)3 Matcher (java.util.regex.Matcher)2 IThreadMessage (org.eclipse.ecf.bulletinboard.IThreadMessage)2 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)2 ID (org.eclipse.ecf.core.identity.ID)2 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)2 WebRequest (org.eclipse.ecf.internal.bulletinboard.commons.webapp.WebRequest)2 ThreadID (org.eclipse.ecf.internal.provider.phpbb.identity.ThreadID)2 Header (org.apache.commons.httpclient.Header)1 MemberID (org.eclipse.ecf.internal.provider.phpbb.identity.MemberID)1 ThreadMessageID (org.eclipse.ecf.internal.provider.phpbb.identity.ThreadMessageID)1 MemberID (org.eclipse.ecf.internal.provider.vbulletin.identity.MemberID)1 ThreadID (org.eclipse.ecf.internal.provider.vbulletin.identity.ThreadID)1 MemberFactory (org.eclipse.ecf.internal.provider.vbulletin.internal.MemberFactory)1 ThreadMessageFactory (org.eclipse.ecf.internal.provider.vbulletin.internal.ThreadMessageFactory)1