/**
   * Test method for {@link org.apache.camel.component.sjms.jms.ObjectPool#borrowObject()}.
   *
   * @throws Exception
   */
  @Test
  public void testBorrowObject() throws Exception {
    ConnectionFactoryResource connections = new ConnectionFactoryResource(1, connectionFactory);
    connections.fillPool();
    SessionPool sessions = new SessionPool(1, connections);
    sessions.fillPool();
    assertNotNull(sessions);
    ActiveMQSession session = (ActiveMQSession) sessions.borrowObject();
    assertNotNull(session);
    assertTrue(!session.isClosed());

    ActiveMQSession session2 = (ActiveMQSession) sessions.borrowObject();
    assertNull(session2);
    sessions.drainPool();
    connections.drainPool();
  }
Example #2
0
  /**
   * @param fileURL the url of the file uploaded to fedora
   * @param ID
   * @param entryType
   * @param dateTime
   * @param session
   * @return
   * @throws JMSException
   * @throws XMLStreamException
   */
  protected Message createNewExperimentMessage(String experimentXMLString)
      throws JMSException, XMLStreamException {

    MapMessage message = session.createMapMessage();
    message.setString("msgParamXML", experimentXMLString);

    return message;
  }
Example #3
0
  public ADQueueWriterImpl() {
    try {
      properties = new Properties();
      properties.load(getClass().getClassLoader().getResourceAsStream("bril.properties"));

      propertiesXML = new Properties();
      propertiesXML.load(getClass().getClassLoader().getResourceAsStream("messagexml.properties"));

      // messaging.url.server for bril-dev server , messaging.url for localhost
      String brokerURL =
          properties.getProperty("messaging.url") + ":" + properties.getProperty("messaging.port");
      System.out.println(brokerURL);
      // String blobUploadURL="?jms.blobTransferPolicy.uploadUrl=http//:localhost:8161/fileserver";
      factory = new ActiveMQConnectionFactory(brokerURL);

      // using the connection factory create JMS connection
      connection = (ActiveMQConnection) factory.createConnection();

      // connection.setBlobTransferPolicy(blobTransferPolicy);

      // start the connection to enable messages to start flowing
      connection.start();

      // JMS session: auto acknowledge
      session = (ActiveMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

      // producer = session.createProducer(null);
      // must be a message queue

      // create JMS queue using the session
      autoDepositQueue = session.createQueue(properties.getProperty("queue.submit.name"));

      // create JMS consumer using the session and destination
      messageProducer = session.createProducer(autoDepositQueue);
      // OutputStream out = connection.createOutputStream(autoDepositQueue);

    } catch (IOException e) {
      System.out.println("IOException : properties file not found  " + e);
    } catch (JMSException e) {
      System.out.println("JMSException :   " + e);
    }
  }
Example #4
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;
  }
  /** 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
      }
    }
  }