예제 #1
0
  protected Message createBlobMessage(
      URL fileURL,
      String ID,
      String checksum,
      String domain,
      String projectName,
      String entryType,
      String dateTime,
      String experimentId,
      ActiveMQSession session) {
    BlobMessage message = null;
    FileInputStream in = null;

    String msgParam;
    try {
      msgParam =
          createXMLParameter(ID, checksum, domain, projectName, entryType, dateTime, experimentId);

      // in = new FileInputStream(fileLocation);
      //	message.setName(name);
      // message = session.createBlobMessage(new File(fileLocation));
      message = session.createBlobMessage(fileURL);
      // message.setName(name);
      message.setObjectProperty("msgParamXML", msgParam);

      // message.setObjectProperty("checksum", checksum);

      // message = session.createBlobMessage(in);
    } catch (JMSException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();

    } catch (XMLStreamException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    } catch (FactoryConfigurationError e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
    return message;
  }
예제 #2
0
  /** Produce the mail to the JMS Queue */
  protected void produceMail(Session session, Map<String, Object> props, int msgPrio, Mail mail)
      throws JMSException, MessagingException, IOException {
    MessageProducer producer = null;
    BlobMessage blobMessage = null;
    boolean reuse = false;

    try {

      // check if we should use a blob message here
      if (useBlob) {
        ActiveMQSession amqSession = getAMQSession(session);

        /*
         * Remove this optimization as it could lead to problems when the same blob content
         * is shared across different messages.
         *
         * I still think it would be a good idea to somehow do this but at the moment it's just
         * safer to disable it.
         *
         * TODO: Re-Enable it again once it works!
         *
         * See JAMES-1240
        if (wrapper instanceof MimeMessageCopyOnWriteProxy) {
            wrapper = ((MimeMessageCopyOnWriteProxy) mm).getWrappedMessage();
        }

        if (wrapper instanceof MimeMessageWrapper) {
            URL blobUrl = (URL) mail.getAttribute(JAMES_BLOB_URL);
            String fromQueue = (String) mail.getAttribute(JAMES_QUEUE_NAME);
            MimeMessageWrapper mwrapper = (MimeMessageWrapper) wrapper;

            if (blobUrl != null && fromQueue != null && mwrapper.isModified() == false) {
                // the message content was not changed so don't need to
                // upload it again and can just point to the url
                blobMessage = amqSession.createBlobMessage(blobUrl);
                reuse = true;
            }

        }*/
        if (blobMessage == null) {
          // just use the MimeMessageInputStream which can read every
          // MimeMessage implementation
          blobMessage = amqSession.createBlobMessage(new MimeMessageInputStream(mail.getMessage()));
        }

        // store the queue name in the props
        props.put(JAMES_QUEUE_NAME, queueName);

        Queue queue = session.createQueue(queueName);

        producer = session.createProducer(queue);
        for (Map.Entry<String, Object> entry : props.entrySet()) {
          blobMessage.setObjectProperty(entry.getKey(), entry.getValue());
        }
        producer.send(
            blobMessage, Message.DEFAULT_DELIVERY_MODE, msgPrio, Message.DEFAULT_TIME_TO_LIVE);

      } else {
        super.produceMail(session, props, msgPrio, mail);
      }
    } catch (JMSException e) {
      if (!reuse && blobMessage != null && blobMessage instanceof ActiveMQBlobMessage) {
        ((ActiveMQBlobMessage) blobMessage).deleteFile();
      }
      throw e;
    } finally {

      try {
        if (producer != null) producer.close();
      } catch (JMSException e) {
        // ignore here
      }
    }
  }