Handling connection error stomp 0.3.3 flutter/dart - spring

When I put a wrong url/ip to my stomp spring service I don't get onWebSocketError fired up and does not print out error as in the code below:
final stompClient = StompClient(
config: StompConfig(
url: 'ws://localhostxx:8080',
onConnect: onConnect,
onWebSocketError: (dynamic error) => print(error.toString()),
stompConnectHeaders: {'Authorization': 'Bearer yourToken'},
webSocketConnectHeaders: {'Authorization': 'Bearer yourToken'}));
I want to show a message to a user that the connection is not available.

Since 0.4.0 the onWebSocketError callback should be more reliably called when errors occur.
https://pub.dev/packages/stomp_dart_client/changelog#040

Related

Token destroy with djoser

I'am using django and trying to destroy a token when user log out, this is the function I'am using :
const logMeOut = async () => {
setAnchorEl(null);
const response = await fetch('http://127.0.0.1:8000/api-auth/token/logout/', {
method: 'POST',
headers: {
'Authorization': 'Token '.concat(GlobalState.userToken),
'Content-Type': 'application/json',
},
})};
However my server is throwing :
POST http://127.0.0.1:8000/api-auth/token/logout/ 401 (Unauthorized)
What I'am I doing wrong ? I know it's something about the headers or something like that... but I have been switching headers and nothing changes.
Okay, I found out what the problem was and I'll leave it here for anyone who might be facing the same issue.
In my particular case, I was getting unauthorized because I send the same token multiple times and the token was destroyed the first time I sent the request to the backend...
Basically, I didn't destroy the token in the frontend and kept sending the same token which was already destroyed, which means there is nothing wrong with the piece of code above and it should work.

Send message with Malign via http request

I try to send a message via http request using Mailgun, the system give me back a 200 ok but the message never send.
here my code, (I run my code inside a parse httpReuest function) any idea?
Parse.Cloud.httpRequest({
url: 'https://api:MYAPIKEY#api.mailgun.net/v3/MYDOMAIN.net/message',
params: {
from: 'XX#XX.net',
to: 'XX.XX#gmail.com',
subject: 'Hello',
text: 'Testing some Mailgun awesomness!'
}
}).then(function(httpResponse) {
console.log('Request response ' + httpResponse.error);
}, function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
});
I found the answer... I make a mistake in the api call the right call is.
url: 'https://api:MYAPIKEY#api.mailgun.net/v3/MYDOMAIN.net/messages',
with messages not message
forgot and s and waste the entire day :-(

How to call a https POST method using gatewayscript in IBM Bluemix APIConnect

I am trying to call another API inside Bluemix or any other HTTPS post method using a gateway script inside IBM Bluemix (API Connect) using the code below:
var urlopen = require('urlopen');
var options = {
target: 'https://pokemons.mybluemix.net/api/pokemons/1',
method: 'POST',
headers: {},
contentType: 'application/json',
timeout: 60,
data: {"Message": "DataPower GatewayScript"}
};
urlopen.open(options, function(error, response) {
if (error) {
// an error occurred during the request sending or response header parsing
session.output.write("urlopen error: "+JSON.stringify(error));
} else {
// get the response status code
var responseStatusCode = response.statusCode;
var responseReasonPhrase = response.reasonPhrase;
console.log("Response status code: " + responseStatusCode);
console.log("Response reason phrase: " + responseReasonPhrase);
// reading response data
response.readAsBuffer(function(error, responseData){
if (error){
throw error ;
} else {
session.output.write(responseData) ;
apim.output('application/json');
}
});
}
});
But I am getting the following error:
{
"httpCode": "500",
"httpMessage": "Internal Server Error",
"moreInformation": "URL open: Cannot create connection to 'https://pokemons.mybluemix.net/api/pokemons/1', status code: 7"
}
Looks like there is some issue with the SSL Connections. If so, how can I get the SSL Details for the default Sandbox Catalog in IBM Bluemix API Connect? Or, how can I make the HTTPS POST calls to the above sample URL?
Since Version 5.0.6:
IBM API Connect 5.0.x
Forward SSLProxy (and Crypto) is replaced with SSLClient. These new profiles support ephemeral ciphers (DHE and ECDHE), perfect forward secrecy, and Server Name Indication (SNI) extension. Note that DHE ciphers in DataPower SSLServerProfile use 2048-bit DH parameters (as server) and accept 1024-bit DH parameters (as client).
In order for you specific example to work on API Connect using HTTPS you need to specify the sslClientProfile.
For example:
var urlopen = require('urlopen');
var options = {
target: 'https://pokemons.mybluemix.net/api/pokemons/1',
method: 'POST',
headers: {},
contentType: 'application/json',
timeout: 60,
sslClientProfile: 'webapi-sslcli-mgmt',
data: {"Message": "DataPower GatewayScript"}
};

Ember acceptance test not working with AJAX

I'm starting to add acceptance tests to my Ember project. Starting off with one which tries to log-in to my app:
import { test } from 'ember-qunit';
import moduleForAcceptance from '../helpers/module-for-acceptance';
moduleForAcceptance('Acceptance | login');
test('logging in', function(assert){
visit('/login');
andThen(function(){
assert.equal(currentURL(), '/login');
});
fillIn('#login input[name=email]', 'my#email.com');
fillIn('#login input[name=password]', 'password');
click('#login button[type=submit]');
andThen(function(){
assert.equal(currentURL(), '/dashboard');
});
});
But it fails because the AJAX call to my REST API for authentication fails. This works fine when the app is running normally, but not when done through an acceptance test.
I've traced it back to the following error being returned by ember-ajax:
Ember AJAX Request POST https://127.0.0.1:8081/login returned a 0\nPayload (Empty Content-Type)\n""
My API isn't even getting the call, so this seems to be an error with sending the REST request. I've checked the hash object in node_modules/ember-ajax/addon/mixins/ajax-request.js just before it's sent through to the jQuery AJAX method:
{ type: 'POST',
data: { email: 'my#email.com', password: 'password' },
url: 'https://127.0.0.1:8081/login',
dataType: 'json',
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
headers: { Authorization: 'Bearer undefined; PublicKey Ab732Jte883Jiubgd84376HhhndikT6' } }
contentType is defined. This is also exactly how hash looks when making the same AJAX call with the app running normally.
So what is there about Ember acceptance tests which would specifically prevent AJAX calls from working? I suspect there's a config or environment property I'm unaware of that I need to change/set to get it working.
I'm running:
ember-cli: 2.8.0
node: 4.5.0
ember-ajax: 2.5.1
ember-cli-qunit: 3.0.1
phantomjs: 2.1.7
What an eejit! My local REST API has an invalid SSL certificate. So I just needed to tell PhantomJS to ignore SSL errors in my testem.js file:
"phantomjs_args": [
"--ignore-ssl-errors=true"
],

Mobile Hybrid application throws 500 error for all POST requests to JIRA Server

I have a Hybrid application using cordova and angular that utilizes the JIRA rest service. I am doing a simple call to add a comment to a JIRA ticket using ajax. All calls were working until the recent upgrade to JIRA 7. After the upgrade all calls except POST still succeed.
var data = {
"body": "quick comment",
};
var req = {
method: 'POST',
url: 'https://our.jiraserver.com/jira/rest/api/2/issue/{issuekey}/comment',
headers: {
'Authorization': 'Basic garbeldygoopasdfasdf',
'Content-Type': 'application/json',
'Access-Control-Allow-Origin':'*'
},
data: data
};
$http(req).then(function(response){
console.log('success', response);
}, function(error){
console.log('errpr', error);
});
A trimmed version of the error the server is throwing (for those TL;DR's)
message: "Expected authority at index 7: file://"
stack-trace: "java.lang.IllegalArgumentException: Expected authority at index 7: file://↵ at java.net.URI.create(URI.java:852)↵ at com.atlassian.applinks.cors.auth.DefaultCorsService.getApplicationLinksByOrigin(DefaultCorsService.java:56)↵ at com.atlassian.applinks.cors.auth.AppLinksCorsDefaults.allowsOrigin(AppLinksCorsDefaults.java:42)↵ at com.atlassian.plugins.rest.common.security.jersey.XsrfResourceFilter$1.apply(XsrfResourceFilter.java:255)↵ at com.atlassian.plugins.rest.common.security.jersey.XsrfResourceFilter$1.apply(XsrfResourceFilter.java:252)↵ at com.google.common.collect.Iterators.indexOf(Iterators.java:778)↵ at
I will note again these calls worked until very recently... as a workaround I setup a node/express servers to simply bounce my api calls through. I send the data there, it makes the same request and succeeds and passes the data back to my app. Of course this isn't ideal as I now have a split code base.
I went to Atlassian support who basically told be they cannot assist with third-party development.
Any suggestions or help would be greatly appreciated.

Resources