use of org.apache.commons.httpclient.methods.PutMethod in project sling by apache.
the class SlingIntegrationTestClient method upload.
/** Upload a file to the Sling repository
* @return the HTTP status code
*/
public int upload(String toUrl, InputStream is) throws IOException {
final PutMethod put = new PutMethod(toUrl);
put.setRequestEntity(new InputStreamRequestEntity(is));
return httpClient.executeMethod(put);
}
use of org.apache.commons.httpclient.methods.PutMethod in project sling by apache.
the class PutMethodServletTest method testPutMethodServletSpecificRT.
public void testPutMethodServletSpecificRT() throws Exception {
final PutMethod put = new PutMethod(testNodeRT.nodeUrl);
final int status = httpClient.executeMethod(put);
assertEquals("PUT to testNodeRT should return 200", 200, status);
final String content = put.getResponseBodyAsString();
assertServlet(content, PUT_SERVLET_SUFFIX);
}
use of org.apache.commons.httpclient.methods.PutMethod in project rhsm-qe by RedHatQE.
the class CandlepinTasks method putResourceUsingRESTfulAPI.
public static String putResourceUsingRESTfulAPI(String authenticator, String password, String url, String path, JSONObject jsonData) throws Exception {
PutMethod put = new PutMethod(url + path);
if (jsonData != null) {
put.setRequestEntity(new StringRequestEntity(jsonData.toString(), "application/json", null));
put.addRequestHeader("accept", "application/json");
put.addRequestHeader("content-type", "application/json");
}
// log the curl alternative to HTTP request
// Example: curl --insecure --user testuser1:password --request PUT --data '{"autoheal":"false"}' --header 'accept: application/json' --header 'content-type: application/json' https://jsefler-onprem-62candlepin.usersys.redhat.com:8443/candlepin/consumers/e60d7786-1f61-4dec-ad19-bde068dd3c19
String user = (authenticator.equals("")) ? "" : "--user " + authenticator + ":" + password + " ";
String request = "--request " + put.getName() + " ";
String data = (jsonData == null) ? "" : "--data '" + jsonData + "' ";
String headers = "";
if (jsonData != null)
for (org.apache.commons.httpclient.Header header : put.getRequestHeaders()) headers += "--header '" + header.toString().trim() + "' ";
log.info("SSH alternative to HTTP request: curl --stderr /dev/null --insecure " + user + request + data + headers + put.getURI());
String response = getHTTPResponseAsString(client, put, authenticator, password);
if (response != null) {
JSONObject responseAsJSONObect = new JSONObject(response);
if (responseAsJSONObect.has("displayMessage")) {
log.warning("Attempt to PUT resource '" + path + "' failed: " + responseAsJSONObect.getString("displayMessage"));
}
}
return response;
}
use of org.apache.commons.httpclient.methods.PutMethod in project dataverse by IQSS.
the class HttpSendReceiveClientStep method buildMethod.
HttpMethodBase buildMethod(boolean rollback, WorkflowContext ctxt) throws Exception {
String methodName = params.getOrDefault("method" + (rollback ? "-rollback" : ""), "GET").trim().toUpperCase();
HttpMethodBase m = null;
switch(methodName) {
case "GET":
m = new GetMethod();
m.setFollowRedirects(true);
break;
case "POST":
m = new PostMethod();
break;
case "PUT":
m = new PutMethod();
break;
case "DELETE":
m = new DeleteMethod();
m.setFollowRedirects(true);
break;
default:
throw new IllegalStateException("Unsupported HTTP method: '" + methodName + "'");
}
Map<String, String> templateParams = new HashMap<>();
templateParams.put("invocationId", ctxt.getInvocationId());
templateParams.put("dataset.id", Long.toString(ctxt.getDataset().getId()));
templateParams.put("dataset.identifier", ctxt.getDataset().getIdentifier());
templateParams.put("dataset.globalId", ctxt.getDataset().getGlobalId());
templateParams.put("dataset.displayName", ctxt.getDataset().getDisplayName());
templateParams.put("dataset.citation", ctxt.getDataset().getCitation());
templateParams.put("minorVersion", Long.toString(ctxt.getNextMinorVersionNumber()));
templateParams.put("majorVersion", Long.toString(ctxt.getNextVersionNumber()));
templateParams.put("releaseStatus", (ctxt.getType() == TriggerType.PostPublishDataset) ? "done" : "in-progress");
m.addRequestHeader("Content-Type", params.getOrDefault("contentType", "text/plain"));
String urlKey = rollback ? "rollbackUrl" : "url";
String url = params.get(urlKey);
try {
m.setURI(new URI(process(url, templateParams), true));
} catch (URIException ex) {
throw new IllegalStateException("Illegal URL: '" + url + "'");
}
String bodyKey = (rollback ? "rollbackBody" : "body");
if (params.containsKey(bodyKey) && m instanceof EntityEnclosingMethod) {
String body = params.get(bodyKey);
((EntityEnclosingMethod) m).setRequestEntity(new StringRequestEntity(process(body, templateParams)));
}
return m;
}
use of org.apache.commons.httpclient.methods.PutMethod in project xwiki-platform by xwiki.
the class ObjectsResourceTest method testPUTObjectUnauthorized.
@Test
public void testPUTObjectUnauthorized() 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());
String originalTagValue = getProperty(object, "tags").getValue();
getProperty(object, "tags").setValue(TAG_VALUE);
PutMethod putMethod = executePutXml(buildURI(ObjectResource.class, getWiki(), this.spaces, this.pageName, objectToBePut.getClassName(), objectToBePut.getNumber()).toString(), object);
Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_UNAUTHORIZED, putMethod.getStatusCode());
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) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertEquals(originalTagValue, getProperty(object, "tags").getValue());
}
Aggregations