null pointer exception in lookup for weblogic mail session - email

javax.naming.NameNotFoundException: While trying to lookup 'mail.IHCMailSession' didn't find subcontext 'mail'. Resolved ''; remaining name 'mail/IHCMailSession'
I have defined jndi as mail/IHCMailSession and searching as
InitialContext ic;
try {
ic = new InitialContext();
session = (Session)ic.lookup(mail/IHCMailSession);
Please help me how to fix this

Related

Big number of values IN Query with ItemReader

The following ItemReader gets a list of thousands accounts (acc).
The database that the ItemReader will connected to in order to retrieve the data is HIVE. I don’t have permission to create any table, only read option.
#Bean
#StepScope
public ItemReader<OmsDto> omsItemReader(#Value("#{stepExecutionContext[acc]}") List<String> accountList) {
String inParams = String.join(",", accountList.stream().map(id ->
"'"+id+"'").collect(Collectors.toList()));
String query = String.format("SELECT ..... account IN (%s)", inParams);
BeanPropertyRowMapper<OmsDto> rowMapper = new BeanPropertyRowMapper<>(OmsDto.class);
rowMapper.setPrimitivesDefaultedForNullValue(true);
JdbcCursorItemReader<OmsDto> reader = new JdbcCursorItemReader<OmsDto>();
reader.setVerifyCursorPosition(false);
reader.setDataSource(hiveDataSource());
reader.setRowMapper(rowMapper);
reader.setSql(query);
reader.open(new ExecutionContext());
return reader;
}
This is the error message that I get when using ItemReader:
Caused by: org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:153) ~[spring-batch-infrastructure-4.2.4.RELEASE.jar:4.2.4.RELEASE]
Caused by: java.sql.SQLException: Error executing query
at com.facebook.presto.jdbc.PrestoStatement.internalExecute(PrestoStatement.java:279) ~[presto-jdbc-0.243.2.jar:0.243.2-128118e]
at com.facebook.presto.jdbc.PrestoStatement.execute(PrestoStatement.java:228) ~[presto-jdbc-0.243.2.jar:0.243.2-128118e]
at com.facebook.presto.jdbc.PrestoPreparedStatement.<init>(PrestoPreparedStatement.java:84) ~[presto-jdbc-0.243.2.jar:0.243.2-128118e]
at com.facebook.presto.jdbc.PrestoConnection.prepareStatement(PrestoConnection.java:130) ~[presto-jdbc-0.243.2.jar:0.243.2-128118e]
at com.facebook.presto.jdbc.PrestoConnection.prepareStatement(PrestoConnection.java:300) ~[presto-jdbc-0.243.2.jar:0.243.2-128118e]
at org.springframework.batch.item.database.JdbcCursorItemReader.openCursor(JdbcCursorItemReader.java:121) ~[spring-batch-infrastructure-4.2.4.RELEASE.jar:4.2.4.RELEASE]
... 63 common frames omitted
Caused by: java.lang.RuntimeException: Error fetching next at https://prestoanalytics-ch2-p.sys.comcast.net:6443/v1/statement/executing/20201118_131314_11079_v3w47/yf55745951e0beccc234c98f36005723457073854/0 returned an invalid response: JsonResponse{statusCode=502, statusMessage=Bad Gateway, headers={cache-control=[no-cache], content-length=[107], content-type=[text/html]}, hasValue=false} [Error: <html><body><h1>502 Bad Gateway</h1>
The server returned an invalid or incomplete response.
</body></html>
]
I was sure that the root cause is because of the driver but I have tested the driver with the same SQL this time using DriverManager and its run perfectly.
#Component
public class OmsItemReader implements ItemReader<OmsDto>, StepExecutionListener {
private ItemReader<OmsDto> delegate;
public SikOmsItemReader() {
Properties properties = new Properties();
properties.setProperty("user", "....");
properties.setProperty("password", "...");
properties.setProperty("SSL", "true");
Connection connection = null;
try {
connection = DriverManager.getConnection("jdbc:presto://.....", properties);
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(
I am not sure what is the different ? Is it the driver or sparing batch ?
I am looking for a workaround. How can I retrieve thousands of accounts via IN clauses with spring batch ?
Thank you

Property leakDetectionThreshold does not exist on target class org.postgresql.ds.PGSimpleDataSource

I am trying to use this property but it gives me that exception, I tried even with: pgjdbc-ng | com.impossibl.postgres.jdbc.PGDataSource but without success, it gives me tha same title exception.
ERROR com.zaxxer.hikari.util.PropertyElf - Property leakDetectionThreshold does not exist on target class org.postgresql.ds.PGSimpleDataSource
java.lang.RuntimeException: Property leakDetectionThreshold does not exist on target class org.postgresql.ds.PGSimpleDataSource
HirakriCP configuration:
ds = new HikariDataSource();
ds.setMaximumPoolSize(poolSize);
ds.setDataSourceClassName("org.postgresql.ds.PGSimpleDataSource");
ds.addDataSourceProperty("serverName", serverAddress);
ds.addDataSourceProperty("databaseName", database);
ds.addDataSourceProperty("user", user);
ds.addDataSourceProperty("portNumber", port);
ds.addDataSourceProperty("password", password);
ds.addDataSourceProperty("leakDetectionThreshold ", 5000);
and alternatively:
ds.setDataSourceClassName("com.impossibl.postgres.jdbc.PGDataSource");
ds.addDataSourceProperty("host", serverAddress);
ds.addDataSourceProperty("database", database);
ds.addDataSourceProperty("user", user);
ds.addDataSourceProperty("port", port);
ds.addDataSourceProperty("password", password);
May I be doing something wrong? I am scared that I couldn't find anyone with the same problem over the internet oO
Than you in advance,
Alexandre
leakDetectionThreshold is not a driver property we need set this datasource property like this:
ds = new HikariDataSource();
ds.setLeakDetectionThreshold(5000);

JBoss return org.jboss.remoting.ProtocolException: Too many channels open

My program encountered a error:
"org.jboss.remoting3.ProtocolException: Too many channels open"
I have search from internet for some solutions to fix this error.Unfortunately, the suggestions from others is not working for me.
Below is the Code on how I call the jndi remote and the properties that I have used.
public static void createUser(String loginID) throws Exception {
Hashtable props = new Hashtable();
try {
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
props.put(Context.PROVIDER_URL, "remote://" + localhost:4447);
props.put("jboss.naming.client.ejb.context", "true");
props.put(Context.SECURITY_PRINCIPAL, "userJBoss");
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
context = new InitialContext(props);
context.lookup("ejb:/createUserOperation/CreateUserGenerator!password.api.CreateUserService");
.....
......
LOGGER.info("DONE");
} catch (Exception e) {
LOGGER.error("ERROR");
} finally {
context.close();
}
}
Due to some certain reason I am not able to show all the content of the method.
The "createUser" will be call everytime when there is a needed of create new user. It will be call up to hundred or thousand time.
I did always close the connection when every time it finish execute the method.
Let say I have call the method for 100 times, some of the users will be created successfully whereas some of the users will be failed.
Error below will prompt to me:
2014-12-04 17:23:23,026 - ERROR [Remoting "config-based-naming-client-endpoint" task-4] (org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver- Line:134) - Failed to open channel for context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext#bbaebd6, receiver=Remoting connection EJB receiver [connection=Remoting connection <78e43506>,channel=jboss.ejb,nodename=webdev01]} org.jboss.remoting3.ProtocolException: Too many channels open
Once the error occurred, it required me to restart my jboss.And it comes again after sometimes.
Appreciate it if anyone wound able to help on my problem faced.
Thanks
You are using mixture of context properties.
This should be enough
final Properties ejbProperties = new Properties();
ejbProperties.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
ejbProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
ejbProperties.put("remote.connections", "1");
ejbProperties.put("remote.connection.1.host", "localhost");
ejbProperties.put("remote.connection.1.port", "4447");
ejbProperties.put("remote.connection.1.username", "ejbuser");
ejbProperties.put("remote.connection.1.password", "ejbuser123!");
final EJBClientConfiguration ejbClientConfiguration = new PropertiesBasedEJBClientConfiguration(ejbProperties);
final ConfigBasedEJBClientContextSelector selector = new ConfigBasedEJBClientContextSelector(ejbClientConfiguration);
EJBClientContext.setSelector(selector);
final Context context = new InitialContext(ejbProperties);
// lookup
Foo proxy = context.lookup("ejb:/createUserOperation/CreateUserGenerator!password.api.CreateUserService");
when using org.jboss.ejb.client.naming it creates EJBClientContext object.
When closing context you are closing InitialContext not EJBClientContext
to close EJBClientContext:
EJBClientContext.getCurrent().close();
There is a known JBoss bug (EAP 6, AS 7) whereby opening and closing too many InitialContext instances too quickly causes the following error:
ERROR: Failed to open channel for context EJBReceiverContext
Instead of:
final Properties properties = ...
final Context context = new InitialContext( properties );
Try caching the context for a set of properties instead:
private Map<Integer, InitialContext> initialContexts = new HashMap<>();
final Context context = getInitialContext(properties);
private InitialContext getInitialContext(final Properties properties) throws Exception {
final Integer hash = properties.hashCode();
InitialContext result = initialContexts.get(hash);
if (result == null) {
result = new InitialContext(properties);
initialContexts.put(hash, result);
}
return result;
}
Remember to call close() when the context is no longer necessary.

Delete all messages in queue Websphere 8.5 SIB via JMX

I want to delete all the messages in a queue configured in Websphere 8.5 SIB. Below are two approaches I tried, but none of them seem to be working and each throws a different exception. Can someone please advise on what is the correct way to achieve this.
Approach 1
MBeanServerConnection connection = getServerConnection();
connection.invoke(new ObjectName("WebSphere:*,type=SIBQueuePoint,name=jms.queue.MY_QUEUE"), "deleteAllQueuedMessages", null, null);
This approach throws the below exception.
javax.management.InstanceNotFoundException: WebSphere:type=SIBQueuePoint,name=jms.queue.MY_QUEUE
Approach 2
MBeanServerConnection connection = getServerConnection();
ObjectName objQueue = new ObjectName(WAS85_RESOURCE_URL + ",type=SIBQueuePoint");
Set<ObjectName> objNames = connection.queryNames(objQueue, null);
for(ObjectName objName: objNames) {
String qName = connection.getAttribute(objName,"identifier").toString();
if(qName.equals("jms.queue.MY_QUEUE")) {
connection.invoke(objName, "deleteAllQueuedMessages", null, null);
}
}
This approach throws the below exception.
javax.management.ReflectionException: Target method not found: com.ibm.ws.sib.admin.impl.JsQueuePoint.deleteAllQueuedMessages
Figured out the issue.
The 2nd approach works. The issue was with my invocation of the deleteAllQueuedMessages message. The method takes a boolean argument which indicates the messages should be moved to the Exception Destination. I was not passing this argument !!!
I corrected the implementation as below and it works now.
connection.invoke(objName, "deleteAllQueuedMessages", new Object[]{false}, new String[]{"java.lang.Boolean"});
A better way to delete all Messages is something like that:
String queryString = "WebSphere:*,type=JMSAdministration";
ObjectName queryServer = new ObjectName(queryString);
String serverStr = "";
Set pet = aClient.queryNames(queryServer, null);
Iterator itsServer = pet.iterator();
if (itsServer.hasNext())
serverStr = itsServer.next().toString();
ObjectName obj = new ObjectName(serverStr);
Object param[] = { "jms/messageQueue","jms/messageCF" };
String signature[] = { "java.lang.String","java.lang.String" };
aClient.invoke(obj, "clear", param, signature);
Using MBean JMSAdministration is better because you can set Query exacly.

Getting java.lang.NoSuchMethodError exception when using GWT + JasperReports

I have integrated JasperReports on my NetBeans platform and I am able to generate reports using the following code:
Map<String, Object> params = new HashMap<String, Object>();
Connection conn = DriverManager.getConnection("databaseUrl", "userid", "password");
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, conn);
JasperExportManager.exportReportToHtmlFile(jasperPrint, reportDest);
JasperViewer.viewReport(jasperPrint);
This stuff works perfect.
But not I'm trying to integrate JasperReports with GWT. I have my server as GlassFish server.
I am getting the Connection object using the followind code:
public static Connection getConnection() {
try {
String JNDI = "JNDI name";
InitialContext initCtx = new InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource) initCtx.lookup(JNDI);
Connection conn = (Connection) ds.getConnection();
return conn;
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
and then
Map<String, Object> params = new HashMap<String, Object>();
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, getConnection());
JasperExportManager.exportReportToHtmlFile(jasperPrint, reportDest);
JasperViewer.viewReport(jasperPrint);
but i always get an Error. Here is a stacktrace:
com.google.gwt.user.server.rpc.UnexpectedException:
Service method 'public abstract java.lang.Boolean com.client.service.GenerateReport()'
threw an unexpected exception: java.lang.NoSuchMethodError:
net.sf.jasperreports.engine.fonts.SimpleFontFamily.setExportFonts(Ljava/util/Map‌​);
I am implementing this on Server. I am having RPC calls to get this method to work when a button is clicked.
Can you please help me how to work on this. (That is to integrate JasperReports with GWT).
I would highly appreciate any explanation with some code as i am just a beginner.
Thanks
Without the aid of error messages, I would say that you have Google App Engine enabled in your eclipse project preferences. GAE does NOT allow you to write to the file system, or make calls to a database.
Try disabling GAE, and things should work fine.