我开始使用jelastic API,我打算用它来自动部署应用程序。关于调用api的每一件事似乎都是直截了当的,我能够毫无问题地进行身份验证。
然后我遇到了试图获取环境列表的问题,我希望从中获取ENV_APPID用于部署:
String PLATFORM_APPID = "1dd8d191d38fff45e62564fcf67fdcd6";
String HOSTER_URL = "https://app.jelastic.dogado.eu";
String USER_EMAIL = "??";
String USER_PASSWORD = "??";
AuthenticationResponse authenticationResponse = authenticationService.signin(USER_EMAIL, USER_PASSWORD);
System.out.println("Signin response: " + authenticationResponse);
if (!authenticationResponse.isOK()) {
System.exit(authenticationResponse.getResult());
}
final String session = authenticationResponse.getSession();
System.out.println("Getting environments list...");
EnvironmentInfoResponses environmentInfoResponses = environmentService.getEnvs(PLATFORM_APPID, session);
System.out.println("GetEnvs response: " + environmentInfoResponses);
代码以下列输出完成(敏感信息替换为问号)
Authenticate user...
Signin response: {"uid":??,"result":0,"session":"5935x8f7c158de1f65562015a09f1aa0c99fd","email":"??","data":{"lang":"en"}}
Getting environments list...
GetEnvs response: {"result":15,"source":"hx-core","error":"system application is not allowed"}
这显然不是我所期望的。代码很简单;我有常量问题吗? (我从示例代码中重用了PLATFORM_APPID)我错过了某种权限吗?
感谢您的任何意见。
答案 0 :(得分:1)
此示例适用于我: 输出:
登录回复:{" uid":uid,"结果":0,"会话":" 73aax79fe1592910526ab550395de436e176e",&#34 ;电子邮件":"""数据" {"朗":"恩"}} 获取环境列表...... GetEnvs回复:{"结果":0," infos":[{"结果":0,"节点":[],& #34; ENV" {" UID":UID," ishaenabled":假," extdomains":[],"发动机&#34 ;:{" id":2,"关键字":" java7","名称":" Java 7" " vcsSupport":假,"类型":"的java""版本":" 1.7.0_51"} "状态":6," isTransferring":假,"结构域":" domain.jelastic.dogado.eu"&#34 ; pricingType":"混合"" APPID":" APPID""上下文":[]," sslstate& #34;:假," shortdomain":"结构域"}"右":" OWNER"}]}
代码:
public class GetEnvList {
private final static String USER_AGENT = "Environment Lifecycle Example";
private final static String USER_AGENT_PARAM = "User-Agent";
private final static String PLATFORM_APPID = "1dd8d191d38fff45e62564fcf67fdcd6";
private final static String HOSTER_URL = "https://app.jelastic.dogado.eu"; // hoster's url, see http://docs.jelastic.com/en/jelastic-hoster-info
private final static String USER_EMAIL = ""; // your email
private final static String USER_PASSWORD = ""; // your password
private static Map<String, String> headers;
private static Authentication authenticationService;
private static Environment environmentService;
static {
headers = new HashMap<>();
headers.put(USER_AGENT_PARAM, USER_AGENT);
authenticationService = new Authentication(PLATFORM_APPID);
authenticationService.setServerUrl(HOSTER_URL + "/1.0/");
environmentService = new Environment(PLATFORM_APPID);
environmentService.setServerUrl(HOSTER_URL + "/1.0/");
}
public static void main(String[] args) {
System.out.println("Authenticate user...");
AuthenticationResponse authenticationResponse = authenticationService.signin(USER_EMAIL, USER_PASSWORD, headers);
System.out.println("Signin response: " + authenticationResponse);
if (!authenticationResponse.isOK()) {
System.exit(authenticationResponse.getResult());
}
final String session = authenticationResponse.getSession();
/**
* Gets the information about all environments of a user.
*/
System.out.println("Getting environments list...");
EnvironmentInfoResponses environmentInfoResponses = environmentService.getEnvs(PLATFORM_APPID, session, headers);
System.out.println("GetEnvs response: " + environmentInfoResponses);
}
}