Why does HotelSearch return an ERR.NGHP-DISTRIBUTION.INTERNAL_ERROR? - sabre

I am trying to use the HotelSearch REST api. I have tested it on the Dev Studio website by Sabre and while it is slow to respond it works on a Chrome browser. I then tried to get his working in the sample app Rest2SG Sabre provide, as well as Postman. However it returns this error on both platforms:
Here is the method I have added to the sample app:
private void getHotelSearch()
{
Job job = new Job("Getting HotelSearch")
{
#Override
protected IStatus run(IProgressMonitor monitor)
{
setText("Waiting for response...");
toggleAllButtons(false);
try
{
Rest2SgRequest request =
lockId > 0 ? new Rest2SgRequest(lockId) : new Rest2SgRequest();
// for the list of available service action names
// please refer to REST documentation
// this same as action in redapp.xml authorization
request.setUrl("/v2.0.0/hotel/search");
//request.setHeaders(getContentDescription())
// previously generated document, normally developer will
// have to prepare one by himself
String payload = getRequestBody("sample.json"); // we
// preload
request.setPayload(payload);
request.setHttpMethod(HTTPMethod.POST);
request.setContentType("application/json");
request.setAuthTokenType(AuthTokenType.SESSIONLESS);
Rest2SgServiceClient client = new Rest2SgServiceClient(COM);
ClientResponse <Rest2SgResponse> rsp = client.send(request);
LOGGER.info("Rest2Sg request processing success: " + rsp.isSuccess());
if (rsp.isSuccess())
{
// check if processing ended in with success
Rest2SgResponse response = rsp.getPayload();
String responseBody = response.getResponseBody();
response.getResponseCode();
response.getResponseHeaders();
setText(responseBody);
}
else
{
printErrors(rsp.getErrors());
System.out.println(rsp.getErrors().toString());
}
}
catch (Exception e)
{
e.printStackTrace();
}
toggleAllButtons(true);
return Status.OK_STATUS;
}
};
job.schedule();
}
Here is the sample JSON:
{
"HotelSearchRQ": {
"POS": {
"Source": {
"PseudoCityCode": "43X5"
}
},
"SearchCriteria": {
"MaxResults": 20,
"SortBy": "DistanceFrom",
"SortOrder": "ASC",
"TierLabels": false,
"GeoSearch": {
"GeoRef": {
"Radius": 2,
"UOM": "MI",
"RefPoint": {
"Value": "DFW",
"ValueContext": "CODE",
"RefPointType": "6",
"StateProv": "TX",
"CountryCode": "US"
}
}
}
}
}
}
Does anyone know why I am getting the error below?
[Error [code=400, description={"errorCode":"ERR.NGHP-DISTRIBUTION.INTERNAL_ERROR","message":"Error occurred while invoking service restish:convertToOutputFormat:1.71.3","status":"Incomplete","type":"Application","timeStamp":"2022-06-20T21:00:51-05"}, type=HTTP]]
As I mentioned this JSON works on their website.

This problem is caused by missing header information. The following line needs to be added to the request:
request.setHeaders("{\"Accept\": \"application/json\"}");

Related

MSAL redirecturi for vue3 app with vue router hash mode resolving as my_host/#/code=....rest-of-aad-response

Since fragments are not supported in aad redirect_uris, I made the redirect_uri my homepage with navigateToLoginRequestUrl. After sign-in, instead of being directed to my_host/#code=...reest-of-aad-response, vue router seems to jump in and hashbang the url to my_host/#/code=...rest-of-aad-response which 404s.
Do I need to switch to history or is there something I am missing and a way to accomplish this in hash mode? Should I use loginPopup instead of loginRedirect?
msal service
import * as msal from '#azure/msal-browser';
export default class msalAuth {
constructor(config) {
const msalConfig = {
auth : {
clientId : config.clientId,
authority : config.authority,
redirectUri : config.redirectUrl,
navigateToLoginRequestUrl : true
},
cache : {
cacheLocation : 'localStorage',
storeAuthStateInCookie : true
},
system: {
loggerOptions: {
loggerCallback: (level, message, containsPii) => {
if (containsPii) {
return;
}
switch (level) {
case msal.LogLevel.Error:
console.error(message);
return;
case msal.LogLevel.Info:
console.info(message);
return;
case msal.LogLevel.Verbose:
console.debug(message);
return;
case msal.LogLevel.Warning:
console.warn(message);
return;
}
}
}
}
};
let graphScopes = Object.values(config.graphScopes);
let state = window.location.origin;
let postLogoutRedirectUri = config.logoutRedirect;
let graphUrl = config.graphUrl;
this.msalAppConfig = {
graphScopes,
state,
loginRequest: {
scopes: graphScopes,
state
},
postLogoutRedirectUri,
graphUrl
};
this.app = new msal.PublicClientApplication(msalConfig);
}
login() {
this.app.loginRedirect(this.msalAppConfig.loginRequest);
}
logout(userName) {
const logoutRequest = {
account : this.app.getAccountByUsername(userName),
postLogoutRedirectUri : this.msalAppConfig.postLogoutRedirectUri,
mainWindowRedirectUri : this.msalAppConfig.postLogoutRedirectUri
}
this.app.logoutPopup(logoutRequest);
}
async handleRedirectPromise() {
return await this.app.handleRedirectPromise();
}
processRedirectResponse(response) {
let accountId = '';
console.log('processRedirectResponse', response);
if (response) {
accountId = response.account.homeAccountId;
// Display signed-in user content, call API, etc.
} else {
// In case multiple accounts exist, you can select
const currentAccounts = this.app.getAllAccounts();
if (currentAccounts.length === 0) {
// no accounts signed-in, attempt to sign a user in
//this.loginRedirect();
} else if (currentAccounts.length > 1) {
// Add choose account code here
accountId = currentAccounts[0].homeAccountId;
} else if (currentAccounts.length === 1) {
accountId = currentAccounts[0].homeAccountId;
}
}
return accountId;
}
}
redirectUri is http://localhost:8080 as am still developing
Thanks!
I switched vue router mode to history instead of hash, and it resolved the issue for anyone coming here with the same problem
Edit: for anyone coming to this and being dismayed that I switched to history mode and are using Azure static webapps. I added a staticwebapp.config.json to my public folder (or anywhere which will place it in root of output when built). This file lets you provide some configuration to the static web app. You can read about it in the ms docs but mine was the following which you can edit / build off of
{
"routes": [
{
"route": "/*",
"serve": "/index.html",
"statusCode": 200
}
],
"navigationFallback": {
"rewrite": "/index.html",
"exclude": [
"/icons/*.{png,jpg,gif,webp,svg}",
"/css/*",
"favicon.ico",
"/fonts/*"
]
},
"mimeTypes": {
".woff2": "font/woff2",
".woff": "font/woff",
".json": "text/json",
".ico": "image/x-icon"
}
}

How to implement push notification in KaiOS app

I am trying to implement push notification in KaiOS app. I simply follow below links.
W3C Push API
Push API introduction
Service Worker Cookbook - Web Push Payload
After follow all links the push is working in browser but not in KaiOS app.
If anybody have any sample code or documents please share.
Any help will be appriciated.
1) First, add this permission in manifest.webapp
"permissions": {
"serviceWorker":{
"description": "required for handle push."
},
"push":{
"description": "New update push."
},
"desktop-notification": {
"description": "New content update notification for the user."
}
}
2) service worker file sw.js code
self.addEventListener('push', function(event) {
event.waitUntil(
self.registration.showNotification('My Push', {
body: 'Push Activated',
})
);
});
self.addEventListener('activate', e => {
self.clients.claim();
});
3) Add service worker on app start
registerSW : function() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('./sw.js').then(function(reg) {
console.log('Service Worker Registered!', reg);
reg.pushManager.getSubscription().then(function(sub) {
if (sub === null) {
} else {
console.log('Subscription object: ', sub);
}
});
}).catch(function(e) {
console.log('SW reg failed');
});
}
}
4) Call service worker by any dom element like button
registerServiceWorker: function() {
Notification.requestPermission().then(function(permission) {
if (permission === 'granted') {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then(function(reg) {
reg.pushManager.subscribe({
userVisibleOnly: true
}).then(function(sub) {
console.log('Endpoint URL: ', sub.endpoint);
}).catch(function(e) {
if (Notification.permission === 'denied') {
console.warn('Permission for notifications was denied');
} else {
console.error('Unable to subscribe to push', e);
}
});
})
}
}
});
}
That's it.
I had same problem as this, but I followed this simple web push notification method,
https://medium.com/#seladir/how-to-implement-web-push-notifications-in-your-node-react-app-9bed79b53f34
as well as I fixed that issue and now It work properly. please don't forget to add permissions like below into the manifest.webapp file.
"permissions": {
"serviceworker": {
"description": "Needed for assocating service worker"
},
"desktop-notification": {
"description": "Needed for creating system notifications."
},
"notifications": {},
"push": {
"description": "Required for being updated with new goals in soccer matches"
},
"geolocation": {
"description": "Marking out user location"
},
"alarms": {
"description": "Scheduling alarms"
}
},
and as well as please refer this kaios documention for run the applicaion on kaios device.
https://developer.kaiostech.com/getting-started/build-your-first-hosted-app/pwa-to-hosted-app

The generic template and list template didn't work

I'm following the facebook messenger develop QuickStart to create a Node.js project, and I improved it to work in quick reply. Then when I tried the Generic Template and List Template, but it didn't work.
As the following source code, when I input the work "generic" or "list", the messenger should reply me with the template messege. But there was nothing happened.
} else if (received_message.text === 'generic') {
console.log('generic in');
response = {
"attachment":{
"type":"template",
"payload":{
"template_type":"generic",
"elements":[
{
"title":"Welcome!",
"image_url":"http://webapplication120181023051009.azurewebsites.net/colorcar1.jpg",
"subtitle":"We have the right hat for everyone.",
"default_action": {
"type": "web_url",
"url": "https://www.taobao.com/",
"messenger_extensions": false,
"webview_height_ratio": "tall",
"fallback_url": "https://www.taobao.com/"
},
"buttons":[
{
"type":"web_url",
"url":"https://www.taobao.com/",
"title":"View Website"
},{
"type":"postback",
"title":"Start Chatting",
"payload":"DEVELOPER_DEFINED_PAYLOAD"
}
]
}
]
}
}
}
// Sends the response message
callSendAPI(sender_psid, response);
// Sends response messages via the Send API
function callSendAPI(sender_psid, response) {
// Construct the message body
let request_body = {
"recipient": {
"id": sender_psid
},
"message": response
}
console.log('PAGE_ACCESS_TOKEN:');
console.log(PAGE_ACCESS_TOKEN);
console.log('request body:');
console.log(request_body);
// Send the HTTP request to the Messenger Platform
request({
"uri": "https://graph.facebook.com/v2.6/me/messages?access_token=" + PAGE_ACCESS_TOKEN,
"qs": { "access_token": PAGE_ACCESS_TOKEN },
"method": "POST",
"json": request_body
}, (err, res, body) => {
if (!err) {
console.log('message sent!')
} else {
console.error("Unable to send message:" + err);
}
});
}
Sorry, I forgot to add the url into whiltelist.

Push notification not showing message body when app is killed. it only shows default icon of app

when my app is running is receive notification along with title message and app icon like this
but when my is killed it does not shoe message body only shows icon and title which is applications name like this
while the code for my OnMessagerecieved method is this
#Override
public void onMessageReceived(RemoteMessage message) {
String from = message.getFrom();
Map data = message.getData();
datarecieved = message;
String orderIds= "";
try {
if(data.get("accountId")!=null)
orderIds = data.get("accountId").toString();
} catch (Exception e) {
e.printStackTrace();
}
String userId=SharedPrefsUtils.getStringPreference(getApplicationContext(),"user_id");
if(userId!=null&&userId.length()>0) {
if (orderIds.equals("-101")) {
generateNotificationForOrder(getApplicationContext(), data);
} else if (!orderIds.equals("")) {
generateNotification(getApplicationContext(), data);
}
}
}
while my JSON for notification is like this
{
"to": "fcm_token",
"data": {
"type": "101 / 102 / 103",
"msg": "CustomerId",
"id": "0",
"accountId": "-101"
},
"content_available": true
}

Jquery Datatables Ajax Response

I am trying to follow the datatable example for Ajax data source (objects) found here. I am using asp.net and have the following handler which receives my data, processes it and provides the response.
public class UsersHandler : IHttpHandler
{
private const string JsHeader = #"{{""data"" {0}}}";
public void ProcessRequest(HttpContext context)
{
IEnumerable<SystemUser> data = SystemUserLogic.LoadAllSystemUsers();
List<SimpleUser> userlist = new List<SimpleUser>();
foreach (SystemUser su in data)
{
SimpleUser simple = new SimpleUser();
simple.Id = su.Id;
simple.FullName = su.NameFirst;
simple.Email = "example#email.co.uk";
userlist.Add(simple);
}
string json = JsonConvert.SerializeObject(userlist, Formatting.Indented);
context.Response.ContentType = "text/plain";
context.Response.ContentEncoding = Encoding.UTF8;
context.Response.Cache.SetNoStore();
context.Response.Expires = -1;
context.Response.Write(String.Format(JsHeader, json));
}
which deliveries the correct response when I catch it in the browser and look at the data via the network traffic. My aspx page contains the following.
$('#table_id').DataTable({
"ajax": '/Handlers_New/UsersHandler.ashx',
"columns": [
{ "data": "Id" },
{ "data": "FullName" },
{ "data": "Email" },
{ "data": "KeyResource" }
]
});
However when the page loads, I am getting this error:
DataTables warning: table id=table_id - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1
The outputted data looks like this,
{"data" [
{
"Id": 1,
"FullName": "Admin",
"Email": "example#email.co.uk",
"KeyResource": false
},
{
"Id": 2,
"FullName": "Jon",
"Email": "example#email.co.uk",
"KeyResource": false
},
{
"Id": 3,
"FullName": "Stephen",
"Email": "example#email.co.uk",
"KeyResource": false
}, etc.....
Please tell me why I am getting this error. Should I be manipulating the json object differently, or am I missing something with the Jquery datatables?
I have managed to fix my issue amazingly due to jsonlint. I ran my code through that and it turns out I was missing a ':' in my jsHeader. So what I had was:
private const string JsHeader = #"{{""data"" {0}}}";
and what I have now which now works is:
private const string JsHeader = #"{{""data"": {0}}}";
Hope this helps any one else encountering a similar issue.

Resources