예제 #1
0
 public void initialise() throws InitialisationException {
   if (endpoint.getRetryPolicyTemplate() != null) {
     retryTemplate = endpoint.getRetryPolicyTemplate();
   } else {
     retryTemplate = connector.getRetryPolicyTemplate();
   }
 }
예제 #2
0
  /**
   * Packages a mule event for the current request
   *
   * @param message the event payload
   * @param uri the destination endpointUri
   * @param synchronous whether the event will be synchronously processed
   * @return the MuleEvent
   * @throws MuleException in case of Mule error
   */
  protected MuleEvent getEvent(MuleMessage message, String uri, boolean synchronous)
      throws MuleException {
    ImmutableEndpoint endpoint =
        manager.getRegistry().lookupEndpointFactory().getOutboundEndpoint(uri);
    // Connector connector = endpoint.getConnector();

    //        if (!connector.isStarted() && manager.isStarted())
    //        {
    //            connector.start();
    //        }

    try {
      MuleSession session =
          new DefaultMuleSession(
              message, ((AbstractConnector) endpoint.getConnector()).getSessionHandler());

      if (credentials != null) {
        message.setProperty(MuleProperties.MULE_USER_PROPERTY, "Plain " + credentials.getToken());
      }

      return new DefaultMuleEvent(message, endpoint, session, synchronous);
    } catch (Exception e) {
      throw new DispatchException(
          CoreMessages.failedToCreate("Client event"), message, endpoint, e);
    }
  }
예제 #3
0
  protected MessageReceiver getTargetReceiver(MuleMessage message, ImmutableEndpoint endpoint)
      throws ConnectException {
    String path = (String) message.getProperty(HttpConnector.HTTP_REQUEST_PROPERTY);
    int i = path.indexOf('?');
    if (i > -1) {
      path = path.substring(0, i);
    }

    StringBuffer requestUri = new StringBuffer(80);
    if (path.indexOf("://") == -1) {
      requestUri.append(endpoint.getProtocol()).append("://");
      requestUri.append(endpoint.getEndpointURI().getHost());
      requestUri.append(':').append(endpoint.getEndpointURI().getPort());

      if (!"/".equals(path)) {
        requestUri.append(path);
      }
    }

    String uriStr = requestUri.toString();
    // first check that there is a receiver on the root address
    if (logger.isTraceEnabled()) {
      logger.trace(
          "Looking up receiver on connector: "
              + connector.getName()
              + " with URI key: "
              + requestUri.toString());
    }

    MessageReceiver receiver = connector.lookupReceiver(uriStr);

    // If no receiver on the root and there is a request path, look up the
    // received based on the root plus request path
    if (receiver == null && !"/".equals(path)) {
      if (logger.isDebugEnabled()) {
        logger.debug(
            "Secondary lookup of receiver on connector: "
                + connector.getName()
                + " with URI key: "
                + requestUri.toString());
      }

      if (receiver == null) {
        receiver = findReceiverByStem(connector.getReceivers(), uriStr);
      }

      if (receiver == null && logger.isWarnEnabled()) {
        logger.warn(
            "No receiver found with secondary lookup on connector: "
                + connector.getName()
                + " with URI key: "
                + requestUri.toString());
        logger.warn(
            "Receivers on connector are: " + MapUtils.toString(connector.getReceivers(), true));
      }
    }

    return receiver;
  }
예제 #4
0
 public Object makeObject(Object key) throws Exception {
   ImmutableEndpoint ep = (ImmutableEndpoint) key;
   MulticastSocket socket = (MulticastSocket) super.makeObject(key);
   socket.setLoopbackMode(((MulticastConnector) ep.getConnector()).isLoopback());
   int ttl = ((MulticastConnector) ep.getConnector()).getTimeToLive();
   if (ttl != Connector.INT_VALUE_NOT_SET) {
     socket.setTimeToLive(ttl);
   }
   return socket;
 }
예제 #5
0
  /**
   * Will receive an event from an endpointUri determined by the url
   *
   * @param url the Mule url used to determine the destination and transport of the message
   * @param timeout how long to block waiting to receive the event, if set to 0 the receive will not
   *     wait at all and if set to -1 the receive will wait forever
   * @return the message received or null if no message was received
   * @throws org.mule.api.MuleException
   */
  public MuleMessage receive(String url, long timeout) throws MuleException {
    ImmutableEndpoint endpoint =
        manager.getRegistry().lookupEndpointFactory().getOutboundEndpoint(url);

    try {
      return endpoint.request(timeout);
    } catch (Exception e) {
      throw new ReceiveException(endpoint, timeout, e);
    }
  }
예제 #6
0
  public String[] getReadAndAckStatements(ImmutableEndpoint endpoint) {
    String str;

    // Find read statement
    String readStmt;
    if ((str = (String) endpoint.getProperty("sql")) != null) {
      readStmt = str;
    } else {
      readStmt = endpoint.getEndpointURI().getAddress();
    }

    // Find ack statement
    String ackStmt;
    if ((str = (String) endpoint.getProperty("ack")) != null) {
      ackStmt = str;
      if ((str = getQuery(endpoint, ackStmt)) != null) {
        ackStmt = str;
      }
      ackStmt = ackStmt.trim();
    } else {
      ackStmt = readStmt + ".ack";
      if ((str = getQuery(endpoint, ackStmt)) != null) {
        ackStmt = str.trim();
      } else {
        ackStmt = null;
      }
    }

    // Translate both using queries map
    if ((str = getQuery(endpoint, readStmt)) != null) {
      readStmt = str;
    }
    if (readStmt == null) {
      throw new IllegalArgumentException("Read statement should not be null");
    } else {
      // MULE-3109: trim the readStatement for better user experience
      readStmt = readStmt.trim();
    }

    if (!"select".equalsIgnoreCase(readStmt.substring(0, 6))
        && !"call".equalsIgnoreCase(readStmt.substring(0, 4))) {
      throw new IllegalArgumentException(
          "Read statement should be a select sql statement or a stored procedure");
    }
    if (ackStmt != null) {
      if (!"insert".equalsIgnoreCase(ackStmt.substring(0, 6))
          && !"update".equalsIgnoreCase(ackStmt.substring(0, 6))
          && !"delete".equalsIgnoreCase(ackStmt.substring(0, 6))) {
        throw new IllegalArgumentException(
            "Ack statement should be an insert / update / delete sql statement");
      }
    }
    return new String[] {readStmt, ackStmt};
  }
예제 #7
0
 // @java.lang.Override
 public void destroyObject(Object key, Object object) throws Exception {
   ImmutableEndpoint ep = (ImmutableEndpoint) key;
   InetAddress inetAddress;
   String host = ep.getEndpointURI().getHost();
   if ("null".equalsIgnoreCase(host)) {
     inetAddress = InetAddress.getLocalHost();
   } else {
     inetAddress = InetAddress.getByName(host);
   }
   MulticastSocket socket = (MulticastSocket) object;
   socket.leaveGroup(inetAddress);
   super.destroyObject(key, object);
 }
예제 #8
0
 public String getQuery(ImmutableEndpoint endpoint, String stmt) {
   Object query = null;
   if (endpoint != null && endpoint.getProperties() != null) {
     Object queries = endpoint.getProperties().get("queries");
     if (queries instanceof Map) {
       query = ((Map) queries).get(stmt);
     }
   }
   if (query == null) {
     if (this.queries != null) {
       query = this.queries.get(stmt);
     }
   }
   return query == null ? null : query.toString();
 }
예제 #9
0
 /**
  * Check if endpoint has a keep-alive property configured. Note the translation from keep-alive
  * in the schema to keepAlive here.
  */
 private boolean getEndpointKeepAliveValue(ImmutableEndpoint endpoint) {
   String value = (String) endpoint.getProperty("keepAlive");
   if (value != null) {
     return Boolean.parseBoolean(value);
   }
   return true;
 }
예제 #10
0
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((dynamicEndpointURI == null) ? 0 : dynamicEndpointURI.hashCode());
   result = prime * result + ((endpoint == null) ? 0 : endpoint.hashCode());
   return result;
 }
예제 #11
0
 public EndpointURI getEndpointURI() {
   if (dynamicEndpointURI != null) {
     return dynamicEndpointURI;
   } else {
     return endpoint.getEndpointURI();
   }
 }
예제 #12
0
 public void testEndpointURIParamsConfig() {
   Service d = muleContext.getRegistry().lookupService("testPropertiesComponent");
   assertNotNull(d);
   final InboundRouterCollection router = d.getInboundRouter();
   assertNotNull(router);
   final List endpoints = router.getEndpoints();
   assertNotNull(endpoints);
   assertFalse(endpoints.isEmpty());
   final ImmutableEndpoint inboundEndpoint = (ImmutableEndpoint) endpoints.get(0);
   assertNotNull(inboundEndpoint);
   final List transformers = inboundEndpoint.getTransformers();
   assertFalse(transformers.isEmpty());
   assertNotNull(transformers.get(0));
   final List responseTransformers = inboundEndpoint.getResponseTransformers();
   assertFalse(responseTransformers.isEmpty());
   assertNotNull(responseTransformers.get(0));
 }
예제 #13
0
 //  @Override
 public String toString() {
   final StringBuffer sb = new StringBuffer(80);
   sb.append(ClassUtils.getSimpleName(this.getClass()));
   sb.append("{this=").append(Integer.toHexString(System.identityHashCode(this)));
   sb.append(", endpoint=").append(endpoint.getEndpointURI().getUri());
   sb.append(", disposed=").append(disposed);
   sb.append('}');
   return sb.toString();
 }
 @Override
 public String toString() {
   return "SftpInputStream{"
       + "fileName='"
       + fileName
       + '\''
       + " from endpoint="
       + endpoint.getEndpointURI()
       + '}';
 }
 @Test
 public void testEndpointProperties() throws Exception {
   ImmutableEndpoint endpoint =
       muleContext.getRegistry().lookupEndpointBuilder("endpoint").buildOutboundEndpoint();
   Map props = endpoint.getProperties();
   assertEquals(
       "#[methodNamespace]#[method]",
       assertKey(props, SoapConstants.SOAP_ACTION_PROPERTY, String.class));
   assertEquals("direct", assertKey(props, SoapConstants.SOAP_ACTION_PROPERTY_CAPS, String.class));
   assertEquals("clientConfig", assertKey(props, "clientConfig", String.class));
   assertEquals(Use.ENCODED_STR, assertKey(props, AxisConnector.USE, String.class));
   assertEquals(Style.DOCUMENT_STR, assertKey(props, AxisConnector.STYLE, String.class));
   assertEquals("value1", assertKey(props, "key1", String.class));
   assertEquals("value2", assertKey(props, "key2", String.class));
   Map options = (Map) assertKey(props, AxisMessageReceiver.AXIS_OPTIONS, Map.class);
   assertEquals(10, options.size());
   assertEquals("value1", assertKey(options, "key1", String.class));
   assertEquals("value2", assertKey(options, "key2", String.class));
   assertEquals("Application", assertKey(options, "scope", String.class));
   assertEquals("echo,getdate", assertKey(options, "allowedMethods", String.class));
   assertEquals("wsdlPortType", assertKey(options, "wsdlPortType", String.class));
   assertEquals("wsdlServiceElement", assertKey(options, "wsdlServiceElement", String.class));
   assertEquals("wsdlTargetNamespace", assertKey(options, "wsdlTargetNamespace", String.class));
   assertEquals("wsdlInputSchema", assertKey(options, "wsdlInputSchema", String.class));
   assertEquals("wsdlSoapActionMode", assertKey(options, "wsdlSoapActionMode", String.class));
   assertEquals("extraClasses", assertKey(options, "extraClasses", String.class));
   Map methods = (Map) assertKey(props, AxisConnector.SOAP_METHODS, Map.class);
   List method1 = (List) assertKey(methods, "method1", List.class);
   assertEquals(3, method1.size());
   assertEquals("symbol;string;IN", method1.get(0));
   assertEquals("GetQuoteResult;string;OUT", method1.get(1));
   assertEquals("return;string", method1.get(2));
   List method2 = (List) assertKey(methods, "method2", List.class);
   assertEquals(2, method2.size());
   assertEquals("param;string;IN", method2.get(0));
   assertEquals("addedFromSpring;string;in", method2.get(1));
   List interfaces = (List) assertKey(props, SoapConstants.SERVICE_INTERFACES, List.class);
   assertEquals(2, interfaces.size());
   assertEquals("class1", interfaces.get(0));
   assertEquals("class2", interfaces.get(1));
 }
예제 #16
0
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   final DynamicEndpointURIEndpoint other = (DynamicEndpointURIEndpoint) obj;
   if (dynamicEndpointURI == null) {
     if (other.dynamicEndpointURI != null) return false;
   } else if (!dynamicEndpointURI.equals(other.dynamicEndpointURI)) return false;
   if (endpoint == null) {
     if (other.endpoint != null) return false;
   } else if (!endpoint.equals(other.endpoint)) return false;
   return true;
 }
예제 #17
0
  public String getStatement(ImmutableEndpoint endpoint) {
    String writeStmt = endpoint.getEndpointURI().getAddress();
    String str;
    if ((str = getQuery(endpoint, writeStmt)) != null) {
      writeStmt = str;
    }
    writeStmt = StringUtils.trimToEmpty(writeStmt);
    if (StringUtils.isBlank(writeStmt)) {
      throw new IllegalArgumentException("Missing statement");
    }

    return writeStmt;
  }
예제 #18
0
  public OutputStream getOutputStream(ImmutableEndpoint endpoint, MuleMessage message)
      throws MuleException {
    OutputStream out;
    String streamName = endpoint.getEndpointURI().getAddress();

    if (STREAM_SYSTEM_OUT.equalsIgnoreCase(streamName)) {
      out = System.out;
    } else if (STREAM_SYSTEM_ERR.equalsIgnoreCase(streamName)) {
      out = System.err;
    } else {
      out = getOutputStream();
    }
    return out;
  }
예제 #19
0
  public Object[] getParams(
      ImmutableEndpoint endpoint, List paramNames, MuleMessage message, String query)
      throws Exception {

    Object[] params = new Object[paramNames.size()];
    for (int i = 0; i < paramNames.size(); i++) {
      String param = (String) paramNames.get(i);
      Object value = null;
      // If we find a value and it happens to be null, thats acceptable
      boolean foundValue = false;
      boolean validExpression = muleContext.getExpressionManager().isValidExpression(param);
      // There must be an expression namespace to use the ExpresionEvaluator i.e. header:type
      if (message != null && validExpression) {
        value = muleContext.getExpressionManager().evaluate(param, message);
        foundValue = value != null;
      }
      if (!foundValue) {
        String name = param.substring(2, param.length() - 1);
        // MULE-3597
        if (!validExpression) {
          logger.warn(
              MessageFormat.format(
                  "Config is using the legacy param format {0} (no evaluator defined)."
                      + " This expression can be replaced with {1}header:{2}{3}",
                  param,
                  ExpressionManager.DEFAULT_EXPRESSION_PREFIX,
                  name,
                  ExpressionManager.DEFAULT_EXPRESSION_POSTFIX));
        }
        value = endpoint.getProperty(name);
      }

      // Allow null values which may be acceptable to the user
      // Why shouldn't nulls be allowed? Otherwise every null parameter has to
      // be defined
      // if (value == null && !foundValue)
      // {
      // throw new IllegalArgumentException("Can not retrieve argument " +
      // name);
      // }
      params[i] = value;
    }
    return params;
  }
  public void close() throws IOException {
    if (logger.isDebugEnabled()) {
      logger.debug("Closing the stream for the file " + fileName);
    }
    try {
      super.close();

      if (autoDelete && !errorOccured) {
        client.deleteFile(fileName);
      }
    } catch (IOException e) {
      logger.error("Error occured while closing file " + fileName, e);
      throw e;
    } finally {
      // We should release the connection from the pool even if some error
      // occurs here
      try {
        ((SftpConnector) endpoint.getConnector()).releaseClient(endpoint, client);
      } catch (Exception e) {
        logger.error(e.getMessage(), e);
      }
    }
  }
 public Connector getOrCreateConnectorByProtocol(ImmutableEndpoint endpoint)
     throws TransportFactoryException {
   return getOrCreateConnectorByProtocol(endpoint.getEndpointURI());
 }
예제 #22
0
 public String getName() {
   return endpoint.getName();
 }
예제 #23
0
 public MuleContext getMuleContext() {
   return endpoint.getMuleContext();
 }
예제 #24
0
 public String getInitialState() {
   return endpoint.getInitialState();
 }
예제 #25
0
 public Filter getFilter() {
   return endpoint.getFilter();
 }
예제 #26
0
 public String getEncoding() {
   return endpoint.getEncoding();
 }
예제 #27
0
 public Connector getConnector() {
   return endpoint.getConnector();
 }
예제 #28
0
 public ConnectionStrategy getConnectionStrategy() {
   return endpoint.getConnectionStrategy();
 }
예제 #29
0
 public void dispatch(MuleEvent event) throws DispatchException {
   endpoint.dispatch(event);
 }
예제 #30
0
 public boolean isOutbound() {
   return endpoint.isOutbound();
 }