List of usage examples for javax.activation DataSource getName
public String getName();
From source file:com.cubusmail.mail.MessageHandler.java
/** * @return Returns the attachments.//w w w.ja v a2 s . com */ public GWTAttachment[] getGWTComposeAttachments() { if (this.composeAttachments != null) { int index = 0; GWTAttachment[] gwtAttachments = new GWTAttachment[this.composeAttachments.size()]; for (DataSource attachment : this.composeAttachments) { gwtAttachments[index] = new GWTAttachment(); gwtAttachments[index].setFileName(attachment.getName()); int size = -1; try { size = attachment.getInputStream().available(); } catch (IOException e) { // do nothing } gwtAttachments[index].setSize(size); gwtAttachments[index].setSizeText(MessageUtils.formatPartSize(size, MessageUtils.createSizeFormat(SessionManager.get().getLocale()))); gwtAttachments[index].setMessageId(0); gwtAttachments[index].setIndex(index); String extension = StringUtils.substringAfterLast(attachment.getName(), "."); if (extension != null) { extension = extension.toLowerCase(); if (ArrayUtils.contains(PREVIEW_EXTENSIONS, extension)) { gwtAttachments[index].setPreview(true); } } index++; } return gwtAttachments; } return null; }
From source file:com.cubusmail.mail.MessageHandler.java
/** * @param msg/*from w w w .j a v a 2s .c o m*/ * @throws MessagingException * @throws IOException */ public void createForwardMessage(Message msg) throws MessagingException, IOException { init(); setSubject("Fwd: " + msg.getSubject()); setHtmlMessage(MessageUtils.isHtmlMessage(msg)); List<MimePart> attachments = MessageUtils.attachmentsFromPart(msg); if (attachments != null) { for (MimePart part : attachments) { DataSource source = part.getDataHandler().getDataSource(); ByteArrayDataSource newSource = new ByteArrayDataSource(source.getInputStream(), source.getContentType()); if (StringUtils.isEmpty(source.getName())) { newSource.setName(this.applicationContext.getMessage("message.unknown.attachment", null, SessionManager.get().getLocale())); } else { newSource.setName(source.getName()); } addComposeAttachment(newSource); } } Preferences prefs = SessionManager.get().getPreferences(); MessageTextUtil.messageTextFromPart(msg, this, true, MessageTextMode.REPLY, prefs, 0); }
From source file:nl.clockwork.mule.ebms.dao.AbstractEbMSDAO.java
@Override public void insertMessage(final EbMSMessage message, final EbMSMessageStatus status) throws DAOException { try {/* w w w.j a v a2s. c om*/ transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override public void doInTransactionWithoutResult(TransactionStatus transactionStatus) { try { Date timestamp = new Date(); KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update(getEbMSMessagePreparedStatement(timestamp, message.getMessageHeader().getCPAId(), message.getMessageHeader().getConversationId(), message.getMessageOrder() == null ? null : message.getMessageOrder().getSequenceNumber().getValue().longValue(), message.getMessageHeader().getMessageData().getMessageId(), message.getMessageHeader().getMessageData().getRefToMessageId(), message.getMessageHeader().getFrom().getRole(), message.getMessageHeader().getTo().getRole(), message.getMessageHeader().getService().getType(), message.getMessageHeader().getService().getValue(), message.getMessageHeader().getAction(), message.getOriginal(), XMLMessageBuilder.getInstance(SignatureType.class) .handle(new ObjectFactory().createSignature(message.getSignature())), XMLMessageBuilder.getInstance(MessageHeader.class) .handle(message.getMessageHeader()), XMLMessageBuilder.getInstance(SyncReply.class).handle(message.getSyncReply()), XMLMessageBuilder.getInstance(MessageOrder.class).handle(message.getMessageOrder()), XMLMessageBuilder.getInstance(AckRequested.class).handle(message.getAckRequested()), XMLMessageBuilder.getInstance(Manifest.class).handle(message.getManifest()), status), keyHolder); for (DataSource attachment : message.getAttachments()) { simpleJdbcTemplate.update("insert into ebms_attachment (" + "ebms_message_id," + "name," + "content_type," + "content" + ") values (?,?,?,?)", keyHolder.getKey().longValue(), attachment.getName() == null ? Constants.DEFAULT_FILENAME : attachment.getName(), attachment.getContentType().split(";")[0].trim(), IOUtils.toByteArray(attachment.getInputStream())); } } catch (Exception e) { throw new RuntimeException(e); } } }); } catch (RuntimeException e) { throw new DAOException(e); } }
From source file:nl.clockwork.mule.ebms.dao.AbstractEbMSDAO.java
@Override public void insertMessage(final EbMSMessage message, final List<EbMSSendEvent> sendEvents) throws DAOException { try {//www.ja v a 2 s. c o m transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override public void doInTransactionWithoutResult(TransactionStatus transactionStatus) { try { Date timestamp = new Date(); KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update(getEbMSMessagePreparedStatement(timestamp, message.getMessageHeader().getCPAId(), message.getMessageHeader().getConversationId(), message.getMessageOrder() == null ? null : message.getMessageOrder().getSequenceNumber().getValue().longValue(), message.getMessageHeader().getMessageData().getMessageId(), message.getMessageHeader().getMessageData().getRefToMessageId(), message.getMessageHeader().getFrom().getRole(), message.getMessageHeader().getTo().getRole(), message.getMessageHeader().getService().getType(), message.getMessageHeader().getService().getValue(), message.getMessageHeader().getAction(), XMLMessageBuilder.getInstance(MessageHeader.class) .handle(message.getMessageHeader()), XMLMessageBuilder.getInstance(SyncReply.class).handle(message.getSyncReply()), XMLMessageBuilder.getInstance(MessageOrder.class).handle(message.getMessageOrder()), XMLMessageBuilder.getInstance(AckRequested.class).handle(message.getAckRequested()), XMLMessageBuilder.getInstance(Manifest.class).handle(message.getManifest())), keyHolder); for (DataSource attachment : message.getAttachments()) { simpleJdbcTemplate.update("insert into ebms_attachment (" + "ebms_message_id," + "name," + "content_type," + "content" + ") values (?,?,?,?)", keyHolder.getKey().longValue(), attachment.getName() == null ? Constants.DEFAULT_FILENAME : attachment.getName(), attachment.getContentType().split(";")[0].trim(), IOUtils.toByteArray(attachment.getInputStream())); } List<Object[]> events = new ArrayList<Object[]>(); for (EbMSSendEvent sendEvent : sendEvents) { //events.add(new Object[]{keyHolder.getKey().longValue(),String.format(getDateFormat(),sendEvent.getTime())}); events.add(new Object[] { keyHolder.getKey().longValue(), sendEvent.getTime() }); } simpleJdbcTemplate.batchUpdate( "insert into ebms_send_event (" + "ebms_message_id," + "time" + ") values (?,?)", events); } catch (Exception e) { throw new RuntimeException(e); } } }); } catch (RuntimeException e) { throw new DAOException(e); } }
From source file:nl.clockwork.mule.ebms.dao.AbstractEbMSDAO.java
@Override public void insertMessage(final EbMSMessage message, final EbMSMessageStatus status, final EbMSMessageError messageError, final EbMSSendEvent sendEvent) throws DAOException { try {//from www. ja v a 2s .co m transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override public void doInTransactionWithoutResult(TransactionStatus transactionStatus) { try { Date timestamp = new Date(); KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update(getEbMSMessagePreparedStatement(timestamp, message.getMessageHeader().getCPAId(), message.getMessageHeader().getConversationId(), message.getMessageOrder() == null ? null : message.getMessageOrder().getSequenceNumber().getValue().longValue(), message.getMessageHeader().getMessageData().getMessageId(), message.getMessageHeader().getMessageData().getRefToMessageId(), message.getMessageHeader().getFrom().getRole(), message.getMessageHeader().getTo().getRole(), message.getMessageHeader().getService().getType(), message.getMessageHeader().getService().getValue(), message.getMessageHeader().getAction(), message.getOriginal(), XMLMessageBuilder.getInstance(SignatureType.class) .handle(new ObjectFactory().createSignature(message.getSignature())), XMLMessageBuilder.getInstance(MessageHeader.class) .handle(message.getMessageHeader()), XMLMessageBuilder.getInstance(SyncReply.class).handle(message.getSyncReply()), XMLMessageBuilder.getInstance(MessageOrder.class).handle(message.getMessageOrder()), XMLMessageBuilder.getInstance(AckRequested.class).handle(message.getAckRequested()), XMLMessageBuilder.getInstance(Manifest.class).handle(message.getManifest()), status), keyHolder); for (DataSource attachment : message.getAttachments()) { simpleJdbcTemplate.update("insert into ebms_attachment (" + "ebms_message_id," + "name," + "content_type," + "content" + ") values (?,?,?,?)", keyHolder.getKey().longValue(), attachment.getName() == null ? Constants.DEFAULT_FILENAME : attachment.getName(), attachment.getContentType().split(";")[0].trim(), IOUtils.toByteArray(attachment.getInputStream())); } jdbcTemplate.update(getEbMSMessagePreparedStatement(timestamp, messageError.getMessageHeader().getCPAId(), messageError.getMessageHeader().getConversationId(), messageError.getMessageHeader().getMessageData().getMessageId(), messageError.getMessageHeader().getMessageData().getRefToMessageId(), messageError.getMessageHeader().getFrom().getRole(), messageError.getMessageHeader().getTo().getRole(), messageError.getMessageHeader().getService().getType(), messageError.getMessageHeader().getService().getValue(), messageError.getMessageHeader().getAction(), XMLMessageBuilder.getInstance(MessageHeader.class) .handle(messageError.getMessageHeader()), XMLMessageBuilder.getInstance(ErrorList.class).handle(messageError.getErrorList())), keyHolder); simpleJdbcTemplate.update( "insert into ebms_send_event (" + "ebms_message_id," + "time" + ") values (?,?)", keyHolder.getKey().longValue(), //String.format(getDateFormat(),sendEvent.getTime()) sendEvent.getTime()); } catch (Exception e) { throw new RuntimeException(e); } } }); } catch (RuntimeException e) { throw new DAOException(e); } }
From source file:nl.clockwork.mule.ebms.dao.AbstractEbMSDAO.java
@Override public void insertMessage(final EbMSMessage message, final EbMSMessageStatus status, final EbMSAcknowledgment acknowledgment, final EbMSSendEvent sendEvent) throws DAOException { try {//from w ww. j a v a2 s. c o m transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override public void doInTransactionWithoutResult(TransactionStatus transactionStatus) { try { Date timestamp = new Date(); KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update(getEbMSMessagePreparedStatement(timestamp, message.getMessageHeader().getCPAId(), message.getMessageHeader().getConversationId(), message.getMessageOrder() == null ? null : message.getMessageOrder().getSequenceNumber().getValue().longValue(), message.getMessageHeader().getMessageData().getMessageId(), message.getMessageHeader().getMessageData().getRefToMessageId(), message.getMessageHeader().getFrom().getRole(), message.getMessageHeader().getTo().getRole(), message.getMessageHeader().getService().getType(), message.getMessageHeader().getService().getValue(), message.getMessageHeader().getAction(), message.getOriginal(), XMLMessageBuilder.getInstance(SignatureType.class) .handle(new ObjectFactory().createSignature(message.getSignature())), XMLMessageBuilder.getInstance(MessageHeader.class) .handle(message.getMessageHeader()), XMLMessageBuilder.getInstance(SyncReply.class).handle(message.getSyncReply()), XMLMessageBuilder.getInstance(MessageOrder.class).handle(message.getMessageOrder()), XMLMessageBuilder.getInstance(AckRequested.class).handle(message.getAckRequested()), XMLMessageBuilder.getInstance(Manifest.class).handle(message.getManifest()), status), keyHolder); for (DataSource attachment : message.getAttachments()) { simpleJdbcTemplate.update("insert into ebms_attachment (" + "ebms_message_id," + "name," + "content_type," + "content" + ") values (?,?,?,?)", keyHolder.getKey().longValue(), attachment.getName() == null ? Constants.DEFAULT_FILENAME : attachment.getName(), attachment.getContentType().split(";")[0].trim(), IOUtils.toByteArray(attachment.getInputStream())); } jdbcTemplate.update(getEbMSMessagePreparedStatement(timestamp, acknowledgment.getMessageHeader().getCPAId(), acknowledgment.getMessageHeader().getConversationId(), acknowledgment.getMessageHeader().getMessageData().getMessageId(), acknowledgment.getMessageHeader().getMessageData().getRefToMessageId(), acknowledgment.getMessageHeader().getFrom().getRole(), acknowledgment.getMessageHeader().getTo().getRole(), acknowledgment.getMessageHeader().getService().getType(), acknowledgment.getMessageHeader().getService().getValue(), acknowledgment.getMessageHeader().getAction(), XMLMessageBuilder.getInstance(MessageHeader.class) .handle(acknowledgment.getMessageHeader()), XMLMessageBuilder.getInstance(Acknowledgment.class) .handle(acknowledgment.getAcknowledgment())), keyHolder); simpleJdbcTemplate.update( "insert into ebms_send_event (" + "ebms_message_id," + "time" + ") values (?,?)", keyHolder.getKey().longValue(), //String.format(getDateFormat(),sendTime) sendEvent.getTime()); } catch (Exception e) { throw new RuntimeException(e); } } }); } catch (RuntimeException e) { throw new DAOException(e); } }
From source file:org.ambraproject.article.service.FetchArticleServiceImpl.java
private Document applyAnnotationsOnContentAsDocument(DataSource content, AnnotationView[] annotations) throws ApplicationException { Document doc = null;//w w w. ja v a 2 s. c o m if (log.isDebugEnabled()) log.debug("Parsing article xml ..."); try { doc = articleTransformService.createDocBuilder().parse(content.getInputStream()); } catch (Exception e) { throw new ApplicationException(e.getMessage(), e); } try { if (annotations.length == 0) return doc; if (log.isDebugEnabled()) log.debug("Applying " + annotations.length + " annotations to article ..."); return Annotator.annotateAsDocument(doc, annotations); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Could not apply annotations to article: " + content.getName(), e); } throw new ApplicationException("Applying annotations failed for resource:" + content.getName(), e); } }
From source file:edu.hawaii.soest.hioos.storx.StorXDispatcher.java
/** * A method that executes the reading of data from the email account to the * RBNB server after all configuration of settings, connections to hosts, * and thread initiatizing occurs. This method contains the detailed code * for reading the data and interpreting the data files. *//*w w w .j av a2 s .com*/ protected boolean execute() { logger.debug("StorXDispatcher.execute() called."); boolean failed = true; // indicates overall success of execute() boolean messageProcessed = false; // indicates per message success // declare the account properties that will be pulled from the // email.account.properties.xml file String accountName = ""; String server = ""; String username = ""; String password = ""; String protocol = ""; String dataMailbox = ""; String processedMailbox = ""; String prefetch = ""; // fetch data from each sensor in the account list List accountList = this.xmlConfiguration.getList("account.accountName"); for (Iterator aIterator = accountList.iterator(); aIterator.hasNext();) { int aIndex = accountList.indexOf(aIterator.next()); // populate the email connection variables from the xml properties // file accountName = (String) this.xmlConfiguration.getProperty("account(" + aIndex + ").accountName"); server = (String) this.xmlConfiguration.getProperty("account(" + aIndex + ").server"); username = (String) this.xmlConfiguration.getProperty("account(" + aIndex + ").username"); password = (String) this.xmlConfiguration.getProperty("account(" + aIndex + ").password"); protocol = (String) this.xmlConfiguration.getProperty("account(" + aIndex + ").protocol"); dataMailbox = (String) this.xmlConfiguration.getProperty("account(" + aIndex + ").dataMailbox"); processedMailbox = (String) this.xmlConfiguration .getProperty("account(" + aIndex + ").processedMailbox"); prefetch = (String) this.xmlConfiguration.getProperty("account(" + aIndex + ").prefetch"); logger.debug("\n\nACCOUNT DETAILS: \n" + "accountName : " + accountName + "\n" + "server : " + server + "\n" + "username : " + username + "\n" + "password : " + password + "\n" + "protocol : " + protocol + "\n" + "dataMailbox : " + dataMailbox + "\n" + "processedMailbox: " + processedMailbox + "\n" + "prefetch : " + prefetch + "\n"); // get a connection to the mail server Properties props = System.getProperties(); props.setProperty("mail.store.protocol", protocol); props.setProperty("mail.imaps.partialfetch", prefetch); try { // create the imaps mail session this.mailSession = Session.getDefaultInstance(props, null); this.mailStore = mailSession.getStore(protocol); } catch (NoSuchProviderException nspe) { try { // pause for 10 seconds logger.debug( "There was a problem connecting to the IMAP server. " + "Waiting 10 seconds to retry."); Thread.sleep(10000L); this.mailStore = mailSession.getStore(protocol); } catch (NoSuchProviderException nspe2) { logger.debug("There was an error connecting to the mail server. The " + "message was: " + nspe2.getMessage()); nspe2.printStackTrace(); failed = true; return !failed; } catch (InterruptedException ie) { logger.debug("The thread was interrupted: " + ie.getMessage()); failed = true; return !failed; } } try { this.mailStore.connect(server, username, password); // get folder references for the inbox and processed data box Folder inbox = mailStore.getFolder(dataMailbox); inbox.open(Folder.READ_WRITE); Folder processed = this.mailStore.getFolder(processedMailbox); processed.open(Folder.READ_WRITE); Message[] msgs; while (!inbox.isOpen()) { inbox.open(Folder.READ_WRITE); } msgs = inbox.getMessages(); List<Message> messages = new ArrayList<Message>(); Collections.addAll(messages, msgs); // sort the messages found in the inbox by date sent Collections.sort(messages, new Comparator<Message>() { public int compare(Message message1, Message message2) { int value = 0; try { value = message1.getSentDate().compareTo(message2.getSentDate()); } catch (MessagingException e) { e.printStackTrace(); } return value; } }); logger.debug("Number of messages: " + messages.size()); for (Message message : messages) { // Copy the message to ensure we have the full attachment MimeMessage mimeMessage = (MimeMessage) message; MimeMessage copiedMessage = new MimeMessage(mimeMessage); // determine the sensor serial number for this message String messageSubject = copiedMessage.getSubject(); Date sentDate = copiedMessage.getSentDate(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM"); // The subfolder of the processed mail folder (e.g. 2016-12); String destinationFolder = formatter.format(sentDate); logger.debug("Message date: " + sentDate + "\tNumber: " + copiedMessage.getMessageNumber()); String[] subjectParts = messageSubject.split("\\s"); String loggerSerialNumber = "SerialNumber"; if (subjectParts.length > 1) { loggerSerialNumber = subjectParts[2]; } // Do we have a data attachment? If not, there's no data to // process if (copiedMessage.isMimeType("multipart/mixed")) { logger.debug("Message size: " + copiedMessage.getSize()); MimeMessageParser parser = new MimeMessageParser(copiedMessage); try { parser.parse(); } catch (Exception e) { logger.error("Failed to parse the MIME message: " + e.getMessage()); continue; } ByteBuffer messageAttachment = ByteBuffer.allocate(256); // init only logger.debug("Has attachments: " + parser.hasAttachments()); for (DataSource dataSource : parser.getAttachmentList()) { if (StringUtils.isNotBlank(dataSource.getName())) { logger.debug( "Attachment: " + dataSource.getName() + ", " + dataSource.getContentType()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); IOUtils.copy(dataSource.getInputStream(), outputStream); messageAttachment = ByteBuffer.wrap(outputStream.toByteArray()); } } // We now have the attachment and serial number. Parse the attachment // for the data components, look up the storXSource based on the serial // number, and push the data to the DataTurbine // parse the binary attachment StorXParser storXParser = new StorXParser(messageAttachment); // iterate through the parsed framesMap and handle each // frame // based on its instrument type BasicHierarchicalMap framesMap = (BasicHierarchicalMap) storXParser.getFramesMap(); Collection frameCollection = framesMap.getAll("/frames/frame"); Iterator framesIterator = frameCollection.iterator(); while (framesIterator.hasNext()) { BasicHierarchicalMap frameMap = (BasicHierarchicalMap) framesIterator.next(); // logger.debug(frameMap.toXMLString(1000)); String frameType = (String) frameMap.get("type"); String sensorSerialNumber = (String) frameMap.get("serialNumber"); // handle each instrument type if (frameType.equals("HDR")) { logger.debug("This is a header frame. Skipping it."); } else if (frameType.equals("STX")) { try { // handle StorXSource StorXSource source = (StorXSource) sourceMap.get(sensorSerialNumber); // process the data using the StorXSource // driver messageProcessed = source.process(this.xmlConfiguration, frameMap); } catch (ClassCastException cce) { } } else if (frameType.equals("SBE")) { try { // handle CTDSource CTDSource source = (CTDSource) sourceMap.get(sensorSerialNumber); // process the data using the CTDSource // driver messageProcessed = source.process(this.xmlConfiguration, frameMap); } catch (ClassCastException cce) { } } else if (frameType.equals("NLB")) { try { // handle ISUSSource ISUSSource source = (ISUSSource) sourceMap.get(sensorSerialNumber); // process the data using the ISUSSource // driver messageProcessed = source.process(this.xmlConfiguration, frameMap); } catch (ClassCastException cce) { } } else if (frameType.equals("NDB")) { try { // handle ISUSSource ISUSSource source = (ISUSSource) sourceMap.get(sensorSerialNumber); // process the data using the ISUSSource // driver messageProcessed = source.process(this.xmlConfiguration, frameMap); } catch (ClassCastException cce) { } } else { logger.debug("The frame type " + frameType + " is not recognized. Skipping it."); } } // end while() if (this.sourceMap.get(loggerSerialNumber) != null) { // Note: Use message (not copiedMessage) when setting flags if (!messageProcessed) { logger.info("Failed to process message: " + "Message Number: " + message.getMessageNumber() + " " + "Logger Serial:" + loggerSerialNumber); // leave it in the inbox, flagged as seen (read) message.setFlag(Flags.Flag.SEEN, true); logger.debug("Saw message " + message.getMessageNumber()); } else { // message processed successfully. Create a by-month sub folder if it doesn't exist // Copy the message and flag it deleted Folder destination = processed.getFolder(destinationFolder); boolean created = destination.create(Folder.HOLDS_MESSAGES); inbox.copyMessages(new Message[] { message }, destination); message.setFlag(Flags.Flag.DELETED, true); logger.debug("Deleted message " + message.getMessageNumber()); } // end if() } else { logger.debug("There is no configuration information for " + "the logger serial number " + loggerSerialNumber + ". Please add the configuration to the " + "email.account.properties.xml configuration file."); } // end if() } else { logger.debug("This is not a data email since there is no " + "attachment. Skipping it. Subject: " + messageSubject); } // end if() } // end for() // expunge messages and close the mail server store once we're // done inbox.expunge(); this.mailStore.close(); } catch (MessagingException me) { try { this.mailStore.close(); } catch (MessagingException me2) { failed = true; return !failed; } logger.info( "There was an error reading the mail message. The " + "message was: " + me.getMessage()); me.printStackTrace(); failed = true; return !failed; } catch (IOException me) { try { this.mailStore.close(); } catch (MessagingException me3) { failed = true; return !failed; } logger.info("There was an I/O error reading the message part. The " + "message was: " + me.getMessage()); me.printStackTrace(); failed = true; return !failed; } catch (IllegalStateException ese) { try { this.mailStore.close(); } catch (MessagingException me4) { failed = true; return !failed; } logger.info("There was an error reading messages from the folder. The " + "message was: " + ese.getMessage()); failed = true; return !failed; } finally { try { this.mailStore.close(); } catch (MessagingException me2) { logger.debug("Couldn't close the mail store: " + me2.getMessage()); } } } return !failed; }
From source file:com.collabnet.tracker.core.TrackerWebServicesClient.java
/** * Attach a file to a PT artifact/*from ww w. j ava2s .c o m*/ * * @param taskId * @param comment * @param attachment * @throws ServiceException * @throws WSException * @throws RemoteException */ public long postAttachment(String taskId, String comment, DataSource attachment) throws ServiceException, WSException, RemoteException { EngineConfiguration config = mClient.getEngineConfiguration(); AttachmentService service = new AttachmentServiceLocator(config); URL portAddress = mClient.constructServiceURL("/tracker/Attachment"); AttachmentManager theService = service.getAttachmentService(portAddress); DataHandler attachmentHandler = new DataHandler(attachment); theService.addAttachment(taskId, attachment.getName(), comment, attachment.getContentType(), attachmentHandler); long[] ids = theService.getAttachmentIds(taskId); Arrays.sort(ids); return ids[ids.length - 1]; }
From source file:edu.stanford.muse.email.EmailFetcherStats.java
private List<String> getAttachmentNames(MimeMessage m, Part p) throws MessagingException, IOException { List<String> result = new ArrayList<String>(); try {//from w w w .j a v a2 s. c o m if (p.isMimeType("multipart/*") || p.isMimeType("message/rfc822")) { if (p.isMimeType("multipart/alternative")) return result; // ignore alternative's because real attachments don't have alternatives DataHandler dh = p.getDataHandler(); DataSource ds = dh.getDataSource(); if (ds instanceof MultipartDataSource) { MultipartDataSource mpds = (MultipartDataSource) ds; for (int i = 0; i < mpds.getCount(); i++) result.addAll(getAttachmentNames(m, mpds.getBodyPart(i))); } else { String name = ds.getName(); if (!Util.nullOrEmpty(name)) result.add(name); } } else { String filename = p.getFileName(); if (filename != null) result.add(filename); } } catch (Exception e) { // sometimes we see javax.mail.MessagingException: Unable to load BODYSTRUCTURE // in this case, just ignore, not much we can do i guess. Util.print_exception(e, log); } return result; }