Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Forbidden when creating Requirements via the OSLC API

Hi,
I am trying to create a new requirement in my test project via OSLC API.
Here is my code: 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
string webContextUrl = "https://jazz.net/sandbox02-rm";
string projectArea = "aaz_Project_1_ReqMng";
JazzRootServicesHelper helper = new JazzRootServicesHelper(webContextUrl, OSLCConstants.OSLC_RM_V2);
string authUrl = webContextUrl.Replace("/rm", "/jts");
JazzFormAuthClient jazzClient = helper.InitFormClient(user, passwd, authUrl);

if (jazzClient == null)
 throw new Exception(LD.TKey("Client is null, please run authentication first", "General"));
if (jazzClient.FormLogin() != HttpStatusCode.OK)
 throw new Exception(LD.TKey("Custom error: login failed on method FormLogin()", "General"));

 string catalogUrl = helper.GetCatalogUrl();
 string serviceProviderUrl = jazzClient.LookupServiceProviderUrl(catalogUrl, projectArea);
 string queryCapability = jazzClient.LookupQueryCapability(serviceProviderUrl, OSLCConstants.OSLC_RM_V2, OSLCConstants.RM_REQUIREMENT_TYPE);
                
 Requirement requirement = new Requirement();
 requirement.SetTitle("New Requirement");
 requirement.SetDescription("This is a New Requirement created via API");
 requirement.SetCreated(DateTime.UtcNow);

 string oslcReqResurceType = requirement.GetRdfTypes()[0].ToString();

 string requirementFactory = jazzClient.LookupCreationFactory(serviceProviderUrl, OSLCConstants.OSLC_RM_V2, oslcReqResurceType);

 HttpResponseMessage creationResponse = jazzClient.CreateResource(requirementFactory, requirement, OslcMediaType.APPLICATION_RDF_XML);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
After successful Authentication I find the factory url 
and perform creation of a new artifact.
I get a response status Forbidden.

//creationResponse.StatusCode: Forbidden

//creationResponse.RequestMessage:
//{Method: POST, RequestUri: //'https://jazz.net/sandbox02-rm/requirementFactory?projectURL=https%3A%2F%2Fjazz.net%2Fsandbox02-rm%2Fprocess%2Fproject-areas%2F_Jk3voapCEe-I9rfLYaQw7w', //Version: 1.1, Content: System.Net.Http.ObjectContent, Headers:
//{
//  Accept: application/rdf+xml
//  OSLC-Core-Version: 2.0
//  Content-Type: application/rdf+xml
/  Content-Length: 732
//}}

When I dig deeper into the response I see expires DateTime - {1994-12-01 16:00:00 +00:00}. As if my request is not valid and because of that creation is prohibited.. 
//creationResponse.Content.Headers.Expires.Value: {1994-12-01 16:00:00 +00:00}
Or is there another reason?
Thx

0 votes


Accepted answer

Permanent link

I've never used Java APIs, I'm not sure if they are supported for DOORS Next.


One thing you can't do is set system-defined properties like creation datetime, similary the creator is system-defined so no point trying to set it.

Also how are you providing a configuration?

And it looks like you're missing required information such as the instanceShape (i.e. the artifact type) and not required but should be provided to avoid putting all artifacts in the root folder) the nav:parent with the folder URI where you want the artifact created. I don't know how you specify these using Java.

Check the body of the response to your POST to see if contains any useful information about the reason for 403.

Here's the details of a successful artifact creation using HTTP Post:

Note:
1. The config is specified in parameter oslc_config.context - it could alternatively be specified in header Configuration-Context
2. In the body content the rdf:about="" is required. It just has to be present, don't think the value matters.

Host: jazz.ibm.com:9443
User-Agent: python-requests/2.31.0
Accept-Encoding: gzip, deflate, br
Accept: application/xml
Connection: Keep-Alive
X-Requested-With: XMLHttpRequest
OSLC-Core-Version: 2.0
Content-Type: application/rdf+xml
Cookie: ...
Content-Length: 1004

    <rdf:Description rdf:about="">
        <rdf:type rdf:resource="http://open-services.net/ns/rm#Requirement"/>
        <dc:description rdf:parseType="Literal">OSLC Creation Example</dc:description>
        <dc:title rdf:parseType="Literal">hello, world</dc:title>
        <oslc:instanceShape rdf:resource="https://jazz.ibm.com:9443/rm/types/OT_vQmPyocYEe-VP_JEQOsc9Q"/>
    </rdf:Description>
</rdf:RDF>

HTTP/1.1 201 Created
X-Powered-By: Servlet/3.0
Strict-Transport-Security: max-age=31536000
Set-Cookie: ...
X-Last-Modified-XSD: 2024-12-02T14:16:47.270Z
Last-Modified: Mon, 02 Dec 2024 14:16:47 GMT
X-Jazz-Created: 2024-12-02T14:16:47.270Z
ETag: "%220%22&_ELnVYLC4Ee-UEJVWrPYLCw"
Content-Length: 0
Content-Language: en-US
Date: Mon, 02 Dec 2024 14:16:48 GMT
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Cache-Control: no-cache="set-cookie, set-cookie2"



Alex Alleg selected this answer as the correct answer

0 votes

Comments

For PUT, POST, DELETE, you might have to provide the header


X-Jazz-CSRF-Prevent = JSESSIONID

where JSESSIONID is the value of the cookie JSESSIONID.

Ian, the JAVA OSLC API might be Eclipse LYO. Otherwise, the EWM Client Libraries API has a HTTP client as well.


One other answer

Permanent link

Thanks to all for your help. 


My code is not Java, but in C#.Net Framework. And i use OSLC4Net.Client.Oslc.Jazz.
Getting instanceShape and further processing solved my problem.

0 votes

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,938

Question asked: Dec 02, 7:52 a.m.

Question was seen: 241 times

Last updated: Dec 03, 6:01 a.m.

Related questions
Confirmation Cancel Confirm