It's all about the answers!

Ask a question

OSLC API and character encoding


Andy Dennis (112) | asked Aug 25 '21, 7:45 a.m.

 Hi,

I'm having some issues with importing artifacts from a spreadsheet using the OSLC API when "special" characters are in use.  The standard DOORS Next import works fine, so I know this should work.

The character codes are 0x02F5 and 0x02F6 which represent MODIFIER LETTER MIDDLE DOUBLE GRAVE ACCENT and MODIFIER LETTER MIDDLE DOUBLE ACUTE ACCENT. 

When these characters are present DOORS Next returns a forbidden error to the call.

Do I need to do special character encoding i.e ˵ for these characters?

Thanks,
Andy

Accepted answer


permanent link
Ian Barnard (1.2k613) | answered Aug 25 '21, 12:31 p.m.
JAZZ DEVELOPER

I tried pasting smart quotes “hello” from Word into a DN artifact. When I get the RDF for that artifact using REST API, it appears as “hello” - I observe that the RDF doesn't specify an encoding so I assume the default would be UTF-8


So maybe you need to encode these unicode characters like that?

Ralph Schoon selected this answer as the correct answer

Comments
Andy Dennis commented Aug 26 '21, 4:16 a.m.

Thanks Ian, I'll give that a try.   


Andy Dennis commented Aug 26 '21, 5:47 a.m.

So, I've added some code to encode in this way


Here is a snip of the content generated for primary text...
Technical Questions (“TQ”) shall be treated as ...

I get the exact same error (403) coming back from the server as if I hadn't escaped those characters


Andy Dennis commented Aug 26 '21, 5:54 a.m.

 Ah - just noticed my webclient class has Windows-1252 set in it, which may be overriding what I'm setting.  I'll look at changing that


Andy Dennis commented Aug 26 '21, 6:01 a.m.

 That was the issue.  The .net class has an encoding attribute, so what ever I was specifying was being overridden by the class attribute.  It's now successfully added the escaped content, so I'll try without, but confident that it will be ok now.  Thanks again for your assistance, much appreciated.

2 other answers



permanent link
David Honey (7606) | answered Aug 25 '21, 8:37 a.m.
JAZZ DEVELOPER

Are you specifying the character set in your PUT or POST Content-Type header?
For example: Content-Type=text/turle; charset=utf-8


Comments
Andy Dennis commented Aug 25 '21, 8:46 a.m.

Ah, I've been specifying in the XML. Thanks, I'll give this a try 


Andy Dennis commented Aug 25 '21, 8:55 a.m.

I've set the post Content-Type to application/xml; charset=utf-8 but still the same error



Ralph Schoon commented Aug 25 '21, 9:17 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Since you provide pretty much no information beyond it is not working, I don't know how anyone should be able to help. You can try to create a requirement based on your display data and see if that even works. 


Andy Dennis commented Aug 25 '21, 10:32 a.m.
Here is an example of a post that causes the error.  I've had to strip most of it out to fit in the post.
If I remove The •, “ and ” characters the requirement is correctly created.
If I leave them in I get a forbidden error returned by the server.
I build the string in c# and pass it through an XML parser prior to the post, so I know that the xml is well formed.

...
<rm_jazz:primaryText rdf:parseType='Literal'>;
<div xmlns='http://www.w3.org/1999/xhtml' id='_Nf2cQJKNEd25PMUBGiN3Dw'>TECHNICAL REQUIREMENTS

Vendors shall adhere to the following instructions in responding to Section 5.1
Technical Requirement (“TR”) ...
Technical Questions (“TQ”) shall be treated as ...
Vendors shall ensure ...
</div></rm_jazz:primaryText>
</oslc_rm:Requirement>
</rdf:RDF>


permanent link
Ralph Schoon (60.5k33643) | answered Aug 25 '21, 8:53 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
 I'm having some issues with importing artifacts from a spreadsheet using the OSLC API when "special" characters are in use.  The standard DOORS Next import works fine, so I know this should work.

This would assume that the DOORS import uses OSLC, which is very certainly not the case. Even if it was using it does not mean that it would not have to encode data in certain cases.


Yes, you have to use encoding where this is required to adhere to the standards.

In OSLC, the URI, headers and body must be valid by the various standards. This might differ if you use rdf+xml or json. In XML characters like > or < are an issue for example.

Look into those standards to find out which characters are allowed and how to encode others. Look into the OSLC standard documents and the fundamental standards for HTML etc. for the URI's and headers.


Comments
Andy Dennis commented Aug 25 '21, 9:02 a.m.

Thanks Ralph.  I'm using CDATA tags but I guess it requirement more work than that.


Andy Dennis commented Aug 25 '21, 10:04 a.m.

 Worth mentioning that I'm running the xml I create through an xml parser and that doesn't have a problem with what I'm sending to the server, so I'm not violating the XML standards 

Your answer


Register or to post your answer.