开发者

Apache Jax-RS breaks spring-integration-mail

I'm trying to write some code that reads email and provides restful web services.

I have a simple test file that reads messages from gmail (over pop). However, it seems that when I add cxf-rf-frontend-jaxrs to my pom.xml then it stops that test file from working.

Anyone able to untangle this?

Thanks, code and stuff follows.

The error is:

org.springframework.integration.core.MessagingException: failure occurred while receiving from folder
    at org.springframework.integration.mail.AbstractMailReceiver.receive(AbstractMailReceiver.java:173)
    at mail.GmailManualTester.testPop(GmailManualTester.java:36)

Caused by: java.lang.NullPointerException
    at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1166)
    at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1135)
    at javax.mail.internet.MimeMessage.<init>(MimeMessage.java:182)
    at org.springframework.integration.mail.Pop3MailReceiver.deleteMessages(Pop3MailReceiver.java:78)
    at org.springframework.integration.mail.AbstractMailReceiver.receive(AbstractMailReceiver.java:164)

The test file is src/test/java/mail/GmailManualTester.java

package mail;
import java.util.Properties;
import javax.mail.Message;
import org.junit.Test;
import org.springframework.integration.mail.Pop3MailReceiver;

public class GmailManualTester {

    @Test
    public void testPop() throws Exception {

        Pop3MailReceiver mail = new Pop3MailReceiver(
        "pop3://USERNAME%40DOMAIN:PASSWORD@pop.gmail.com:995/INBOX");

        Properties props = new Properties();
        props.setProperty("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.setProperty("mail.pop3.socketFactory.fallback", "false");

        mail.setJavaMailProperties(props);

        Message[] messages = mail.receive();
        System.out.println("Got " + messages.length + " messages");

        for (Message message : messages) {
            System.out.println("Subject: " + message.getSubject());
    }
    }
}

and the pom.xml is

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>net.sf</groupId>
  <artifactId>boom</artifactId>
  <packaging>war</packaging>
  <version>1.0</version>
  <name>Example</name>
  <url>http://maven.apache.org</url>

  <dependencies>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.6</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-frontend-jaxrs</artifactId>
      <version>2.3.0</version>
    </dependency>

    <dependency>
      <groupId>org.springframework.integration</groupId>
      <artifactId>spring-integration-mail</artifactId>
      <version>1.0.2SR1</version>
    </dependency>

    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-email</artifactId>
      <version>1.1</version>
    </dependency>

  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
          <debug>false</debug>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

Edit: took ALL the dependencies from the ~/.m2/.../cxf-rt-frontend-jaxrs-2.3.0.pom file and put them in my own pom.xml as exclusions. Turned them on and off until I find just one causing it:

If I put this in to my pom file, I can retrieve messages. If I comment it out, I get the error from above. Still need to dig further into that now, though. Excluding that probably breaks the webs开发者_如何学Pythonervices in my app.

<exclusion>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-core</artifactId>
    </exclusion>


cxf-rt-core depends on geronimo-javamail_1.4_spec which is a different javamail provider than what spring brings in (I think). However, cxf just uses it as a javamail provider, so any provider should work fine. Thus, if you add an exclusion for that and allow the spring version to come in, you should be all set.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜