Source:
static public boolean sendXMPP( @ParamDoc(name="to") String to, @ParamDoc(name="message") String message, @ParamDoc(name="attachmentUrl") String attachmentUrl) { boolean success = false; try { XMPPConnection conn = XMPPConnect.getConnection(); if (attachmentUrl == null) { ChatManager chatmanager = ChatManager.getInstanceFor(conn); Chat newChat = chatmanager.createChat(to, new MessageListener() { public void processMessage(Chat chat, Message message) { logger.debug("Received message on XMPP: {}", message.getBody()); } }); try { newChat.sendMessage(message); logger.debug("Sent message '{}' to '{}'.", message, to); success = true; } catch (XMPPException e) { logger.error("Error sending message '{}'", message, e); } catch (NotConnectedException e) { logger.error("Error sending message '{}'", message, e); } } else { FileTransferManager manager = new FileTransferManager(conn); OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(to); InputStream is = null; try { URL url = new URL(attachmentUrl); is = url.openStream(); OutgoingFileTransfer.setResponseTimeout(10000); transfer.sendStream(is, url.getFile(), is.available(), message); logger.debug("Sent message '{}' with attachment '{}' to '{}'.", new String[] { message, attachmentUrl, to }); success = true; } catch (IOException e) { logger.error("Could not open url '{}' for sending it via XMPP", attachmentUrl, e); } finally { if (is != null) { try { is.close(); } catch (IOException e) { logger.warn("Could not close stream", e); } } } } } catch (NotInitializedException e) { logger.warn("Could not send XMPP message as connection is not correctly initialized!"); } return success; }

Target:
static public boolean sendXMPP( @ParamDoc(name="to") String to, @ParamDoc(name="message") String message, @ParamDoc(name="attachmentUrl") String attachmentUrl) { boolean success = false; try { XMPPConnection conn = XMPPConnect.getConnection(); if (attachmentUrl == null) { ChatManager chatmanager = ChatManager.getInstanceFor(conn); Chat newChat = chatmanager.createChat(to, new MessageListener() { public void processMessage(Chat chat, Message message) { logger.debug("Received message on XMPP: {}", message.getBody()); } }); try { newChat.sendMessage(message); logger.debug("Sent message '{}' to '{}'.", message, to); success = true; } catch (XMPPException e) { logger.error("Error sending message '{}'", message, e); } catch (NotConnectedException e) { logger.error("Error sending message '{}'", message, e); } } else { FileTransferManager manager = new FileTransferManager(conn); OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(to); InputStream is = null; try { URL url = new URL(attachmentUrl); is = url.openStream(); OutgoingFileTransfer.setResponseTimeout(10000); transfer.sendStream(is, url.getFile(), is.available(), message); logger.debug("Sent message '{}' with attachment '{}' to '{}'.", new String[] { message, attachmentUrl, to }); success = true; } catch (IOException e) { logger.error("Could not open url '{}' for sending it via XMPP", attachmentUrl, e); } finally { IOUtils.closeQuitely(is); } } } catch (NotInitializedException e) { logger.warn("Could not send XMPP message as connection is not correctly initialized!"); } return success; }