tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Apache Fan (JIRA)" <j...@apache.org>
Subject [jira] [Created] (OPENEJB-2113) Embeddable EjbContainer - unable to set up environment variables
Date Sun, 05 Apr 2015 12:11:33 GMT
Apache Fan created OPENEJB-2113:
-----------------------------------

             Summary: Embeddable EjbContainer - unable to set up environment variables
                 Key: OPENEJB-2113
                 URL: https://issues.apache.org/jira/browse/OPENEJB-2113
             Project: OpenEJB
          Issue Type: Bug
          Components: configuration
    Affects Versions: 4.7.1
         Environment: Tomee 1.7.1, Java 1.7.0_72 64bit, Windows 7
            Reporter: Apache Fan


My singleton EJB pulls environment value resources from web.xml and Tomee's context.xml. It
works fine when executed in Tomee, but it is not possible to initialize the bean by using
Embeddable EJBContext, the references to the resource remain null.

EJB:
{noformat}
    @Resource(name = "serviceendpoint.url")
    private String serviceEndpointUrl;

    @Resource(lookup = "java:comp/env/serviceendpoint.url")
    private String serviceEndpointUrl2;
{noformat}

web.xml
{noformat}
  <env-entry>
    <env-entry-name>serviceendpoint.url</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>https://blabla.com/rest/</env-entry-value>
  </env-entry>
{noformat}

Tomee context.xml:
{noformat}
<Environment name="serviceendpoint.url" type="java.lang.String" value="https://blabla-bla-bla.com/api/"
/>
{noformat}

Use of EJBContext:
{noformat}
final Properties p = new Properties();
p.put("serviceendpoint.url", "https://blahhhhhh.com/rest/");

final Context context = EJBContainer.createEJBContainer(p).getContext();
context.bind("java:comp/env/serviceendpoint.url", "https://blahhhhhh.com/rest/");

MyBean bean = (MyBean) context.lookup("java:global/myApp/myBean");
{noformat}

As a result the serviceEndpointUrl and serviceEndpointUrl2 members remain null during the
use of EJBContainer. In Tomee container they do fine.

What could cause this problem?

Workaround:
{noformat}
@PostConstruct
public void getConnection() {
  if (serviceEndpointUrl == null) {
            // support for embedded EJB container for testing:
            serviceEndpointUrl = System.getProperty("serviceendpoint.url");
            if (serviceEndpointUrl == null) {
                throw new IllegalStateException("unable to determine the value of environment
var: serviceendpoint.url");
            }
  }
....
}
{noformat}
 




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message