我想用java发送json格式的命令到keystone给指定的用户加admin角色,我找到了一个rackspace发布的keystone API extension,其中有"add global role to user" API, 网址是:http://docs.rackspace.com/openstack-extensions/auth/OS-KSADM-admin-devguide/content/PUT_addUserRole_v2.0_users__userId__roles_OS-KSADM__roleId__Admin_API_Service_Developer_Operations-d1e1357.html我试着按照API中的URI格式发送请求,可是得不到结果,我的代码:
其中c53612ae37ec4721a7a72863a1c48726为User_id, 3a6089fd5802419ea97d14a4909b9853为admin_idprivate static void addRole(){
try {
//创建连接
URL url = new URL(key_admin_url + "/users/" + "c53612ae37ec4721a7a72863a1c48726" + "/roles/OS-KSADM/" + "3a6089fd5802419ea97d14a4909b9853");
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("PUT");
connection.setUseCaches(false);
connection.setInstanceFollowRedirects(true);
connection.setRequestProperty("Content-Type",
"application/json");
connection.setRequestProperty("X-Auth-Token",
"012345SECRET99TOKEN012345");
connection.connect(); //POST 请求
DataOutputStream out = new DataOutputStream(
connection.getOutputStream());
out.writeBytes("");
out.flush();
out.close(); //读取响应
BufferedReader reader = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
String lines;
StringBuffer sb = new StringBuffer("");
while ((lines = reader.readLine()) != null) {
lines = new String(lines.getBytes(), "utf-8");
sb.append(lines);
}
System.out.println(sb);
reader.close();
// 断开连接
connection.disconnect();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
请问有人这样连接过么? 正确的发送方式应该是怎样的呢?谢谢jsonjavaapirackspacekeystone
其中c53612ae37ec4721a7a72863a1c48726为User_id, 3a6089fd5802419ea97d14a4909b9853为admin_idprivate static void addRole(){
try {
//创建连接
URL url = new URL(key_admin_url + "/users/" + "c53612ae37ec4721a7a72863a1c48726" + "/roles/OS-KSADM/" + "3a6089fd5802419ea97d14a4909b9853");
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("PUT");
connection.setUseCaches(false);
connection.setInstanceFollowRedirects(true);
connection.setRequestProperty("Content-Type",
"application/json");
connection.setRequestProperty("X-Auth-Token",
"012345SECRET99TOKEN012345");
connection.connect(); //POST 请求
DataOutputStream out = new DataOutputStream(
connection.getOutputStream());
out.writeBytes("");
out.flush();
out.close(); //读取响应
BufferedReader reader = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
String lines;
StringBuffer sb = new StringBuffer("");
while ((lines = reader.readLine()) != null) {
lines = new String(lines.getBytes(), "utf-8");
sb.append(lines);
}
System.out.println(sb);
reader.close();
// 断开连接
connection.disconnect();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
请问有人这样连接过么? 正确的发送方式应该是怎样的呢?谢谢jsonjavaapirackspacekeystone
解决方案 »
- 遗留开发进入PaaS平台即服务五要素
- 关于在ubuntu安装openstack的问题,求论坛的各位大神帮忙
- 完全虚拟化和部分虚拟化的IO流程
- 跪求大神指导docker上怎么搭建Python环境啊,呜呜,给个网址也行啊,百度不到查好多试了都不成功好烦躁,求好心人
- 谷歌 苹果 亚马逊 云安全哪家强?
- 嵌入式云计算ARM处理器,那个性能强大呢?
- Spark RRD统计操作
- Hadoop 执行简单的编程报错。java.io.IOException: Initialization of all the collectors faile
- spark源码阅读环境搭建问题
- 求大神给套方案
- 【每日译帖】用keystone配置swift和curl
- swift上传文件提示“the volume 'sdb1' has only 135.2kb disk space remaining”
第二,要确定请求的服务器地址及服务端口号是否写对了http://{$keystone_server}:35357
第三,要确定X-Auth-Token是使用admin账号获得的token
第四,为user添加role要用‘PUT’方法而不是你默认的‘POST’方法,这个你要好好看看API文档,学习下RESTful接口。