JMS Client using glassfish server - java

Hello i am trying to connect my server from a local client in my Computer
I have a remote server running..
when I am running my code from Netbeans everything works fine...
when i am trying from the CMD i am getting this error
java.lang.NullPointerException
at com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:347)
at com.sun.enterprise.naming.impl.SerialContext.getProviderCacheKey(SerialContext.java:354)
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:384)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:329)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:477)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
at javax.naming.InitialContext.lookup(Unknown Source)
at test4.Test4.main(Test4.java:45)
Exception in thread "main" javax.naming.NamingException: Lookup failed for 'jms/connection' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.NullPointerException]]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:491)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
at javax.naming.InitialContext.lookup(Unknown Source)
at test4.Test4.main(Test4.java:45)
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.NullPointerException]
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:334)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:477)
... 3 more
Caused by: java.lang.NullPointerException
at com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:347)
at com.sun.enterprise.naming.impl.SerialContext.getProviderCacheKey(SerialContext.java:354)
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:384)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:329)
... 4 more
public static void main(String[] args) throws NamingException {
Context initialContext = Test4.getInitialContext();
ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("jms/connection");
System.out.println("yeee:"+connectionFactory.toString());
JMSContext jMSContext = connectionFactory.createContext();
Queue myQueue = (Queue)initialContext.lookup("jms/myQueue");
JMSProducer jMSProducer = jMSContext.createProducer();
jMSProducer.send(myQueue, "Hi,Zion");
System.out.println("work work work wrok wrok");
}
public static Context getInitialContext() throws NamingException{
System.setProperty("org.omg.CORBA.ORBInitialHost", "MyIP");
System.setProperty("org.omg.CORBA.ORBInitialPort", "3800");
return new InitialContext();
}

ok i figure it out!!!i should to put all the paths with the jars lib where the glassfish was installed and run java -cp "c:/programFiles/glassfish/lib/*" test4.Test4
can close the Topic.

Related

Exception on call EntityManagerFactory intance after setting javax.net.ssl.keyStore system property

I'm getting the exception below creating an EntityManagerFactory instance after setting javax.net.ssl.keyStore system property. I don't get this exception if I call EMF before the
javax.net.ssl.keyStore system property setting.
Any suggestions? Should be my jdbc connection ssl encrypted as well?
Thank you.
public static void main(String[] args) {
System.setProperty("javax.net.ssl.keyStore", "ServerAccesKey.jks");
System.setProperty("jenter code hereavax.net.ssl.keyStorePassword", "acceskey");
EntityManagerFactory createEntityManagerFactory = Persistence.createEntityManagerFactory("JavaApplication4PU");
EntityManager createEntityManager = createEntityManagerFactory.createEntityManager();
}
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.10.v20211216-fe64cd39c3): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Error Code: 0
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:858)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:222)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:200)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getDatabaseSession(EntityManagerFactoryImpl.java:542)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:153)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:191)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:80)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at javaapplication4.JavaApplication4.main(JavaApplication4.java:30)
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.10.v20211216-fe64cd39c3): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

"Read past end of file" on lookup jms/RemoteConnectionFactory on wildfly

I'm trying to do basic a JMS operation using WildFly 26.1.1. I have simple method to lookup jms/RemoteConnectionFactory:
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
properties.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
InitialContext ic=new InitialContext(properties);
ConnectionFactory f = (ConnectionFactory) ic.lookup("jms/RemoteConnectionFactory") ;
Unfortunately I'm still receiving this exception:
Exception in thread "main" javax.naming.CommunicationException: WFNAM00020: Remote naming operation failed [Root exception is java.io.EOFException: Read past end of file]
at org.wildfly.naming.client.remote.RemoteClientTransport.lookup(RemoteClientTransport.java:289)
at org.wildfly.naming.client.remote.RemoteContext.lambda$lookupNative$0(RemoteContext.java:190)
at org.wildfly.naming.client.NamingProvider.performExceptionAction(NamingProvider.java:222)
at org.wildfly.naming.client.remote.RemoteContext.performWithRetry(RemoteContext.java:100)
at org.wildfly.naming.client.remote.RemoteContext.lookupNative(RemoteContext.java:188)
at org.wildfly.naming.client.AbstractFederatingContext.lookup(AbstractFederatingContext.java:74)
at org.wildfly.naming.client.store.RelativeFederatingContext.lookupNative(RelativeFederatingContext.java:58)
at org.wildfly.naming.client.AbstractFederatingContext.lookup(AbstractFederatingContext.java:74)
at org.wildfly.naming.client.AbstractFederatingContext.lookup(AbstractFederatingContext.java:60)
at org.wildfly.naming.client.AbstractFederatingContext.lookup(AbstractFederatingContext.java:66)
at org.wildfly.naming.client.WildFlyRootContext.lookup(WildFlyRootContext.java:144)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at first.jms.WildflyJms.sendMessage(WildflyJms.java:17)
at first.jms.WildflyJms.main(WildflyJms.java:9)
Caused by: java.io.EOFException: Read past end of file
at org.jboss.marshalling.SimpleDataInput.eofOnRead(SimpleDataInput.java:151)
at org.jboss.marshalling.SimpleDataInput.readUnsignedByteDirect(SimpleDataInput.java:294)
at org.jboss.marshalling.SimpleDataInput.readUnsignedByte(SimpleDataInput.java:249)
at org.jboss.marshalling.river.BlockUnmarshaller.readUnsignedByte(BlockUnmarshaller.java:258)
at org.jboss.marshalling.river.BlockUnmarshaller.readInt(BlockUnmarshaller.java:296)
at org.jboss.marshalling.river.BlockUnmarshaller.readUTF(BlockUnmarshaller.java:326)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.readExternal(ActiveMQConnectionFactory.java:200)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1444)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:298)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:231)
at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:41)
at org.wildfly.naming.client.remote.RemoteClientTransport.lookup(RemoteClientTransport.java:271)
... 13 more
Caused by: an exception which occurred:
in object of type org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory

org.springframework.messaging.MessagingException: Problem occurred while synchronizing remote to local directory

I have a spring batch application where batch runs continuously to pull data from another server through SFTP. In log continuously I'm getting below mentioned error but it seems batch is working as expected its pulling file from another server without any issue. I don't know why its throwing error in log. And strange is same code is not throwing any error in qa env its only throwing error in prod.
Batch is doing its job but its throwing error also in log.
Can anyone please provide me suggestion how to get rid of this error?
Below is he code for creating sessionfactory.
**public SessionFactory<LsEntry> pimSftpSessionFactory() {
Resource resource = new FileSystemResource(
sftpProperties.privateKeyLocation);
Properties config = new Properties();
config.put("PreferredAuthentications", "publickey,password");
DefaultSftpSessionFactory sftpSessionFactory = new DefaultSftpSessionFactory();
sftpSessionFactory.setHost(sftpProperties.hostName);
sftpSessionFactory.setPort(sftpProperties.port);
sftpSessionFactory.setUser(sftpProperties.username);
sftpSessionFactory.setKnownHosts(sftpProperties.knownHosts);
sftpSessionFactory.setPrivateKey(resource);
sftpSessionFactory.setSessionConfig(config);
return sftpSessionFactory;**
Pom entry:
**<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-sftp</artifactId>
</dependency>**
Error:
03 Sep 2020 01:47:56.688 ERROR o.s.i.handler.LoggingHandler - org.springframework.messaging.MessagingException: Problem occurred while synchronizing remote to local directory; nested exception is org.springframework.messaging.MessagingException: Failed to obtain pooled item; nested exception is java.lang.IllegalStateException: failed to create SFTP Session
at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.synchronizeToLocalDirectory(AbstractInboundFileSynchronizer.java:303)
at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizingMessageSource.doReceive(AbstractInboundFileSynchronizingMessageSource.java:200)
at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizingMessageSource.doReceive(AbstractInboundFileSynchronizingMessageSource.java:62)
at org.springframework.integration.endpoint.AbstractMessageSource.receive(AbstractMessageSource.java:134)
at org.springframework.integration.endpoint.SourcePollingChannelAdapter.receiveMessage(SourcePollingChannelAdapter.java:224)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.doPoll(AbstractPollingEndpoint.java:245)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.access$000(AbstractPollingEndpoint.java:58)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:190)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:186)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller$1.run(AbstractPollingEndpoint.java:353)
at org.springframework.integration.util.ErrorHandlingTaskExecutor$1.run(ErrorHandlingTaskExecutor.java:55)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:51)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller.run(AbstractPollingEndpoint.java:344)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.messaging.MessagingException: Failed to obtain pooled item; nested exception is java.lang.IllegalStateException: failed to create SFTP Session
at org.springframework.integration.util.SimplePool.getItem(SimplePool.java:178)
at org.springframework.integration.file.remote.session.CachingSessionFactory.getSession(CachingSessionFactory.java:123)
at org.springframework.integration.file.remote.RemoteFileTemplate.execute(RemoteFileTemplate.java:441)
at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.synchronizeToLocalDirectory(AbstractInboundFileSynchronizer.java:264)
... 22 more
Caused by: java.lang.IllegalStateException: failed to create SFTP Session
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:393)
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:57)
at org.springframework.integration.file.remote.session.CachingSessionFactory$1.createForPool(CachingSessionFactory.java:81)
at org.springframework.integration.file.remote.session.CachingSessionFactory$1.createForPool(CachingSessionFactory.java:78)
at org.springframework.integration.util.SimplePool.doGetItem(SimplePool.java:188)
at org.springframework.integration.util.SimplePool.getItem(SimplePool.java:169)
... 25 more
Caused by: java.lang.IllegalStateException: failed to connect
at org.springframework.integration.sftp.session.SftpSession.connect(SftpSession.java:273)
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:388)
... 30 more
Caused by: com.jcraft.jsch.JSchException: java.io.IOException: Pipe closed
at com.jcraft.jsch.ChannelSftp.start(ChannelSftp.java:315)
at com.jcraft.jsch.Channel.connect(Channel.java:152)
at com.jcraft.jsch.Channel.connect(Channel.java:145)
at org.springframework.integration.sftp.session.SftpSession.connect(SftpSession.java:268)
... 31 more
Caused by: java.io.IOException: Pipe closed
at java.io.PipedInputStream.read(PipedInputStream.java:307)
at java.io.PipedInputStream.read(PipedInputStream.java:377)
at com.jcraft.jsch.ChannelSftp.fill(ChannelSftp.java:2909)
at com.jcraft.jsch.ChannelSftp.header(ChannelSftp.java:2935)
at com.jcraft.jsch.ChannelSftp.start(ChannelSftp.java:262)
... 34 more

RabbitMQ SSL giving handshake failure when using SpringAMQP

I have rabbitMQ installed using the following configuration
[
{rabbit, [
{ssl_listeners, [5671]},
{ssl_options, [{cacertfile,"C:\\dev\\rabbitcert\\testca\\cacert.pem"},
{certfile,"C:\\dev\\rabbitcert\\server\\cert.pem"},
{keyfile,"C:\\dev\\rabbitcert\\server\\key.pem"},
{verify,verify_peer},
{fail_if_no_peer_cert,false}]}
]}
].
And i am Instantiating the Connection Factory as such (data replaced with dummy):
private static ConnectionFactory getConnectionFactoryForQueue(){
com.rabbitmq.client.ConnectionFactory connectionFactory = new com.rabbitmq.client.ConnectionFactory();
connectionFactory.setUsername("user");
connectionFactory.setHost("MyIpAddress.0.1.1");
connectionFactory.setPassword("pass");
connectionFactory.setPort(5671);
connectionFactory.setVirtualHost("/");
SsmProtos.SSLDetails ssl = listener.getSslDetails();
char[] keyPassphrase = "keyPassPhrase".toCharArray();
try {
KeyStore ks = KeyStore.getInstance("PKCS12");
ks.load(new FileInputStream("path/to/keycert.p12"), keyPassphrase);
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(ks, keyPassphrase);
char[] trustPassphrase = "trustPassPhrase".toCharArray();
KeyStore tks = KeyStore.getInstance("JKS");
tks.load(new FileInputStream("path/to/trust/store"), trustPassphrase);
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(tks);
SSLContext c = SSLContext.getInstance("SSLv3");
c.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
connectionFactory.useSslProtocol(c);
} catch (NoSuchAlgorithmException | CertificateException | IOException |
UnrecoverableKeyException | KeyStoreException | KeyManagementException e) {
throw new IllegalArgumentException("Failed Setting up SSL",e);
}
return new CachingConnectionFactory(connectionFactory);
}
When I try to connect I get the following error from the Java side
Errors encountered:Error creating bean with name 'getSsmRequestAmqpAdmin' defined in class com.ixaris.ssm.server.service.ServerConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.amqp.core.AmqpAdmin com.ixaris.ssm.shared.busobject.ServerInfoConfiguration.getSsmRequestAmqpAdmin()] threw exception; nested exception is org.springframework.amqp.AmqpIOException: java.net.SocketException: Software caused connection abort: recv failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getSsmRequestAmqpAdmin' defined in class com.ixaris.ssm.server.service.ServerConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.amqp.core.AmqpAdmin com.ixaris.ssm.shared.busobject.ServerInfoConfiguration.getSsmRequestAmqpAdmin()] threw exception; nested exception is org.springframework.amqp.AmqpIOException: java.net.SocketException: Software caused connection abort: recv failed
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:597)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.amqp.core.AmqpAdmin com.ixaris.ssm.shared.busobject.ServerInfoConfiguration.getSsmRequestAmqpAdmin()] threw exception; nested exception is org.springframework.amqp.AmqpIOException: java.net.SocketException: Software caused connection abort: recv failed
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:188)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:586)
Caused by: org.springframework.amqp.AmqpIOException: java.net.SocketException: Software caused connection abort: recv failed
at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:63)
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:195)
Caused by: java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:150)
And the following appears on the rabbitMQ Logs (192.168.24.75 is my IP)
=INFO REPORT==== 14-Aug-2014::11:25:07 ===
accepting AMQP connection <0.272.0> (192.168.24.75:49860 -> 192.168.24.75:5671)
=ERROR REPORT==== 14-Aug-2014::11:25:08 ===
SSL: certify: ssl_handshake.erl:1391:Fatal error: handshake failure
=ERROR REPORT==== 14-Aug-2014::11:25:13 ===
error on AMQP connection <0.272.0>:
{ssl_upgrade_error,{tls_alert,"handshake failure"}}
Both the application and the queue are on my machine at the moment. I have opened up TCP ports 5671 and 5672 on my firewall.
Am I missing something?
The issue was not in that code, but rather with the path to my Keycert
I was using the Server Certificate rather than the Client Certificate.

java.net.SocketTimeoutException while lookup in EJB

In my application I got the following error when i trying to lookup some EJB object from tomcat.
2012-01-09 15:54:00,825 ERROR [ AccessRight ] NAMING EXCEPTION IN FACTORYjavax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]
2012-01-09 15:54:00,825 ERROR BaseLoadServlet.java getMenuCollection(): Exception : com.elitecore.billing.delegates.base.exception.LookupException
Can anybody tell what is this error ?

Categories

Resources