use of org.apache.commons.httpclient.methods.StringRequestEntity in project xwiki-platform by xwiki.
the class WikiManagerRestTest method executePost.
protected PostMethod executePost(String uri, String userName, String password, Object object) throws Exception {
HttpClient httpClient = new HttpClient();
httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));
httpClient.getParams().setAuthenticationPreemptive(true);
PostMethod postMethod = new PostMethod(uri);
postMethod.addRequestHeader("Accept", MediaType.APPLICATION_XML.toString());
StringWriter writer = new StringWriter();
marshaller.marshal(object, writer);
RequestEntity entity = new StringRequestEntity(writer.toString(), MediaType.APPLICATION_XML.toString(), "UTF-8");
postMethod.setRequestEntity(entity);
httpClient.executeMethod(postMethod);
return postMethod;
}
use of org.apache.commons.httpclient.methods.StringRequestEntity in project xwiki-platform by xwiki.
the class WikiManagerRestTest method executePut.
protected PutMethod executePut(String uri, String userName, String password, Object object) throws Exception {
HttpClient httpClient = new HttpClient();
httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));
httpClient.getParams().setAuthenticationPreemptive(true);
PutMethod putMethod = new PutMethod(uri);
putMethod.addRequestHeader("Accept", MediaType.APPLICATION_XML.toString());
StringWriter writer = new StringWriter();
marshaller.marshal(object, writer);
RequestEntity entity = new StringRequestEntity(writer.toString(), MediaType.APPLICATION_XML.toString(), "UTF-8");
putMethod.setRequestEntity(entity);
httpClient.executeMethod(putMethod);
return putMethod;
}
use of org.apache.commons.httpclient.methods.StringRequestEntity in project xwiki-platform by xwiki.
the class InstallMojo method executePutXml.
private PutMethod executePutXml(String uri, Object object, Marshaller marshaller, HttpClient httpClient) throws Exception {
PutMethod putMethod = new PutMethod(uri);
putMethod.addRequestHeader("Accept", MediaType.APPLICATION_XML.toString());
StringWriter writer = new StringWriter();
marshaller.marshal(object, writer);
RequestEntity entity = new StringRequestEntity(writer.toString(), MediaType.APPLICATION_XML.toString(), "UTF-8");
putMethod.setRequestEntity(entity);
httpClient.executeMethod(putMethod);
return putMethod;
}
use of org.apache.commons.httpclient.methods.StringRequestEntity in project spatial-portal by AtlasOfLivingAustralia.
the class SpeciesListUtil method createNewList.
public static String createNewList(String name, String items, String description, String url, String user, boolean makePrivate) {
String postUrl = CommonData.getSpeciesListServer() + "/ws/speciesList/";
HttpClient client = new HttpClient();
PostMethod post = new PostMethod(postUrl);
// set the cookie from the user
try {
post.setRequestHeader(StringConstants.COOKIE, "ALA-Auth=" + java.net.URLEncoder.encode(user, StringConstants.UTF_8));
} catch (Exception e) {
// should not happen as utf-8 is a supported encoding
LOGGER.error("failed to encode user: " + user, e);
}
LOGGER.debug(post.getRequestHeader(StringConstants.COOKIE));
if (name != null && items != null) {
try {
java.util.Map map = new java.util.HashMap();
map.put(StringConstants.LISTNAME, name);
if (description != null) {
map.put(StringConstants.DESCRIPTION, description);
}
if (url != null) {
map.put("url", url);
}
map.put("listItems", items);
map.put("listType", "SPATIAL_PORTAL");
map.put("isPrivate", makePrivate);
String content = JSONValue.toJSONString(map);
LOGGER.debug("create new list : " + content + " for user " + user);
String contentType = StringConstants.APPLICATION_JSON;
String charset = StringConstants.UTF_8;
StringRequestEntity requestEntity = new StringRequestEntity(content, contentType, charset);
post.setRequestEntity(requestEntity);
int result = client.executeMethod(post);
LOGGER.debug(result);
LOGGER.debug(post.getResponseBodyAsString());
if (result == 201) {
return post.getResponseHeader("druid").getValue();
}
} catch (Exception e) {
LOGGER.error("Error uploading list", e);
}
}
return null;
}
use of org.apache.commons.httpclient.methods.StringRequestEntity in project ovirt-engine by oVirt.
the class AttestationService method attestHosts.
public List<AttestationValue> attestHosts(List<String> hosts) {
String pollURI = Config.getValue(ConfigValues.PollUri);
List<AttestationValue> values = new ArrayList<>();
PostMethod postMethod = new PostMethod("/" + pollURI);
try {
postMethod.setRequestEntity(new StringRequestEntity(writeListJson(hosts)));
postMethod.addRequestHeader("Accept", CONTENT_TYPE);
postMethod.addRequestHeader("Content-type", CONTENT_TYPE);
HttpClient httpClient = getClient();
int statusCode = httpClient.executeMethod(postMethod);
String strResponse = postMethod.getResponseBodyAsString();
log.debug("return attested result: {}", strResponse);
if (statusCode == 200) {
values = parsePostedResp(strResponse);
} else {
log.error("attestation error: {}", strResponse);
}
} catch (JsonParseException e) {
log.error("Failed to parse result: {}", e.getMessage());
log.debug("Exception", e);
} catch (IOException e) {
log.error("Failed to attest hosts, make sure hosts are up and reachable: {}", e.getMessage());
log.debug("Exception", e);
} finally {
postMethod.releaseConnection();
}
return values;
}
Aggregations