I'm having trouble using the javax.mail package on AWS Lambda.
When trying to get the content of an email, the getContent() method returns a MimeMultipart object when run locally. When run mounted to the AWS lambda java8 docker image, it returns IMAPInputStream.
I've seen solutions to this that involve setting the class loader on the current thread like so: Thread.currentThread().setContextClassLoader(this.class.getClassLoader());
However, this did not work for me. The classloader when running locally differs from the classloader when running against the lambda java8 docker image.
Local: sun.misc.Launcher$AppClassLoader
Docker: java.net.URLClassLoader
I tried explicitly loading the class using the system class loader sun.misc.Launcher$AppClassLoader like this:
Class c = java.lang.ClassLoader.getSystemClassLoader().loadClass("helpers.MailReader");
MailReader mail = (MailReader)c.newInstance();
This works fine when run locally, but again fails against the docker image with this:
java.lang.ClassNotFoundException: helpers.MailReader
So there is something different about the system class loader across the environments.
I don't know that much about Java, and it seems like I'm just missing something simple and making this more complicated than it is.
What could be the difference in environments that could produce this?
EDIT: Debug output from javax.activation.debug:
MailcapCommandMap: load HOME
new MailcapFile: file /home/sbx_user1051/.mailcap
MailcapCommandMap: load SYS
new MailcapFile: file /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-1.b16.32.amzn1.x86_64/jre/lib/mailcap
MailcapCommandMap: load JAR
MailcapCommandMap: getResources
MailcapCommandMap: URL file:/var/task/META-INF/mailcap
new MailcapFile: InputStream
parse: text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain
Type: text/plain
Command: content-handler, Class: com.sun.mail.handlers.text_plain
parse: text/html;; x-java-content-handler=com.sun.mail.handlers.text_html
Type: text/html
Command: content-handler, Class: com.sun.mail.handlers.text_html
parse: text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml
Type: text/xml
Command: content-handler, Class: com.sun.mail.handlers.text_xml
parse: multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed; x-java-fallback-entry=true
Type: multipart/*
Command: content-handler, Class: com.sun.mail.handlers.multipart_mixed
parse: message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822
Type: message/rfc822
Command: content-handler, Class: com.sun.mail.handlers.message_rfc822
MailcapCommandMap: successfully loaded mailcap file from URL: file:/var/task/META-INF/mailcap
MailcapCommandMap: load DEF
new MailcapFile: InputStream
parse: image/gif;; x-java-view=com.sun.activation.viewers.ImageViewer
Type: image/gif
Command: view, Class: com.sun.activation.viewers.ImageViewer
parse: image/jpeg;; x-java-view=com.sun.activation.viewers.ImageViewer
Type: image/jpeg
Command: view, Class: com.sun.activation.viewers.ImageViewer
parse: text/*;; x-java-view=com.sun.activation.viewers.TextViewer
Type: text/*
Command: view, Class: com.sun.activation.viewers.TextViewer
parse: text/*;; x-java-edit=com.sun.activation.viewers.TextEditor
Type: text/*
Command: edit, Class: com.sun.activation.viewers.TextEditor
Merging commands for type text/*
MailcapCommandMap: successfully loaded mailcap file: /META-INF/mailcap.default
MailcapCommandMap: createDataContentHandler for multipart/alternative
search DB #1
search DB #2
search fallback DB #1
got content-handler
class com.sun.mail.handlers.multipart_mixed
Can't load DCH com.sun.mail.handlers.multipart_mixed; Exception: java.lang.ClassNotFoundException: com/sun/mail/handlers/multipart_mixed
search fallback DB #2
No solutions I found online related to this have helped
My code is:
File file = new File( "T:\\sub1\\15a12f0103135510.jpg");
long lastModified = file.lastModified();
System.out.println( "last modified: " + lastModified);
System.out.println( "done: " + file.exists());
Last modified returns 0. file.exists returns false. However, I can access and open the file through windows explorer, no problem. Accessing the network share directly doesn't work either (in code). Tried smb - shows errors too. I am the admin user on the machine. What could possibly be the reason? what can I check?
if I do the following:
URL url = new URL( "file://host/share/sub1/15a12f0103135510.jpg");
url.openStream();
I get the following error:
java.io.IOException: sun.net.ftp.FtpProtocolException: Welcome message: 501 Proxy unable to contact ftp server
at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:308)
at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:400)
at java.net.URL.openStream(URL.java:1045)
at apiteest.ApiTest.main(ApiTest.java:24)
Caused by: sun.net.ftp.FtpProtocolException: Welcome message: 501 Proxy unable to contact ftp server
at sun.net.ftp.impl.FtpClient.connect(FtpClient.java:1022)
at sun.net.ftp.impl.FtpClient.connect(FtpClient.java:1005)
at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:294)
... 3 more
Suppressed: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:210)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
at sun.net.ftp.impl.FtpClient.readServerResponse(FtpClient.java:420)
at sun.net.ftp.impl.FtpClient.readReply(FtpClient.java:497)
at sun.net.ftp.impl.FtpClient.issueCommand(FtpClient.java:539)
at sun.net.ftp.impl.FtpClient.close(FtpClient.java:1131)
at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:303)
... 3 more
Exception in thread "main" java.io.IOException: sun.net.ftp.FtpProtocolException: Welcome message: 501 Proxy unable to c
ontact ftp server
Update:
the code works when executed from powershell but not when executed from powershell started as administrator (the same user though). it also doesn't work from a service, even though the service runs under the same user. Why is it so? And how to enable the share (and possibly the mapped drive) for the service?
I have a problem with the URL where I am trying to catch my DB.
Here is the code:
TransactionalGraph graph = new OrientGraph("/home/danicroque/Escritorio/demoCroque", "admin", "admin");
Here is the error:
run:
may 20, 2016 2:49:46 AM com.orientechnologies.common.log.OLogManager log
INFORMACIÓN: OrientDB auto-config DISKCACHE=907MB (heap=846MB os=3.802MB disk=447.700MB)
Exception in thread "main" com.orientechnologies.orient.core.exception.ODatabaseException: Error on opening database '/home/danicroque/Escritorio/demoCroque'
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.<init>(ODatabaseDocumentTx.java:204)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.<init>(ODatabaseDocumentTx.java:168)
at com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.openOrCreate(OrientBaseGraph.java:1818)
at com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.<init>(OrientBaseGraph.java:161)
at com.tinkerpop.blueprints.impls.orient.OrientTransactionalGraph.<init>(OrientTransactionalGraph.java:102)
at com.tinkerpop.blueprints.impls.orient.OrientTransactionalGraph.<init>(OrientTransactionalGraph.java:98)
at com.tinkerpop.blueprints.impls.orient.OrientGraph.<init>(OrientGraph.java:103)
at pruebatodook.PruebaTodoOk.run(PruebaTodoOk.java:23)
at pruebatodook.PruebaTodoOk.main(PruebaTodoOk.java:16)
Caused by: com.orientechnologies.orient.core.exception.OConfigurationException: Error in database URL: the engine was not specified. Syntax is: <engine>:<db-type>:<db-name>[?<db-param>=<db-value>[&]]*. URL was: /home/danicroque/Escritorio/demoCroque
at com.orientechnologies.orient.core.Orient.loadStorage(Orient.java:441)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.<init>(ODatabaseDocumentTx.java:187)
... 8 more
may 20, 2016 2:49:46 AM com.orientechnologies.common.log.OLogManager log
INFORMACIÓN: OrientDB Engine shutdown complete
/home/danicroque/.cache/netbeans/8.1/executor-snippets/run.xml:53: Java returned: 1
BUILD FAILED (total time: 1 second)
I am trying to run this code in Ubuntu with Netbeans. The name of the DB is demoCroque and the URL is /home/Escritorio/demoCroque.
How can I solve this problem?
It looks like your URL is formed incorrectly.
See here: http://orientdb.com/docs/2.2/Console-Command-Connect.html
<database-url> Defines the URL of the database you want to connect to.
It uses the format <mode>:<path>
<mode> Defines the mode you want to use in connecting to the database.
It can be PLOCAL or REMOTE.
<path> Defines the path to the database.
Try something like this as your URL:
REMOTE:192.168.1.1/demoCroque
Or
PLOCAL:../home/Escritorio/demoCroque
Edit: for the purpose of testing use a full file path until you know it works correctly, for example:
PLOCAL:C:/projects/myproject/Escritorio/demoCroque
I am working on a java project in which i have to communicate with the ejabberd (create/delete a jabber user etc.. ) xmpp server. From the different suggestions available in the internet I understood that xml rpc one method to achieve that.
I tried to install the mod_xmlrpc as per the suggesions in this thread. Error while starting ejabberd with xml_rpc
But I had failed to start the ejabberd after configuration of mod_xmlrpc. The ejabberd log says,
=ERROR REPORT==== 2015-03-15 20:23:27 ===
C(<0.42.0>:gen_mod:75) : Problem starting the module mod_adhoc for host "example.com"
options: []
exit: {noproc,
{gen_server,call,
[ejabberd_iq_sup,
{start_child,["example.com",mod_adhoc,process_local_iq]},
infinity]}}
=ERROR REPORT==== 2015-03-15 20:23:27 ===
C(<0.42.0>:gen_mod:80) : ejabberd initialization was aborted because a module start failed.
and the erlang log says,
=CRASH REPORT==== 15-Mar-2015::20:23:27 ===
crasher:
initial call: supervisor:ejabberd_listener/1
pid: <0.270.0>
registered_name: []
exception exit: {undef,
[{ejabberd_xmlrpc,socket_type,[],[]},
{ejabberd_listener,'-bind_tcp_ports/0-fun-0-',1,
[{file,"ejabberd_listener.erl"},{line,63}]},
{lists,foreach,2,[{file,"lists.erl"},{line,1323}]},
{ejabberd_listener,init,1,
[{file,"ejabberd_listener.erl"},{line,52}]},
{supervisor,init,1,
[{file,"supervisor.erl"},{line,239}]},
{gen_server,init_it,6,
[{file,"gen_server.erl"},{line,304}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,239}]}]}
in function gen_server:init_it/6 (gen_server.erl, line 328)
ancestors: [ejabberd_sup,<0.42.0>]
messages: []
links: [#Port<0.3747>,<0.234.0>,#Port<0.3744>]
dictionary: []
trap_exit: true
status: running
heap_size: 987
stack_size: 27
reductions: 1215
neighbours:
=SUPERVISOR REPORT==== 15-Mar-2015::20:23:27 ===
Supervisor: {local,ejabberd_sup}
Context: start_error
Reason: {undef,
[{ejabberd_xmlrpc,socket_type,[],[]},
{ejabberd_listener,'-bind_tcp_ports/0-fun-0-',1,
[{file,"ejabberd_listener.erl"},{line,63}]},
{lists,foreach,2,[{file,"lists.erl"},{line,1323}]},
{ejabberd_listener,init,1,
[{file,"ejabberd_listener.erl"},{line,52}]},
{supervisor,init,1,[{file,"supervisor.erl"},{line,239}]},
{gen_server,init_it,6,
[{file,"gen_server.erl"},{line,304}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,239}]}]}
Offender: [{pid,undefined},
{name,ejabberd_listener},
{mfargs,{ejabberd_listener,start_link,[]}},
{restart_type,permanent},
{shutdown,infinity},
{child_type,supervisor}]
Since I am a newbie to the ejabberd & erlang world I am finding it hard to track the root cause. Please help me to identify the root cause of this crash.
BTW is there any other method for communicating with ejabberd (create/delete a jabber user etc..) from java services ?
The erlang log says that it can't find the function socket_type with no argument in the module ejabberd_xmlrpc. As it is a valid call, and both the module and function exist in the application ejabberd, this means that something went wrong during installation (compilation fails, wrong path ???)
This question already has answers here:
Steps needed to use MySQL database with Play framework 2.0
(10 answers)
Closed 9 years ago.
There is my configure :
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql:root:play2test" //Cannot connect to database [default] -> play mark this line
db.default.user=root
db.default.pass=123456
I already created play2test.mwb with MySql-workbench, i have tried other way like :
db.default.driver="com.mysql.jdbc.Driver"
db.default.url="jdbc:mysql:root:play2test"
db.default.user="root"
db.default.pass="123456"
but allways get this error : db has type STRING rather than OBJECT
in terminal :
[error] c.j.b.h.AbstractConnectionHook - Failed to obtain initial connection Sleeping for 0ms and trying again. Attempts left: 0. Exception: null
[error] application -
! #6epj0nb4d - Internal server error, for request [GET /] ->
play.api.Configuration$$anon$1: Configuration error [Cannot connect to database [default]]
at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:71) ~[play_2.9.1.jar:2.0.4]
at play.api.Configuration.reportError(Configuration.scala:258) ~[play_2.9.1.jar:2.0.4]
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:249) ~[play_2.9.1.jar:2.0.4]
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:240) ~[play_2.9.1.jar:2.0.4]
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194) ~[scala-library.jar:0.11.3]
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194) ~[scala-library.jar:0.11.3]
Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql:root:play2test
at java.sql.DriverManager.getConnection(DriverManager.java:640) ~[na:1.6.0_27]
at java.sql.DriverManager.getConnection(DriverManager.java:200) ~[na:1.6.0_27]
at com.jolbox.bonecp.BoneCP.obtainRawInternalConnection(BoneCP.java:256) ~[bonecp.jar:0.7.1.RELEASE]
at com.jolbox.bonecp.BoneCP.<init>(BoneCP.java:305) ~[bonecp.jar:0.7.1.RELEASE]
at com.jolbox.bonecp.BoneCPDataSource.maybeInit(BoneCPDataSource.java:150) ~[bonecp.jar:0.7.1.RELEASE]
at com.jolbox.bonecp.BoneCPDataSource.getConnection(BoneCPDataSource.java:112) ~[bonecp.jar:0.7.1.RELEASE]
I tried to uncomment at
ebean.default="models.*"
and added the sbt dependency:
"mysql" % "mysql-connector-java" % "5.1.21"
But it did'nt work :((((
So how can i solved it :(.
Sry if my english is bad
Try following way:
db.default.url="jdbc:mysql://your_server_address:3306/play2test"
db.default.driver="com.mysql.jdbc.Driver"
db.default.user=root
db.default.pass="123456"
db.default.host=your_server_address
Your connection url is formatted wrong. Try using:
db.default.url="jdbc:mysql://localhost/play2test"
And make sure you set the product dependency in /project/Build.scala, change the 5.1.25 to whatever version your mysql connector is
val appDependencies = Seq(
"mysql" % "mysql-connector-java" % "5.1.25"
)
And in the same file, make sure that this line is not commented
ebean.default="models.*"
The url should be something like:
db.default.url="jdbc:mysql://your_server_address/play2test"