I have a spring boot application that is connected to a kafka cluster. How can I run KSQL from java code?
At the moment, there is no direct way to use KSQL as a library in java. There is an open issue#734 for the same.
But you can run the KSQL statement using REST API and that implementation can be done in Spring Boot Application.
A Rest call would look something like this:
POST /query HTTP/1.1
Accept: application/vnd.ksql.v1+json
Content-Type: application/vnd.ksql.v1+json
{
"ksql": "SELECT * FROM pageviews;",
"streamsProperties": {
"ksql.streams.auto.offset.reset": "earliest"
}
}
// Through Curl
curl -X "POST" "http://localhost:8088/ksql" \
-H "Content-Type: application/vnd.ksql.v1+json; charset=utf-8" \
-d $'{
"ksql": "LIST STREAMS;",
"streamsProperties": {}
}'
You can find the documentation here :
https://docs.confluent.io/current/ksql/docs/developer-guide/api.html#rest-endpoint
Since ksqlDB 0.10 there is now a Java client: https://docs.ksqldb.io/en/latest/developer-guide/ksqldb-clients/java-client/
Related
I am new on Icinga2, using 2.4.0 version and I am trying to execute some API calls but I have found a problem when I have tried to create a service manually.
This is the command that I execute to create a service called api_dummy_service_1 for api_dummy_host_1 host:
curl -u $ICINGA2_API_USER:$ICINGA2_API_PASSWORD \
-H 'Accept: application/json' -X PUT \
-k "https://$ICINGA2_HOST:$ICINGA2_API_PORT/v1/objects/services/api_dummy_host_1!api_dummy_service_1" \
-d '{ "templates": [ "generic-service" ], "attrs": { "display_name": "api_dummy_service_1", "check_command" : "dns", "vars.dns_lookup": "google-public-dns-a.google.com.", "vars.dns_expected_answer": "8.8.8.8", "host_name": "api_dummy_host_1" } }' | python -m json.tool
When I execute it, the following error message appears:
-bash: !api_dummy_service_1: event not found
I have examinated Icinga logs, I have activated debug mode on Icinga also and tried to search information related to this in internet with no results.
Can anyone help me please? Thanks in advance!
Issue fixed! After doing more test in detail we have detected that the problem was related to the URL that we use to connect with icinga2 API, the ! character must be escaped.
I have changed ! to %21 and the command works
I am having a hard time understanding how Spring Boot (v1.3.3) handles the X-Requested-With: XMLHttpRequest header. My understanding is that this header tells Spring Boot to return, for requests without an authenticated session, a 401-Unauthorized error rather than a 302-Found with a location to the login page.
I have set up my AngularJS client to send this header for any routing, and then configured an $http interceptor to act on the 401 error by displaying a dialog. Doesn't work for me, with a Spring Boot server with no additional security configuration.
With some investigation with CURL:
It seems that the -H "Accept: application/json" header also needs to be provided.
curl -v -H "X-Requested-With: XMLHttpRequest" localhost:9080/ returns a 302, while curl -v -H "X-Requested-With: XMLHttpRequest" -H "Accept: application/json" localhost:9080/ returns a 401.
Questions: Why is the application/json header required as well? Can I configure it differently (i.e. not require application/json header)? Should I configure it this way, or take another approach? The reason I don't want to require the application/json header is because I am not allowing public access to some resources, such as HTML templates and JS code, and want a 401 returned for these resources as well.
It seems that the JSESSIONID cookie may be affecting the response.
curl -v -H "X-Requested-With: XMLHttpRequest" -H "Accept: application/json" localhost:9080/ returns a 401, while curl -v -H "X-Requested-With: XMLHttpRequest" -H "Accept: application/json" -H "Cookie: JSESSIONID=63EA6E09F64B98938E4495DF9898323A" localhost:9080/' returns a 302.
Questions: Why does the presence of the (valid) JSESSIONID cookie make any difference?
I have looked at the source code for Spring Security and Spring Boot and I just cannot put together the pieces. Any help is much appreciated.
i'm trying to send a parse.com push notification from ruby 1.8.7.
i got a test working with curl. but with ruby's net::http i'm getting Timeout::Error: Resource temporarily unavailable
how can i debug this? i don't know how to see why the parse server is responding differently or otherwise see what's happening. i tried sending the request to my own server and the headers looked ok to me.
i simplified what i'm doing to this:
http = Net::HTTP.new('api.parse.com', 443)
response = http.post("/1/push", "{\"where\":{},\"data\":{\"alert\":\"Elliot net http json test 1\"}}", {"X-Parse-Application-Id"=>"xxxxx", "Content-Type"=>"application/json", "X-Parse-REST-API-Key"=>"xxxxx"})
the json there is hard to read, it's from:
api_req = {:where => {}, :data => {:alert => "Elliot net http json test 1"}}.to_json
puts api_req
# {"where":{},"data":{"alert":"Elliot net http json test 1"}}
i also tried several other ways of sending a request with net::http. same result.
the curl request that worked was:
curl -X POST \
-H "X-Parse-Application-Id: xxxxxx" \
-H "X-Parse-REST-API-Key: xxxxx" \
-H "Content-Type: application/json" \
-d '{
"where": {},
"data": {
"alert": "Elliot curl test #4"
}
}' \
https://api.parse.com/1/push
i'm not using parse-ruby-client because i ran into problems with dependencies assuming a newer version of ruby. all i need to do is send some simple push notifications, and it seems like this should work without too much trouble.
can anyone help me get this working or tell me how to get some useful info about what's happening to debug?
As per the REST API Developers guide,
All API access is over HTTPS, and accessed via the https://api.parse.com domain.
So all you need to do is to add http.use_ssl = true.
How i can send request like this via rails
POST /token/ HTTP/1.1
Host: api.admitad.com
Authorization: Basic XXX
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
grant_type=client_credentials&scope=public_data&client_id=XXX
based on admitad api
You can send the POST request via the command line with a tool like cURL:
curl --data-urlencode "grant_type=client_credentials&scope=public_data&client_id=XXX" http://api.admitad.com/token
If you want to use HTTP basic authorization, add the -u option:
curl --data-urlencode "grant_type=client_credentials&scope=public_data&client_id=XXX" http://api.admitad.com/token -u "client_id:public_key"
Another similar command line tool is httpie.org, which uses a slightly different syntax.
I'm following the instructions here http://developer.bigcommerce.com/api/webhooks/quickstart to set up webhooks to initiate some third-party order processing. We've been doing this on an hourly batch, real-time webhook triggers will save us a lot of lag time.
I think I've set up the webhook broadcaster, but can't see any evidence that it's being fired- I've created a bunch of new orders and nothing reaches the rails server.
How can I tell if BigCommerce is firing events when / where I expect?
Generated the access token for the given app/user/domain:
curl -XPOST -d '{
"client_id":"[BigCommerceAppClientId]",
"client_secret":"[BigCommerceAppSecret]",
"user":"admin",
"token":"[adminAPIToken]",
"store_domain":"https://[myStore].mybigcommerce.com"
}' https://hooks-beta.bigcommerce.com/token
yields ===>
{
"access_token":"[webHooksAccessToken]",
"producer":"store/[myStoreKey]"
}
Subscribed to webhooks for store/events/listener:
curl -XPOST -d '{
"producer":"store/[myStoreKey]",
"scope":"store/order/created",
"deliverymethod":"HTTP_POST",
"destination":{"url":"http://[myPublicRailsServer]/hooks"}
}' -H 'X-Auth-Client: [BigCommerceAppClientId]' -H 'X-Auth-Token:[X-Auth-Token]' https://hooks-beta.bigcommerce.com
yields ===>
{
"client_id":"[webHooksAccessToken]",
"created_at":"2013-06-27T19:57:38+00:00",
"deliverymethod":"HTTP_POST","destination":{"url":"http://[myPublicRailsServer]/hooks"},
"id":651,
"producer":"store/[myStoreKey]",
"scope":"store/order/created",
"updated_at":"2013-06-27T19:57:38+00:00"
}
I lied. The problem was apparently trying to use https instead of http. Everything works as expected.
Furthermore- BigCommerce provides a hook to check the active clients for a given application:
curl -XGET -H
'X-Auth-Client: [BigCommerceAppClientId]' -H
'X-Auth-Token: [BigCommerceAppSecret]'
https://hooks-beta.bigcommerce.com/producer/store/[myStoreKey]