GistLabs / mechanize

mechanize for java
http://gistlabs.com/software/mechanize-for-java/
Mozilla Public License 2.0
78 stars 21 forks source link

mechanize for java

mechanize is a stateful HTTP web services client library (RESTful) with support for HTML, JSON, and XML services. Because mechanize is stateful and allow inspection of web resources, it naturally support GET-then-POST semantics and helps avoid hard-coding clients.

See the Mechanize Wiki for more details and opinions on how RESTful clients should behave.

====== Releases:

========

Here is a testcase showing mechanize at work with HTML:

    @Test public void testGooglePageSearchForm() {
        MechanizeAgent agent = new MechanizeAgent();
        Document page = agent.get("http://www.google.com");
        Form form = page.form("f");
        form.get("q").set("mechanize java");
        Resource response = form.submit();
        assertTrue(response.getTitle().startsWith("mechanize java"));
    }

Here is a testcase showing mechanize using a Google JSON web service:

    @Test
    public void testGoogleApi() throws JSONException {
        MechanizeAgent agent = new MechanizeAgent();
        JsonDocument json = agent.doRequest(googleUrl).add("shortUrl", shortUrl).add("projection", "FULL").get();

        assertEquals(longUrl, json.getRoot().find("longUrl").getValue());

        String value = json.getRoot().find("analytics month countries#US count").getValue();
        assertTrue(value, Integer.valueOf(value)>=1);
    }

=========

Include this library (or download) from the Maven repository: http://search.maven.org/#browse%7C687823805