2
votes

I’m developing Java EE application which has many integrations with other services. All integrations are done over remote EJB beans. So currently I have 3 or 4 EJB projects which are deployed as EARs on WebSphere to serve as mocks (since I don’t have access to real services in my development environment). What I want to do is to combine all of those mocks into one EAR package so I can have a single configuration page for mocks (return values, exceptions, etc.). So I made generalMock.ear application. The problem is now that EJB binding name is different than before.

For example the real application uses following binding name:

binding-name="java:global/company-app-calculator-ear/company-app-calculator-ejb/CalculatorSb!com.company.beans.app.calculator.CalculatorSbRemote" 

But now the binding name looks like this:

binding-name="java:global/general-mock-ear/company-app-calculator-ejb/CalculatorSb!com.company.beans.app.calculator.CalculatorSbRemote" 

Is there a way to change the global binding name? I have tried to create file “ibm-ejb-jar-bnd.xml” and add it to EJB mock’s META-INF folder where I wanted to change the binding name but I’s not working. Here is the content of my “ibm-ejb-jar-bnd.xml” configuration file:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-bnd_1_0.xsd"
             version="1.0">

    <session name="CalculatorSb">
        <interface
                binding-name="java:global/company-app-calculator-ear/company-app-calculator-ejb/CalculatorSb!com.company.beans.app.calculator.CalculatorSbRemote"
                class="com.company.beans.app.calculator.CalculatorSbRemote"/>
    </sescomon>
</ejb-jar-bnd>

I'm using IBM WebSphere 8.5 running on Java 1.6 EE.

2

2 Answers

3
votes

The format of the java: names are defined by the Java EE and EJB specifications for portability across providers. In general, the specification does not provide a way to override these names, nor does WebSphere.

The <interface> element in the ibm-ejb-jar-bnd.xml file may be used in traditional WebSphere to define where an EJB is bound in the server context root (not a java: location), in addition to the java: location. The binding-name value must not start with java:.

Basically, you would need to change the name of your mock EAR, or set the application name in application.xml, but it seems that would only solve the problem for one of the EJB modules in your mock application.

Perhaps consider using EJB references instead of performing direct lookups in java:global. This would allow your application to always lookup the EJB reference name, which would never change. You would just need to bind the EJB reference name to either the real name or mock name depending on the environment.

1
votes

Have you tried using the simple-binding-name for EJB by adding a file META-INF/ibm-ejb-jar-bnd.xml? It will look something like this for:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar-bnd
        xmlns="http://websphere.ibm.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-bnd_1_0.xsd"
        version="1.0">

    <session simple-binding-name="ejb/session/myEJBBean" name="myEJBBean">

</ejb-jar-bnd>

Now client can connect to above EJB by mapping ejb rerference to the simple binding name.

<ejb-ref name="myRef" binding-name="ejb/session/myEJBBean"/>