示例#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);
    }
示例#2
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);
     }
   }
 }
  @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);
      }
    }
  }
示例#4
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());
    }
  }