I am trying to connect to my local XMPP server using the XIFF library however I am unable to do so.
I installed eJabberd on my localhost and connected to it with an XMPP client (Pandion) and this is working fine... I am able to connect to the local jabber server.
Next, I tried connecting to the XMPP server using the following code:
LoginView.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="Login">
<s:layout>
<s:FormLayout/>
</s:layout>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script source="connection/Connection.as"/>
<s:Spacer/>
<s:Label text="Username"/>
<s:TextInput id="txtUsername" width="200"/>
<s:Spacer/>
<s:Label text="Password"/>
<s:TextInput id="txtPassword" width="200" displayAsPassword="true"/>
<s:Button id="btnLogin" label="Login" click="login(txtUsername.text, txtPassword.text)" mouseUp="navigator.pushView(HomeView)"/>
</s:View>
Connection.as:
import org.igniterealtime.xiff.conference.Room;
import org.igniterealtime.xiff.core.UnescapedJID;
import org.igniterealtime.xiff.core.XMPPConnection;
import org.igniterealtime.xiff.events.LoginEvent;
private var con:XMPPConnection;
private var room:Room;
private function login (username:String, password:String): void {
con = new XMPPConnection ();
con.username = username + "#mydomain";
con.password = password;
con.server = "localhost";
con.port = 5222;
con.connect (0);
}
However I am unable to connect to connect to the XMPP server using the ActionScript code above. Just wondering where I may be going wrong.
Any help would be appreciated.
Thanks!
Looks like a cross-domain policy issue. Try:
Locate your policy log file first
Launch your SWF
Check policy file contents
Another way of doing the same thing is opening browser networking log and checking if Flash is trying to load file like http://localhost/crossdomain.xml.
There are two general solutions to this problem:
Serve correct crossdomain.xml from your server OR
Serve SWF file from the same host as the XMPP data
For debugging purposes adding SWF file location do local-trusted sandbox should resolve all the issues.
Related
I have a Xamarin android app which attaches a log file to Email. With Android 10, this was working fine. But when I try this on Android 11 phones, it says " Unable to attach a file" in the email application.
Then, I came across this blog explaining the package visibility in Android 11, and the changes that needs to be done
https://devblogs.microsoft.com/xamarin/android-11-package-visibility/
SO, I made changes accordingly by adding this in my manifest file
<queries>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:scheme="mailto" />
</intent>
</queries>
I do have permission for reading and writing external storage files.
Below is the code, which I use for attaching logs and sending it through email.
Intent intent = new Intent(Intent.ActionSend);
if ((ContextCompat.CheckSelfPermission(ysiCurrentActivity.Current.Activity, Android.Manifest.Permission.ReadExternalStorage) == Android.Content.PM.Permission.Granted) &&
(ContextCompat.CheckSelfPermission(ysiCurrentActivity.Current.Activity, Android.Manifest.Permission.WriteExternalStorage) == Android.Content.PM.Permission.Granted))
{
ysiMainActivity activity = (ysiMainActivity)ysiCurrentActivity.Current.Activity;
if (activity.GetExternalFilesDir(null) != null && !string.IsNullOrWhiteSpace(activity.GetExternalFilesDir(null).AbsolutePath))
{
string sFilePath = Path.Combine(activity.GetExternalFilesDir(null).AbsolutePath, "MobileAppLogs.log");
if (!File.Exists(sFilePath))
{
FileStream fileStream = new FileStream(sFilePath, FileMode.Create);
fileStream.Dispose();
}
using (StreamWriter streamWriter = new StreamWriter(sFilePath, false))
{
streamWriter.Write(logs);
}
Java.IO.File file = new Java.IO.File(sFilePath);
file.SetReadable(true, false);
Android.Net.Uri uri = Android.Net.Uri.FromFile(file);
intent.SetData(Uri.Parse("mailto:"));
intent.SetType("message/rfc822");
intent.PutExtra(Intent.ExtraSubject, "Logs");
intent.PutExtra(Intent.ExtraStream, uri);
ysiCurrentActivity.Current.Activity.StartActivity(Intent.CreateChooser(intent, "Send email"));
}
}
else
{
return false;
}
Even after adding the manifest changes, I still cannot attach the logs to email.
Am i still missing something.
You can use Xamarin.Essentials: Email to achieve this.
The Email class enables an application to open the default email application with a specified information including subject, body, and recipients.
When we check part File Attachments,we could find that:
This feature enables an app to email files in email clients on the
device. Xamarin.Essentials will automatically detect the file type
(MIME) and request the file to be added as an attachment. Every email
client is different and may only support specific file extensions, or
none at all.
Here is a sample of writing text to disk and adding it as an email attachment:
var message = new EmailMessage
{
Subject = "Hello",
Body = "World",
};
var fn = "Attachment.txt";
var file = Path.Combine(FileSystem.CacheDirectory, fn);
File.WriteAllText(file, "Hello World");
message.Attachments.Add(new EmailAttachment(file));
await Email.ComposeAsync(message);
Note:
If your project's Target Android version is set to Android 11 (R API 30) you must update your Android Manifest with queries that are used with the new package visibility requirements.
Open the AndroidManifest.xml file under the Properties folder and add the following inside of the manifest node:
<queries>
<intent>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
</intent>
</queries>
For more details,check:https://learn.microsoft.com/en-us/xamarin/essentials/email?context=xamarin%2Fandroid&tabs=android&WT.mc_id=docs-xamarinblog-jamont.
I have task to write code to get listener+receiver using JavaEE EJB 3.x+ JBoss(using Wildcat 14) + IBM MQ 9.x (MQ on my docker container). Write receiver was easy with all configuration for IBM MQ, using Message Driven Bean. And it works fine. I can send message from my MQ explorer in browser to my reciever deployed in JBoss. But I have problem with sender. I wanted to use com.ibm.mq.jms.context.WMQInitialContextFactory for JNDI Factory but it is, in present, deprecated context(not safe etc.). People are recommending using com.sun.jndi.fscontext.RefFSContextFactory but it's a file context. It wants url to local folder for bindings. But my program will be deployed on other computer in future so I dont't want to using local file-context. Or I'm bad understanding positive in this way??
P.S. Before, I had task for same program but using spring boot and it was ultra easy using default spring boot context and JMSTemplate.convertandsend
I guess that I am a bit puzzled by your question. If you wish to send a message via IBM MQ, you would first have a configuration like:
<subsystem xmlns="urn:jboss:domain:resource-adapters:5.0">
<resource-adapters>
<resource-adapter id="wmq.jmsra.rar" statistics-enabled="true">
<archive>
wmq.jmsra.rar
</archive>
<transaction-support>XATransaction</transaction-support>
<connection-definitions>
<connection-definition class-name="com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl" jndi-name="java:jboss/jms/MQConnectionFactory" enabled="true" pool-name="MQConnectionFactory">
<config-property name="transportType">
CLIENT
</config-property>
<config-property name="password">
redhat
</config-property>
<config-property name="queueManager">
${wmq.queue.manager}
</config-property>
<config-property name="userName">
redhat
</config-property>
<config-property name="connectionNameList">
${wmq.connectionlist}
</config-property>
</connection-definition>
</connection-definitions>
<admin-objects>
<admin-object class-name="com.ibm.mq.connector.outbound.MQQueueProxy" jndi-name="java:jboss/mqQueue" enabled="true" pool-name="mqQueue">
<config-property name="baseQueueName">
REDHAT.QUEUE
</config-property>
<config-property name="baseQueueManagerName">
REDHAT.QUEUE.MANAGER
</config-property>
</admin-object>
</admin-objects>
</resource-adapter>
</resource-adapters>
You would then either do JNDI lookups on your connection factory and destination and then send a message. Alternatively, you would do resource injection and let the JBoss container populate your connection factory and destination.
Something like:
#Resource(mappedName = "java:jboss/jms/MQConnectionFactory")
private ConnectionFactory connectionFactory;
You can use the connection factory and destination from JNDI to populate a JMSTemplate if you like.
We have a Google Gadget that connects to Fusion Tables through the Fusion Table API with the user’s Google Account. It performs SELECT and INSERT.
We built the gadget using OAuth1 (shindig library for opensocial). It worked fine for the deprecated version of the Fusion Table API. When we migrated it to the new PAPI, the select qworks fine because authentication with OAuth2 is not necessary. For the INSERT however, it is necessary. The documentation for opensocial has not been completely updated:http://docs.opensocial.org/display/OSREF/OpenSocial+Specification+Considerations
I cannot figure out how to successfully use OAuth2 to perform an Insert. We have the API privileges to read/write at the domain level and the user has owner privileges to the Fusion table.
The error I am getting is saying “Invalid Credentials” Pretty vague and I cannot tell why.
Here is our gadget header:
<OAuth>
<Service name="google">
<Access url="https://www.google.com/accounts/OAuthGetAccessToken" method="GET" />
<Request url="https://www.google.com/accounts/OAuthGetRequestToken?scope=https://www.googleapis.com/auth/fusiontables%20https://docs.google.com/feeds/default/private"
method="GET" />
<Authorization url="https://www.google.com/accounts/OAuthAuthorizeToken?oauth_callback=http://oauth.gmodules.com/gadgets/oauthcallback" />
</Service>
</OAuth>
I am not sure exactly how to update, so I added another header:
<OAuth2>
<Service name="google">
<Authorization url="https://www.google.com/accounts/OAuthAuthorizeToken?oauth_callback=http://oauth.gmodules.com/gadgets/oauth2callback" />
</Service>
</OAuth2>
When we make the call, we do the following:
options = {};
options[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
options[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
options[gadgets.io.RequestParameters.POST_DATA] = postData;
options[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.OAUTH2;
options[gadgets.io.RequestParameters.HEADERS] = {'Authorization':'{encrypted fusiontable key}'}; //not sure if this helps but its extra
options[gadgets.io.RequestParameters.OAUTH_SERVICE_NAME] = "google";
options[gadgets.io.RequestParameters.OAUTH_USE_TOKEN] = "always";
URL = https://www.googleapis.com/fusiontables/v1/query?key={encrypted fusiontable key} &client_id={id number}”;
postData=”sql=INSERT…”;
gadgets.io.makeRequest(URL, handlerWrapper, options);
Thanks!
If you're doing a write request, you will need to supply the oauth token that encodes the user's permission to access the table. It looks like this might be in gadgets.io.RequestParameters.OAUTH_REQUEST_TOKEN. The key is used for read access from public tables. Also, you may need to set the OAUTH_SERVICE_NAME to "fusiontables".
I have recently developed a NPAPI plugin (using FireBreath) in combination with a Google Chrome Extension. I am embedding the plugin using the background.html page and access it from multiple extension pages. Thus, the plugin remains loaded in the background page (until the extension is unloaded or the browser is closed).
I am now searching for the easiest way to port this extension to Firefox. Using the Addon SDK and it's API, i can reproduce the communication between the addon code and HTML user interface.
As there is no such global background DOM as in the Chrome Extension, how would I load the NPAPI plugin just once, without inserting it in every page of the app UI?
I've seen that using a XUL overlay would allow that - is there a way using just the addon sdk?
Edit: I've created an answer to this question with a minimal solution to this problem using page-workers.
You'll want to look at the page-worker module:
https://addons.mozilla.org/en-US/developers/docs/sdk/1.8/packages/addon-kit/page-worker.html
The caveat I would give is that the NPAPI plugin might have made assumptions about visibility or other details of the environment it is running in that simply don't apply in the page-worker environment. If you run into errors, I'd be interested to hear them!
The following code provides a minimal working solution to the problem using the page-workers as as canuckistani suggested.
Note: This solution requires the addon-sdk's unsafeWindow to access the plugin member methods. If there's a better solution that does not depend on that, feel free to send a me a note/comment.
data/background.html
<html>
<head>
<script type="text/javascript" charset="utf-8">
function pluginLoaded() {
// Create an event once plugin is loaded
// This allows the contentscript to detect plugin state
var evt = document.createEvent("CustomEvent");
evt.initCustomEvent("pluginLoaded", true, false, null);
window.dispatchEvent(evt);
}
</script>
</head>
<body>
<object id="myplugin" type="application/x-myplugin" width="0" height="0">
<param name="onload" value="pluginLoaded" />
</object>
</body>
</html>
data/background.js
var module = null;
window.addEventListener("pluginLoaded", function( event ) {
// set the module through unsafeWindow
module = unsafeWindow.document.getElementById("myplugin");
module = XPCNativeWrapper.unwrap(module);
self.port.emit("pluginLoaded");
});
// Handle incoming requests to the plugin
self.port.on("pluginCall", function(msg) {
var response;
if (module) {
// Call NPAPI-plugin member method
response = module[msg.method].apply(this, msg.args);
} else {
response = {error: true, error_msg: "Module not loaded!"};
}
self.port.emit("pluginResponse", {data: response});
});
main.js
// Create background page that loads NPAPI plugin
var plugin = require("page-worker").Page({
contentURL: data.url("background.html"),
contentScriptFile: data.url("background.js"),
contentScriptWhen: "ready"
});
// Send request to plugin
plugin.port.emit("pluginCall", message);
is there any server available that i can use for getting zip codes on the basis on city/state ?
Thanks
You can use geonames postal code search. For example:
http://ws.geonames.org/postalCodeSearch?adminCode1=CA&placename=San+Francisco&maxRows=3
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<geonames>
<totalResultsCount>76</totalResultsCount>
<code>
<postalcode>94102</postalcode>
<name>San Francisco</name>
<countryCode>US</countryCode>
<lat>37.781334</lat>
<lng>-122.416728</lng>
<adminCode1>CA</adminCode1>
<adminName1>California</adminName1>
<adminCode2>075</adminCode2>
<adminName2>San Francisco</adminName2>
<adminCode3/>
<adminName3/>
</code>
<code>
<postalcode>94103</postalcode>
<name>San Francisco</name>
<countryCode>US</countryCode>
<lat>37.77254</lat>
<lng>-122.414664</lng>
<adminCode1>CA</adminCode1>
<adminName1>California</adminName1>
<adminCode2>075</adminCode2>
<adminName2>San Francisco</adminName2>
<adminCode3/>
<adminName3/>
</code>
<code>
<postalcode>94107</postalcode>
<name>San Francisco</name>
<countryCode>US</countryCode>
<lat>37.762147</lat>
<lng>-122.397099</lng>
<adminCode1>CA</adminCode1>
<adminName1>California</adminName1>
<adminCode2>075</adminCode2>
<adminName2>San Francisco</adminName2>
<adminCode3/>
<adminName3/>
</code>
</geonames>
You can use the US Postal Service HTTP/XML API
According to this page on the US Postal Service website which documents their XML based web API, specifically Section 3.0 (page 13) of this PDF document, they have a URL where you can send an XML request containing an address minus the Zip Code and they will respond with an XML document containing the complete address.
You can't do a lookup with just a city and state though, because a single city can contain multiple ZIP codes, so you need to pass the street address as well.
According to their documentation, this is what your request would look like:
GET http://SERVERNAME/ShippingAPITest.dll?API=ZipCodeLookup&XML=<ZipCodeLookupRequest%20USERID="xxxxxxx"><Address ID="0"><Address1></Address1> <Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State></Address></ZipCodeLookupRequest>
And here's what you would receive back:
<?xml version="1.0"?>
<ZipCodeLookupResponse>
<Address ID="0">
<Address2>6406 IVY LN</Address2>
<City>GREENBELT</City>
<State>MD</State>
<Zip5>20770</Zip5>
<Zip4>1441</Zip4>
</Address>
</ZipCodeLookupResponse>
USPS does require that you register with them before you can use the API, but, as far as I could tell, there is no charge for access. By the way, their API has some other features: you can do Address Standardization and Zip Code Lookup, as well as the whole suite of tracking, shipping, labels, etc.