Exemple #1
0
    protected HttpResponse buildFailureResponse(RequestLine requestLine, MuleMessage message)
        throws TransformerException {
      EndpointURI uri = endpoint.getEndpointURI();
      String failedPath =
          uri.getScheme()
              + "://"
              + uri.getHost()
              + ":"
              + uri.getPort()
              + message.getProperty(HttpConnector.HTTP_REQUEST_PATH_PROPERTY);

      if (logger.isDebugEnabled()) {
        logger.debug("Failed to bind to " + failedPath);
      }

      HttpResponse response = new HttpResponse();
      response.setStatusLine(requestLine.getHttpVersion(), HttpConstants.SC_NOT_FOUND);
      response.setBody(HttpMessages.cannotBindToAddress(failedPath).toString());
      RequestContext.setEvent(
          new DefaultMuleEvent(
              new DefaultMuleMessage(response),
              endpoint,
              new DefaultMuleSession(service, connector.getMuleContext()),
              true));
      // The DefaultResponseTransformer will set the necessary headers
      return transformResponse(response);
    }
 /**
  * Create an endpoint and check its properties.
  *
  * @throws Exception if something goes wrong
  */
 public void testValidEndpointURI() throws Exception {
   EndpointURI endpointUri =
       new MuleEndpointURI("legstar-wmq://CICS01.BRIDGE.REQUEST.QUEUE", muleContext);
   endpointUri.initialise();
   assertEquals("legstar-wmq", endpointUri.getScheme());
   assertEquals("legstar-wmq", endpointUri.getSchemeMetaInfo());
   assertEquals("CICS01.BRIDGE.REQUEST.QUEUE", endpointUri.getAddress());
 }
Exemple #3
0
 protected void doConnect() throws Exception {
   if (transport == null) {
     try {
       transport = castConnector().getSessionDetails(endpoint).newTransport();
       EndpointURI uri = endpoint.getEndpointURI();
       transport.connect(uri.getHost(), uri.getPort(), uri.getUser(), uri.getPassword());
     } catch (Exception e) {
       throw new EndpointException(
           org.mule.config.i18n.MessageFactory.createStaticMessage(
               "Unable to connect to mail transport."),
           e);
     }
   }
 }
  /**
   * Creates an uninitialied connector from the provided MuleEndpointURI. The scheme is used to
   * determine what kind of connector to create. Any params set on the uri can be used to initialise
   * bean properties on the created connector.
   *
   * <p>Note that the initalise method will need to be called on the connector returned. This is so
   * that developers can control when the connector initialisation takes place as this is likely to
   * initialse all connecotr resources.
   *
   * @param url the MuleEndpointURI url to create the connector with
   * @return a new Connector
   * @throws TransportFactoryException
   */
  public Connector createConnector(EndpointURI url) throws TransportFactoryException {

    try {
      Connector connector;
      String scheme = url.getFullScheme();

      TransportServiceDescriptor sd =
          (TransportServiceDescriptor)
              muleContext
                  .getRegistry()
                  .lookupServiceDescriptor(ServiceType.TRANSPORT, scheme, null);
      if (sd == null) {
        throw new ServiceException(CoreMessages.noServiceTransportDescriptor(scheme));
      }

      connector = sd.createConnector();
      if (connector != null) {
        if (connector instanceof AbstractConnector) {
          ((AbstractConnector) connector).initialiseFromUrl(url);
        }
      } else {
        throw new TransportFactoryException(
            CoreMessages.objectNotSetInService("Connector", scheme));
      }

      connector.setName(new ObjectNameHelper(muleContext).getConnectorName(connector));

      return connector;
    } catch (Exception e) {
      throw new TransportFactoryException(
          CoreMessages.failedToCreateObjectWith("Endpoint", url), e);
    }
  }
Exemple #5
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;
 }
 /**
  * Get user/password from URI.
  *
  * @throws Exception if something goes wrong
  */
 public void testUserPasswordURI() throws Exception {
   EndpointURI endpointUri =
       new MuleEndpointURI("legstar-wmq://user:[email protected]", muleContext);
   endpointUri.initialise();
   assertEquals("legstar-wmq", endpointUri.getScheme());
   assertEquals("legstar-wmq", endpointUri.getSchemeMetaInfo());
   assertEquals("CICS01.BRIDGE.REQUEST.QUEUE", endpointUri.getAddress());
   assertEquals("user:password", endpointUri.getUserInfo());
   assertEquals("user", endpointUri.getUser());
   assertEquals("password", endpointUri.getPassword());
 }
 @Test
 public void testUrlWithProvider() throws Exception {
   EndpointURI url = new MuleEndpointURI("vm://some.queue?endpointName=vmProvider", muleContext);
   url.initialise();
   assertEquals(VMConnector.VM, url.getScheme());
   assertEquals("some.queue", url.getAddress());
   assertEquals("vmProvider", url.getEndpointName());
   assertEquals("vm://some.queue?endpointName=vmProvider", url.toString());
   assertEquals(1, url.getParams().size());
 }
Exemple #8
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;
 }
Exemple #9
0
  protected void sendMailMessage(Message message) throws MessagingException {
    // sent date
    message.setSentDate(Calendar.getInstance().getTime());

    /*
     * Double check that the transport is still connected as some SMTP servers may
     * disconnect idle connections.
     */
    if (!transport.isConnected()) {
      EndpointURI uri = endpoint.getEndpointURI();
      if (logger.isInfoEnabled()) {
        logger.info("Connection closed by remote server. Reconnecting.");
      }
      transport.connect(uri.getHost(), uri.getPort(), uri.getUser(), uri.getPassword());
    }

    transport.sendMessage(message, message.getAllRecipients());

    if (logger.isDebugEnabled()) {
      StringBuffer msg = new StringBuffer();
      msg.append("Email message sent with subject'")
          .append(message.getSubject())
          .append("' sent- ");
      msg.append(", From: ").append(MailUtils.mailAddressesToString(message.getFrom())).append(" ");
      msg.append(", To: ")
          .append(MailUtils.mailAddressesToString(message.getRecipients(Message.RecipientType.TO)))
          .append(" ");
      msg.append(", Cc: ")
          .append(MailUtils.mailAddressesToString(message.getRecipients(Message.RecipientType.CC)))
          .append(" ");
      msg.append(", Bcc: ")
          .append(MailUtils.mailAddressesToString(message.getRecipients(Message.RecipientType.BCC)))
          .append(" ");
      msg.append(", ReplyTo: ").append(MailUtils.mailAddressesToString(message.getReplyTo()));

      logger.debug(msg.toString());
    }
  }
  /** Returns an initialized connector. */
  public Connector getOrCreateConnectorByProtocol(EndpointURI uri)
      throws TransportFactoryException {
    String connectorName = uri.getConnectorName();
    if (null != connectorName) {
      // TODO this lookup fails currently on Mule 2.x! MuleAdminAgentTestCase
      Connector connector = muleContext.getRegistry().lookupConnector(connectorName);
      if (connector != null) {
        return connector;
      }
    }

    Connector connector = getConnectorByProtocol(uri.getFullScheme());
    if (connector == null) {
      connector = createConnector(uri);
      try {
        BeanUtils.populate(connector, uri.getParams());
        muleContext.getRegistry().registerConnector(connector);
      } catch (Exception e) {
        throw new TransportFactoryException(e);
      }
    }
    return connector;
  }
Exemple #11
0
  /**
   * Creates an uninitialied connector from the provided MuleEndpointURI. The scheme is used to
   * determine what kind of connector to create. Any params set on the uri can be used to initialise
   * bean properties on the created connector.
   *
   * <p>Note that the initalise method will need to be called on the connector returned. This is so
   * that developers can control when the connector initialisation takes place as this is likely to
   * initialse all connecotr resources.
   *
   * @param url the MuleEndpointURI url to create the connector with
   * @return a new Connector
   * @throws TransportFactoryException
   */
  public static Connector createConnector(EndpointURI url, MuleContext muleContext)
      throws TransportFactoryException {

    try {
      Connector connector;
      String scheme = url.getSchemeMetaInfo();

      TransportServiceDescriptor sd =
          (TransportServiceDescriptor)
              muleContext
                  .getRegistry()
                  .lookupServiceDescriptor(
                      ServiceDescriptorFactory.TRANSPORT_SERVICE_TYPE, scheme, null);
      if (sd == null) {
        throw new ServiceException(CoreMessages.noServiceTransportDescriptor(scheme));
      }

      connector = sd.createConnector();
      if (connector != null) {
        connector.setMuleContext(muleContext);
        if (connector instanceof AbstractConnector) {
          ((AbstractConnector) connector).initialiseFromUrl(url);
        }
      } else {
        throw new TransportFactoryException(
            CoreMessages.objectNotSetInService("Connector", scheme));
      }

      connector.setName(ObjectNameHelper.getConnectorName(connector));

      // TODO Do we still need to support this for 2.x?
      // set any manager default properties for the connector
      // these are set on the Manager with a protocol i.e.
      // jms.specification=1.1
      //            Map props = new HashMap();
      //
      // PropertiesUtils.getPropertiesWithPrefix(RegistryContext.getRegistry().lookupProperties(),
      //                connector.getProtocol().toLowerCase(), props);
      //            if (props.size() > 0)
      //            {
      //                props = PropertiesUtils.removeNamespaces(props);
      //                BeanUtils.populateWithoutFail(connector, props, true);
      //            }

      return connector;
    } catch (Exception e) {
      throw new TransportFactoryException(
          CoreMessages.failedToCreateObjectWith("Endpoint", url), e);
    }
  }
  @Override
  protected void doConnect() throws Exception {
    if (folder == null || !folder.isOpen()) {
      Store store = castConnector().getSessionDetails(endpoint).newStore();

      EndpointURI uri = endpoint.getEndpointURI();
      String encoding = endpoint.getEncoding();
      String user = (uri.getUser() != null ? URLDecoder.decode(uri.getUser(), encoding) : null);
      String pass =
          (uri.getPassword() != null ? URLDecoder.decode(uri.getPassword(), encoding) : null);
      store.connect(uri.getHost(), uri.getPort(), user, pass);

      folder = store.getFolder(castConnector().getMailboxFolder());
      ensureFolderIsOpen(folder);

      if (castConnector().getMoveToFolder() != null) {
        moveToFolder = store.getFolder(castConnector().getMoveToFolder());
        ensureFolderIsOpen(moveToFolder);
      }
    }
  }
Exemple #13
0
  @SuppressWarnings("unchecked")
  protected void registerReceiverWithMuleService(MessageReceiver receiver, EndpointURI ep)
      throws MuleException {
    CxfMessageReceiver cxfReceiver = (CxfMessageReceiver) receiver;
    Server server = cxfReceiver.getServer();

    uriToServer.put(server.getEndpoint().getEndpointInfo().getAddress(), server);

    // TODO MULE-2228 Simplify this API
    SedaService c = new SedaService();

    String uniqueServiceName = createServiceName(server.getEndpoint());
    c.setName(uniqueServiceName);

    c.setModel(muleContext.getRegistry().lookupSystemModel());

    CxfServiceComponent svcComponent = new CxfServiceComponent(this, (CxfMessageReceiver) receiver);
    svcComponent.setBus(bus);

    c.setComponent(new DefaultJavaComponent(new SingletonObjectFactory(svcComponent)));

    // No determine if the endpointUri requires a new connector to be
    // registed in the case of http we only need to register the new
    // endpointUri if the port is different
    String endpoint = receiver.getEndpointURI().getAddress();
    String scheme = ep.getScheme().toLowerCase();

    InboundEndpoint originalEndpoint = receiver.getEndpoint();
    boolean sync = originalEndpoint.isSynchronous();

    // If we are using sockets then we need to set the endpoint name appropiately
    // and if using http/https
    // we need to default to POST and set the Content-Type
    if (scheme.equals("http")
        || scheme.equals("https")
        || scheme.equals("ssl")
        || scheme.equals("tcp")
        || scheme.equals("servlet")) {
      originalEndpoint.getProperties().put(HttpConnector.HTTP_METHOD_PROPERTY, "POST");
      originalEndpoint.getProperties().put(HttpConstants.HEADER_CONTENT_TYPE, "text/xml");
    }

    QName serviceName = server.getEndpoint().getEndpointInfo().getName();

    EndpointBuilder protocolEndpointBuilder = new EndpointURIEndpointBuilder(endpoint, muleContext);
    protocolEndpointBuilder.setSynchronous(sync);
    protocolEndpointBuilder.setName(ep.getScheme() + ":" + serviceName.getLocalPart());
    protocolEndpointBuilder.setTransactionConfig(originalEndpoint.getTransactionConfig());

    EndpointBuilder receiverEndpointBuilder =
        new EndpointURIEndpointBuilder(originalEndpoint, muleContext);

    // Apply the transformers to the correct endpoint
    EndpointBuilder transformerEndpoint;
    if (cxfReceiver.isApplyTransformersToProtocol()) {
      transformerEndpoint = protocolEndpointBuilder;
      receiverEndpointBuilder.setTransformers(Collections.emptyList());
      receiverEndpointBuilder.setResponseTransformers(Collections.emptyList());
    } else {
      transformerEndpoint = receiverEndpointBuilder;
    }

    // Ensure that the transformers aren't empty before setting them. Otherwise Mule will get
    // confused
    // and won't add the default transformers.
    if (originalEndpoint.getTransformers() != null
        && !originalEndpoint.getTransformers().isEmpty()) {
      transformerEndpoint.setTransformers(originalEndpoint.getTransformers());
    }

    if (originalEndpoint.getResponseTransformers() != null
        && !originalEndpoint.getResponseTransformers().isEmpty()) {
      transformerEndpoint.setResponseTransformers(originalEndpoint.getResponseTransformers());
    }

    // apply the filters to the correct endpoint
    EndpointBuilder filterEndpoint;
    if (cxfReceiver.isApplyFiltersToProtocol()) {
      filterEndpoint = protocolEndpointBuilder;
      receiverEndpointBuilder.setFilter(null);
    } else {
      filterEndpoint = receiverEndpointBuilder;
    }
    filterEndpoint.setFilter(originalEndpoint.getFilter());

    // apply the security filter to the correct endpoint
    EndpointBuilder secFilterEndpoint;
    if (cxfReceiver.isApplySecurityToProtocol()) {
      secFilterEndpoint = protocolEndpointBuilder;
      receiverEndpointBuilder.setSecurityFilter(null);
    } else {
      secFilterEndpoint = receiverEndpointBuilder;
    }
    secFilterEndpoint.setSecurityFilter(originalEndpoint.getSecurityFilter());

    String connectorName = (String) originalEndpoint.getProperty(CxfConstants.PROTOCOL_CONNECTOR);
    if (connectorName != null) {
      protocolEndpointBuilder.setConnector(
          muleContext.getRegistry().lookupConnector(connectorName));
    }

    InboundEndpoint protocolEndpoint =
        muleContext
            .getRegistry()
            .lookupEndpointFactory()
            .getInboundEndpoint(protocolEndpointBuilder);

    InboundEndpoint receiverEndpoint =
        muleContext
            .getRegistry()
            .lookupEndpointFactory()
            .getInboundEndpoint(receiverEndpointBuilder);

    receiver.setEndpoint(receiverEndpoint);

    c.setInboundRouter(new DefaultInboundRouterCollection());
    c.getInboundRouter().addEndpoint(protocolEndpoint);
    services.add(c);
  }