sargue / mailgun

Java library to easily send emails using the Mailgun service
MIT License
152 stars 40 forks source link

Executing on Stand Alone Gradle project, but facing exception #14

Closed saikiranvadlakonda closed 7 years ago

saikiranvadlakonda commented 7 years ago
Configuration config = new Configuration("xx.xxxxx.xx", "key-xxxxxxx4", "saikiran<saikiran@xxxxx.xx>");
Response res = Mail.using(config).to("saikiranjgl@xxx.com").subject("Testing Mail").text("Invoking Mail API from Java ").build().send();
System.out.println(res.responseMessage());

I'm running above code on stand alone Gradle Application, I've added all the jars, but still getting below Exception, could you guide me where I'm doing wrong.

Exception in thread "main" javax.ws.rs.ProcessingException: javax.ws.rs.core.Response$Status$Family.familyOf(I)Ljavax/ws/rs/core/Response$Status$Family;
    at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:261)
    at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:684)
    at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:681)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
    at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:681)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:437)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:343)
    at net.sargue.mailgun.Mail.send(Mail.java:40)
    at cloudseed.wishkarma.services.MailingService.sendMail(MailingService.java:40)
    at cloudseed.wishkarma.app.ChatApp.main(ChatApp.java:59)
Caused by: java.lang.NoSuchMethodError: javax.ws.rs.core.Response$Status$Family.familyOf(I)Ljavax/ws/rs/core/Response$Status$Family;
    at org.glassfish.jersey.message.internal.Statuses$StatusImpl.<init>(Statuses.java:63)
    at org.glassfish.jersey.message.internal.Statuses$StatusImpl.<init>(Statuses.java:54)
    at org.glassfish.jersey.message.internal.Statuses.from(Statuses.java:143)
    at org.glassfish.jersey.client.internal.HttpUrlConnector._apply(HttpUrlConnector.java:402)
    at org.glassfish.jersey.client.internal.HttpUrlConnector.apply(HttpUrlConnector.java:285)
    at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:252)
    ... 12 more
sargue commented 7 years ago

Hi.

The error seems related to a mismatch on the JAX-RS dependency. You said that you've added all the jars. Are you deploying the dependencies manually or using something like Gradle or Maven? A dependency manager is highly recommended as the JAX-RS runtime uses quite a few dependencies itself.

saikiranvadlakonda commented 7 years ago

Yeah! I'm using gradle, actually it's a gradle project. Below is my gradle dependencies.

dependencies {
  compile 'it.swim:swim-api-java:0.1.20170130085755'
  compile 'it.swim:swim-server-java:0.1.20170206011444'
  compile group: 'com.ganyo', name: 'gcm-server', version: '1.0.2'

  // https://mvnrepository.com/artifact/com.sun.jersey/jersey-client
compile group: 'com.sun.jersey', name: 'jersey-client', version: '1.18.1'
  // https://mvnrepository.com/artifact/com.sun.jersey/jersey-core
compile group: 'com.sun.jersey', name: 'jersey-core', version: '1.18.1'
// https://mvnrepository.com/artifact/com.sun.jersey.contribs/jersey-multipart
compile group: 'com.sun.jersey.contribs', name: 'jersey-multipart', version: '1.18.1'

  // https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api
compile group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0'

  // https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-client
compile group: 'org.glassfish.jersey.core', name: 'jersey-client', version: '2.25.1'

compile 'net.sargue:mailgun:1.3.2'

  testCompile 'org.testng:testng:6.9.10'
}

Thank you for quick response.

sargue commented 7 years ago

I can see that you have a Jersey 1.x dependency on your gradle definition. This project uses Jersey 2.x.

You have both a 1.x and 2.x version of Jersey client in your definition. That won't work correctly. Does your project need Jersey 1.x?

saikiranvadlakonda commented 7 years ago

Initially I was reading mailgun documentation, so that's why I've added those. Well I'll remove all those and check it out.

sargue commented 7 years ago

If you are not using JAX-RS/Jersey on your own project just don't add any dependency on jersey or jax-rs. I count 5 dependencies that you can remove.

saikiranvadlakonda commented 7 years ago

Happy to say, It's working fine now. I've another doubt, how to send multiple to:saikiran, satish, ramesh using this API.

sargue commented 7 years ago

Great to be able to help.

As for your specific question: you just repeat the .to("recipient@example.com") invocation as many times as you want.

saikiranvadlakonda commented 7 years ago

Hi, I would like to do other operations like retrieving stored messages, how could we achieve these type of operations. Could you kindly guide me.

sargue commented 7 years ago

This library is designed just to send messages. No other operations from the Mailgun API are supported or planned.