Skip to content
This repository was archived by the owner on Jun 26, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed lib/commons-logging-1.1.1.jar
Binary file not shown.
Binary file removed lib/httpclient-4.2.1.jar
Binary file not shown.
Binary file removed lib/httpcore-4.2.1.jar
Binary file not shown.
Binary file removed lib/httpmime-4.2.1.jar
Binary file not shown.
58 changes: 58 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.mediawiki</groupId>
<artifactId>api</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>java-mwapi</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.5</source>
</configuration>
</plugin>
</plugins>
</build>



<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.1-beta1</version>
</dependency>
<dependency>
<groupId>org.mediawiki</groupId>
<artifactId>java-mwapi</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
<type>jar</type>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOError;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import javax.xml.parsers.*;
Expand All @@ -13,7 +14,7 @@
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import de.mastacode.http.Http.HttpRequestBuilder;
import org.mediawiki.api.de.mastacode.http.Http.HttpRequestBuilder;

public class ApiResult {
private Node doc;
Expand All @@ -27,7 +28,8 @@ public class ApiResult {
static ApiResult fromRequestBuilder(HttpRequestBuilder builder, HttpClient client) throws IOException {
try {
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = docBuilder.parse(builder.use(client).charset("utf-8").data("format", "xml").asResponse().getEntity().getContent());
InputStream response = builder.use(client).charset("utf-8").data("format", "xml").asResponse().getEntity().getContent();
Document doc = docBuilder.parse(response);
return new ApiResult(doc);
} catch (ParserConfigurationException e) {
// I don't know wtf I can do about this on...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;

import de.mastacode.http.*;
import de.mastacode.http.Http.HttpRequestBuilder;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.AbstractHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.mediawiki.api.de.mastacode.http.Http;
import org.mediawiki.api.de.mastacode.http.Http.HttpRequestBuilder;
import org.mediawiki.api.de.mastacode.http.ProgressListener;

public class MWApi {
public class RequestBuilder {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.mastacode.http;
package org.mediawiki.api.de.mastacode.http;

import java.io.IOException;
import java.io.InputStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.mastacode.http;
package org.mediawiki.api.de.mastacode.http;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.mastacode.http;
package org.mediawiki.api.de.mastacode.http;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -58,7 +58,7 @@
import org.apache.http.util.ByteArrayBuffer;
import org.apache.http.util.EntityUtils;

import de.mastacode.http.Http.HttpRequestBuilder;


/**
* Fluent builder for the {@linkplain HttpClient} to simplify its usage.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.mastacode.http;
package org.mediawiki.api.de.mastacode.http;

public interface ProgressListener {
void onProgress(long transferred, long total);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,24 @@
package org.mediawiki.api.tests;

import static org.junit.Assert.*;
package org.mediawiki.api;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.List;

import javax.management.RuntimeErrorException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;

import org.apache.http.impl.client.DefaultHttpClient;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.mediawiki.api.ApiResult;
import org.mediawiki.api.MWApi;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSSerializer;

import com.sun.jmx.snmp.SnmpString;

import de.mastacode.http.ProgressListener;
import org.mediawiki.api.de.mastacode.http.ProgressListener;

public class MWApiTest {

// Test accounts on local wiki. For write tests
// Test accounts on local wiki. For write tests
// Setup your local wiki and create this account before running tests
private final String USERNAME = "yuvipanda";
private final String PASSWORD = "plasmafury";
private final String WRITEAPIURL = "http://localhost/w/api.php";
private final String PASSWORD = "testingtesting";
private final String WRITEAPIURL = "http://test2.wikipedia.org/w/api.php";

// Use testwiki for read only tests
private final String READAPIURL = "http://test.wikipedia.org/w/api.php";
Expand Down Expand Up @@ -111,7 +90,7 @@ private String sha1Of(String filepath) throws IOException {
public void testUpload() throws IOException {
setupWriteableAPI();

String filepath = this.getClass().getResource("test.png").getFile();
String filepath = Thread.currentThread().getContextClassLoader().getResource("test.png").getFile();
assertEquals("Success", api.login(USERNAME, PASSWORD));
FileInputStream stream = new FileInputStream(filepath);
ApiResult result = api.upload("test", stream, "yo!", "Wassup?");
Expand Down Expand Up @@ -144,8 +123,8 @@ private long countBytes(InputStream source) throws IOException {
@Test
public void testUploadWithProgress() throws IOException {
setupWriteableAPI();
String filepath = this.getClass().getResource("test.png").getFile();

String filepath = Thread.currentThread().getContextClassLoader().getResource("test.png").getFile();
assertEquals("Success", api.login(USERNAME, PASSWORD));
FileInputStream stream = new FileInputStream(filepath);
FileInputStream streamForCounting = new FileInputStream(filepath);
Expand Down Expand Up @@ -208,4 +187,4 @@ public void testAnonymousEditToken() throws IOException {
assertEquals("+\\", api.getEditToken());
}

}
}