Search in sources :

Example 86 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project ecf by eclipse.

the class Forum method getThreads.

public Collection<IThread> getThreads() {
    PHPBBParser parser = (PHPBBParser) bb.getParser();
    Map<ID, IThread> threadMap = null;
    try {
        WebRequest request = new GetRequest(bb.getHttpClient(), new URL(id.toExternalForm()), "");
        request.addParameter(new NameValuePair("f", String.valueOf(id.getLongValue())));
        request.execute();
        String resp = request.getResponseBodyAsString();
        request.releaseConnection();
        threadMap = parser.parseThreads(resp);
        for (IThread thread : threadMap.values()) {
            ((AbstractBBObject) thread).setBulletinBoard(bb);
            ((Thread) thread).forum = this;
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return new HashSet<IThread>(threadMap.values());
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) AbstractBBObject(org.eclipse.ecf.internal.bulletinboard.commons.AbstractBBObject) WebRequest(org.eclipse.ecf.internal.bulletinboard.commons.webapp.WebRequest) GetRequest(org.eclipse.ecf.internal.bulletinboard.commons.webapp.GetRequest) ID(org.eclipse.ecf.core.identity.ID) ForumID(org.eclipse.ecf.internal.provider.phpbb.identity.ForumID) IOException(java.io.IOException) URL(java.net.URL) IThread(org.eclipse.ecf.bulletinboard.IThread) HashSet(java.util.HashSet)

Example 87 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair 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 88 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project ecf by eclipse.

the class Forum method getThreads.

public Collection<IThread> getThreads() {
    VBParser parser = (VBParser) bb.getParser();
    Map<ID, IThread> threadMap = null;
    WebRequest request = new GetRequest(bb.getHttpClient(), getURL(), "");
    request.addParameter(new NameValuePair("f", String.valueOf(id.getLongValue())));
    try {
        request.execute();
        String resp = request.getResponseBodyAsString();
        request.releaseConnection();
        threadMap = parser.parseThreads(resp);
        for (IThread thread : threadMap.values()) {
            ((AbstractBBObject) thread).setBulletinBoard(bb);
            ((Thread) thread).forum = this;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return new HashSet<IThread>(threadMap.values());
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) AbstractBBObject(org.eclipse.ecf.internal.bulletinboard.commons.AbstractBBObject) WebRequest(org.eclipse.ecf.internal.bulletinboard.commons.webapp.WebRequest) GetRequest(org.eclipse.ecf.internal.bulletinboard.commons.webapp.GetRequest) ID(org.eclipse.ecf.core.identity.ID) ForumID(org.eclipse.ecf.internal.provider.vbulletin.identity.ForumID) IOException(java.io.IOException) IThread(org.eclipse.ecf.bulletinboard.IThread) HashSet(java.util.HashSet)

Example 89 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project ecf by eclipse.

the class TestCookieCompatibilitySpec method testParseAttributeNullPath.

public void testParseAttributeNullPath() throws Exception {
    CookieSpec cookiespec = new CookieSpecBase();
    Cookie cookie = new Cookie();
    cookiespec.parseAttribute(new NameValuePair("path", null), cookie);
    assertEquals("/", cookie.getPath());
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) NameValuePair(org.apache.commons.httpclient.NameValuePair)

Example 90 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project ecf by eclipse.

the class TestCookieCompatibilitySpec method testParseAttributeUnknownValue.

public void testParseAttributeUnknownValue() throws Exception {
    CookieSpec cookiespec = new CookieSpecBase();
    Cookie cookie = new Cookie();
    cookiespec.parseAttribute(new NameValuePair("nonsense", null), cookie);
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) NameValuePair(org.apache.commons.httpclient.NameValuePair)

Aggregations

NameValuePair (org.apache.commons.httpclient.NameValuePair)217 ArrayList (java.util.ArrayList)114 Credentials (org.apache.commons.httpclient.Credentials)64 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)64 Test (org.junit.Test)61 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)49 JsonObject (javax.json.JsonObject)43 PostMethod (org.apache.commons.httpclient.methods.PostMethod)41 HashMap (java.util.HashMap)28 IOException (java.io.IOException)23 Header (org.apache.commons.httpclient.Header)21 JsonArray (javax.json.JsonArray)20 HttpClient (org.apache.commons.httpclient.HttpClient)19 HashSet (java.util.HashSet)17 HttpMethod (org.apache.commons.httpclient.HttpMethod)16 GetMethod (org.apache.commons.httpclient.methods.GetMethod)16 Cookie (org.apache.commons.httpclient.Cookie)13 GetRequest (org.eclipse.ecf.internal.bulletinboard.commons.webapp.GetRequest)10 LinkedList (java.util.LinkedList)8 Map (java.util.Map)8