在使用uDeploy REST API

时间:2017-03-30 11:43:21

标签: udeploy

我们正在尝试使用Rest端点与uDeploy集成。我无法找到相同的任何好的文档/教程。 HTTP Get请求工作正常,但PUT,POST,DELETE操作需要传递身份验证。我试过提供用户名密码以及JSESSIONID。这是错误消息:

  

错误401:未经授权。请求缺少存储的会话ID。

请求是:

  

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

标题是:

  

接受编码:gzip,deflate,sdch,br

     

接受语言:EN-US,EN; Q = 0.8

     

连接:保活

     

的Content-Length:304

     

内容类型:应用/ JSON

     

的Cookie:JSESSIONID_9080 = 8C686C10312E552DE0714944283B3159; timelineDocked = TRUE; timelineExpanded =真

     

主机:itec-udeploy.fmr.com

     

产地:https://UDEPLOY-END-POINT

     

的Referer:https://UDEPLOY-END-POINT

     

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

     

X-请求-随着:XMLHttpRequest的

     

授权:XXXXXXXXXXXXXX

身体:

  

{"的applicationID":" 64876c59 ..."" applicationProcessId":" 3713c68b ....",& #34;描述":""" environmentId":" 2aae4c4a ..."" onlyChanged":&# 34;假""属性":{}," scheduleCheckbox":假," snapshotId":" 255e2208 ...&#34 ;}

1 个答案:

答案 0 :(得分:2)

好的,我正在发布我问自己的问题的答案。 为了使用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 );
}