Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8209391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:42:16+00:00 2026-06-07T09:42:16+00:00

I developed a VCard plugin for OpenFire XMPP server with the main purpose of

  • 0

I developed a VCard plugin for OpenFire XMPP server with the main purpose of creating/updating and retrieving users’ avatars via HTTP requests. Unfortunately, the plugin does not work as expected – VCard changes are propogated into the database (ofVcard table), but neither the user whose userpic was updated nor his buddies see the refreshed image. Here is how I create/update the VCards:

   ...
   XMPPServer server = XMPPServer.getInstance();
   VCardManager vcardManager = server.getVCardManager();

public void createOrUpdateVcard(String username, String vcard)
                              throws Exception {
                    SAXReader reader = new SAXReader();
                    reader.setValidation(false);
                    // convert String into InputStream
                    InputStream is = new ByteArrayInputStream(vcard.getBytes());
                    // read it with BufferedReader
                    BufferedReader br = new BufferedReader(new InputStreamReader(is));

                    try {
                              // Reading malformed XML will lead to DocumentException
                              Document document = reader.read(is);
                              Element vCardElement = document.getRootElement();
                              log.info("Username: " + username);
                              vcardManager.setVCard(username, vCardElement);
                    } catch (DocumentException e) {
                              throw new MalformedXmlException(e);
                    }
     }
     ...

When I change avatars directly from the client (we are using Jitsi), the changes are not only immediately stored in the database, but all the buddies get the refreshed image. I see that VCardManager, which I use, dispatches events internally:

VCardEventDispatcher.dispatchVCardUpdated(username, newvCard);

but they seem not to have any effect.

I cannot figure out what is the difference between the way the setVcard method is called from the handleIQ(IQ packet) in IQvCardHandler and in my own code. What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:42:17+00:00Added an answer on June 7, 2026 at 9:42 am

    Ok, I will answer my question myself – maybe someone would find this info helpful.

    It turned out to be not as simple as just storing a picture into a database. There is a message exchange, expected to happen between the involved parties. The crucial part of this exchange is that there is a presence update, sent by the client, which informs the server and consequently all his buddies about his new profile image. Please refer to XEP-0153: vCard-Based Avatars for further details. This is the piece of code, that “emulates” the presence update which will be sent to all of the user’s buddies:

        public void createOrUpdateVcard(String username, String vcard)
            throws MalformedXmlException, UserNotFoundException, SetVcardException {
        SAXReader reader = new SAXReader();
        reader.setValidation(false);
        InputStream is = new ByteArrayInputStream(vcard.getBytes());
    
        try {
            // Reading malformed XML will lead to DocumentException
            Document document = reader.read(is);
            Element vCardElement = document.getRootElement();
            //Checking that the user exists
            User user = userManager.getUser(username);
            //This might be redundant
            String userUsername = user.getUsername();
            log.debug("Setting VCard for " + userUsername);
            //Storing vCard into the database
            VCardManager.getInstance().setVCard(userUsername, vCardElement);        
    
    
            Presence presence = new Presence();
            JID userJID = server.createJID(username, null);
            presence.setFrom(userJID);
            presence.setStatus("");
            presence.setPriority(30);
    
            Element xElement = presence.addChildElement("x", "vcard-temp:x:update");
            Element photoElement = xElement.addElement("photo");
    
            SecureRandom random = new SecureRandom();
                        //We do not care about the actual hash - just push updates every time
            String fakeHash = new BigInteger(130, random).toString(32);
            photoElement.setText(fakeHash);
    
            Element cElement = presence.addChildElement("c", "http://jabber.org/protocol/caps");
            cElement.addAttribute( "ext", "voice-v1 video-v1 camera-v1" )
            .addAttribute("hash", "sha-1");
    
            System.out.println("SENDING PRESENCE UPDATE:\n" + presence.toXML());
            broadcastUpdate(presence);
    
        } catch (DocumentException e) {
            throw new MalformedXmlException(e);
        }catch (UserNotFoundException e){
            throw new UserNotFoundException();
        } catch (Exception e){
            //Unfortunately setVCard method above just throws Exception.
            //This catch block is for wrapping it up
            throw new SetVcardException();
        }
    }
    

    This is a slightly adjusted method from the PresenceUpdateHandler class:

    private void broadcastUpdate(Presence update) {
        if (update.getFrom() == null) {
            return;
        }
        if (localServer.isLocal(update.getFrom())) {
            // Do nothing if roster service is disabled
            if (!RosterManager.isRosterServiceEnabled()) {
                return;
            }
            // Local updates can simply run through the roster of the local user
            String name = update.getFrom().getNode();
            try {
                if (name != null && !"".equals(name)) {
                    Roster roster = rosterManager.getRoster(name);
                    roster.broadcastPresence(update);
                }
            }
            catch (UserNotFoundException e) {
                log.warn("Presence being sent from unknown user " + name, e);
            }
            catch (PacketException e) {
                log.error(LocaleUtils.getLocalizedString("admin.error"), e);
            }
        }
        else {
            // Foreign updates will do a reverse lookup of entries in rosters
            // on the server
            log.warn("Presence requested from server "
                    + localServer.getServerInfo().getXMPPDomain()
                    + " by unknown user: " + update.getFrom());
        }
    }
    

    For debugging OpenFire issues I would strongly recommend running it locally in debug mode – see instructions here: 2. Be aware, that newer eclipse releases do not have Create project from existing source, but you have to click on New -> Java Project, untick the Use default location check box and Browse to the project location.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I developed a web site using rails 2.3.8, and a IM server using openfire(java).
I developed a spinner using the suggestions on: http://blog.oio.de/2010/11/08/how-to-create-a-loading-animation-spinner-using-jquery/ The spinner works when I
We developed an Eclipse plugin and tested & delivered on Win 32bit os. One
I developed one application with Pinax http://pinaxproject.com/ . I created project by pinax-admin setup_project
I developed a simple plugin to sent request to a JSON text file, retrieve
I developed an application locally using the Visual Studio 2008 built-in web server and
I developed an application (100% local, no access to servers) using SQL Server Compact
Developed a Windows application that remotely accesses an SQL Server online. However, the client's
I developed a web application, that permits my users to manage some aspects of
I developed a library and I need that the users of that library can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.