Search in sources :

Example 76 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project xwiki-platform by xwiki.

the class ObjectsResourceTest method testPOSTObjectFormUrlEncoded.

@Test
public void testPOSTObjectFormUrlEncoded() throws Exception {
    final String TAG_VALUE = "TAG";
    NameValuePair[] nameValuePairs = new NameValuePair[2];
    nameValuePairs[0] = new NameValuePair("className", "XWiki.TagClass");
    nameValuePairs[1] = new NameValuePair("property#tags", TAG_VALUE);
    PostMethod postMethod = executePostForm(buildURI(ObjectsResource.class, getWiki(), this.spaces, this.pageName).toString(), nameValuePairs, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
    Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_CREATED, postMethod.getStatusCode());
    Object object = (Object) unmarshaller.unmarshal(postMethod.getResponseBodyAsStream());
    Assert.assertEquals(TAG_VALUE, getProperty(object, "tags").getValue());
    GetMethod getMethod = executeGet(buildURI(ObjectResource.class, getWiki(), this.spaces, this.pageName, object.getClassName(), object.getNumber()).toString());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    object = (Object) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    Assert.assertEquals(TAG_VALUE, getProperty(object, "tags").getValue());
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) PostMethod(org.apache.commons.httpclient.methods.PostMethod) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Object(org.xwiki.rest.model.jaxb.Object) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 77 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project xwiki-platform by xwiki.

the class ObjectsResourceTest method testPUTObjectFormUrlEncoded.

@Test
public void testPUTObjectFormUrlEncoded() throws Exception {
    final String TAG_VALUE = UUID.randomUUID().toString();
    Object objectToBePut = createObjectIfDoesNotExists("XWiki.TagClass", this.spaces, this.pageName);
    GetMethod getMethod = executeGet(buildURI(ObjectResource.class, getWiki(), this.spaces, this.pageName, objectToBePut.getClassName(), objectToBePut.getNumber()).toString());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Object object = (Object) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    NameValuePair[] nameValuePairs = new NameValuePair[1];
    nameValuePairs[0] = new NameValuePair("property#tags", TAG_VALUE);
    PostMethod postMethod = executePostForm(String.format("%s?method=PUT", buildURI(ObjectResource.class, getWiki(), this.spaces, this.pageName, objectToBePut.getClassName(), objectToBePut.getNumber()).toString()), nameValuePairs, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
    Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_ACCEPTED, postMethod.getStatusCode());
    Object updatedObjectSummary = (Object) unmarshaller.unmarshal(postMethod.getResponseBodyAsStream());
    Assert.assertEquals(TAG_VALUE, getProperty(updatedObjectSummary, "tags").getValue());
    Assert.assertEquals(object.getClassName(), updatedObjectSummary.getClassName());
    Assert.assertEquals(object.getNumber(), updatedObjectSummary.getNumber());
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) PostMethod(org.apache.commons.httpclient.methods.PostMethod) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Object(org.xwiki.rest.model.jaxb.Object) ObjectResource(org.xwiki.rest.resources.objects.ObjectResource) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 78 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project xwiki-platform by xwiki.

the class TagsResourceTest method testPUTTagsFormUrlEncoded.

@Test
public void testPUTTagsFormUrlEncoded() throws Exception {
    createPageIfDoesntExist(TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME, "Test");
    String tagName = UUID.randomUUID().toString();
    GetMethod getMethod = executeGet(buildURI(PageResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME).toString());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    NameValuePair[] nameValuePairs = new NameValuePair[1];
    nameValuePairs[0] = new NameValuePair("tags", tagName);
    PostMethod postMethod = executePostForm(String.format("%s?method=PUT", buildURI(PageTagsResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME).toString()), nameValuePairs, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
    Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_ACCEPTED, postMethod.getStatusCode());
    getMethod = executeGet(buildURI(PageTagsResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME).toString());
    Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
    Tags tags = (Tags) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
    boolean found = false;
    for (Tag t : tags.getTags()) {
        if (tagName.equals(t.getName())) {
            found = true;
            break;
        }
    }
    Assert.assertTrue(found);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) PostMethod(org.apache.commons.httpclient.methods.PostMethod) GetMethod(org.apache.commons.httpclient.methods.GetMethod) Tag(org.xwiki.rest.model.jaxb.Tag) PageTagsResource(org.xwiki.rest.resources.pages.PageTagsResource) Tags(org.xwiki.rest.model.jaxb.Tags) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 79 with NameValuePair

use of org.apache.commons.httpclient.NameValuePair in project spatial-portal by AtlasOfLivingAustralia.

the class PhylogeneticDiversityListResults method evalArea.

private void evalArea(SelectedArea sa) {
    try {
        Query sq = QueryUtil.queryFromSelectedArea(selectedQuery, sa, null, false, null);
        CSVReader r = new CSVReader(new StringReader(sq.speciesList()));
        JSONArray ja = new JSONArray();
        for (String[] s : r.readAll()) {
            ja.add(s[1]);
        }
        // call pd with specieslist=ja.toString()
        String url = CommonData.getSettings().getProperty(CommonData.PHYLOLIST_URL) + "/phylo/getPD";
        NameValuePair[] params = new NameValuePair[2];
        params[0] = new NameValuePair("noTreeText", StringConstants.TRUE);
        params[1] = new NameValuePair("speciesList", ja.toString());
        JSONParser jp = new JSONParser();
        JSONArray pds = (JSONArray) jp.parse(Util.readUrlPost(url, params));
        Map<String, String> pdrow = new HashMap<String, String>();
        Map<String, JSONArray> speciesRow = new HashMap<String, JSONArray>();
        for (int j = 0; j < pds.size(); j++) {
            String tree = "" + ((JSONObject) pds.get(j)).get(StringConstants.STUDY_ID);
            pdrow.put(tree, ((JSONObject) pds.get(j)).get("pd").toString());
            speciesRow.put(tree, (JSONArray) ((JSONObject) pds.get(j)).get("taxaRecognised"));
            // maxPD retrieval
            String maxPd = ((JSONObject) pds.get(j)).get("maxPd").toString();
            for (int k = 0; k < selectedTrees.size(); k++) {
                if (((Map<String, String>) selectedTrees.get(k)).get(StringConstants.STUDY_ID).equals(tree)) {
                    ((Map<String, String>) selectedTrees.get(k)).put("maxPd", maxPd);
                }
            }
        }
        areaPds.add(pdrow);
        areaSpeciesMatches.add(speciesRow);
    } catch (Exception e) {
        LOGGER.error("failed processing a pd for a selected area.", e);
    }
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) Query(au.org.ala.spatial.util.Query) CSVReader(au.com.bytecode.opencsv.CSVReader) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) StringReader(java.io.StringReader) JSONParser(org.json.simple.parser.JSONParser)

Example 80 with NameValuePair

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

the class MemberGroup method attainDetailsFetched.

private void attainDetailsFetched() {
    if (!detailsFetched) {
        GetRequest request = new GetRequest(bb.getHttpClient(), bb.getURL(), "groupcp.php");
        request.addParameter(new NameValuePair("g", String.valueOf(id.getLongValue())));
        String resp = null;
        try {
            request.execute();
            resp = request.getResponseBodyAsString();
        } catch (IOException e) {
            e.printStackTrace();
        }
        request.releaseConnection();
        if (resp != null) {
            MemberGroup group = ((PHPBBParser) bb.getParser()).parseMemberGroup(resp);
            group.detailsFetched = true;
            this.description = group.getDescription();
        }
    }
}
Also used : IMemberGroup(org.eclipse.ecf.bulletinboard.IMemberGroup) NameValuePair(org.apache.commons.httpclient.NameValuePair) GetRequest(org.eclipse.ecf.internal.bulletinboard.commons.webapp.GetRequest) IOException(java.io.IOException)

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