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
Related
I'm trying to write a Java application for digitally signing documents using a bit4Id miniLector token.
I'm in a Linux development environment.
The token is correctly installed, I can sign my documents also with the app downloaded from the manufacturer, but I have to write a new one for other purposes. The driver used is located at
/usr/lib/x86_64-linux-gnu/engines-1.1/pkcs11.so
I'm stuck with this error:
/usr/lib/jvm/jdk1.8.0_111/bin/java ...
Exception in thread "main" java.security.ProviderException: Initialization failed
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:376)
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:103)
at com.itextpdf.samples.signatures.chapter02.C2_01_SignHelloWorld.main
(C2_01_SignHelloWorld.java:83)
Caused by: java.io.IOException: ERROR: C_GetFunctionList == NULL
at sun.security.pkcs11.wrapper.PKCS11.connect(Native Method)
at sun.security.pkcs11.wrapper.PKCS11.<init>(PKCS11.java:138)
at sun.security.pkcs11.wrapper.PKCS11.getInstance(PKCS11.java:151)
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:313)
... 2 more
The provider is listed in $JAVA_HOME/jre/lib/security/java.security file as:
security.provider.10=sun.security.pkcs11.SunPKCS11
The code behaving this way is this:
String configFile = "/opt/bar/cfg/pkcs11.cfg";
Provider provider = new sun.security.pkcs11.SunPKCS11(configFile); <-- line 83
The needed libraries are all imported by my IDE and I have no compile/link errors.
I didn't find this exact type of error in hours of googling.
If you need any further information let me know, any kind help is very appreciated, thanks.
For visual clarity I add all missing information with respect to the original question here below
Updates
Content of the pkcs11.cfg file:
$ cat /opt/bar/cfg/pkcs11.cfg
name="bit4id miniLector-EVO"
library=/usr/lib/x86_64-linux-gnu/engines-1.1/pkcs11.so
Ok, I got it.
The problem is the driver.
Replacing
/usr/lib/x86_64-linux-gnu/engines-1.1/pkcs11.so
with
/opt/Firma4NG/System/Firma4NG_Linux/Firma4/drivers/mu-x64/libbit4xpki.so
that is one of the manufacturer's driver, now I can go further and, for example, dumping all info about the card:
Information for provider SunPKCS11-bit4id miniLector-EVO
Library info:
cryptokiVersion: 2.20
manufacturerID: bit4id srl
flags: 0
libraryDescription: bit4id PKCS#11
libraryVersion: 1.02
...
This question can be closed.
I am using matlabcontrol to start matlab-sessions and everything works fine if i start it from eclipse. A new Matlab-session is opened or, if one is already open&connected, the old one is reactivated.
However, I want to do this via a windows command line that is called from a python program.
If I compile and export this to a .jar-file, it still works, but ONLY if an old, manually started MATLAB session is still open.
my current cmd-command is simply:
java -jar StartmatlabSim.jar
If no session is open, i get the following error in the cmd:
C:\Users\rEngel\Desktop>java -jar StartmatlabSim.jar
Exception in thread "main" java.lang.reflect.InvocationTargetException
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.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: matlabcontrol.MatlabConnectionException: Support code location could not be determined. Could not ge
t path from URI location.
URI Location: jar:rsrc:matlabcontrol-4.1.0.jar!/
URL Location: jar:rsrc:matlabcontrol-4.1.0.jar!/
Code Source: (jar:rsrc:matlabcontrol-4.1.0.jar!/ <no signer certificates>)
Protection Domain: ProtectionDomain (jar:rsrc:matlabcontrol-4.1.0.jar!/ <no signer certificates>)
java.net.URLClassLoader#677327b6
<no principals>
java.security.Permissions#27973e9b (
("java.security.AllPermission" "<all permissions>" "<all actions>")
)
Class Loader: java.net.URLClassLoader#677327b6
Class Loader Class: class java.net.URLClassLoader
at matlabcontrol.Configuration.getSupportCodeLocation(Configuration.java:295)
at matlabcontrol.RemoteMatlabProxyFactory.createProcess(RemoteMatlabProxyFactory.java:289)
at matlabcontrol.RemoteMatlabProxyFactory.requestProxy(RemoteMatlabProxyFactory.java:125)
at matlabcontrol.RemoteMatlabProxyFactory.getProxy(RemoteMatlabProxyFactory.java:144)
at matlabcontrol.MatlabProxyFactory.getProxy(MatlabProxyFactory.java:81)
at StartMatlab.main(StartMatlab.java:14)
... 5 more
EDIT: For some reason, the system seems to treat a manually started session different from a commandline-started session. Strangely, a batch file with only that single command line also works, but not if it is called from python - it must be clicked on or executed from cmd (!?!?!?).
I am totally lost here....
Beeing able to run and launch my MATLAB-sessions is important for me, because I need to include it into a python-program (mosaik), which uses a cmd-command to start java.
If anybody recognizes the issue and knows a fix I would be very grateful.
Thank you®ards,
Robin
P.S.:
The Java-code is:
import matlabcontrol.*;
public class StartMatlab {
public static void main(String[] args)
throws MatlabConnectionException, MatlabInvocationException
{
// create proxy
MatlabProxyFactoryOptions options = new MatlabProxyFactoryOptions.Builder()
.setUsePreviouslyControlledSession(true).setHidden(true)
.build();
MatlabProxyFactory factory = new MatlabProxyFactory(options);
MatlabProxy proxy = factory.getProxy();
// call builtin function
proxy.eval("disp('hello world')");
// close connection
proxy.disconnect();
}
}
Also, I included matlabcontrol-4.1.0.jar to the .jar build path and chose to package the library into the jar file during export.
How can I use Sequel gem to connect to db2 database,
I am trying below command,
connection = Sequel.connect(:adapter => 'jdbc',
:driver => 'com.ibm.db2.jcc.DB2Driver',
:host => 'jdbc:db2://myhostname/50000/dbname',
:user=> 'userid',
:password=>'password')
but still unable to connect,kindly suggest if I am missing on anything. Thanks!
Just for the record: Issue was fixed with:
require 'sequel'
require 'logger'
require 'activerecord-jdbc-adapter'
require 'file path of sqljdbc4.jar'
require 'file path of \db2jcc_license_cisuz.jar'
require 'file path of \db2jcc_license_cu.jar'
require 'file path of \db2jcc.jar'
connection = Sequel.connect(
adapter: "jdbc",
url: "jdbc:db2://xyx.pqr.net:PORT/Databasename:user=username;password=password;",
host: "xyz.net",
port: "11111",
database: "Databasename
)
I am unable to configure org.apache.activemq.ActiveMQSslConnectionFactory in
HermesJMS.It ends up saying an error
Caused by: java.io.IOException: Could not load resource: D:\ActiveMQCertificates\broker.ks
at org.apache.activemq.ActiveMQSslConnectionFactory.getUrlOrResourceAsStream(ActiveMQSslConnectionFactory.java:186)
at org.apache.activemq.ActiveMQSslConnectionFactory.loadClientCredential(ActiveMQSslConnectionFactory.java:158)
at org.apache.activemq.ActiveMQSslConnectionFactory.createKeyManager(ActiveMQSslConnectionFactory.java:142)
at org.apache.activemq.ActiveMQSslConnectionFactory.createTransport(ActiveMQSslConnectionFactory.java:105)
... 51 more
I have the keystore file at D:\ActiveMQCertificates\broker.ks .But the hermes is unable to load the resource.
The config in Hermes is
brokerURL : ssl://localhost:61616
keyStore : D:\ActiveMQCertificates\broker.ks
KeystorePaswword :xxxxx
How to specify the keystore path in Hermes?
Help me in this.
Thanks,
Mahesh
According to the link, try to adding it in JAVA_OPTS
java -Djavax.net.ssl.trustStore= -Djavax.net.ssl.trustStorePassword=xxxxxxxx
It seems the connection factory doesn't know how to handle simple file name. Try creating a new file with the String, then convert the URi to string and pass that as parameter. Found solution here.E.g.:
connectionFactory.setTrustStore(new File("/path/to/store").toURI().toString());
I'm on step 5 of the Using Endpoints in an iOS Client tutorial and when I try to generate all the header and implementation classes for iOS by utilizing the tictactoe-v1-rpc.discovery file it's currently failing with "ERROR: Failed to fetch the api description" (see below)
In the terminal I enter:
ConfusedDeer-mbp:/ ConfusedDeer$
/Users/ConfusedDeer/Library/Developer/Xcode/DerivedData/ServiceGenerator-eoemzskhioxhvgbxjfcwxowhamno/Build/Products/Debug/ServiceGenerator
\ ~/Desktop/tictactoe-v1-rpc.discovery --outputDir
/Users/ConfusedDeer/Desktop/API
===============================================================================
Generation Settings:
Output Directory:
~/Desktop/API
Discovery RPC URL: https://www.googleapis.com/rpc?prettyPrint=false
Flags:
Use service name directory: NO
Remove unknown files: NO
Add 'Generated' directory: NO
Allow rootURL overrides: YES
Loading API File(s):
Fetching / ~/Desktop/tictactoe-v1-rpc.discovery
ERROR: Failed to fetch the api description /
~/Desktop/tictactoe-v1-rpc.discovery, error: Error
Domain=NSURLErrorDomain Code=-1100 "The requested URL was not found on
this server." UserInfo=0x7fec72c2cf30
{NSUnderlyingError=0x7fec72c2c680 "The requested URL was not found on
this server.",
NSErrorFailingURLStringKey=file:///%20~/Desktop/tictactoe-v1-rpc.discovery,
NSErrorFailingURLKey=file:///%20~/Desktop/tictactoe-v1-rpc.discovery,
NSLocalizedDescription=The requested URL was not found on this
server.}
Generating:
Writing:
No changes from what is already on disk.
ConfusedDeer-mbp:/ ConfusedDeer$
After further troubleshooting I was finally able to generate my iOS client libraries!
The command I used to accomplish this was:
/Users/ConfusedDeer/Library/Developer/Xcode/DerivedData/ServiceGenerator-eoemzskhioxhvgbxjfcwxowhamno/Build/Products/Debug/ServiceGenerator /Users/ConfusedDeer/Desktop/tictactoe-v1-rpc.discovery --outputDir /Users/ConfusedDeer/Desktop/API
There were two issues with the original command I was using. I was finally able to locate the issue by placing:
file:///%20~/Desktop/tictactoe-v1-rpc.discovery
In the browser URL and noticed there was a %20, which is a space. Once I removed all the spaces and the tilde (~) and placed the following in the URL
file:///Users/ConfusedDeer/Desktop/tictactoe-v1-rpc.discovery
once the rpc.discovery file appeared in the browser I realized that the google commmand line tool would be able to locate it.
Another issue was the output directory had to be relative (duh!) from where I executed the command in the terminal..
After I ran:
/Users/ConfusedDeer/Library/Developer/Xcode/DerivedData/ServiceGenerator-eoemzskhioxhvgbxjfcwxowhamno/Build/Products/Debug/ServiceGenerator /Users/ConfusedDeer/Desktop/tictactoe-v1-rpc.discovery --outputDir /Users/ConfusedDeer/Desktop/API
in generated the following:
===============================================================================
Generation Settings:
Output Directory: ~/Desktop/API
Discovery RPC URL: https://www.googleapis.com/rpc?prettyPrint=false
Flags:
Use service name directory: NO
Remove unknown files: NO
Add 'Generated' directory: NO
Allow rootURL overrides: YES
Loading API File(s):
Fetching ~/Desktop/tictactoe-v1-rpc.discovery
+-- Loaded: tictactoe:v1
Generating:
tictactoe(v1)
Writing:
GTLQueryTictactoe.h (1744 bytes) - NEW
GTLQueryTictactoe.m (1907 bytes) - NEW
GTLServiceTictactoe.h (1507 bytes) - NEW
GTLServiceTictactoe.m (1472 bytes) - NEW
GTLTictactoe.h (583 bytes) - NEW
GTLTictactoe_Sources.m (702 bytes) - NEW
GTLTictactoeBoard.h (725 bytes) - NEW
GTLTictactoeBoard.m (638 bytes) - NEW
GTLTictactoeConstants.h (663 bytes) - NEW
GTLTictactoeConstants.m (529 bytes) - NEW
GTLTictactoeScore.h (974 bytes) - NEW
GTLTictactoeScore.m (879 bytes) - NEW
GTLTictactoeScoreCollection.h (976 bytes) - NEW
GTLTictactoeScoreCollection.m (918 bytes) - NEW
GTLTictactoeUser.h (878 bytes) - NEW
GTLTictactoeUser.m (682 bytes) - NE
SUCCESS!