[GLASSFISH-2105] EJB Web Service resource injection occuring after @PostConstruct method is invoked Created: 19/Jan/07  Updated: 25/Feb/12  Resolved: 01/Jun/07

Status: Resolved
Project: glassfish
Component/s: web_services
Affects Version/s: 9.1pe
Fix Version/s: 9.1pe

Type: Bug Priority: Major
Reporter: Joe Fialli Assignee: mikeg
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All


Attachments: Java Source File PublisherBean.java     Java Source File Simple.java     Java Archive File wstxSampleService-ejb.jar    
Issue Links:
Related
is related to GLASSFISH-18406 @EJB injection fails but JNDI lookup ... Open
Issuezilla Id: 2,105

 Description   

Copying a JMS Connection Factory idiom used by a Stateless EJB in Java EE
tutorial, this idion does not work for a Web Service EJB. The resource injected
connection factory is null, when the @PostConstruct method is called. Here
is app server log trace of issue.

Component versions involved:
Glassfish promoted build 30.
Developer build of latest WSIT libraries from 1/19/2007.

Begin app server log trace of deployment of web service:

wsgen successful
wsgen successful
DPL5306:EJB Web Service Endpoint [Simple] listening at address
http://scarry-nt.east.sun.com:8080/SimpleService/Simple
DPL5306:EJB Web Service Endpoint [Bank] listening at address
http://scarry-nt.east.sun.com:8080/BankService/Bank
deployed with moduleid = wstxSampleService-ejb
ADM1041:Sent the event to instance:[ModuleDeployEvent – enable
ejb/wstxSampleService-ejb]
acquiring JMS connection for instance wstx.sample.service.Simple@173d72d
assertion failure: connectionFactory should not be null, resource injection for
connectionFactory has not occurred yet.
Simple.makeConnection:Exception: java.lang.NullPointerException

End app server log file.

Workaround for this problem is to call makeConnection()
once within one of the EJB methods when it notices that
connection has not been set yet.

Will attach source file and ejb jar file for this issue.

Fragment of web service ejb illustrating key components

@WebService(portName = "SimpleServiceBinding",
targetNamespace = "http://tempuri.org/"
)
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class Simple {

private Connection connection = null;

@Resource(mappedName = "jms/ConnectionFactory")
private ConnectionFactory connectionFactory;

/**

  • Creates the connection.
    */
    @PostConstruct
    public void makeConnection() {
    logger.info("acquiring JMS connection for instance " + this.toString());
    try
    Unknown macro: { if (connectionFactory == null) { System.out.println("assertion failure: connectionFactory should not be null, resource injection for connectionFactory has not occurred yet."); } connection = connectionFactory.createConnection(); }

    catch (Throwable t)

    { // JMSException could be thrown logger.severe("Simple.makeConnection:" + "Exception: +t.toString()); }

    }



 Comments   
Comment by Joe Fialli [ 19/Jan/07 ]

Created an attachment (id=699)
Web Service EJB with resource injection of JMS connection factory and a @PostConstruct annotated method

Comment by Joe Fialli [ 19/Jan/07 ]

Created an attachment (id=700)
EJB jar to recreate this issue. Just deploy ejb jar and look at server log for reported error to recreate. Error will not print if resource injection of connectionFactory instance occurs BEFORE the @PostConstruct method is called.

Comment by Joe Fialli [ 19/Jan/07 ]

Created an attachment (id=701)
Java EE tutorial sample that JMS Connection idiom was adapted from.

Comment by vijaysr [ 21/Feb/07 ]

reassigning

Comment by gfbugbridge [ 27/Apr/07 ]

<BT6543271>

Comment by mikeg [ 01/Jun/07 ]

Fixed in build b50.

Generated at Sun Sep 25 02:50:22 UTC 2016 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.