EJB Remote JNDI lookup не работает для сервера glassfish4, размещенного на aws ec2 - PullRequest
1 голос
/ 20 июня 2020

У меня есть Ear с Ejb, развернутым на сервере Glassfi sh, запущенном на экземпляре ec2 на aws. У меня также есть база данных aws RDS, которую я хочу использовать в своем приложении. У меня есть локальное автономное клиентское приложение, которое пытается вызвать функцию из удаленного ejb, используя контекст поиска jndi. машина в db).

Вот мой код: Реализация Ejb

package com.example;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 * Session Bean implementation class FirstStatelessEjb
 */
@Stateless
@LocalBean
public class FirstStatelessEjb implements FirstStatelessEjbRemote {
    
    @PersistenceContext
    private EntityManager entityManager;

    /**
     * Default constructor. 
     */
    public FirstStatelessEjb() {
        // TODO Auto-generated constructor stub
    }
    
    @Override
    public void insert(String name) {
        entityManager.persist(new User(name));
    }

}

постоянство. xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="myFirstEjb">
        <jta-data-source>jdbc/test</jta-data-source>
        <class>com.example.User</class>
    </persistence-unit>
</persistence>

Главный класс в автономном клиенте

package standaloneClient;

import java.util.Hashtable;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.example.FirstStatelessEjbRemote;

public class Main {
    
    public static void main(String[] args) throws NamingException {
        Properties jndiProps = new Properties();
        jndiProps.put("org.omg.CORBA.ORBInitialHost", "ec2-xx-xx-xxx-xxx.us-east-1e.compute-1.amazonaws.com");
//      jndiProps.put("org.omg.CORBA.ORBInitialPort","4848");

        Context context = new InitialContext(jndiProps);
        FirstStatelessEjbRemote firstEjb = (FirstStatelessEjbRemote) context.lookup("java:global/myFirtEar/myFirstEjb/FirstStatelessEjb!com.example.FirstStatelessEjb");
        firstEjb.insert("Teo");
    }

}

Имя поиска взято из журналов сервера glassfi sh.

Glassfi sh jdb c ресурсы

Экземпляр ec2 с Glassfi sh имеет открытые порты: 8080,4848,3700,3306

Ошибка

org.omg.CORBA.COMM_FAILURE: FINE: 00410001: Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: ec2-54-89-178-215.us-east-1e.compute-1.amazonaws.com; port: 3700  vmcid: OMG  minor code: 1  completed: No
    at com.sun.proxy.$Proxy19.connectFailure(Unknown Source)
    at com.sun.corba.ee.impl.transport.ConnectionImpl.<init>(ConnectionImpl.java:253)
    at com.sun.corba.ee.impl.transport.ConnectionImpl.<init>(ConnectionImpl.java:276)
    at com.sun.corba.ee.impl.transport.ContactInfoImpl.createConnection(ContactInfoImpl.java:129)
    at com.sun.corba.ee.impl.protocol.ClientRequestDispatcherImpl.beginRequest(ClientRequestDispatcherImpl.java:242)
    at com.sun.corba.ee.impl.protocol.ClientDelegateImpl.request(ClientDelegateImpl.java:220)
    at com.sun.corba.ee.impl.protocol.ClientDelegateImpl.is_a(ClientDelegateImpl.java:378)
    at org.omg.CORBA.portable.ObjectImpl._is_a(ObjectImpl.java:130)
    at org.omg.CosNaming.NamingContextHelper.narrow(NamingContextHelper.java:69)
    at com.sun.enterprise.naming.impl.SerialContext$ProviderCacheKey.getNameService(SerialContext.java:1205)
    at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:393)
    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(InitialContext.java:417)
    at standaloneClient.Main.main(Main.java:22)
Caused by: java.lang.RuntimeException: java.nio.channels.UnresolvedAddressException
    at org.glassfish.enterprise.iiop.impl.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:344)
    at com.sun.corba.ee.impl.transport.ConnectionImpl.<init>(ConnectionImpl.java:250)
    ... 14 more
Caused by: java.nio.channels.UnresolvedAddressException
    at sun.nio.ch.Net.checkAddress(Net.java:101)
    at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:622)
    at com.sun.corba.ee.impl.misc.ORBUtility.openSocketChannel(ORBUtility.java:110)
    at org.glassfish.enterprise.iiop.impl.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:329)
    ... 15 more
Exception in thread "main" javax.naming.NamingException: Lookup failed for 'java:global/myFirtEar/myFirstEjb/FirstStatelessEjb!com.example.FirstStatelessEjbReomte' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=ec2-54-89-178-215.us-east-1e.compute-1.amazonaws.com, 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, org.omg.CORBA.ORBInitialHost=ec2-54-89-178-215.us-east-1e.compute-1.amazonaws.com, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is org.omg.CORBA.COMM_FAILURE: FINE: 00410001: Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: ec2-54-89-178-215.us-east-1e.compute-1.amazonaws.com; port: 3700  vmcid: OMG  minor code: 1  completed: No]]
    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(InitialContext.java:417)
    at standaloneClient.Main.main(Main.java:22)
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=ec2-54-89-178-215.us-east-1e.compute-1.amazonaws.com, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is org.omg.CORBA.COMM_FAILURE: FINE: 00410001: Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: ec2-54-89-178-215.us-east-1e.compute-1.amazonaws.com; port: 3700  vmcid: OMG  minor code: 1  completed: No]
    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: org.omg.CORBA.COMM_FAILURE: FINE: 00410001: Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: ec2-54-89-178-215.us-east-1e.compute-1.amazonaws.com; port: 3700  vmcid: OMG  minor code: 1  completed: No
    at com.sun.proxy.$Proxy19.connectFailure(Unknown Source)
    at com.sun.corba.ee.impl.transport.ConnectionImpl.<init>(ConnectionImpl.java:253)
    at com.sun.corba.ee.impl.transport.ConnectionImpl.<init>(ConnectionImpl.java:276)
    at com.sun.corba.ee.impl.transport.ContactInfoImpl.createConnection(ContactInfoImpl.java:129)
    at com.sun.corba.ee.impl.protocol.ClientRequestDispatcherImpl.beginRequest(ClientRequestDispatcherImpl.java:242)
    at com.sun.corba.ee.impl.protocol.ClientDelegateImpl.request(ClientDelegateImpl.java:220)
    at com.sun.corba.ee.impl.protocol.ClientDelegateImpl.is_a(ClientDelegateImpl.java:378)
    at org.omg.CORBA.portable.ObjectImpl._is_a(ObjectImpl.java:130)
    at org.omg.CosNaming.NamingContextHelper.narrow(NamingContextHelper.java:69)
    at com.sun.enterprise.naming.impl.SerialContext$ProviderCacheKey.getNameService(SerialContext.java:1205)
    at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:393)
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:329)
    ... 4 more
Caused by: java.lang.RuntimeException: java.nio.channels.UnresolvedAddressException
    at org.glassfish.enterprise.iiop.impl.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:344)
    at com.sun.corba.ee.impl.transport.ConnectionImpl.<init>(ConnectionImpl.java:250)
    ... 14 more
Caused by: java.nio.channels.UnresolvedAddressException
    at sun.nio.ch.Net.checkAddress(Net.java:101)
    at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:622)
    at com.sun.corba.ee.impl.misc.ORBUtility.openSocketChannel(ORBUtility.java:110)
    at org.glassfish.enterprise.iiop.impl.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:329)
    ... 15 more
...