Erste Frage.Verwenden von Google E-Mail-Service mit SSL auf Resin 3.1 in AWS
Ich suche nach Hilfe konfigurieren Java & Harz, damit ich eine HTTPS-URL-Verbindung von innerhalb meiner App zu öffnen. Die Resin-Dokumentation sagt nicht, ich denke, ich mache das Richtige in Java, aber ich stoße auf einen "java.lang.NoClassDefFoundError: Konnte nicht initialisieren class sun.net.www.protocol.https.DelegateHttpsUrlConnection" . Ich erwarte, dass das Update entweder eine einzelne Zeile in einer Konfigurationsdatei oder ein fehlendes Glas ist ... aber welches?
Weitere Details:
Oracle Linux JDK 1.7 Resin 3.1 (ja, es ist alt) Google Mail api v1 (Maven Abhängigkeit siehe unten)
Ich habe eine GmailSender Klasse implementiert, die E-Mail aussendet von meiner App:
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
...
private Credential authorizeServiceAccount() throws IOException, GeneralSecurityException {
Credential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(serviceAccountId)
.setServiceAccountPrivateKeyFromP12File(new File(privateKeyFileName))
.setServiceAccountScopes(SCOPES)
.setServiceAccountUser(serviceAccountUser)
.build();
return credential;
}
Gmail getGmailService() throws IOException, GeneralSecurityException {
Credential credential = authorizeServiceAccount();
return new Gmail.Builder(httpTransport, JSON_FACTORY, credential)
.setApplicationName(applicationName)
.build();
}
public void send(SimpleMailMessage simpleMailMessage) throws MailException {
Message m;
try {
MimeMessage mm = asMimeMessage(simpleMailMessage);
m = asMessage(mm);
} catch (IOException e) {
throw new MailPreparationException("Unable to create email", e);
} catch (MessagingException e) {
throw new MailPreparationException("Unable to create email", e);
}
try {
Gmail gmail = getGmailService();
m = gmail.users().messages().send("me", m).execute();
} catch (IOException e) {
throw new MailSendException("Unable to send mail", e);
} catch (GeneralSecurityException e) {
throw new MailSendException("Could not send email", e);
} catch (Throwable t) {
throw new MailSendException("Unexpected failure sending email", t);
}
String id = m.getId();
//System.out.println("Mail sent. Id is: " + id);
}
und die maven config:
Und die Ausnahme - sieht meist gut mit Ausnahme der Klasse def Ausgabe:
20160326-15:15:54.481org.springframework.mail.MailSendException; nested exceptions (0) are: 20160326-15:15:54.481Caused by: java.lang.NoClassDefFoundError: Could not initialize class sun.net.www.protocol.https.DelegateHttpsURLConnection 20160326-15:15:54.481 at sun.net.www.protocol.https.HttpsURLConnectionImpl.(HttpsURLConnectionImpl.java:86) 20160326-15:15:54.481 at sun.net.www.protocol.https.Handler.openConnection(Handler.java:62) 20160326-15:15:54.481 at sun.net.www.protocol.https.Handler.openConnection(Handler.java:57) 20160326-15:15:54.481 at java.net.URL.openConnection(URL.java:971) 20160326-15:15:54.481 at com.google.api.client.http.javanet.DefaultConnectionFactory.openConnection(DefaultConnectionFactory.java:31) 20160326-15:15:54.481 at com.google.api.client.http.javanet.NetHttpTransport.buildRequest(NetHttpTransport.java:136) 20160326-15:15:54.481 at com.google.api.client.http.javanet.NetHttpTransport.buildRequest(NetHttpTransport.java:62) 20160326-15:15:54.481 at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:863) 20160326-15:15:54.481 at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:283) 20160326-15:15:54.481 at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307) 20160326-15:15:54.481 at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:384) 20160326-15:15:54.481 at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489) 20160326-15:15:54.481 at com.google.api.client.auth.oauth2.Credential.intercept(Credential.java:217) 20160326-15:15:54.481 at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:859) 20160326-15:15:54.481 at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419) 20160326-15:15:54.481 at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352) 20160326-15:15:54.481 at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469) 20160326-15:15:54.481 at MyPackage.GmailSender.send(GmailSender.java:155)
Ich habe mit der Einstellung der Protokolle in meinem Harz experimentiert Startskript:
args="-jar $RESIN_HOME/lib/resin.jar -server-root $SERVER_ROOT -conf $config -server $SERVER_NAME"
#args="-Dhttps.protocols=TLSv1.2,TLSv1.1,TLSv1 -jar $RESIN_HOME/lib/resin.jar -server-root $SERVER_ROOT -conf $config -server $SERVER_NAME"
Aber diese Änderung scheint keinen Einfluss haben. Was vermisse ich??
Danke !!
Ich entferne mich von diesem Ansatz, um die schnellere und sicherere Google Mail-API zu verwenden. Meine Junit-Tests laufen gut - sie laufen einfach nicht im Web-Container. – tfield