CA Service Management

 View Only

 conect to rest_access but another tables not found in postman basic Auth

Lirio Sousa's profile image
Lirio Sousa posted Jul 10, 2023 11:09 AM

hello somebody help me 

I conect to http://localhost:8050/caisd-rest/rest_access and status is 200 ok in postman but,  i´m tryng connect to http://localhost:8050/caisd-rest/cnt and the postman return 404 not found here the codes:

code snipett sucess to rest_access

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:8050/caisd-rest/rest_access");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("X-AccessKey", "2050397415");
request.Headers.Add("Cache-Control", "no-cache");
request.Headers.Add("X-Obj-Attrs", "*");
request.Headers.Add("Authorization", "Basic U2VydmljZURlc2s6U0FkMjAyMSM=");
var content = new StringContent("", null, "text/plain");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());

code snipett not workink to cnt

http://localhost:8050/caisd-rest/cnt

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:8050/caisd-rest/cnt");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("X-AccessKey", "2050397415");
request.Headers.Add("Cache-Control", "no-cache");
request.Headers.Add("X-Obj-Attrs", "*");
request.Headers.Add("Authorization", "Basic U2VydmljZURlc2s6U0FkMjAyMSM=");
var content = new StringContent("", null, "text/plain");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
Attachments  View in library
1.PNG 172 KB
2.PNG 152 KB
Joe Gavan's profile image
Joe Gavan

Hi Lirio,

First you need to POST to rest_access in order to get a session ID

e.g.

HttpWebRequest request = WebRequest.Create("http://localhost:8050/caisd-rest/rest_access") as HttpWebRequest;
request.Method = "POST";
request.Headers.Add("Authorization", "Basic U2VydmljZURlc2s6U0FkMjAyMSM=");
request.ContentType = "application/json";
request.CookieContainer = new CookieContainer();
request.Accept = "application/json";
String body = "{\"rest_access\":{}}";
using (StreamWriter streamWriter = new StreamWriter(request.GetRequestStream())) streamWriter.Write(body); }
 
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
using (var streamreader = new StreamReader(response.GetResponseStream())) {
Console.WriteLine(streamreader.ReadToEnd());
}}

This returns a JSON string such as:

{"rest_access":{"@id":401654,"@REL_ATTR":401654,"@COMMON_NAME":321054765,"link":{"@href":"http://localhost:8050/caisd-rest/rest_access/401654","@rel":"self"},"access_key":321054765,"expiration_date":1689661629}}

The session key is "access_key":321054765 and needs to be passed to subsequent calls as X-Obj-Attrs within the header

e.g.

request = WebRequest.Create("http://localhost:8050/caisd-rest/cnt") as HttpWebRequest;
request.Method = "GET";
request.Headers.Add("X-AccessKey", "321054765");
request.ContentType = "application/json";
request.CookieContainer = new CookieContainer();
request.Accept = "application/json";
 
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
using (var streamreader = new StreamReader(response.GetResponseStream())) {
Console.WriteLine(streamreader.ReadToEnd());
}}

Regards

Joe

Lirio Sousa's profile image
Lirio Sousa

Hi Joe 

Thanks for the correction actually I can always get the access key and the code you provided works perfectly but when I try to access beyond the rest_access object it doesn't work it always returns 404 not found either cnt, in or another object

Even in postman as if it didn't exist

Joe Gavan's profile image
Joe Gavan

Hi Lirio,

Sorry to hear you are still having issues.

Going back to the basics,

  • What service desk release / cumulative update are you running?
  • Any additional hardware between your client and the server (e.g. Load Balancer)?
  • Can you see any errors within the log files : jsrvr.log, jrest.log, pdm_tomcat_REST.log in the standard logs folder x:\Program Files (x86)\CA\Service Desk Manager\log
  • Can you see any evidence of the incoming messages within the localhost_access_log.yyyy-mm-dd.txt file within x:\Program Files (x86)\CA\Service Desk Manager\bopcfg\www\CATALINA_BASE_REST\logs

If the environment you have is a test box and you have the ability to backup / snapshot, you could always try the following commands from the NX_ROOT/bin directory to redeploy the rest jars:

# Undeploy 
pdm_rest_util.cmd -undeploy
 
#Deploy
pdm_rest_util.cmd -deploy

Regards

Joe

Lirio Sousa's profile image
Lirio Sousa

Hi Joe

The version is 17.3.0.22 the latest

I used Soap UI to test the rest with the link: http://helpservicetst:8050/caisd-rest/?_wadl as per Broadcom knowledge https://knowledge.broadcom.com/external/article/45577/rest-web -services-calls-testing-demo-usi.html and I noticed that my wadl only shows rest_access as an object

should there be other objects like cn and in?

Attachment  View in library
my _wadl.PNG 40 KB
Lindsay Estabrooks's profile image
Lindsay Estabrooks

Are you trying to retrieve all contacts?

Will the following work?

http://localhost:8050/caisd-rest/cnt?WC=userid%3D'ServiceDesk'
Joe Gavan's profile image
Joe Gavan

Hi Lirio,

If all you see in the wadl is rest_access then clearly something is broken in your environment - mine has many entries :

Going back to my earlier post, I believe you need to undeploy and redeploy using the pdm_rest_util command.  This will remove the current jar and compile up a new version based on your available objects:

If you check the webapps folder the war files should be around 4/5MB, I suspect you will find yours are much smaller:

If you want to see the contents of the current caisd-rest.war file you can run "jar tf caisd-rest.war" from within that webapps directory

Included within the output will be the available services:

Hope this helps

Regards

Joe

Lirio Sousa's profile image
Lirio Sousa

Hi Joe, 

I have an error while i am trying to deploy from jd.javadoc.doclet.

Joe Gavan's profile image
Joe Gavan

I too get an error from the Java Docs part but that doesn't stop the rest services working.

Did you get a message regarding the war file being deployed and if so does it make any difference ?

Joe

Lirio Sousa's profile image
Lirio Sousa

Hi Joe

 unfortunately it didn't make any difference the file kept with the size smaller than 4 mb

 I opened the env file and put the JRE 20.0.1 and I did the deploy and it didn't make any difference

in the attachment the deploy with the JRE 20.0.1 version

Joe Gavan's profile image
Joe Gavan

Might be a daft question, but is this a new environment you have just built and if so did you install 17.3 and then apply CU22 on top ?

Lirio Sousa's profile image
Lirio Sousa

yes it is the last one

Joe Gavan's profile image
Joe Gavan

Hi Lirio,

Having built a new single server environment with 17.3 and then CU22, I find the REST services to work as intended without any need to change the JRE.  Running pdm_rest_util outputs the same error that you have but does generate and compile the java modules that make up the WAR file and  continue to work.

So it may be possible that the issue is something else within your new environment. Does the service desk user interface work ok ?

Can you try the following commands to check that the objects are as intended :

  • objnames | findstr -i ca_contact
  • pdm_extract ca_contact > ca_contact.txt
  • bop_sinfo -f cnt
  • bop_sinfo -f All | findstr -i "Factory REST"

Regards

Joe

Attachments  View in library
Lirio Sousa's profile image
Lirio Sousa

Hi Joe

Service desk UI works great.

when running the commands it displays the information of the objects without error:

below cmd showed all REST Operations = CREATE READ UPDATE of the other tables

Joe Gavan's profile image
Joe Gavan

Hi Lirio,

Seems your objects are fine in Service Desk but just not appearing in REST.  I believe the war file build must be failing for some reason and so can you confirm if you see any lines like those highlighted below in your jrest.log file when calling pdm_rest_util -deploy ?

As can be seen from the screenshot above, Service Desk relies heavily on the old style short names (i.e. Progra~2 ) rather than the longer names with spaces etc. So, can you try the following commands to confirm both 8dot3 naming, Java versions and folder names:

  • dir /X c:\progra*
  • java -version
  • nx_env -d  > %TEMP%\setenv.cmd

%TEMP%\setenv.cmd > nul

"%NX_JRE_INSTALL_DIR%/bin/java" -version

    • echo "%NX_ROOT%"
    • dir "%NX_ROOT%/java/lib/"

    The following command should list the services within your war file:

    • "%NX_JRE_INSTALL_DIR%/bin/jar" tf "%NX_ROOT%\bopcfg\www\CATALINA_BASE_REST\webapps\caisd-rest.war" | findstr -i "\/service\/"

    Plus the following can be used to check the permissions on the temporary folder that the deploy script uses:

    • cacls "C:\Progra~2\ca\service~1\temp"

    I have attached screenshots from my working system for comparison.  Also, I suspect from earlier posts that you have installed on Windows 2019, can you confirm the OS and SQL versions ?

    Regards

    Joe

    Lirio Sousa's profile image
    Lirio Sousa

    Hi Joe,

    I apologize for taking so long to respond.

    Thank you for your availability in the thread discussed, we managed to solve it with the help of broadcom support for the solution of not generating the objects we added in the option:

    rest_webservice_resources_to_expose to rest_access, in, cnt, grp, cr, crs, pri, alg, urg, imp, pcat, org
    and we restart

    Although by definition it was not necessary all should already be exposed when the rest access is but it was the solution

    https://techdocs.broadcom.com/us/en/ca-enterprise-software/business-management/ca-service-management/17-3/building/building-ca-service-desk-manager/web-services-management.html