在使用 uDeploy REST 部署应用程序时需要帮助 API

Need help in deploying an application using uDeploy REST API

我们正在尝试使用 Rest 端点与 uDeploy 集成。我找不到任何好的 documentation/tutorial 。 HTTP Get 请求工作正常,但 PUT、POST、DELETE 操作需要通过身份验证。我试过提供用户名密码和 JSESSIONID。这是错误消息:

Error 401: Unauthorized. Request is missing the stored session ID.

请求是:

PUT https://UDEPLOY-END-POINT/rest/deploy/application/54e73305-cb50-4192-8c43-e37bdb9932de/runProcess

headers 是:

Accept-Encoding:gzip, deflate, sdch, br

Accept-Language:en-US,en;q=0.8

Connection:keep-alive

Content-Length:304

Content-Type:application/json

Cookie:JSESSIONID_9080=8C686C10312E552DE0714944283B3159; timelineDocked=true; timelineExpanded=true

Host:itec-udeploy.fmr.com

Origin:https://UDEPLOY-END-POINT

Referer:https://UDEPLOY-END-POINT

User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36

X-Requested-With:XMLHttpRequest

Authorization:XXXXXXXXXXXXXX

body :

{"applicationId":"64876c59...","applicationProcessId":"3713c68b....","description":"","environmentId":"2aae4c4a...","onlyChanged":"false","properties":{},"scheduleCheckbox":false,"snapshotId":"255e2208..."}

好的,我发布了我问自己的问题的答案。 为了使用 REST Api 到 Java 与 uDeploy 交互,您需要 "udclient.jar" ,它在 uDeploy 安装目录中可用。 这是一个示例 java 程序:

@Override
public String retrieve(String url, String userName, String password, boolean trustAllCerts) {
HttpClientBuilder httpClientBuilder = new HttpClientBuilder();
httpClientBuilder.setUsername(userName);
httpClientBuilder.setPassword(password);
httpClientBuilder.setTrustAllCerts(trustAllCerts);

    DefaultHttpClient client = httpClientBuilder.buildClient();

    int statusCode = 0;
    StringBuilder stringBuilder = new StringBuilder();

    try {
        HttpGet request = new HttpGet(new URI(getEncodedUrl(url)));
        org.apache.http.HttpResponse resp = client.execute(request);
        BufferedReader br = new BufferedReader ( 
                new InputStreamReader(resp.getEntity().getContent()));

        statusCode = resp.getStatusLine().getStatusCode();

        String currentLine = null;
        while ((currentLine = br.readLine()) != null){
            stringBuilder = stringBuilder.append(currentLine);
        }

    } catch (IOException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
return stringBuilder.toString();
}

public static void main(String[] args) {
String uDeployUrl = "";
String userName = "";
String password = "";
boolean trustAllCerts = true;
String response = retrieve(uDeployUrl ,userName ,password ,trustAllCerts );
}