Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: 7.1 Rest example not working.
Hello,
I have tried the example at: https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-1/jax-rs
I was unable to get this to work using 7.1 GA3 and 7.1 GA 1. I also had two other co-workers tried this example with the same result. I built the stock example using gradlew. I didn't add any additional code to the file that was generated after choosing Liferay Module Project (see attached file). I deployed the jar using the deploy directory.
I then went to Control Panel → Configuration → OAuth2 Administration to finish up the configuration. I grabbed the client id and secret to get the bearer token.
I was able to get the bearer token as seen here:
$ curl http://localhost:8080/o/oauth2/token -d 'grant_type=client_credentials&client_id=id-97bb1294-99f4-4f17-8f02-6f835186d&client_secret=secret-5e421c7c-c453-af56-3e79-b86c61bc151f'
{"access_token":"9e439dc87cc4f167c4aefb9c97182846db7962da6981fb5c6779f9b4d83f1b","token_type":"Bearer","expires_in":600}
When I tried to access the rest endpoint I do not get the correct message back, it just seems to be consumed as seen here:
mperico@Mikes-Mac:~/liferay7/rest-example/build/libs
$ curl --header "Authorization: Bearer 9e439dc87cc4f167c4aefb9c97182846db7962da6981fb5c6779f9b4d83f1b" http://localhost:8080/o/greetings/morning
mperico@Mikes-Mac:~/liferay7/rest-example/build/libs
As you can see, I do not get back the appropriate greeting, which should be "Good morning!"
If I delete some characters from the bearer token, I do get the correct error message (403)from the service, so something must be working.
mperico@Mikes-Mac:~/liferay7/rest-example/build/libs
$ curl --header "Authorization: Bearer 9e439dc87cc4f167c4aefb9c97182846db7962da6981fb5c6779f9b4d83f1" http://localhost:8080/o/greetings/gggg/ggg
<!doctype html><html lang="en"><head><title>HTTP Status 403 – Forbidden</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color
525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color
525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color
525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color
525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color
525D76;border:none;}</style></head><body><h1>HTTP Status 403 – Forbidden</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> Authorization required</p><p><b>Description</b> The server understood the request but refuses to authorize it.</p><hr class="line" /><h3>Apache Tomcat/9.0.6</h3></body></html>
What do I need to do to get this to work properly?
I have tried the example at: https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-1/jax-rs
I was unable to get this to work using 7.1 GA3 and 7.1 GA 1. I also had two other co-workers tried this example with the same result. I built the stock example using gradlew. I didn't add any additional code to the file that was generated after choosing Liferay Module Project (see attached file). I deployed the jar using the deploy directory.
I then went to Control Panel → Configuration → OAuth2 Administration to finish up the configuration. I grabbed the client id and secret to get the bearer token.
I was able to get the bearer token as seen here:
$ curl http://localhost:8080/o/oauth2/token -d 'grant_type=client_credentials&client_id=id-97bb1294-99f4-4f17-8f02-6f835186d&client_secret=secret-5e421c7c-c453-af56-3e79-b86c61bc151f'
{"access_token":"9e439dc87cc4f167c4aefb9c97182846db7962da6981fb5c6779f9b4d83f1b","token_type":"Bearer","expires_in":600}
When I tried to access the rest endpoint I do not get the correct message back, it just seems to be consumed as seen here:
mperico@Mikes-Mac:~/liferay7/rest-example/build/libs
$ curl --header "Authorization: Bearer 9e439dc87cc4f167c4aefb9c97182846db7962da6981fb5c6779f9b4d83f1b" http://localhost:8080/o/greetings/morning
mperico@Mikes-Mac:~/liferay7/rest-example/build/libs
As you can see, I do not get back the appropriate greeting, which should be "Good morning!"
If I delete some characters from the bearer token, I do get the correct error message (403)from the service, so something must be working.
mperico@Mikes-Mac:~/liferay7/rest-example/build/libs
$ curl --header "Authorization: Bearer 9e439dc87cc4f167c4aefb9c97182846db7962da6981fb5c6779f9b4d83f1" http://localhost:8080/o/greetings/gggg/ggg
<!doctype html><html lang="en"><head><title>HTTP Status 403 – Forbidden</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color
What do I need to do to get this to work properly?
Attachments:
Has anyone successfully gotten the JAX-RS example working with liferay 7.1 GA3?
example: https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-1/jax-rs
If someone can try to see if this works for them, it would be appreciated. It should only take about 5 minutes to verify.
example: https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-1/jax-rs
If someone can try to see if this works for them, it would be appreciated. It should only take about 5 minutes to verify.
Hi,You can check with blade sample example from below URL : https://github.com/liferay/liferay-blade-samples/tree/7.1/liferay-workspace/apps/rest
For this rest services, just check properly Gradle sync with their dependencies.
For this rest services, just check properly Gradle sync with their dependencies.