mailjet / mailjet-apiv3-java

[API v3] Mailjet Java API Wrapper
https://dev.mailjet.com
MIT License
66 stars 36 forks source link

MailjetResponse not working at all #44

Closed sicoa closed 8 years ago

sicoa commented 8 years ago

Greetings We have been testing your new api implementation, and there seems to be a deep issue. I have attached a screenshot of my simple code and debug screen for more details. Description: client = new MailjetClient("mycreds", "mycreds"); request = new MailjetRequest(Contact.resource); response = client.get(request); ---> This prints out the correct response to the console

What is clearly the response issue, is that it carries out only the response status and not the data JSON part. It may print it on the console, but it does not return it. I cannot access it at all. I have tried your own testing examples and they do not work as well. They also have some minor mistakes like semicolons and exception declarations missing, just details (in all of http://dev.mailjet.com/guides/?java#the-limit-filter). Thank you for any help SicoaDev

capture

WeshGuillaume commented 8 years ago

Hey @sicoa !

Thanks for using Mailjet (and for mentionning out the typos in the documentation ;)).

I am not sure I get your issue. I have this code showing how to use the MailjetResponse if it helps. If not please let me know for more investigations:


/**
 *
 * @author Guillaume Badi - Mailjet
 */
public class Main {

    public static void main(String[] args) throws MailjetException {
        MailjetClient client = new MailjetClient("______", "______");

        MailjetRequest request;
        MailjetResponse response;
        JSONArray contacts;

        request = new MailjetRequest(Contact.resource)
                    .filter(Contact.LIMIT, 15);
        response = client.get(request);
        System.out.println(response.getStatus());
        contacts = response.getData();

        System.out.println(contacts);

        for(int n = 0; n < contacts.length(); n++)
        {
            JSONObject contact = contacts.getJSONObject(n);
            System.out.println(contact.getString("Email"));
        }
    }
}

/*

200
[{"Name":"","LastActivityAt":"2015-08-26T08:08:59Z","Email":"email@mailjet.com","LastUpdateAt":"","UnsubscribedAt":"", (...)]
testdelete+1440576527@mailjet.com
email@mailjet.com
email+testurl@mailjet.com
email+testurl@gmail.com
email+testurl2@gmail.com
email+testurl2@mailjet.com
email+testurl3@mailjet.com
email+testurl4@mailjet.com

*/
sicoa commented 8 years ago

Thank you for the quick response Mr GuillaumeBadi! I have tried your implementation with no success. I get the same error as before: JSONObject does not recognize Data part and response is still the same as the screenshot. Only has the Status part and the rest null even though "response = client.get(request);" prints the correct results at the console.. Any thoughts would be more than welcome and maybe you could specify what libraries you use. My imports in case anything is wrong:

import com.mailjet.client.errors.MailjetException;

import java.io.UnsupportedEncodingException; import java.net.MalformedURLException;

import org.json.JSONArray; import org.json.JSONObject;

import com.mailjet.client.MailjetClient; import com.mailjet.client.MailjetRequest; import com.mailjet.client.MailjetResponse; import com.mailjet.client.resource.Contact;

{"Total":6,"Data":[{"LastActivityAt":"2015-07-21T10:35:51Z","UnsubscribedBy":"","IsSpamCom................."UnsubscribedAt":"","Name":""}],"Count":6} 200 Νov 30, 2015 2:50:08 ΜΜ org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [SicoaRest] in context with path [/Mailjetv1] threw exception [org.json.JSONException: JSONObject["Data"] not found.] with root cause org.json.JSONException: JSONObject["Data"] not found. at org.json.JSONObject.get(JSONObject.java:475) at org.json.JSONObject.getJSONArray(JSONObject.java:622) at com.mailjet.client.MailjetResponse.getData(MailjetResponse.java:32) at com.sicoa.mailjet.rest.Test.testList(Test.java:58) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161) at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99) at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389) at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347) at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102) at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:308) at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) 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:267) at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:291) at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1140) at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:403) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:386) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:334) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source)

WeshGuillaume commented 8 years ago

Actually, you shouldn't have to use anymore

import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;

Did you clone/download the last version of the wrapper ?

Best, Guillaume

sicoa commented 8 years ago

Yes, The ones i use are the same as in here: client-1.0-SNAPSHOT.jar and client-1.0-SNAPSHOT-sources.jar

The client part needs them in my project. When i trace the source of my MailjetClient it does derive from client-1.0-SNAPSHOT.jar ..

Thank you once more for the directions given Mr Guillaume Badi Remaining yours

WeshGuillaume commented 8 years ago

Ow I see, I think the jars in /target did not update with the release so there are not up to date with the code. Let me fix that

sicoa commented 8 years ago

Goodmorning have you by any chance uploaded the correct ones? I tried them just now and they still do not work as expected.. Client still needs the extra exception handlers. Thank you

WeshGuillaume commented 8 years ago

Hey ! Sorry for the delay.

Rebuilding the jar lead me to a fix I needed to investigate on. When you provide invalid credentials, it wont send you an error. Anyway, the target is now 3.0.0. Please keep me up to date :)

Best, Guillaume. :airplane:

sicoa commented 8 years ago

Greetings once more Mr Guillaume Badi I appreciate a lot your immediate response and all seems to be working fine indeed. I will carry on the tests as i progress and keep you informed of any issues that may arise.

One last request: Because here at fmjet.com we have been integrating your API in our FileMaker solutions, and have been givving it a lot of effort and nice work, we would be grateful if you list us in your integration section.

Remaining yours SicoaDev

arnaudbreton commented 8 years ago

Hey @sicoa,

I lead API & Developers Relations here at Mailjet. I'm glad to read that you have successfully integrated with our API and see this issue solved.

We would be more than happy to feature your work to our developers community. Could you please send us more information about it (what you do with it, how you integrated it, etc) to api@mailjet.com?

Have a nice day, Arnaud.