GithubHelp home page GithubHelp logo

Response Status 400 about mailjet-apiv3-java HOT 8 CLOSED

mailjet avatar mailjet commented on May 27, 2024
Response Status 400

from mailjet-apiv3-java.

Comments (8)

anaice avatar anaice commented on May 27, 2024

PS.: I forgot to mention: my development tomcat is running with SSL using a self signed cert. Previously I had to import your GoDaddy cert (*.mailjet.com) into my keystore due a handshake problem.

from mailjet-apiv3-java.

WeshGuillaume avatar WeshGuillaume commented on May 27, 2024

Hey @anaice !

Can you try to paste the output of the debug mode here ?
To enable it: client.setDebug(MailjetClient.VERBOSE_DEBUG)

Thanks 👍

from mailjet-apiv3-java.

anaice avatar anaice commented on May 27, 2024

Hi @GuillaumeBadi

Nice hint.

=== HTTP Request ===
POST https://api.mailjet.com/v3/send
Accept-Charset:UTF-8
user-agent:mailjet-apiv3-java/v3.0.0
Content-Type:application/json
Accept:application/json
=== HTTP Response ===
Receive url: https://api.mailjet.com/v3/send
Status: 400
null:HTTP/1.1 400 Invalid characters detected
Date:Tue, 01 Mar 2016 11:25:17 GMT
Vary:Accept-Encoding
Content-Length:0
Content-Type:text/html
Connection:keep-alive
Server:nginx
Content:
null

I just noted my:

email = new MailjetRequest(Email.resource) .property(Email.FROMNAME, "Teste")

is actually

email = new MailjetRequest(Email.resource) .property(Email.FROMNAME, "Equipe NetCaçambas")

So i think the problem here is my ç character. When I remove it my email is sent.

Same code running with JUnit (using ç character):

=== HTTP Request ===
POST https://api.mailjet.com/v3/send
Accept-Charset:UTF-8
user-agent:mailjet-apiv3-java/v3.0.0
Content-Type:application/json
Accept:application/json
=== HTTP Response ===
Receive url: https://api.mailjet.com/v3/send
Status: 200
null:HTTP/1.1 200 OK
Date:Tue, 01 Mar 2016 11:35:13 GMT
Content-Length:90
Connection:keep-alive
Content-Type:application/json
Server:nginx
Content:
{ "Sent" : [{ "Email" : "[email protected]", "MessageID" : 19421806538239714 }] }

Merci Beaucoup!

from mailjet-apiv3-java.

WeshGuillaume avatar WeshGuillaume commented on May 27, 2024

I guess it is a matter of encoding. the default String encoding in Java is utf16. It needs to be converted in utf8. I still don't know why but it works on my local environment, I cant reproduce the error locally.

from mailjet-apiv3-java.

anaice avatar anaice commented on May 27, 2024

You are right @GuillaumeBadi

When I force a conversion and it works.

`
(...)

        MailjetClient client = new MailjetClient("_", "_");
        client.setDebug(MailjetClient.VERBOSE_DEBUG);

        MailjetRequest email;
        JSONArray recipients;
        MailjetResponse response;

        recipients = new JSONArray()
                        .put(new JSONObject().put(Contact.EMAIL, "[email protected]"));

        try {
            email = new MailjetRequest(Email.resource)
            .property(Email.FROMNAME, convertToUTF8("Equipe NetCaçambas"))
            .property(Email.FROMEMAIL, "[email protected]")
            .property(Email.SUBJECT, "Testando")
            .property(Email.HTMLPART, convertToUTF8("<html> <body> <h1>Teste</h1> <p>NetCaçambas Software</p></body> </html>"))
            .property(Email.RECIPIENTS, recipients);
            response = client.post(email);
        } catch (MailjetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

(...)

/**
 * convert from internal Java String format -> UTF-8
 * From: https://fabioangelini.wordpress.com/2011/08/04/converting-java-string-fromto-utf-8/
 * @param s
 * @return
 */
public static String convertToUTF8(String s) {
    String out = null;
    try {
        out = new String(s.getBytes("UTF-8"), "ISO-8859-1");
    } catch (java.io.UnsupportedEncodingException e) {
        return null; // =~
    }
    return out;
}

`

Debug Msgs:

=== HTTP Request ===
POST https://api.mailjet.com/v3/send
Accept-Charset:UTF-8
user-agent:mailjet-apiv3-java/v3.0.0
Content-Type:application/json
Accept:application/json
=== HTTP Response ===
Receive url: https://api.mailjet.com/v3/send
Status: 200
null:HTTP/1.1 200 OK
Date:Tue, 01 Mar 2016 16:37:14 GMT
Content-Length:90
Content-Type:application/json
Connection:keep-alive
Server:nginx
Content:
{ "Sent" : [{ "Email" : "[email protected]", "MessageID" : 20547703824686000 }] }

I just don't get why my JUnit works without any conversion.
Anyway, I will work with conversions to use the api.

Thank you!

from mailjet-apiv3-java.

WeshGuillaume avatar WeshGuillaume commented on May 27, 2024

It seems to be an issue only from webapps.

Thanks for finding this. I am going to add it in the readme ✈️

from mailjet-apiv3-java.

WeshGuillaume avatar WeshGuillaume commented on May 27, 2024

Hey, you might be interested: https://github.com/mailjet/mailjet-apiv3-java/releases/tag/v3.1.0 :)

from mailjet-apiv3-java.

anaice avatar anaice commented on May 27, 2024

Coool =D
Thanks.

from mailjet-apiv3-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.