Lock/Unlock RRC artifacts using OSLC API
I had a mechanism to programatically lock/unlock artifacts using OSLC for RRC. This worked fine in version 4.0.3 however is not running in the upgraded version 5.0.1 and throwing an exception 400/Bad Request.
The code snippet for locking an artifact is as follows-
https://inmbzp4102.in.dst.ibm.com:9443/rm/locks/"+artifactURI - the locking URI
public String getLockUnlockResource(String uri) {
HttpGet get = new HttpGet(uri);
get.setHeader("Accept", "application/xml");
get.setHeader("OSLC-Core-Version", "2.0");
get.setHeader("X-Jazz-CSRF-Prevent","0000UfsWrlfdGf4tF6SMIpVjnly:-1");
String responseXML = getResourceForLock(get);
return responseXML;
}
public String getResourceForLock(HttpGet get) {
String resourceXML="";
System.out.println("\n=== " + get.getRequestLine());
HttpResponse jfsResponse;
try {
jfsResponse = HttpUtils.sendGetForSecureDocument(
server, get, login, password, httpclient, JTS_Server);
getResponseCode = jfsResponse.getStatusLine().getStatusCode();
if(getResponseCode==404)
{
jfsResponse.getEntity().consumeContent();
return "404";
}
if(jfsResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
throw new Error("Bad status: " + jfsResponse.getStatusLine() + " for " + get.getRequestLine());
}
HttpEntity responseEntity = jfsResponse.getEntity();
resourceXML = printEntity(responseEntity);
jfsResponse.getEntity().consumeContent();
} catch (Throwable t) {
// TODO Auto-generated catch block
t.printStackTrace();
}
return resourceXML;
}
The code snippet for locking an artifact is as follows-
https://inmbzp4102.in.dst.ibm.com:9443/rm/locks/"+artifactURI - the locking URI
public String getLockUnlockResource(String uri) {
HttpGet get = new HttpGet(uri);
get.setHeader("Accept", "application/xml");
get.setHeader("OSLC-Core-Version", "2.0");
get.setHeader("X-Jazz-CSRF-Prevent","0000UfsWrlfdGf4tF6SMIpVjnly:-1");
String responseXML = getResourceForLock(get);
return responseXML;
}
public String getResourceForLock(HttpGet get) {
String resourceXML="";
System.out.println("\n=== " + get.getRequestLine());
HttpResponse jfsResponse;
try {
jfsResponse = HttpUtils.sendGetForSecureDocument(
server, get, login, password, httpclient, JTS_Server);
getResponseCode = jfsResponse.getStatusLine().getStatusCode();
if(getResponseCode==404)
{
jfsResponse.getEntity().consumeContent();
return "404";
}
if(jfsResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
throw new Error("Bad status: " + jfsResponse.getStatusLine() + " for " + get.getRequestLine());
}
HttpEntity responseEntity = jfsResponse.getEntity();
resourceXML = printEntity(responseEntity);
jfsResponse.getEntity().consumeContent();
} catch (Throwable t) {
// TODO Auto-generated catch block
t.printStackTrace();
}
return resourceXML;
}