How to set/get profile data with XMPP using Smack - java

I am working on a XMPP client on Android, using the Smack library. The roster/messaging/presence stuff is running very well. However, I didn't find a way to store additional profile information (userpicture, the dogs name, ...).
The only way I see from googling is using VCards. But it simply did not work. I tried the following:
VCard vCard = new VCard();
vCard.load(connection);
vCard.setEmailHome("meine_home#email.de");
vCard.setLastName("Scheller");
vCard.setField("blafasel", "asdf");
vCard.save(connection);
Then I was looking for a way to see that VCard information. It did neither show up in iChat nor in this System.out:
vCard.load(connection, user);
System.out.println(user + " has this vCard: " + vCard.toXML());
So anything went wrong, but theres no indication what it was. I tried this with the google talk server and my own copy of openfire with the same result. Btw, I am using this version of Smack: http://davanum.wordpress.com/2007/12/31/android-just-use-smack-api-for-xmpp/
What am I doing wrong here? What is the correct way of storing profile related information with Smack?

I have checked out the source of Smack and went through the important parts with a debugger, as well as using the Smack Debug Window. The problem is inside the VCard implementation of the Smack API. Saving a VCard does work as described, however the loading is broken.
parseIQ(XmlPullParser parser) is part of the PacketReader.java class and handles different types of packages. It only handles tags with the following namespaces:
"jabber:iq:auth",
"jabber:iq:roster",
"jabber:iq:register",
"urn:ietf:params:xml:ns:xmpp-bind"
It also looks if there is any registered IQProvider in the ProviderManager. And this is the root of my problem. There is no IQProvider for VCards registered. So whatever information is inside of the vCard tag simply gets dropped.
It is not too hard to register this IQProvider though:
ProviderManager.getInstance().addIQProvider("vCard", "vcard-temp", new VCardProvider());
This solved my little example above for saving my own vCard and downloading it again. I am still having trouble with downloading other users vcards... Gonna have a closer look into this and maybe open up another thread for that issue.

You can use the following code to get info.
VCard card = new VCard();
card.load(connection, "user#fqdn");
System.out.println("Voice: "+card.getPhoneHome("VOICE"));

Try setting a vCard for that user with another client first, and see how that changes your results. In order to diagnose further, you'll need to turn on protocol debugging in Smack (use "-Dsmack.debugEnabled=true" on a desktop machine), and post the relevant bits here.

Related

How do I respond to tickets with camel Jira Producer?

I'm following the examples here -> https://github.com/apache/camel-k-examples. Working on 05-knative-source-jira
When running this integration, I'm able to read and log new jira issues just fine, I fall down when I try to use info from the ticket, or respond to the ticket with the jira addComment producer.
I've tried just putting a static ticket number in for the IssueKey option, but I get build errors and can't even get the producer to run.
I've tried tinkering with the URI...
Ex: Changing URI to -> .to("jira://addComment?IssueKey=EQ-7") returns below on build
No signature of method: org.apache.camel.builder.ValueBuilder.to() is applicable for argument types: (String) values: [jira://addComment&IssueKey=EQ-7]
I've tried this with both ? and &, as well as adding properties to the URI with similar results.
I feel like I'm missing something pretty fundamental, so any docs pointers would be well appreciated.
Full integration here
// camel-k: language=groovy
from('knative:channel/jira')
.unmarshal()
.json()
.log('Recieved: ${body}')
.to('direct:ticket')
from("direct:ticket")
.setBody().simple("testing")
.to("jira://addComment?IssueKey=EQ-7")
I ended up sorting through enough docs to find the answer. I'll share details just for others who might find this (or if I google it again).
The key was to
a) Set the required headers for the issue key. Seting headers examples
b) Ensure that my properties are set correctly. I used a configmap to set my properties, and then referenced them as shown below in the URI. I believe this should also be possible through DSL but URI was easiest for me to just get working.
Functional Integration below.
from("direct:ticket")
.setHeader("IssueKey").simple('${body["key"]}')
.setBody().simple("We've recieved the ticket -- we'll update you soon!")
.to("jira://addComment?jiraUrl={{url}}&consumerKey={{consumer_key}}&accessToken={{access_token}}&privateKey={{private_key}}&verificationCode={{verification_code}}")

Braintree create submerchant unsuccessful but with no errors in the result object

I wanted to use the Braintree Marketplace (I've got the approval and signed to use the marketplace functionality). I used JAVA for my backend and played with the Sandbox account.
I was trying to create a submerchant accorinding to the tutorials in the overview and the specific section. E.g., the code I directly copied from the guide is (I'VE ALSO TRIED TO USE MY VALID PERSONAL INFORMATION BELOW):
MerchantAccountRequest request = new MerchantAccountRequest().
individual().
firstName("Jane").
lastName("Doe").
email("jane#14ladders.com").
phone("5553334444").
dateOfBirth("1981-11-19").
ssn("456-45-4567").
address().
streetAddress("111 Main St").
locality("Chicago").
region("IL").
postalCode("60622").
done().
done().
funding().
descriptor("Blue Ladders").
destination(MerchantAccount.FundingDestination.BANK).
email("funding#blueladders.com").
mobilePhone("071101307").
accountNumber("1123581321").
routingNumber("071101307").
done().
tosAccepted(true).
masterMerchantAccountId("14ladders_marketplace").
id("blue_ladders_store");
Result<MerchantAccount> result = gateway.merchantAccount().create(request);
I've also tried to use the testing first name
com.braintreegateway.test.MerchantAccount.Approve
so that the creation should always succeed. The code snippet is:
Result<MerchantAccount> result = gateway.merchantAccount().create(
new MerchantAccountRequest().
individual()
.firstName(com.braintreegateway.test.MerchantAccount.Approve)
.done()
);
However, in any case, when I tried to check if the result is successful (and if not, what the errors are):
logger.info("Is the result successful? " + result.isSuccess());
ValidationErrors errors = result.getErrors();
logger.info("Number of errors returned " + result.getErrors().size());
The result.isSuccess() always returns false, while there are no errors in result.getErrors(). I also cannot find any (error) information from the sandbox web account. Any insights what might go wrong? or is this because I haven't enabled the marketplace functionality?
Thanks!
I work at Braintree. If you have more questions, you can always get in touch with our support team. It looks like you already have an open ticket with us and got a response, but I'll post his here for others who have the same problem.
You're looking for result.getErrors().getAllDeepValidationErrors() not just result.getErrors().
For more information on this type of failure, see the validation errors page in the Braintree docs.

Problems connecting to YouTube Data API v3 using Java client library - sample code outdated?

This is a very basic beginner question, but I checked the main API site (https://developers.google.com/youtube/v3/) pretty thoroughly and messed around for quite a frustrating while with the sample code, used Google to find other working examples and I came up with nothing so I decided to ask here.
My aim is to write a simple Java program that connects to a YouTube account and retrieves the names and contents of the user's playlists, then possibly saves them to a text file or w/e.
I didn't find much on the site to explain exactly what steps are involved in properly connecting to a YouTube account through Java, so I tried running some sample code. If I take this for example:
https://developers.google.com/youtube/v3/code_samples/java#retrieve_my_uploads
And paste it into Eclipse, it tells me the following:
The type "FileCredentialStore" is deprecated.
At the following method:
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load( JSON_FACTORY, MyUploads.class.getResourceAsStream("/client_secrets.json"));
It tells me:
"The method load(JsonFactory, Reader) in the type GoogleClientSecrets is not applicable for the arguments (JsonFactory, InputStream)"
A bit of Googling led me somewhere that suggested the method used in the example which uses an InputStream was deprecated and later removed in 1.16 I believe.
Later the following error occurs:
channelRequest.setMine("true");
Where the String "true", should be the boolean value true. Again I'm assuming a previous version of that method was deprecated.
I've tried messing around with it, trying to piece things together from Google but it hasn't worked at all. The code seems to be outdated and not to work with the latest version of the API, and most code I can find online seems old too. I don't know enough about what I'm doing and I can't find any documentation that actually outlines what steps are required, why, and how they work.
For instance, I can't figure out what client_secrets.json is for and how it's supposed to be set up, beyond it being a part of authentication. If the API site explained it fully, I couldn't find where.
Does anyone know of a site with some working up-to-date sample code that performs some simple connection and data retrieval? Or a proper step-by-step guide that explains how to connect?
I would've thought something like the YouTube API would be straightforward and well-documented but I just can't get my head around it, unless I've missed something important but I'm out of ideas.
Google API says:
load method with InputStream is Deprecated. (scheduled to be removed in 1.16) Use load(JsonFactory, Reader) instead. Source
Thus convert InputStream to Reader and problem solved
private static GoogleClientSecrets loadClientSecrets(String clientSecretsLocation) {
try {
Reader reader = new InputStreamReader(BigQueryJavaGettingStarted.class.getResourceAsStream(clientSecretsLocation));
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(new JacksonFactory(),
reader);
} catch (Exception e) {
System.out.println("Could not load client_secrets.json");
e.printStackTrace();
}
return clientSecrets;
}

writing a simple ofx4j program

I have been using http://ofx4j.sourceforge.net/userguide.html as a guide to write a small java program to download my bank account statement from wells fargo. I keep getting an error saying Invalid Signon. I have the right url. I am using the same password and username as I use to logon to their webpage. Does anyone have any other simple samples that I could look at or use?
I had the same problem.
I was trying to log into Chase Bank but I was getting an Invalid Signon.
The problem that I had is that I was using the wrong data, oxf4j might have obsolete data
stored for the banks it has stored.
Go to gnucash to get the right updated setting for your bank:
http://wiki.gnucash.org/wiki/OFX_Direct_Connect_Bank_Settings.
Then you need to create a new BaseFinancialInstitutionData object
like this (this example is for chase credit card):
BaseFinancialInstitutionData data = new BaseFinancialInstitutionData();
data.setFinancialInstitutionId("10898");
data.setOFXURL(new URL("https://ofx.chase.com"));
data.setOrganization("B1");
FinancialInstitutionService service = new FinancialInstitutionServiceImpl();
FinancialInstitution fi = service.getFinancialInstitution(data);

Java Netscape LDAP Delete

I have been using the Java Netscape LDAP library to modify LDAP entries (http://www.mozilla.org/directory/javasdk.html). I now need a way to delete an entry. I looked through the library but could not find anything that I think would work.
Found “LDAPDelete” but that looks like it’s used from the command line.
If someone could post some sample code of how do this with an object ID it would very helpful.
ADDED:
After searching and finding the object I used the return value from getDN() method as the DN string.
Take a look at LDAPConnection.delete(java.lang.string dn) Thats what you should be using to delete an entry.
In pseudo code:
LDAPConnection myCon = new LDAPConnection("192.168.1.1",389);
myCon.delete("cn=Alan,ou=engineers,dc=fool,dc=com");
You'll have to javify that example, but that should work.
Netscape Directory API Documentation

Categories