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);
}
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);
}
}
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);
}
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;
}
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);
}
}
Aggregations