2

We are trying to integrate with uDeploy using Rest endpoints. I am not able to find any good documentation/tutorial for the same. The HTTP Get requests are working fine, but the PUT,POST,DELETE operations require an authentication to be passed. I have tried giving the user name password as well as the JSESSIONID. This is the error message:

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

The request is :

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

The headers are :

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

The body :

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

1 Answers1

2

Ok, I am posting the answer for the question that i asked myself. In order to interact with uDeploy using REST Api through Java , you would need "udclient.jar" , which will be available in the uDeploy install directory. Here is a sample java program:

@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 );
}