List of usage examples for javax.activation DataSource getInputStream
public InputStream getInputStream() throws IOException;
InputStream
representing the data and throws the appropriate exception if it can not do so. From source file:at.gv.egovernment.moa.id.auth.servlet.PEPSConnectorWithLocalSigningServlet.java
private String getCitizienSignatureFromSignResponse(SignResponse dssSignResponse) throws IllegalArgumentException, TransformerConfigurationException, UtilsException, TransformerException, TransformerFactoryConfigurationError, IOException, ApiUtilsException { // fetch signed doc DataSource ds = LightweightSourceResolver.getDataSource(dssSignResponse); if (ds == null) { throw new ApiUtilsException("No datasource found in response"); }//from w w w. j av a2 s. c o m InputStream incoming = ds.getInputStream(); String citizenSignature = IOUtils.toString(incoming); incoming.close(); return citizenSignature; }
From source file:com.cubusmail.mail.MessageHandler.java
/** * @param msg/*from w w w . j ava 2s . com*/ * @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:com.cubusmail.mail.MessageHandler.java
/** * @return Returns the attachments./*from w w w . j a v a 2 s . c om*/ */ 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:nl.clockwork.mule.ebms.dao.postgresql.EbMSDAOImpl.java
@Override public void insertMessage(final EbMSMessage message, final EbMSMessageStatus status) throws DAOException { try {/*from w ww . ja v a 2 s . c om*/ transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override public void doInTransactionWithoutResult(TransactionStatus transactionStatus) { try { Date timestamp = new Date(); Long key = (Long) jdbcTemplate.query(new EbMSMessagePreparedStatement(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), new IdExtractor()); for (DataSource attachment : message.getAttachments()) { simpleJdbcTemplate.update( "insert into ebms_attachment (" + "ebms_message_id," + "name," + "content_type," + "content" + ") values (?,?,?,?)", key, 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 (Exception e) { throw new DAOException(e); } }
From source file:org.shredzone.cilla.service.impl.HeaderServiceImpl.java
@Override @CacheEvict(value = "processedImages", allEntries = true) public void updateImage(Header header, DataSource headerImg, DataSource fullImg) throws CillaServiceException { if (header.getId() == 0) { throw new IllegalArgumentException("header is not persisted"); }/* www. ja va2 s . c o m*/ try { Date now = new Date(); if (headerImg != null) { Store headerStore = header.getHeaderImage(); headerStore.setContentType(headerImg.getContentType()); headerStore.setName(headerImg.getName()); headerStore.setLastModified(now); Dimension dim = imageProcessor.analyzeDimension(headerImg); if (dim != null) { header.setWidth(dim.width); header.setHeight(dim.height); } else { header.setWidth(0); header.setHeight(0); } ResourceDataSource headerDs = storeDao.access(header.getHeaderImage()); FileCopyUtils.copy(headerImg.getInputStream(), headerDs.getOutputStream()); } if (fullImg != null) { Store fullStore = header.getFullImage(); fullStore.setContentType(fullImg.getContentType()); fullStore.setName(fullImg.getName()); fullStore.setLastModified(now); ExifAnalyzer fullExif = imageProcessor.createExifAnalyzer(fullImg); header.setLocation(fullExif != null ? fullExif.getGeolocation() : null); ResourceDataSource fullDs = storeDao.access(header.getFullImage()); FileCopyUtils.copy(fullImg.getInputStream(), fullDs.getOutputStream()); } eventService.fireEvent(new Event<Header>(EventType.HEADER_UPDATE, header)); } catch (IOException ex) { throw new CillaServiceException("Could not read medium", ex); } }
From source file:nl.clockwork.mule.ebms.dao.postgresql.EbMSDAOImpl.java
@Override public void insertMessage(final EbMSMessage message, final List<EbMSSendEvent> sendEvents) throws DAOException { try {/*from w w w. j a v a 2s . c o m*/ transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override public void doInTransactionWithoutResult(TransactionStatus transactionStatus) { try { Date timestamp = new Date(); Long key = (Long) jdbcTemplate.query(new EbMSMessagePreparedStatement(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())), new IdExtractor()); for (DataSource attachment : message.getAttachments()) { simpleJdbcTemplate.update( "insert into ebms_attachment (" + "ebms_message_id," + "name," + "content_type," + "content" + ") values (?,?,?,?)", key, 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[]{key,String.format(getDateFormat(),sendEvent.getTime())}); events.add(new Object[] { key, sendEvent.getTime() }); } simpleJdbcTemplate.batchUpdate( "insert into ebms_send_event (" + "ebms_message_id," + "time" + ") values (?,?)", events); } catch (Exception e) { throw new RuntimeException(e); } } }); } catch (Exception e) { throw new DAOException(e); } }
From source file:nl.clockwork.mule.ebms.dao.postgresql.EbMSDAOImpl.java
@Override public void insertMessage(final EbMSMessage message, final EbMSMessageStatus status, final EbMSMessageError messageError, final EbMSSendEvent sendEvent) throws DAOException { try {/* w w w .j a va2s .c om*/ transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override public void doInTransactionWithoutResult(TransactionStatus transactionStatus) { try { Date timestamp = new Date(); Long key = (Long) jdbcTemplate.query(new EbMSMessagePreparedStatement(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), new IdExtractor()); for (DataSource attachment : message.getAttachments()) { simpleJdbcTemplate.update( "insert into ebms_attachment (" + "ebms_message_id," + "name," + "content_type," + "content" + ") values (?,?,?,?)", key, attachment.getName() == null ? Constants.DEFAULT_FILENAME : attachment.getName(), attachment.getContentType().split(";")[0].trim(), IOUtils.toByteArray(attachment.getInputStream())); } key = (Long) jdbcTemplate.query(new EbMSMessagePreparedStatement(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())), new IdExtractor()); simpleJdbcTemplate.update( "insert into ebms_send_event (" + "ebms_message_id," + "time" + ") values (?,?)", key, //String.format(getDateFormat(),sendEvent.getTime()) sendEvent.getTime()); } catch (Exception e) { throw new RuntimeException(e); } } }); } catch (Exception e) { throw new DAOException(e); } }
From source file:nl.clockwork.mule.ebms.dao.postgresql.EbMSDAOImpl.java
@Override public void insertMessage(final EbMSMessage message, final EbMSMessageStatus status, final EbMSAcknowledgment acknowledgment, final EbMSSendEvent sendEvent) throws DAOException { try {//ww w .j a v a2s . c om transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override public void doInTransactionWithoutResult(TransactionStatus transactionStatus) { try { Date timestamp = new Date(); Long key = (Long) jdbcTemplate.query(new EbMSMessagePreparedStatement(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), new IdExtractor()); for (DataSource attachment : message.getAttachments()) { simpleJdbcTemplate.update( "insert into ebms_attachment (" + "ebms_message_id," + "name," + "content_type," + "content" + ") values (?,?,?,?)", key, attachment.getName() == null ? Constants.DEFAULT_FILENAME : attachment.getName(), attachment.getContentType().split(";")[0].trim(), IOUtils.toByteArray(attachment.getInputStream())); } key = (Long) jdbcTemplate.query(new EbMSMessagePreparedStatement(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())), new IdExtractor()); simpleJdbcTemplate.update( "insert into ebms_send_event (" + "ebms_message_id," + "time" + ") values (?,?)", key, //String.format(getDateFormat(),sendEvent.getTime()) sendEvent.getTime()); } catch (Exception e) { throw new RuntimeException(e); } } }); } catch (Exception e) { throw new DAOException(e); } }
From source file:de.innovationgate.wgpublisher.services.WGACoreServicesImpl.java
public void updateWGAConfiguration(RemoteSession session, DataSource wgaConfiguration) throws WGAServiceException { if (!isAdminServiceEnabled()) { throw new WGAServiceException("Administrative services are disabled"); }/* ww w . j av a 2 s.c om*/ if (!isAdminSession(session)) { throw new WGAServiceException("You need an administrative login to access this service."); } try { WGAConfiguration configBean = WGAConfiguration.read(wgaConfiguration.getInputStream()); _core.saveWgaConfiguration(configBean); } catch (Exception e) { throw new WGAServiceException("Update of wga configuration failed.", e); } }
From source file:org.shredzone.cilla.service.impl.HeaderServiceImpl.java
@Override public void create(Header header, DataSource headerImg, DataSource fullImg) throws CillaServiceException { if (headerImg == null || fullImg == null) { throw new IllegalArgumentException("no header and/or full-view provided"); }/*from ww w.ja v a 2 s. c om*/ try { Date now = new Date(); Store headerStore = header.getHeaderImage(); headerStore.setContentType(headerImg.getContentType()); headerStore.setName(headerImg.getName()); headerStore.setLastModified(now); Store fullStore = header.getFullImage(); fullStore.setContentType(fullImg.getContentType()); fullStore.setName(fullImg.getName()); fullStore.setLastModified(now); Dimension dim = imageProcessor.analyzeDimension(headerImg); if (dim != null) { header.setWidth(dim.width); header.setHeight(dim.height); } ExifAnalyzer fullExif = imageProcessor.createExifAnalyzer(fullImg); header.setLocation(fullExif != null ? fullExif.getGeolocation() : null); headerDao.persist(header); ResourceDataSource headerDs = storeDao.access(header.getHeaderImage()); FileCopyUtils.copy(headerImg.getInputStream(), headerDs.getOutputStream()); ResourceDataSource fullDs = storeDao.access(header.getFullImage()); FileCopyUtils.copy(fullImg.getInputStream(), fullDs.getOutputStream()); } catch (IOException ex) { throw new CillaServiceException("Could not read medium", ex); } eventService.fireEvent(new Event<Header>(EventType.HEADER_NEW, header)); }