Spring boot and RAML - maven

I tried to build and run this project
https://github.com/adorsys/raml-springboot-example
I build the project as right click and Maven install.That time raml-springboot-impl.jar is not generating under raml-springboot-impl project.
Do you have any idea about this.

Try to type or copy+paste the following commands in the terminal/bash as shown in the git repos README.md:
(I'll post my example from Mac, you'll probably have to modify it sensibly)
cd to the repo-s root:
cd /Users/username/Documents/RAML/raml-springboot-example
generate the package:
mvn clean package
run project:
java -jar raml-springboot-impl/target/raml-springboot-impl.jar
Create a new Todo:
curl -i -X POST -H 'Content-Type: application/json' -d '{ "task": "Design the API", "priority": 1 }' localhost:8080/api/todos
List all Todos
curl -i -H 'Accept: application/json' localhost:8080/api/todos
Get one Todo by id
curl -i -H 'Accept: application/json' localhost:8080/api/todos/1
If you feel more comfortable if you can see stuff in the browser, you can just paste the last two links in Chrome or whatever you're using ;)
Also, you can try https://www.getpostman.com/ for testing endpoints that accept other than 'GET' requests (like the first one here) ;)

Related

How to send a message to Slack using curl from gitlab-ci.yml?

I am using GitLab for a CI/CD process. I want to send messages to my channel in Slack. Following the API works from the terminal:
curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"}' https://hooks.slack.com/services/xxx/yyyy/zzzz
However, when I put this line into my .yml file, it gives me a "yaml invalid error". Complete block is here:
slack_jar:
stage: slack
before_script:
- echo "hi there"
script:
- curl -F file=#target/springApp-0.0.1.jar -F channels=#application_dev_backend -F token='xoxb-1111-2222-yyyyyy' https://slack.com/api/files.upload
only:
- dev
slack_message:
stage: slack
script:
- echo "Send Slack Messages"
- curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"}' https://hooks.slack.com/services/xxxx/yyyy/zzzz
only:
- dev
The first stage (sending file) is correct, but the second one is not working. This is the error message I get:
Status: syntax is incorrect Error: jobs:slack_message:script config should be a string or an array of strings
Based on your error message, the curl command in slack_message is incorrect. Try wrapping the entire command in quotes and escaping the internal quotes. The way you have it, the YAML parser thinks the Content-type: application/json is a key:value pair of a dictionary.
Try this instead:
slack_message:
stage: slack
script:
- echo "Send Slack Messages"
- "curl -X POST -H 'Content-type: application/json' --data '{\"text\":\"Hello, World!\"}' https://hooks.slack.com/services/xxxx/yyyy/zzzz"
only:
- dev
Pro Tip
You can use the CI Lint tool to validate the contents of gitlab-ci.yaml. You can access this in the CI/CD > Pipelines screen. See CI Lint.
There is also a useful website http://www.yamllint.com/ where you can input YAML, and it will (a) validate it, and (b) return a UTF-8 version. If you have string problems, the UTF-8 version will look mangled (which is what happens with your YAML).
Please give required privilege to bot User to post in channel.
follow the below ci.yaml
#please select the image which has curl command
slack_notification:
image: ubuntu:latest
script:
- echo "Get user id with curl from Slack"
- curl -X GET -H 'Authorization:Bearer <bot token>' https://slack.com/api/users.lookupByEmail?email=$GITLAB_USER_EMAIL | jq -r '.user.id'
# From the above if you change the | jq -r '.user.name' then you will get the name of the user from slack.
- echo "Slack post request"
- >
curl -X POST -H 'Authorization:Bearer <bot token>' -H 'Content-type: application/json' --data '{"channel":"<channel id which start CXXXX>","text":"Your job has been finished please validate Job Url '"$CI_PIPELINE_URL"'"}' https://slack.com/api/chat.postMessage
CI_PIPELINE_URL: This will give the job url.
Slack reference: https://api.slack.com/web

get list of all dependencies of Spring Initializr, using curl

In the official doc, it tells how to use curl to create a spring project.
eg,
curl https://start.spring.io/starter.zip -d dependencies=web,devtools \
-d bootVersion=2.1.9.RELEASE -o my-project.zip
My question is, how can I use curl to get the list of all dependencies?
the output should be look like something below
# output of `curl ...` to get all dependencies of Spring Initializr
...
web
devtools
...
Maybe it's too late and you don't need anymore, but can be helpful to the others...
There is a url that's retrieve relevant info, like version, options and dependencies.
curl -H 'Accept: application/json' https://start.spring.io
If you want to filter only the names of dependencies, with jq help, you can request using this command:
curl -H 'Accept: application/json' https://start.spring.io | jq '.dependencies.values[].values[].id'
The result is something like this:
"devtools"
"lombok"
"configuration-processor"
"web"
"webflux"
"data-rest"
"session"
"data-rest-explorer"
"data-rest-hal"
...

TeamCity API setting configuration parameters

I have configuration parametr current_build_date (User Defined Parameter) I want just to set this parameter to current date by API TeamCity.
On docs I have seen this:
http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator>/parameters/<parameter_name>
I know my Build configuration ID, but I can't understand how by this to make buildTypeLocator.
I assume result will be something like this:
curl -u Login:Password \
-X PUT \
-d 'valueOfMyParam' \
-H 'Content-Type: text/plain' \
http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator>/parameters/current_build_date
I will realy appreciate if somebody who knows TeamCity API will help me with this problem.
I made attempt just to pass instead of buildTypeLocator my Build configuration ID and I got ERROR:
[17:08:25][Step 3/3] Error has occurred during request processing (Not Found).
[17:08:25][Step 3/3] Error: jetbrains.buildServer.server.rest.errors.NotFoundException: No project found by name or internal/external id 'BuildConfigurationID'.
If there are any problems or ambiguities with my question please add comment, i'll try to fix it.
If you browse the REST API endpoints in a browser you'll be able to see the format of the build locator.
Visit http://teamcity:8111/httpAuth/app/rest/buildTypes/ and you'll see the entries have a href attribute that contains the buildLocator (generally a property:value combination)
You'll then be able to navigate using that url / communicate via the API
Hope this helps
I solved problem: build type locator was id:Build configuration ID
current_build_date=`date +%%Y-%%m-%%d:%%H:%%M:%%S`
echo $current_build_date;
curl -u Login:Password \
-X PUT \
-d $current_build_date \
-H 'Content-Type: text/plain' \
https://teamcity.billing.ru/httpAuth/app/rest/buildTypes/id:Build
configuration ID/parameters/current_build_date

Parse server response "Unexpected token"

I'm working on putting a Parse Server on Heroku. I'm using this app:
https://github.com/ParsePlatform/parse-server-example
Uploading to heroku using this guide:
https://devcenter.heroku.com/articles/getting-started-with-nodejs
I've updated the db and server URLs in the parse server code, and everything uploads and deploys properly. However, when I attempt to use cURL to test the server as indicated in this guide:
https://github.com/ParsePlatform/parse-server
I get the following error:
{"error":"Unexpected token '"}
I have copied and pasted the cURL command, modified for my url:
curl -X POST -H "X-Parse-Application-Id: myAppId" -H "Content-Type: application/json" -d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' http://my-app-name.herokuapp.com/parse/classes/GameScore
Heroku logs show the request coming in (so I know it's going to the right place) but no errors. I'm deploying from Windows 7, if that matters. This is my first experience with heroku and parse server so I'm kind of flying blind. Anybody see the problem?
Try to invert simple quote to double quote for your POST data field, it's work for me :
#here : "{'score':1337,'playerName':'Sean Plott','cheatMode':false}"
curl -X POST -H "X-Parse-Application-Id: myAppId" -H "Content-Type: application/json" -d "{'score':1337,'playerName':'Sean Plott','cheatMode':false}" http://my-app-name.herokuapp.com/parse/classes/GameScore
instead
#here : '{"score":1337,"playerName":"Sean Plott","cheatMode":false}'
curl -X POST -H "X-Parse-Application-Id: myAppId" -H "Content-Type: application/json" -d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' http://my-app-name.herokuapp.com/parse/classes/GameScore
I had that issue - for me the fix was is I was using a restApi key which is no longer needed in the Parse-Server.
It was also affecting my s3 adapter - was not allowing me to upload any images through dashboard.
I removed the restApi key and everything started working.

How to update a TeamCity build parameter using REST+cURL

I have a configuration parameter called "testing" in one of my build configurations in TeamCity. After taking a look at the TeamCity REST API doc here I could get information about this parameter using the following cURL command line commands on Windows:
(1) curl -X GET -H "Authorization: Basic (...)" http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/parameters
(2) curl -X GET -H "Authorization: Basic (...)" http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/parameters/testing
Response:
(1) <?xml version="1.0" encoding="UTF-8" standalone="yes"?><property name="testing" value="11"/></properties>
(2) 11
But then, when I try to update this "testing" build parameter using the following command, I get an error message:
curl -X PUT -d "1" -H "Authorization: Basic (...)" http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/parameters/testing
Response:
Error has occurred during request processing (Unsupported Media Type).
Error: javax.ws.rs.WebApplicationException
Not supported request. Please check URL, HTTP method and transfered data are correct.
I already successfully use a similar command to update the buildNumberCounter setting of the same build configuration:
curl -X PUT -d "1" -H "Authorization: Basic (...)" http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/settings/buildNumberCounter
That's why I thought I can do the same with a build parameter in a similar way. What am I missing here?
UPDATE:
I managed to update the "testing" build parameter with value "1" using Fiddler. The request I composed had the following content:
Request: PUT
URL: http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/parameters/testing
Request headers: Authorization: Basic (...)
Request body: 1
So the problem with my cURL command above is probably somewhere around the -d "1" option. But where?
UPDATE 2:
I'm not sure if that makes any difference, but I use this cURL build on Windows 7.
Instead of fixing the failing cURL command, as a workaround, we use now Node.js to compose and send the REST request to TeamCity.
The script that needs to be fed to node.exe is as follows:
// Equivalent cURL command:
// curl -X PUT -d "1" -H "Authorization: Basic (...)" http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/parameters/testing
var http = require('http'),
options = {
hostname: 'teamcity',
port: 8080,
path: '/httpAuth/app/rest/buildTypes/id:bt7/parameters/testing',
method: 'PUT',
headers: { 'Authorization': 'Basic (...)' }
},
req;
req = http.request(options, function(res) { });
// write data to request body
req.write('1');
req.end();
Although the workaround works perfectly, I would still like to know what's wrong with the above cURL command?
For parameters that are non-XML like the one you are asking about, just add:
--Header "Content-Type: text/plain"
For parameters that are XML then you'll want to switch that to:
--Header "Content-Type: application/xml"
I was having a hard time figuring this out too but I found the answer. Instead of using -d and -H at the front. Use --data and --header at the end as shown below . I found this in the TeamCity docs buried in a "click to expand" example.
Set build number counter:
curl -v --basic --user <username>:<password> --request PUT http://<teamcity.url>/app/rest/buildTypes/<buildTypeLocator>/settings/buildNumberCounter --data <new number> --header "Content-Type: text/plain"
Set build number format:
curl -v --basic --user <username>:<password> --request PUT http://<teamcity.url>/app/rest/buildTypes/<buildTypeLocator>/settings/buildNumberPattern --data <new format> --header "Content-Type: text/plain"
I guess the REST API expect XML as input, add
-H "Content-type:text/xml"
and put XML as input. If you have a XML file file.xml :
curl -d "#/path/to/file.xml" -H "Content-type:text/xml" (...)

Resources