cancel
Showing results for 
Search instead for 
Did you mean: 

CAP Service returns 503 service unavailable when run through app router

0 Kudos
1,249

I am learning CAP and i am struck with the following issue. Seeking community help to help me fix and learn. I created a CAP service (sample bookshop srv) and deployed the application to BTP. While executing the app router locally, i can see the data is fetched correctly and data is displayed in the UI5 application. But after deploying to BTP, when i run the app router i get the error, Service Unavailable.

the service call returns 503 service unavailable when executed through App router, and 401 unauthorized when running the service instance. I did not define any restriction in my CAP Service.

I tried deleting the services and deploy it again. I tried adding a role in the xs-security.json and assigned the role to my user. It did not work. I have attached the mta.yaml, xs-app.json, xs-security.json file. i appreciate if someone can help.

Thanks,

Arun K

mta.txt xs-app.txt xs-security.txt

Epena
Participant
0 Kudos

Hello, perhaps it would help us to help you if you provided a repo with your code.

Regards.

0 Kudos

Hi Edgar,


The code is in the repository link.

https://github.com/arunkrishnamoorthy/cap-local-auth-setup.git

Regards,
Arun K

Accepted Solutions (0)

Answers (1)

Answers (1)

martinstenzig
Contributor
0 Kudos

A couple of ideas to investigate the issue.

1. Open another terminal and log the output of the app router `cf logs exercise2`. Then run the request again and see what output you get in the terminal.

2. The service instance should return a 401 if you try to call directly. In order to test it individually you can create a service key on your exercise2-auth instance and then use the information to retrieve a bearer token and then call your exercise-srv with the Bearer token in the Authorization header.

0 Kudos

Hi Martin,

When I deployed the mta.yaml file, only the auth instance got created. The service instance did not create. So i run the following command `cf create-service-key exercise2-auth default` to create the service key and then bind the service key using `cds bind -2 exercise2-auth:default` but still the service returns me error. Then i tried to redeploy from mta.yaml file, i got the error saying the old xsuaa instance and the new xsuaa instance id is different, cannot modify. what is the best approach to create the xsuaa instance and its service key.

Thanks & Regards,
Arun K

martinstenzig
Contributor
0 Kudos

`cds bind...` only makes sense if you want to run parts or all of your app locally. Are you using the Business Application Studio for your development?

0 Kudos

Hi Martin,

I am following this tutorial: Link to the tutorial

https://github.com/arunkrishnamoorthy/cap-local-auth-setup.git

I am using trial instance, business application studio. After deploying when i run the app router, i get the following message when calling odata service.

Regards,
Arun K

martinstenzig
Contributor
0 Kudos

Arun, there seem to be a few things wrong in your current project. Let's answer the previous question first. If you want to test your service without the app router you can create a file (I usually create it in a new sub directory I call 'test') with a name like 'testrest.http' (the http extension is important). Then you want to copy and paste the following into it:

# Information from UAA service key ('cf csk exercise6-xsuaa-service mstest' and then 'cf service-key exercise6-xsuaa-service mstest')
@clientid=[fill in]
@clientsecret=[fill in]
@uaa_url=[fill in]
# URL from your service as shown during deployment of you can find with 'cf apps' in the 'route' column. Don't forget to prefix with https://
@service_url=https://[fill in]
# OAUTH 2.0 Client Credentials
# @name Bearer_Token_Request
POST {{uaa_url}}/oauth/token
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials
&client_id={{clientid}}
&client_secret={{clientsecret}}

####
GET {{service_url}}/catalog/Interactions_Header
Authorization: Bearer {{Bearer_Token_Request.response.body.access_token}}
####
POST {{service_url}}/catalog/Interactions_Header
Authorization: Bearer {{Bearer_Token_Request.response.body.access_token}}
Content-Type: application/json
{
"ID":1,
"PARTNER":"RIZ"
}

The in Business Application studio you should have the words 'Send Request' over the get and post lines. Execute the bearer token request first and then run the get or post. That should work.

martinstenzig
Contributor
0 Kudos

On my machine I could not even successfully deploy your repo via 'mbt build' and 'cf deploy'. The first thing that was a problem is that your package.json in the app directory has references to old node engines. You probably want to take that section out.

The next thing that I believe is incorrect is your mta.yaml is the ui_deployer section. Have another look through the exercise and make sure you either correct or redo the UI sections.

As an alternative I can also offer our step by step repo: https://github.com/RizInno/cds-customer-stepbystep

0 Kudos

Hi,

Before deploying, I changed the node engine version to 18 and then deployed. I guess I missed that changes from being pushed to git. Thank you. Appreciate your help. I will take a look into the git repo that you shared and try it out.


Regards,
Arun K

0 Kudos

Hi Martin,

I was checking the service from the postman and authenticating the service to see if the service returns the data. I got the same error 503 service unavailable. I checked the logs using cf logs exercise6-srv --recent and the message was related to the maximum no of pools. I saw you response in one of the similar issue raised here and maintained the following in the package.json file.

"db": { "kind": "hana-cloud", "pool": { "max": 100, "min": 10 } },Now I am getting this message. Socket hung up. Any idea how I can fix this. Error: error while forwarding request to https://71bd99e1trial-dev-exercise6-srv.cfapps.us10-001.hana.ondemand.com/catalog/Interactions_Heade...: socket hang up correlation_id = b87dd50e-c9b0-4c9a-7033-93e296d7fcf3

Regards,
Arun K

martinstenzig
Contributor
0 Kudos

If you are running this in the trial setup, make sure that you started up the HANA instance before trying the sample. The HANA DB in the Trial setup automatically shuts down after a few hours.

0 Kudos

Hi Martin,

I am running in trial set up. I started the HANA instance before running this. I still get the error. I tried the same example in my company hana account. The application executed without any errors. I could not find what mistake I did in the trial account.


Regards,
Arun K

martinstenzig
Contributor
0 Kudos

That'a really weird... there was a time you would have to specify 'hanatrial' as db in the mta.yaml, or package.json, but I don't know if that still applies. I am working in a full company T&D setup and very rarely use the trial landscape