Search in sources :

Example 96 with StringRequestEntity

use of org.apache.commons.httpclient.methods.StringRequestEntity in project lobcder by skoulouzis.

the class TestWebWAVFS method testCreateAndDeleteFile.

@Test
public void testCreateAndDeleteFile() throws IOException, DavException {
    System.err.println("testCreateAndDeleteFile");
    // Make sure it's deleted
    String testFileURI1 = uri.toASCIIString() + TestSettings.TEST_FILE_NAME1;
    DeleteMethod del = new DeleteMethod(testFileURI1);
    int status = client1.executeMethod(del);
    testFileURI1 = uri.toASCIIString() + TestSettings.TEST_FILE_NAME1;
    PutMethod put = new PutMethod(testFileURI1);
    put.setRequestEntity(new StringRequestEntity(TestSettings.TEST_DATA, "text/plain", "UTF-8"));
    status = client1.executeMethod(put);
    assertEquals(HttpStatus.SC_CREATED, status);
    String testFileURI2 = uri.toASCIIString() + TestSettings.TEST_TXT_FILE_NAME;
    put = new PutMethod(testFileURI2);
    put.setRequestEntity(new StringRequestEntity(TestSettings.TEST_DATA, "text/plain", "UTF-8"));
    status = client1.executeMethod(put);
    assertEquals(HttpStatus.SC_CREATED, status);
    utils.deleteResource(testFileURI1, true);
    utils.deleteResource(testFileURI2, true);
}
Also used : DeleteMethod(org.apache.jackrabbit.webdav.client.methods.DeleteMethod) StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) PutMethod(org.apache.jackrabbit.webdav.client.methods.PutMethod) Test(org.junit.Test)

Example 97 with StringRequestEntity

use of org.apache.commons.httpclient.methods.StringRequestEntity in project lobcder by skoulouzis.

the class TestWebWAVFS method testPutGet.

// @Test
// public void testUpDownloadFileWithSpace() throws IOException, DavException {
// System.err.println("testUpDownloadFileWithSpace");
// String testFileURI1 = uri.toASCIIString() + "file with spaces";
// 
// utils.createFile(testFileURI1, true);
// 
// GetMethod get = new GetMethod(testFileURI1);
// int status = client1.executeMethod(get);
// assertEquals(HttpStatus.SC_OK, status);
// assertEquals(TestSettings.TEST_DATA, get.getResponseBodyAsString());
// 
// utils.deleteResource(testFileURI1, false);
// }
@Test
public void testPutGet() throws VlException, IOException {
    System.err.println("testPutGet");
    String testFileURI1 = uri.toASCIIString() + TestSettings.TEST_FILE_NAME1 + ".txt";
    try {
        PutMethod put = new PutMethod(testFileURI1);
        put.setRequestEntity(new StringRequestEntity(TestSettings.TEST_DATA, "text/plain", "UTF-8"));
        int status = client1.executeMethod(put);
        assertEquals(HttpStatus.SC_CREATED, status);
        GetMethod get = new GetMethod(testFileURI1);
        client1.executeMethod(get);
        status = get.getStatusCode();
        assertEquals(HttpStatus.SC_OK, status);
        String content = get.getResponseBodyAsString();
        assertEquals(TestSettings.TEST_DATA.length(), content.length());
        assertTrue(content.equals(TestSettings.TEST_DATA));
    } finally {
        utils.deleteResource(testFileURI1, false);
    }
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) GetMethod(org.apache.commons.httpclient.methods.GetMethod) PutMethod(org.apache.jackrabbit.webdav.client.methods.PutMethod) Test(org.junit.Test)

Example 98 with StringRequestEntity

use of org.apache.commons.httpclient.methods.StringRequestEntity in project lobcder by skoulouzis.

the class TestWebWAVFS method testSetGetPropertySet.

@Test
public void testSetGetPropertySet() throws IOException, DavException {
    System.err.println("testSetGetPropertySet");
    String testFileURI1 = this.uri.toASCIIString() + TestSettings.TEST_FILE_NAME1 + ".txt";
    PutMethod put = new PutMethod(testFileURI1);
    put.setRequestEntity(new StringRequestEntity(TestSettings.TEST_DATA, "text/plain", "UTF-8"));
    int status = client1.executeMethod(put);
    assertEquals(HttpStatus.SC_CREATED, status);
    PropFindMethod propFind = new PropFindMethod(testFileURI1, DavConstants.PROPFIND_ALL_PROP_INCLUDE, DavConstants.DEPTH_0);
    status = client1.executeMethod(propFind);
    assertEquals(HttpStatus.SC_MULTI_STATUS, status);
    MultiStatus multiStatus = propFind.getResponseBodyAsMultiStatus();
    MultiStatusResponse[] responses = multiStatus.getResponses();
    assertEquals(HttpStatus.SC_OK, responses[0].getStatus()[0].getStatusCode());
    DavPropertySet allProp = utils.getProperties(responses[0]);
    // DavPropertyIterator iter = allProp.iterator();
    // while (iter.hasNext()) {
    // DavProperty<?> p = iter.nextProperty();
    // System.out.println("P: " + p.getName() + " " + p.getValue());
    // }
    String isCollStr = (String) allProp.get(DavPropertyName.ISCOLLECTION).getValue();
    Boolean isCollection = Boolean.getBoolean(isCollStr);
    assertFalse(isCollection);
    String lenStr = (String) allProp.get(DavPropertyName.GETCONTENTLENGTH).getValue();
    assertEquals(Long.valueOf(lenStr), Long.valueOf(TestSettings.TEST_DATA.length()));
    String contentType = (String) allProp.get(DavPropertyName.GETCONTENTTYPE).getValue();
    assertEquals("text/plain; charset=UTF-8", contentType);
    utils.deleteResource(testFileURI1, true);
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) PropFindMethod(org.apache.jackrabbit.webdav.client.methods.PropFindMethod) PutMethod(org.apache.jackrabbit.webdav.client.methods.PutMethod) Test(org.junit.Test)

Example 99 with StringRequestEntity

use of org.apache.commons.httpclient.methods.StringRequestEntity in project cloudstack by apache.

the class BigSwitchBcfApi method executeCreateObject.

protected <T> String executeCreateObject(final T newObject, final String uri, final Map<String, String> parameters) throws BigSwitchBcfApiException {
    checkInvariants();
    PostMethod pm = (PostMethod) createMethod("post", uri, _port);
    setHttpHeader(pm);
    try {
        pm.setRequestEntity(new StringRequestEntity(gson.toJson(newObject), CONTENT_JSON, null));
    } catch (UnsupportedEncodingException e) {
        throw new BigSwitchBcfApiException("Failed to encode json request body", e);
    }
    executeMethod(pm);
    String hash = checkResponse(pm, "BigSwitch HTTP create failed: ");
    pm.releaseConnection();
    return hash;
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) PostMethod(org.apache.commons.httpclient.methods.PostMethod) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 100 with StringRequestEntity

use of org.apache.commons.httpclient.methods.StringRequestEntity in project cloudstack by apache.

the class NeutronNetworksNorthboundAction method createNeutronNetwork.

@SuppressWarnings("unchecked")
public <T> T createNeutronNetwork(final NeutronNetworkWrapper newNetworkWrapper) throws NeutronRestApiException {
    try {
        String uri = NeutronNorthboundEnum.NETWORKS_URI.getUri();
        StringRequestEntity entity = new StringRequestEntity(gsonNeutronNetwork.toJson(newNetworkWrapper), JSON_CONTENT_TYPE, null);
        String bodystring = executePost(uri, entity);
        T result = (T) gsonNeutronNetwork.fromJson(bodystring, TypeToken.get(NeutronNetworkWrapper.class).getType());
        return result;
    } catch (UnsupportedEncodingException e) {
        throw new NeutronRestApiException("Failed to encode json request body", e);
    }
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NeutronRestApiException(org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException) NeutronNetworkWrapper(org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper)

Aggregations

StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)102 PostMethod (org.apache.commons.httpclient.methods.PostMethod)63 HttpClient (org.apache.commons.httpclient.HttpClient)33 Test (org.junit.Test)23 PutMethod (org.apache.commons.httpclient.methods.PutMethod)19 RequestEntity (org.apache.commons.httpclient.methods.RequestEntity)18 IOException (java.io.IOException)15 UnsupportedEncodingException (java.io.UnsupportedEncodingException)13 AuthRequestHandler (org.apache.commons.httpclient.server.AuthRequestHandler)12 HttpRequestHandlerChain (org.apache.commons.httpclient.server.HttpRequestHandlerChain)12 HttpServiceHandler (org.apache.commons.httpclient.server.HttpServiceHandler)12 Header (org.apache.commons.httpclient.Header)9 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)9 GetMethod (org.apache.commons.httpclient.methods.GetMethod)9 InputStream (java.io.InputStream)8 InputStreamRequestEntity (org.apache.commons.httpclient.methods.InputStreamRequestEntity)7 StringWriter (java.io.StringWriter)6 Map (java.util.Map)6 ByteArrayRequestEntity (org.apache.commons.httpclient.methods.ByteArrayRequestEntity)6 PutMethod (org.apache.jackrabbit.webdav.client.methods.PutMethod)6