Exemplo n.º 1
0
 public void testUpperCaseString() throws Exception {
   UMOImmutableEndpoint ep =
       new ImmutableMuleEndpoint("jnp://localhost/TestService?method=upperCaseString", false);
   UMOMessage message = ep.send(getTestEvent("hello", ep));
   assertNotNull(message.getPayload());
   assertEquals("HELLO", message.getPayloadAsString());
 }
Exemplo n.º 2
0
 public void testBadMethodName() throws Exception {
   UMOImmutableEndpoint ep =
       new ImmutableMuleEndpoint("jnp://localhost/TestService?method=foo", false);
   try {
     ep.send(getTestEvent("hello", ep));
   } catch (UMOException e) {
     assertTrue(e.getCause() instanceof NoSuchMethodException);
   }
 }
Exemplo n.º 3
0
 public void testNoMethodSet() throws Exception {
   UMOImmutableEndpoint ep = new ImmutableMuleEndpoint("jnp://localhost/TestService", false);
   try {
     ep.send(getTestEvent("hello", ep));
   } catch (UMOException e) {
     assertTrue(e instanceof DispatchException);
     assertTrue(
         e.getMessage()
             .startsWith(Messages.get("rmi", RmiConnector.MSG_PARAM_SERVICE_METHOD_NOT_SET)));
   }
 }
Exemplo n.º 4
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;
  }
Exemplo n.º 5
0
 /**
  * Passive mode is OFF by default. The value is taken from the connector settings. In case there
  * are any overriding properties set on the endpoint, those will be used.
  *
  * @see #setPassive(boolean)
  */
 public void enterActiveOrPassiveMode(FTPClient client, UMOImmutableEndpoint endpoint) {
   // well, no endpoint URI here, as we have to use the most common denominator
   // in API :(
   final String passiveString = (String) endpoint.getProperty(FtpConnector.PROPERTY_PASSIVE_MODE);
   if (passiveString == null) {
     // try the connector properties then
     if (isPassive()) {
       if (logger.isTraceEnabled()) {
         logger.trace("Entering FTP passive mode");
       }
       client.enterLocalPassiveMode();
     } else {
       if (logger.isTraceEnabled()) {
         logger.trace("Entering FTP active mode");
       }
       client.enterLocalActiveMode();
     }
   } else {
     // override with endpoint's definition
     final boolean passiveMode = Boolean.valueOf(passiveString).booleanValue();
     if (passiveMode) {
       if (logger.isTraceEnabled()) {
         logger.trace("Entering FTP passive mode (endpoint override)");
       }
       client.enterLocalPassiveMode();
     } else {
       if (logger.isTraceEnabled()) {
         logger.trace("Entering FTP active mode (endpoint override)");
       }
       client.enterLocalActiveMode();
     }
   }
 }
Exemplo n.º 6
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;
    }
  }
Exemplo n.º 7
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);
    }
  }
Exemplo n.º 8
0
  public void passivateObject(Object key, Object object) throws Exception {
    UMOImmutableEndpoint ep = (UMOImmutableEndpoint) key;

    boolean keepSocketOpen =
        MapUtils.getBooleanValue(
            ep.getProperties(),
            TcpConnector.KEEP_SEND_SOCKET_OPEN_PROPERTY,
            ((TcpConnector) ep.getConnector()).isKeepSendSocketOpen());
    Socket socket = (Socket) object;

    if (!keepSocketOpen) {
      try {
        if (socket != null) {
          socket.close();
        }
      } catch (IOException e) {
        logger.debug("Failed to close socket after dispatch: " + e.getMessage());
      }
    }
  }
Exemplo n.º 9
0
  /**
   * Transfer type is BINARY by default. The value is taken from the connector settings. In case
   * there are any overriding properties set on the endpoint, those will be used.
   *
   * <p>The alternative type is ASCII.
   *
   * <p>
   *
   * @see #setBinary(boolean)
   */
  public void setupFileType(FTPClient client, UMOImmutableEndpoint endpoint) throws Exception {
    int type;

    // well, no endpoint URI here, as we have to use the most common denominator
    // in API :(
    final String binaryTransferString =
        (String) endpoint.getProperty(FtpConnector.PROPERTY_BINARY_TRANSFER);
    if (binaryTransferString == null) {
      // try the connector properties then
      if (isBinary()) {
        if (logger.isTraceEnabled()) {
          logger.trace("Using FTP BINARY type");
        }
        type = FTP.BINARY_FILE_TYPE;
      } else {
        if (logger.isTraceEnabled()) {
          logger.trace("Using FTP ASCII type");
        }
        type = FTP.ASCII_FILE_TYPE;
      }
    } else {
      // override with endpoint's definition
      final boolean binaryTransfer = Boolean.valueOf(binaryTransferString).booleanValue();
      if (binaryTransfer) {
        if (logger.isTraceEnabled()) {
          logger.trace("Using FTP BINARY type (endpoint override)");
        }
        type = FTP.BINARY_FILE_TYPE;
      } else {
        if (logger.isTraceEnabled()) {
          logger.trace("Using FTP ASCII type (endpoint override)");
        }
        type = FTP.ASCII_FILE_TYPE;
      }
    }

    client.setFileType(type);
  }
Exemplo n.º 10
0
 public XmppMessageDispatcher(UMOImmutableEndpoint endpoint) {
   super(endpoint);
   this.connector = (XmppConnector) endpoint.getConnector();
 }
Exemplo n.º 11
0
 public TransactedPollingMessageReceiver(
     UMOConnector connector, UMOComponent component, final UMOImmutableEndpoint endpoint)
     throws CreateException {
   super(connector, component, endpoint);
   this.setReceiveMessagesInTransaction(endpoint.getTransactionConfig().getFactory() != null);
 }