import org.restlet.resource.ClientResource; //导入方法依赖的package包/类
/**
* Update the plugin information of the drupal site with the plugin data
*
* @param cS CookieSetting retrieved from the login method
* @param nodeId the nodeId of the node on the drupal site
* @param plugin the plugin data that is going to be used on the update
*/
public static void putPlugin(CookieSetting cS, String nodeId, MarketPlacePlugin2 plugin) {
Client client = new Client(new Context(), Protocol.HTTP);
client.getContext().getParameters().add("use ForwardedForHeader", "false");
ClientResource pluginResource = new ClientResource(DRUPALPATH + "/rest/node/" + nodeId);
pluginResource.setNext(client);
pluginResource.getRequest().getCookies().add(cS);
//the only data needed to update a plugin is the node, type, field_os and plugin_category
String pluginData = "{"
+ plugin.formatBaseData() + ","
+ plugin.formatFieldCategory() + ","
+ plugin.formatFieldPluginCategory() + ","
+ plugin.formatFieldOS() + ","
+ plugin.formatFieldFile()
+ "}";
LOG.info("PluginData {}", pluginData);
Representation rep = pluginResource.put(new JsonRepresentation(pluginData));
Response resp2 = pluginResource.getResponse();
if (resp2.getStatus().isSuccess()) {
try {
LOG.info(resp2.getEntity().getText());
} catch (IOException e) {
LOG.error("IOException: {}", e.getMessage());
}
} else {
LOG.info(resp2.getStatus().getName());
}
}