How to receive a message via Push in Cloud Pub/Sub using Java - publish-subscribe

I am trying to implement Google Cloud Pub/Sub to receive a message(via Push) using Java but I couldn't find documentation for Java.
I am able to receive message via pull, also any leads to setup and test Endpoint locally would be very helpful.
I have verified and added domain as Endpoint wondering what to do next to start receiving message at that endpoint.

A push endpoint in any language is simply an HTTP web server that can receive POST requests with a JSON body of the following form:
{
"message": {
"attributes": {
"key": "value"
},
"data": "SGVsbG8gQ2xvdWQgUHViL1N1YiEgSGVyZSBpcyBteSBtZXNzYWdlIQ==",
"messageId": "136969346945"
},
"subscription": "projects/myproject/subscriptions/mysubscription"
}
Documentation for registering your push endpoint is here. There are plenty of Java web server options available such as Tomcat and Jetty.

When you say that you were able to receive the message via pull, do you use some kind of scheduler in the Java app. to pull the message from pub/sub periodically?
If you are still looking for the answer, you can find here the way to write a push end point (sample) and a way to invoke the same from local.
Hope this helps.

Related

SAP Cloud Platform : Basic Authentication showing when accessing service in WEB IDE app. Why?

I'm using a the same destination on a number of apps, which are connecting fine.
Created a new app (using the same SAP WEB IDE template).
The Service is retrieved fine when selecting New/OData service from the project menu, proving my Destination credentials are fine.
Now, when I run the app. I'm getting a basic authentication window. Cancelling this means I can't connect to the metadata of the service and therefore can't retrieve any data.
https://webidetesting0837185-s0015641139trial.dispatcher.hanatrial.ondemand.com/SAPUI5-ABAP-SFI/sap/opu/odata/sap/ZSV_SURVEY_SRV/$metadata?sap-language=EN 401 (Unauthorized)
My username and password is not being accepted even though it's correct.
Any ideas?
If you User/Password is not accepted I think you missing some configuration in the backend, check the logs like ST22 or SLG1 for authorization issues. Also check if your destinations in Cloud Connector work properly.
To solve this in generell not using basic authentication, you need to work with SAP CP's destination service. Retrieving from onPremise or via AppToAppSSO as Type/Mode of the destination OR work with API Service on SAP CP. For first way change (destination service) reference in your SAPUI5 instead of relative paths in neo-app.json like this:
{
"routes": [
{
"path": "/destinations/SFSF_ODATA_PROXY",
"target": {
"type": "destination",
"name": "sap_hcmcloud_core_odata"
},
"description": "SFSF Proxy OData"
}
],
"cacheControl": [
{
"directive": "public",
"maxAge": 0
}
]
}
Make sure you enter the credentials for your backend (and not for your CP account for example). You can also try and maintain the credentials in the destination itself by setting AuthenticationType as BasicAuthentication.
I have already solved this issue with change Authentication as Basic Authentication

Using passport-http on Hyperledger composer REST API

I would like to know if it is possible to use passport-http to secure the REST API of Hyperledger Composer generated with the composer-rest-server and what would be the export COMPOSER_PROVIDERS='{}' configuration.
The idea is to use the identities previously generated and assigned to participants with the composer to authenticate the GET and POST requests on the API.
If it were possible, how would the userID and userSecret be passed, as a special http header, in the body or as a simple basic auth header?
I've not tried, but it should be able to. The Composer REST server uses the open source Passport authentication middleware, its a matter of configuration. Multiple Passport strategies can be selected, allowing clients of the REST server to select a preferred authentication mechanism.
The strategy for passport-http is here -> https://github.com/jaredhanson/passport-http
You can try something like:
export COMPOSER_PROVIDERS='{
"basic": {
"provider": "basic",
"module": "passport-http",
"clientID": "REPLACE_WITH_CLIENT_ID",
"clientSecret": "REPLACE_WITH_CLIENT_SECRET",
"authPath": "/auth/local",
"callbackURL": "/auth/local/callback",
"successRedirect": "/",
"failureRedirect": "/login"
}
}'
I assume you know how to configure your passport-http strategy.
and check out RESTful Node.js Application with passport-http - and see an example (right near the end) of an app consuming REST Endpoints right near the end.

how to view the cf rest api requests submitted from the bluemix web console?

Most of my experience with Bluemix so far has been using the web management console. I would now like to start using the cloud foundry rest API.
I've had a look through the cf rest API documentation for creating a service instance and see this:
{
"space_guid": "bbbeed31-f908-477a-aab9-8cdcd19e1348",
"name": "my-service-instance",
"service_plan_guid": "fe173a83-df28-4891-8d91-46334e04600d",
"parameters": {
"the_service_broker": "wants this object"
},
"tags": [
"accounting",
"mongodb"
]
}
I have no idea what I need to set for the tags or parameters for a Bluemix service. How can I find this out on for each bluemix service?
When I instantiate a service using the Bluemix web console, is it possible to view the rest API requests that are submitted in the background so that I can reverse engineer the API calls??
You won't be able to see the commands sent by the BlueMix console directly, but you could replicate the commands with the Cloud Foundry CLI and set an environment variable of CF_TRACE=true to output all requests to STDOUT. You can also set it as CF_TRACE=/path/to/file.
The UUIDs could be changed. If you're going to use the API, you'll need to look things up by name, find their UUIDs, and then use them in subsequent requests. I've been working on something similar, that really should have been implemented as a Terraform provider: https://github.com/EngineerBetter/cf-converger

Azure Push Notification REST No Service is Hosted at the Specified Address

I am using Azure mobile services to do Push Notifications. I have a push notification service bus created. When I try to connect to that through a REST service I get the following response:
404No service is hosted at the specified address. TrackingId:dfc9aea1-e229-4eb7-b393-c8cd6bce258d_G19,TimeStamp:11/3/2014 8:39:21 PM
The POSTMAN request looks like so which duplicates the problem:
How do I further troubleshoot this because the service is there? What am I missing?
A reference to the above API can be found here:
http://msdn.microsoft.com/en-us/library/azure/dn223266.aspx
After troubleshooting with Microsoft we found the problem to be two-fold.
The Connection String key you should be using is found on the hubs page. Named DefaultFullSharedAccessSignature.
The next thing is the hub name shouldn't be the namespace.
In my URI…
https://qb-alphahub-ns.servicebus.windows.net/qb-alphahub-ns/messages/?api-version=2013-10
Should be
https://qb-alphahub-ns.servicebus.windows.net/qb-alphahub/messages/?api-version=2013-10
I had the exact same issue when sending requests via Python and Postman.
I tried the above solution with no luck. My issue ended up being two-fold as well:
My namespace was named the same as my notification hub. Had to rename my hub.
I had to add an extra header to the POST: "X-WNS-Type": "wns/toast"
After making the changes, my toast notifications started working with successful responses from the Notification Hub web services.

Get auth token for accesing Orion FI-LAB instance

i'm trying to make a request to orion broker using REST Client, for example a NGSI10 queryContext with a payload like this one:
{
"entities": [
{
"type": "*",
"isPattern": "false",
"id": "Sevilla:01727449"
}
]
}
and I always receive the same result:
Auth-token not found in request header
The orion context broker that i´m using is fi-ware lab context broker and I want to know how to make a authorized request to this CB using REST Client, if it is possible.
Thanks
The Orion instance at FI-LAB uses OAuth authentication. Thus, you need to include a valid X-Auth-Token HTTP header in your requests to Orion.
Your application should implement OAuth and negotiate with the security framework a valid token for that. However, for debug or quick testing you can use the following shell script in order to get a fresh X-Auth-Token:
https://github.com/fgalan/oauth2-example-orion-client/blob/master/token_script.sh
The script will ask you your FI-LAB user and password.
Please, have a look to https://wiki.fi-ware.org/Publish/Subscribe_Broker_-_Orion_Context_Broker_-_User_and_Programmers_Guide#FI-LAB_context_management_platform to get more detail on Orion FI-LAB deployment.
EDIT: the recently published Orion Quick Start guide also includes an example on how to use the token_script.sh script that can be useful.