6

This is my first question in Stack Overflow so I expect it will not be too much simple. I've been looking around Internet for a good solution but by now I don't have it.

I am a very begginer to EJB, JNDI and Java EE world in general, but on the last months I've been able to do some acceptable things in this environment. Now I am focusing a problem at work and by now the solution is not as good as I would like.

The scenario is this: I have a EAR application running in Glassfih 3.1.2. I have declared EJBs within this EAR app with stateless beans offering methods through a remote Interface.

This is my Remote Bean running in a server called server1, for example

package com.booreg;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;

import com.booreg.IMyRemoteBean;

@Stateless
@LocalBean
public class MyRemoteBean implements IMyRemoteBean
{
    @Override
    public String helloWorld()
    {
        return "Hi what's up boy";
    }
}

This is the interface for it

package com.booreg;

import javax.ejb.Remote;

@Remote
public interface IMyRemoteBean
{
    public String helloWorld();
}

Then I have a second EAR app that must run imperatively on another server, called server2. The second APP is using JSF and Managed Beans. We have a Managed Bean acting as a remote client of MyRemoteBeanRemote, as this:

package com.nucleus;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import com.booreg.IMyRemoteBean;

@ManagedBean
@ViewScoped
public class MyManagedBean
{
    @EJB( name="TheRef") IMyRemoteBean myRemoteBean;

    public String getPhrase() { return myRemoteBean.helloWorld(); }
}

I've arrived to the point that this works declaring an ejb-ref inside WEB-INF/sun-web.xml file in my web project.

<ejb-ref>
    <ejb-ref-name>TheRef</ejb-ref-name>
    <jndi-name>corbaname:iiop:server1:3700#java:global/booreg/booreg.ejb/MyRemoteBean!com.booreg.IMyRemoteBean</jndi-name>
</ejb-ref>

I understand that with this sun-web.xml file the jndi-name makes the second app to know where to locate the ejb implementation located at first app. But here I have some questions:

  1. It's necessary to declare one ejb-ref entry for each EJB interface I have in my project ?
  2. How can I avoid making a static reference to server/port (server1:3700 during development) inside sun-web.xml ? When this will go into production I will have to change manually the sever name for each ?? This sounds bizarre. Can I use some kind of variable at server side to specify server/port ?

I expect I have explained myself well enough.

Many thanks

Update: finally, thanks to this link I see that is possible to make references to the ejb server (server1) creating a jndi.properties file inside my classpath. This file should contain lines like this.

java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory
java.naming.factory.url.pkgs=com.sun.enterprise.naming
java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl
org.omg.CORBA.ORBInitialHost=server1
org.omg.CORBA.ORBInitialPort=3700

But I am still facing problems. When deploying the application appear the next exception at server1 an I can't deploy the application.

ADVERTENCIA: IOP00100006: Class com.sun.jersey.server.impl.cdi.CDIExtension is not Serializable
org.omg.CORBA.BAD_PARAM: ADVERTENCIA: IOP00100006: Class com.sun.jersey.server.impl.cdi.CDIExtension is not Serializable  vmcid: SUN  minor code: 6 completed: Maybe
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at com.sun.corba.ee.spi.orbutil.logex.corba.CorbaExtension.makeException(CorbaExtension.java:248)
    at com.sun.corba.ee.spi.orbutil.logex.corba.CorbaExtension.makeException(CorbaExtension.java:95)
    at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator.handleFullLogging(WrapperGenerator.java:387)
    at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator.access$400(WrapperGenerator.java:107)
    at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator$2.invoke(WrapperGenerator.java:511)
    at com.sun.corba.ee.spi.orbutil.proxy.CompositeInvocationHandlerImpl.invoke(CompositeInvocationHandlerImpl.java:99)
    at $Proxy117.notSerializable(Unknown Source)
    at com.sun.corba.ee.impl.orbutil.ORBUtility.throwNotSerializableForCorba(ORBUtility.java:783)
    at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.write_abstract_interface(CDROutputStream_1_0.java:697)
    at com.sun.corba.ee.impl.encoding.CDROutputObject.write_abstract_interface(CDROutputObject.java:545)
    at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.writeAbstractObject(Util.java:493)
    ...

Anybody has any idea ?

4

1 に答える 1

0

@dgisbert

あなたが言及した最後のコメントでは、一方のサーバーはパブリックであり、もう一方のサーバーは企業の内部サーバーです。パブリック サーバーからアプリケーション レイヤーを適切に呼び出すことは、ベスト プラクティスではありません。これは、重要なビジネス レイヤーへのアクセスを直接許可していることを意味します。パブリック サイトからのすべての呼び出しが WebServer -> App Server を経由する必要があるように、EJB 呼び出しの上に Web サービス レイヤーを配置することをお勧めします。このようにして、攻撃のリスクを大幅に減らすことができます

于 2013-02-08T17:08:35.247 に答える