javamail new MimeMessage hangs - jakarta-mail

If you provide correct values for emailSenderAddress and emailSenderPassword this snippet works in debug mode in Netbeans and in command line.
BUT if you don't add the import DataHandler, it works only in debug mode.
public class mailTest {
// dummy DataHandler to be sure to keep the import !
private DataHandler dh;
private void prepareMessage() {
java.util.Properties props = System.getProperties();
props.put("", "");
props.put("mail.smtps.auth", "true");
// simple class derived from Authenticator not relevant for the current discussion
GMailAuthenticator auth = new GMailAuthenticator(<emailSenderAddress>, <emailSenderPassword>);
javax.mail.Session session = javax.mail.Session.getInstance(props, auth);
javax.mail.Message msg = new javax.mail.internet.MimeMessage(session);
System.out.println("new MimeMessage ok !");
public static void main(String[] args) {
mailTest mt = new mailTest();
class GMailAuthenticator extends Authenticator {
String user;
String pw;
public GMailAuthenticator(String username, String password) {
this.user = username; = password;
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, pw);

What JDK version are you using? DataHandler is part of the javax.activation (JavaBeans Activation Framework, aka JAF) API, which is included in JDK 8 and earlier but not in JDK 11. JavaMail needs JAF, whether you use it explicitly in your program or not. On JDK 11, you'll need to add it to your project explicitly. If you have a Maven project, you can add a dependency on com.sun.activation:javax.activation:1.2.0.


How to make BasicAuthentication in SolrJ - CloudSolrClient?

I am using Solr 7.5 Server and I had used External Zookeeper.When I browse using the Solr Admin UI It ask authentication to me.
For Java Client I had used the below Code
BasicAuthSolrClientCache bs = new BasicAuthSolrClientCache("solr", "SolrRocks");
CloudSolrClient solrCloudClient = bs.getCloudSolrClient(zkHost);
SolrInputDocument doc = new SolrInputDocument();
doc.addField("cat", "book");
doc.addField("id", "book-1");
doc.addField("name", "The Legend of the Hobbit part 1");
public class BasicAuthSolrClientCache extends SolrClientCache {
private static final Logger log =
private final Map<String, SolrClient> solrClients = new HashMap<>();
private final String username;
private final String password;
public BasicAuthSolrClientCache(String username, String password) {
this.username = username;
this.password = password;
public synchronized CloudSolrClient getCloudSolrClient(String zkHost) {
CloudSolrClient client;
if (solrClients.containsKey(zkHost)) {
client = (CloudSolrClient) solrClients.get(zkHost);
} else {
client = new CloudSolrClient.Builder()
solrClients.put(zkHost, client);
return client;
public synchronized HttpSolrClient getHttpSolrClient(String host) {
HttpSolrClient client;
if (solrClients.containsKey(host)) {
client = (HttpSolrClient) solrClients.get(host);
} else {
client = new HttpSolrClient.Builder(host)
solrClients.put(host, client);
return client;
public synchronized void close() {
for(Map.Entry<String, SolrClient> entry : solrClients.entrySet()) {
try {
} catch (IOException e) {
log.error("Error closing SolrClient for " + entry.getKey(), e);
private HttpClient getHttpClient() {
CredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials = new
UsernamePasswordCredentials(this.username, this.password);
provider.setCredentials(AuthScope.ANY, credentials);
But it give the exception like the below,
Exception in thread "main" org.apache.solr.client.solrj.impl.CloudSolrClient$RouteException: IOException occured when talking to server at: at
How to authenticate SolrCloud using SolrJ
I found a easy way to do this.
You add a request interceptor like this so you do not have to worry about creating a properly configured HttpClient instance yourself. This will just add the interceptor to the default HttpClient that Solrj creates.
org.apache.solr.client.solrj.impl.HttpClientUtil.addRequestInterceptor(new SolrPreemptiveAuthInterceptor());
The RequestInterceptor looks like this:
public class SolrPreemptiveAuthInterceptor implements HttpRequestInterceptor {
final static Logger log = LoggerFactory.getLogger(SolrPreemptiveAuthInterceptor.class);
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
// If no auth scheme available yet, try to initialize it preemptively
if (authState.getAuthScheme() == null) {"No AuthState: set Basic Auth");
HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(HttpClientContext.CREDS_PROVIDER);
Credentials creds = credsProvider.getCredentials(authScope);
if(creds == null){"No Basic Auth credentials: add them");
creds = getCredentials(authScope);
authState.update(new BasicScheme(), creds);
private Credentials getCredentials(AuthScope authScope) {
String user = "";
String password = "";
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(user, password);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(authScope, creds);"Creating Basic Auth credentials for user {}", user);
return credsProvider.getCredentials(authScope);
You can also use UpdateRequest for indexing requests to do a basic authentication via SolrJ:
UpdateRequest ur = new UpdateRequest();
ur.setBasicAuthCredentials("YOU USER NAME", "USER PASSWORD");

HTTP Handler and Resteasy Deployment with undertow and resteasy

I am trying to run both HTTPServer and also the REST Handler. Only one works at a time not able to make it work both at same time. I need to serve html pages and also the api.
here is my code.
public class HttpServer {
private final UndertowJaxrsServer server = new UndertowJaxrsServer();
private static String rootPath = System.getProperty("user.dir");
private final Undertow.Builder serverBuilder;
public HttpServer(Integer port, String host) {
serverBuilder = Undertow
.addHttpListener(port, host)
new FileResourceManager(new File(
rootPath + "/web"), 100))
rootPath + "/web/index.html")));
public DeploymentInfo deployApplication(String appPath,
Class<? extends Application> applicationClass) {
ResteasyDeployment deployment = new ResteasyDeployment();
return server.undertowDeployment(deployment, appPath);
public void deploy(DeploymentInfo deploymentInfo) throws ServletException {
public static void main(String[] args) throws ServletException {
HttpServer myServer = new HttpServer(8080, "");
DeploymentInfo di = myServer
.deployApplication("/rest", MyApplication.class)
.setContextPath("/my").setDeploymentName("My Application");
The UndertowJaxrsServer is overriding the filehandler of your builder:
public UndertowJaxrsServer start(Undertow.Builder builder)
server = builder.setHandler(root).build();
return this;
Seems like there is no way to pass another handler to the UndertowJaxrsServer. Possible workarounds might be:
Deploy another application with one resource class which simply serves files.
Use the blank Undertow and loose the comfort of easy JAX-RS deployments.
From version 3.1.0.Beta2 and higher you can try this
UndertowJaxrsServer server = new UndertowJaxrsServer();
ResteasyDeployment deployment = new ResteasyDeployment();
DeploymentInfo deploymentInfo = server.undertowDeployment(deployment, "/");
resource(new PathResourceManager(Paths.get(STATIC_PATH),100)).
RestEasy app will be available at /api/* and static files at /*

Configuration of custom Log4j appender doesn't work

I have created a custom appender (will be used for Linux). For creating of this appender I used this article How write custom log4j appender
public class SolrAppender extends AppenderSkeleton {
private String path = null;
public void setPath(String path) { this.path = path; }
public String getPath() { return this.path; }
public boolean requiresLayout() {
return true;
public void close() {
public void activateOptions() {
public synchronized void append(LoggingEvent event) {
SolrServer server = new HttpSolrServer(path);
SolrInputDocument document = new SolrInputDocument();
//some logic
UpdateResponse response = server.add(document);
Configuration of this appender is
# Solr appender
log4j.appender.SOLR = ricardo.solr.appender.QueryParser.SolrAppender
log4j.appender.SOLR.layout = org.apache.log4j.SimpleLayout
log4j.appender.SOLR.path = http://XX.XXX.XX.XX:8985/application/core
Appender works correct if path is hardcoded. Why path is not set via configuration?
From what I've seen so far, the name of a property of an appender, in the configuration, should start with an upper case character, so 'Path' instead of 'path', so you should use:
log4j.appender.SOLR.Path = http://XX.XXX.XX.XX:8985/application/core
Not sure why it's not the case for 'layout', though.

Is it appropriate to have EntityManager in a bundle class?

I want to know if it is efficient in JSF to define EntityManager and TypedQuery in a bundle class that is supposed to read messages from database?
What if I create an instance of a #Stateless bean and use its functions that return query results inside the bundle class?
UPDATE: Included some code:
protected class DBControl extends Control{
public ResourceBundle newBundle
(String baseName, Locale locale, String format, ClassLoader loader, boolean reload)
throws IllegalAccessException, InstantiationException, IOException
return new ArticleResources(locale);
protected class ArticleResources extends ListResourceBundle{
private Locale locale;
public ArticleResources (Locale locale){
this.locale = locale;
String language = locale.getLanguage();
protected Object[][] getContents(){
TypedQuery<ArticleLcl> query = em.createNamedQuery("ArticleLcl.findForLocale", ArticleLcl.class);
query.setParameter("lang", language);
List<ArticleLcl> articles = query.getResultList();
Object[][] allArticles = new Object[articles.size()][3];
int i = 0;
for(Iterator<ArticleLcl> it = articles.iterator(); it.hasNext();){
ArticleLcl article =;
allArticles[i] = new Object[]{article.getArticleId().getArticleId().toString(),article.getArticleTitle()};
return allArticles;
By the way this code does not work and my entity manager is null. But I wonder am I doing the right thing?

Google app engine JRE Class "Black List"

There is a "JRE Class White List" for the Google App Engine.
What I would really like is a "Black List" -- in other words, Java APIs that will not work on GAE. Does such a list exist? Have any developers run into problems with Java APIs on GAE?
It seems that they've taken more of a white-list approach:
There is also more detail about the sandbox (what files it can access and so on) here:
The restrictions seem to be pretty intuitive (like restricted filesystem access, no JNI, etc).
I got a card advertising this service at Google I/O:
LTech AppEngine Compatibility Analyzer
Sounds like it might be of use to you. I have not tried it, if you do try it, please come back and comment. Thanks!
i use Servlet in my GAE project, however it is not in the whitelist even when it will work without any problem. In fact, Google mention how to use Servlet but it is not in the whitelist
import javax.servlet.http.*;
Mentioned here:
but not included here:
I love GAE (because the free quota) but the documentation is a mess.
I use IntelliJ and it mark as an error when the import not in the whitelist. However, it is possible to disable it.
I was looking for something when i came across this query and so thought to share the details on the black & white list of GAE(Google App Engine) so anyone getting such issue could address it properly. Details :-
appengine-agentruntime.jar has two instance variables as :-
private static Agent agent
private static Set<String> blackList
We getting blackList from agent & agent = AppEngineDevAgent.getAgent(). So if we check b) appengine-agent.jar we can find agent is Class<?> implClass = agentImplLoader.loadClass("");
And then going to AgentImpl class i.e. c) appengine-agentimpl.jar we can
see blacklist variable getting populated at class load with the static initialization & it refers Whitelist for filtering the allowed classes.
static {
public static Set<String> getBlackList() {
return blackList;
private static boolean isBlackListed(String className) {
Set<String> whiteList = WhiteList.getWhiteList();
return (!whiteList.contains(className))
&& (!className.startsWith("com.sun.xml.internal.bind."));
Finally can check d) appengine-tools-sdk-1.8.3.jar for list of all WhiteList classes.
Conclusion: As a hack in order to use any JRE class which do not belong to this WhiteList one need to play around either with the WhiteList or with the BlackList. A possible hack would be if you unjar the appengine-agentruntime.jar library & comment the content of reject method as
public static void reject(String className) {
/*throw new NoClassDefFoundError(className + " is a restricted class. Please see the Google " + " App Engine developer's guide for more details.");*/
And then again jar it and use in your project.Hope it helps.
a) appengine-agentruntime.jar :- It holds the actual Runtime class which throws exception (from reject method) for classes which do not belong to above white list.
public class Runtime {
private static Agent agent = (Agent) ClearCast.cast(
AppEngineDevAgent.getAgent(), Agent.class);
private static Set<String> blackList = agent.getBlackList();
public static ClassLoader checkParentClassLoader(ClassLoader loader) {
ClassLoader systemLoader = ClassLoader.getSystemClassLoader();
return (loader != null) && (loader != systemLoader) ? loader
: Runtime.class.getClassLoader();
public static void recordClassLoader(ClassLoader loader) {
public static void reject(String className) {
throw new NoClassDefFoundError(className
+ " is a restricted class. Please see the Google "
+ " App Engine developer's guide for more details.");
private static boolean isBlackListed(Class klass) {
String className = klass.getName().replace('.', '/');
return blackList.contains(className);
b) appengine-agent.jar :-
public class AppEngineDevAgent {
private static final String AGENT_IMPL = "";
private static final String AGENT_IMPL_JAR = "appengine-agentimpl.jar";
private static final Logger logger = Logger.getLogger(AppEngineDevAgent.class.getName());
private static Object impl;
public static void premain(String agentArgs, Instrumentation inst) {
URL agentImplLib = findAgentImplLib();
URLClassLoader agentImplLoader = new URLClassLoader(
new URL[] { agentImplLib }) {
protected PermissionCollection getPermissions(CodeSource codesource) {
PermissionCollection perms = super.getPermissions(codesource);
perms.add(new AllPermission());
return perms;
try {
Class<?> implClass = agentImplLoader
impl = ((AgentImplStruct) ClearCast.staticCast(implClass,
AgentImplStruct agentImplStruct = (AgentImplStruct) ClearCast.cast(
impl, AgentImplStruct.class);;
} catch (Exception e) {
"Unable to load the App Engine dev agent. Security restrictions will not be completely emulated.",
public static Object getAgent() {
return impl;
c) appengine-agentimpl.jar :-
public class BlackList {
private static final Logger logger = Logger.getLogger(BlackList.class.getName());
private static Set<String> blackList = new HashSet();
static {
public static Set<String> getBlackList() {
return blackList;
private static boolean isBlackListed(String className) {
Set<String> whiteList = WhiteList.getWhiteList();
return (!whiteList.contains(className))
&& (!className.startsWith("com.sun.xml.internal.bind."));
private static void initBlackList() {
Set<File> jreJars = getCurrentJreJars();
for (File f : jreJars) {
JarFile jarFile = null;
try {
jarFile = new JarFile(f);
} catch (IOException e) {
"Unable to read a jre library while constructing the blacklist. Security restrictions may not be entirely emulated. "
+ f.getAbsolutePath());
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry entry = (JarEntry) entries.nextElement();
String entryName = entry.getName();
if (entryName.endsWith(".class")) {
String className = entryName.replace('/', '.').substring(0,
entryName.length() - ".class".length());
if (isBlackListed(className)) {
blackList.add(className.replace('.', '/'));
blackList = Collections.unmodifiableSet(blackList);
private static Set<File> getCurrentJreJars() {
return getJreJars(System.getProperty("java.home"));
d) appengine-tools-sdk-1.8.3.jar :- It has a class called WhiteList which includes all allowed JRE classes.
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class WhiteList {
private static Set<String> whiteList = new HashSet(
Arrays.asList(new String[] {
//Removed other classes to keep this article short
"" }));
public static Set<String> getWhiteList() {
return whiteList;