Search in sources :

Example 1 with PostRequest

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

the class VBulletin method login.

public boolean login(IBBCredentials credentials) throws BBException {
    PostRequest request = new PostRequest(httpClient, url, "login.php");
    NameValuePair[] params = { new NameValuePair("vb_login_username", credentials.getUsername()), new NameValuePair("cookieuser", "1"), new NameValuePair("vb_login_password", credentials.getPassword()), new NameValuePair("submit", "Login"), new NameValuePair("s", ""), new NameValuePair("do", "login"), new NameValuePair("forceredirect", "0"), new NameValuePair("vb_login_md5password", ""), new NameValuePair("vb_login_md5password_utf", "") };
    request.setParameters(params);
    try {
        request.execute();
        request.releaseConnection();
        Map<String, String> detectedCookies = VBCookies.detectCookies(httpClient.getState().getCookies());
        if (detectedCookies.containsKey(VBCookies.KEY_SESS_ID)) {
            // We have a session id
            sessionId = detectedCookies.get(VBCookies.KEY_SESS_ID);
        }
        if (detectedCookies.containsKey(VBCookies.KEY_USER_ID)) {
            // We have a user id
            ID id = new MemberFactory().createBBObjectId(namespace, url, (String) detectedCookies.get(VBCookies.KEY_USER_ID));
            if (id == null) {
                return false;
            } else {
                loggedInMemberId = id;
                return true;
            }
        }
    } catch (Exception e) {
        throw new BBException(e);
    }
    return false;
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) PostRequest(org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest) MemberFactory(org.eclipse.ecf.internal.provider.vbulletin.internal.MemberFactory) BBException(org.eclipse.ecf.bulletinboard.BBException) ID(org.eclipse.ecf.core.identity.ID) ThreadID(org.eclipse.ecf.internal.provider.vbulletin.identity.ThreadID) MemberID(org.eclipse.ecf.internal.provider.vbulletin.identity.MemberID) IOException(java.io.IOException) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) BBException(org.eclipse.ecf.bulletinboard.BBException)

Example 2 with PostRequest

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

the class VBulletin method logout.

public boolean logout() throws BBException {
    PostRequest request = new PostRequest(httpClient, url, "logout.php");
    try {
        request.execute();
        request.releaseConnection();
        loggedInMemberId = null;
        return true;
    } catch (Exception e) {
        throw new BBException(e);
    }
}
Also used : PostRequest(org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest) BBException(org.eclipse.ecf.bulletinboard.BBException) IOException(java.io.IOException) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) BBException(org.eclipse.ecf.bulletinboard.BBException)

Example 3 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(), "posting.php");
    NameValuePair[] params = new NameValuePair[] { new NameValuePair("subject", msg.getName()), new NameValuePair("message", msg.getMessage()), new NameValuePair("t", String.valueOf(id.getLongValue())), new NameValuePair("mode", "reply"), // checkbox : disabled new NameValuePair("notify", "on"),
    new NameValuePair("post", "Submit") };
    request.addParameters(params);
    String resp = null;
    try {
        request.execute();
        resp = request.getResponseBodyAsString();
        String info = ((PHPBBParser) bb.getParser()).parseInformationMessage(resp);
        Matcher m = Pattern.compile("<a href=\"viewtopic.php\\?p=([0-9]+)(?:.*?)\">").matcher(info);
        if (m.find()) {
            synchronized (this) {
                try {
                    lastReadMessageId = (ThreadMessageID) new ThreadMessageFactory().createBBObjectId(bb.getNamespace(), bb.getURL(), m.group(1));
                    return lastReadMessageId;
                } catch (NumberFormatException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IDCreateException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        } else {
            throw new BBException("The message was not posted.");
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) Matcher(java.util.regex.Matcher) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) BBException(org.eclipse.ecf.bulletinboard.BBException) IOException(java.io.IOException) PostRequest(org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest) IllegalWriteException(org.eclipse.ecf.bulletinboard.IllegalWriteException) IThreadMessage(org.eclipse.ecf.bulletinboard.IThreadMessage)

Example 4 with PostRequest

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

the class PHPBB method login.

public boolean login(IBBCredentials credentials) throws BBException {
    PostRequest request = new PostRequest(httpClient, url, "login.php");
    NameValuePair[] params = { new NameValuePair("username", credentials.getUsername()), new NameValuePair("password", credentials.getPassword()), // disabled checkbox: new NameValuePair("autologin", "on"),
    new NameValuePair("redirect", ""), new NameValuePair("login", "Log in") };
    request.setParameters(params);
    try {
        request.execute();
        request.releaseConnection();
        Map<String, String> detectedCookies = PHPBBCookies.detectCookies(httpClient.getState().getCookies());
        if (detectedCookies.containsKey(PHPBBCookies.KEY_SESS_ID)) {
            // We have a session id
            sessionId = detectedCookies.get(PHPBBCookies.KEY_SESS_ID);
        }
        if (detectedCookies.containsKey(PHPBBCookies.KEY_USER_ID)) {
            // We have a user id
            ID id = new MemberFactory().createBBObjectId(getNamespace(), url, (String) detectedCookies.get(PHPBBCookies.KEY_USER_ID));
            if (id == null) {
                return false;
            } else {
                loggedInMemberId = id;
                return true;
            }
        }
    } catch (Exception e) {
        throw new BBException(e);
    }
    return false;
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) PostRequest(org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest) BBException(org.eclipse.ecf.bulletinboard.BBException) ID(org.eclipse.ecf.core.identity.ID) ThreadMessageID(org.eclipse.ecf.internal.provider.phpbb.identity.ThreadMessageID) MemberID(org.eclipse.ecf.internal.provider.phpbb.identity.MemberID) ThreadID(org.eclipse.ecf.internal.provider.phpbb.identity.ThreadID) IOException(java.io.IOException) BBException(org.eclipse.ecf.bulletinboard.BBException)

Example 5 with PostRequest

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

the class PHPBB method logout.

public boolean logout() throws BBException {
    PostRequest request = new PostRequest(httpClient, url, "login.php");
    request.addParameter(new NameValuePair("logout", "true"));
    try {
        request.execute();
        request.releaseConnection();
        loggedInMemberId = null;
        return true;
    } catch (Exception e) {
        throw new BBException(e);
    }
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) PostRequest(org.eclipse.ecf.internal.bulletinboard.commons.webapp.PostRequest) BBException(org.eclipse.ecf.bulletinboard.BBException) IOException(java.io.IOException) BBException(org.eclipse.ecf.bulletinboard.BBException)

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