Exemple #1
0
  public Object makeObject(Object key) throws Exception {
    UMOImmutableEndpoint ep = (UMOImmutableEndpoint) key;
    int port = ep.getEndpointURI().getPort();
    InetAddress inetAddress = InetAddress.getByName(ep.getEndpointURI().getHost());
    Socket socket = createSocket(port, inetAddress);
    socket.setReuseAddress(true);

    TcpConnector connector = (TcpConnector) ep.getConnector();
    connector.configureSocket(TcpConnector.CLIENT, socket);

    return socket;
  }
Exemple #2
0
  /**
   * Make a specific request to the underlying transport
   *
   * @param endpoint the endpoint to use when connecting to the resource
   * @param timeout the maximum time the operation should block before returning. The call should
   *     return immediately if there is data available. If no data becomes available before the
   *     timeout elapses, null will be returned
   * @return the result of the request wrapped in a UMOMessage object. Null will be returned if no
   *     data was avaialable
   * @throws Exception if the call to the underlying protocal cuases an exception
   */
  protected UMOMessage doReceive(UMOImmutableEndpoint endpoint, long timeout) throws Exception {

    Session session = null;
    Destination dest = null;
    MessageConsumer consumer = null;
    try {
      boolean topic = false;
      String resourceInfo = endpoint.getEndpointURI().getResourceInfo();
      topic = (resourceInfo != null && JmsConstants.TOPIC_PROPERTY.equalsIgnoreCase(resourceInfo));

      session = connector.getSession(false, topic);
      dest =
          connector
              .getJmsSupport()
              .createDestination(session, endpoint.getEndpointURI().getAddress(), topic);
      consumer = connector.getJmsSupport().createConsumer(session, dest, topic);

      try {
        Message message = null;
        if (timeout == RECEIVE_NO_WAIT) {
          message = consumer.receiveNoWait();
        } else if (timeout == RECEIVE_WAIT_INDEFINITELY) {
          message = consumer.receive();
        } else {
          message = consumer.receive(timeout);
        }
        if (message == null) {
          return null;
        }

        message = connector.preProcessMessage(message, session);

        return new MuleMessage(connector.getMessageAdapter(message));
      } catch (Exception e) {
        connector.handleException(e);
        return null;
      }
    } finally {
      connector.closeQuietly(consumer);
      connector.closeQuietly(session);
    }
  }
Exemple #3
0
  /*
   * (non-Javadoc)
   *
   * @see org.mule.providers.AbstractMessageDispatcher#doDispatch(org.mule.umo.UMOEvent)
   */
  protected void doDispatch(UMOEvent event) throws Exception {
    if (logger.isDebugEnabled()) {
      logger.debug("Dispatch event: " + event);
    }

    UMOImmutableEndpoint endpoint = event.getEndpoint();
    String writeStmt = endpoint.getEndpointURI().getAddress();
    String str;
    if ((str = this.connector.getQuery(endpoint, writeStmt)) != null) {
      writeStmt = str;
    }
    if (StringUtils.isEmpty(writeStmt)) {
      throw new IllegalArgumentException("Write statement should not be null");
    }
    if (!"insert".equalsIgnoreCase(writeStmt.substring(0, 6))
        && !"update".equalsIgnoreCase(writeStmt.substring(0, 6))
        && !"delete".equalsIgnoreCase(writeStmt.substring(0, 6))) {
      throw new IllegalArgumentException(
          "Write statement should be an insert / update / delete sql statement");
    }
    List paramNames = new ArrayList();
    writeStmt = JdbcUtils.parseStatement(writeStmt, paramNames);
    Object[] paramValues = JdbcUtils.getParams(endpoint, paramNames, event.getTransformedMessage());

    UMOTransaction tx = TransactionCoordination.getInstance().getTransaction();
    Connection con = null;
    try {
      con = this.connector.getConnection();

      int nbRows = connector.createQueryRunner().update(con, writeStmt, paramValues);
      if (nbRows != 1) {
        logger.warn("Row count for write should be 1 and not " + nbRows);
      }
      if (tx == null) {
        JdbcUtils.commitAndClose(con);
      }
      logger.debug("Event dispatched succesfuly");
    } catch (Exception e) {
      logger.debug("Error dispatching event: " + e.getMessage(), e);
      if (tx == null) {
        JdbcUtils.rollbackAndClose(con);
      }
      throw e;
    }
  }