3 Replies Latest reply on May 2, 2017 3:29 PM by Brian Parker

    Incoporating MailGun into a JBoss/Wildfly standalone war

    Brian Parker Newbie

      I am attempting to integrate MailGun into a jsp application . We use standalone.xml and wars.

       

      I need to import the following:

       

      import com.sun.jersey.api.client.Client;
      import com.sun.jersey.api.client.ClientResponse;
      import com.sun.jersey.api.client.ClientResponse.Status;
      import com.sun.jersey.api.client.WebResource;
      import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
      import com.sun.jersey.core.util.MultivaluedMapImpl;

       

      I have download a few different jersey jars but I have not been able to place them in the correct spot.

       

      I have tried adding them the the WEB-INF/lib of the specific war and that did not work.

       

      I have tried adding them to an existing module and that did not work either.

       

      Has anyone successfully integrated MailGun into a jasp application?

        • 1. Re: Incoporating MailGun into a JBoss/Wildfly standalone war
          Tomaz Cerar Master

          WEB-INF/lib is correct location for putting jars.

           

          and according to docs from mailgun Libraries — Mailgun API  documentation

          you need to add

           

          jersey-client.jar (version ~ 1.17 - 1.18.1)

          jersey-core.jar (version ~ 1.17 - 1.18.1)

          jersey-multipart.jar (version ~ 1.17 - 1.18.1)

          • 2. Re: Incoporating MailGun into a JBoss/Wildfly standalone war
            Brian Parker Newbie

            Thanks Tomaz.

             

            I had tried putting  jersey-bundle.jar as I found a suggestion that this would handle all the dependencies but it did not work.

             

            I added jersey-client and core versions 1.17 but could not find a jersey-multipart 1.17 . I did find a jersey-multipart.jar and added that.

             

            When I start JBoss AS 7 I get the following warnings. I do not get them in Wildfly 9:

            08:58:35,434 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$App' for service type 'javax.ws.rs.ext.MessageBodyReader'

            08:58:35,434 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$Text' for service type 'javax.ws.rs.ext.MessageBodyReader'

            08:58:35,435 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General' for service type 'javax.ws.rs.ext.MessageBodyReader'

            08:58:35,435 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$App' for service type 'javax.ws.rs.ext.MessageBodyReader'

            08:58:35,435 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$Text' for service type 'javax.ws.rs.ext.MessageBodyReader'

            08:58:35,450 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General' for service type 'javax.ws.rs.ext.MessageBodyReader'

            08:58:35,450 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$App' for service type 'javax.ws.rs.ext.MessageBodyReader'

            08:58:35,451 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$Text' for service type 'javax.ws.rs.ext.MessageBodyReader'

            08:58:35,454 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General' for service type 'javax.ws.rs.ext.MessageBodyReader'

            08:58:35,454 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.SourceProvider$StreamSourceReader' for service type 'javax.ws.rs.ext.MessageBodyReader'

            08:58:35,454 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.SourceProvider$SAXSourceReader' for service type 'javax.ws.rs.ext.MessageBodyReader'

            08:58:35,455 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.SourceProvider$DOMSourceReader' for service type 'javax.ws.rs.ext.MessageBodyReader'

            08:58:35,455 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$App' for service type 'javax.ws.rs.ext.MessageBodyReader'

            08:58:35,455 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$Text' for service type 'javax.ws.rs.ext.MessageBodyReader'

            08:58:35,456 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$General' for service type 'javax.ws.rs.ext.MessageBodyReader'

            08:58:35,456 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$App' for service type 'javax.ws.rs.ext.MessageBodyWriter'

            08:58:35,457 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$Text' for service type 'javax.ws.rs.ext.MessageBodyWriter'

            08:58:35,457 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General' for service type 'javax.ws.rs.ext.MessageBodyWriter'

            08:58:35,457 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$App' for service type 'javax.ws.rs.ext.MessageBodyWriter'

            08:58:35,458 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$Text' for service type 'javax.ws.rs.ext.MessageBodyWriter'

            08:58:35,458 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General' for service type 'javax.ws.rs.ext.MessageBodyWriter'

            08:58:35,458 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$App' for service type 'javax.ws.rs.ext.MessageBodyWriter'

            08:58:35,459 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$Text' for service type 'javax.ws.rs.ext.MessageBodyWriter'

            08:58:35,459 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General' for service type 'javax.ws.rs.ext.MessageBodyWriter'

            08:58:35,459 WARN  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015893: Encountered invalid class name 'com.sun.jersey.core.impl.provider.entity.SourceProvider$SourceWriter' for service type 'javax.ws.rs.ext.MessageBodyWriter'

             

            and then when I try the MailGun jsp page I get the following error in both JBoss 7 and Wildfly 9.

             

            08:59:51,295 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/webrate].[jsp]] (http-/0.0.0.0:8101-1) JBWEB000236: Servlet.service() for servlet jsp threw exception: org.apache.jasper.JasperException: JBWEB004062: Unable to compile class for JSP:

             

             

            JBWEB004060: An error occurred at line: 11 in the jsp file: /testmail.jsp

            Client cannot be resolved to a type

            8: <%@ page import="com.sun.jersey.core.util.MultivaluedMapImpl.*" %>

            9:

            10: <%

            11: Client client = Client.create();

            12: client.addFilter(new HTTPBasicAuthFilter("api",   "key-15b5efa5d0c9cf5c4fa5c9ab66b83bb0"));

            13: WebResource webResource =  client.resource("https://api.mailgun.net/v3/mg.emco.ca/messages");

            14:

             

             

             

             

            JBWEB004060: An error occurred at line: 11 in the jsp file: /testmail.jsp

            Client cannot be resolved

            8: <%@ page import="com.sun.jersey.core.util.MultivaluedMapImpl.*" %>

            9:

            10: <%

            11: Client client = Client.create();

            12: client.addFilter(new HTTPBasicAuthFilter("api",   "key-15b5efa5d0c9cf5c4fa5c9ab66b83bb0"));

            13: WebResource webResource =  client.resource("https://api.mailgun.net/v3/mg.emco.ca/messages");

            14:

             

             

             

             

            JBWEB004060: An error occurred at line: 12 in the jsp file: /testmail.jsp

            HTTPBasicAuthFilter cannot be resolved to a type

            9:

            10: <%

            11: Client client = Client.create();

            12: client.addFilter(new HTTPBasicAuthFilter("api",   "key-15b5efa5d0c9cf5c4fa5c9ab66b83bb0"));

            13: WebResource webResource =  client.resource("https://api.mailgun.net/v3/mg.emco.ca/messages");

            14:

            15: MultivaluedMapImpl formData = new MultivaluedMapImpl();

             

             

             

             

            JBWEB004060: An error occurred at line: 13 in the jsp file: /testmail.jsp

            WebResource cannot be resolved to a type

            10: <%

            11: Client client = Client.create();

            12: client.addFilter(new HTTPBasicAuthFilter("api",   "key-15b5efa5d0c9cf5c4fa5c9ab66b83bb0"));

            13: WebResource webResource =  client.resource("https://api.mailgun.net/v3/mg.emco.ca/messages");

            14:

            15: MultivaluedMapImpl formData = new MultivaluedMapImpl();

            16: formData.add("from", "info@mg.emco.ca");

             

             

             

             

            JBWEB004060: An error occurred at line: 15 in the jsp file: /testmail.jsp

            MultivaluedMapImpl cannot be resolved to a type

            12: client.addFilter(new HTTPBasicAuthFilter("api",   "key-15b5efa5d0c9cf5c4fa5c9ab66b83bb0"));

            13: WebResource webResource =  client.resource("https://api.mailgun.net/v3/mg.emco.ca/messages");

            14:

            15: MultivaluedMapImpl formData = new MultivaluedMapImpl();

            16: formData.add("from", "info@mg.emco.ca");

            17: formData.add("to", "brian@wisl.com");

            18: formData.add("subject", "Hello");

             

             

             

             

            JBWEB004060: An error occurred at line: 15 in the jsp file: /testmail.jsp

            MultivaluedMapImpl cannot be resolved to a type

            12: client.addFilter(new HTTPBasicAuthFilter("api",   "key-15b5efa5d0c9cf5c4fa5c9ab66b83bb0"));

            13: WebResource webResource =  client.resource("https://api.mailgun.net/v3/mg.emco.ca/messages");

            14:

            15: MultivaluedMapImpl formData = new MultivaluedMapImpl();

            16: formData.add("from", "info@mg.emco.ca");

            17: formData.add("to", "brian@wisl.com");

            18: formData.add("subject", "Hello");

             

             

             

             

            JBWEB004060: An error occurred at line: 22 in the jsp file: /testmail.jsp

            apiResponse cannot be resolved to a variable

            19: formData.add("text", "Testing some Mailgun awesomness!");

            20:

            21:

            22: return  apiResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, formData).toString();

            23:

            24: %>

             

             

             

             

            JBWEB004060: An error occurred at line: 22 in the jsp file: /testmail.jsp

            MediaType.APPLICATION_FORM_URLENCODED cannot be resolved to a type

            19: formData.add("text", "Testing some Mailgun awesomness!");

            20:

            21:

            22: return  apiResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, formData).toString();

            23:

            24: %>

             

             

             

             

            JBWEB004060: An error occurred at line: 22 in the jsp file: /testmail.jsp

            ClientResponse cannot be resolved to a type

            19: formData.add("text", "Testing some Mailgun awesomness!");

            20:

            21:

            22: return  apiResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, formData).toString();

            23:

            24: %>

             

             

             

             

            JBWEB004211: Stacktrace:

              at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

              at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:69) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

              at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:447) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

              at org.apache.jasper.compiler.Compiler.compile(Compiler.java:361) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

              at org.apache.jasper.compiler.Compiler.compile(Compiler.java:339) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

              at org.apache.jasper.compiler.Compiler.compile(Compiler.java:326) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

              at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:606) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

              at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

              at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:309) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

              at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:242) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

              at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final.jar:1.0.2.Final]

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

              at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-8.0.0.Alpha1-SNAPSHOT.jar:8.0.0.Alpha1-SNAPSHOT]

              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:920) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

              at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0]

             

            The actual jsp page is:

             

            <%@ page language="java" import="com.ibm.redback.redbeans.*, javax.servlet.http.*" %>

            <%@ page isThreadSafe="false" import="java.util.*" %>

            <%@ page import="com.sun.jersey.api.client.Client.*" %>

            <%@ page import="com.sun.jersey.api.client.ClientResponse.*" %>

            <%@ page import="com.sun.jersey.api.client.ClientResponse.Status.*" %>

            <%@ page import="com.sun.jersey.api.client.WebResource.*" %>

            <%@ page import="com.sun.jersey.api.client.filter.HTTPBasicAuthFilter.*" %>

            <%@ page import="com.sun.jersey.core.util.MultivaluedMapImpl.*" %>

            <%

              Client client = Client.create();

              client.addFilter(new HTTPBasicAuthFilter("api",   "key-15b5efa5d0c9cf5c4fa5c9ab66b83bb0"));

              WebResource webResource =  client.resource("https://api.mailgun.net/v3/mg.emco.ca/messages");

             

              MultivaluedMapImpl formData = new MultivaluedMapImpl();

              formData.add("from", "info@mg.emco.ca");

              formData.add("to", "brian@wisl.com");

              formData.add("subject", "Hello");

              formData.add("text", "Testing some Mailgun awesomness!");

             

              return  apiResponse = webResource.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, formData).toString();

             

            %>

            • 3. Re: Incoporating MailGun into a JBoss/Wildfly standalone war
              Brian Parker Newbie

              I followed the link from MailGun and downlaoded the Jersey 1.19.1 zip archive. The then placed all of the jars from both the lib and contribs directories from this zip file in the WEB-INF/lib directory and it worked.

               

              I am sure there are more jars than I need and I may go about removing them one by one to see.

               

              Thanks for nudge from your earlier response Tomaz.