Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 347654

Summary: MessageDriven bean EJB 3 wizard generates non-portable code
Product: [WebTools] WTP EJB Tools Reporter: Max Rydahl Andersen <manderse>
Component: jst.ejbAssignee: Kaloyan Raev <kaloyan>
Status: RESOLVED FIXED QA Contact: Kaloyan Raev <kaloyan>
Severity: major    
Priority: P3 CC: cbridgha, ccc, stryker
Version: unspecifiedFlags: kaloyan: review? (stryker)
Target Milestone: 3.4.2   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Ensuring a new property is added
kaloyan: iplog+
Reworked patch - fix done in the JET template and model none

Description Max Rydahl Andersen CLA 2011-05-30 09:54:59 EDT
Build Identifier: Indigo/Helios probably also Ganymede

The code generated by MessageDriven bean wizard is generating code that uses the non-portable mappedName attribute. It should use the standardized ActivationConfig property instead.

Reproducible: Always

Steps to Reproduce:
1. Create EJB3 Project
2. Run 'EJB/Message Driven Bean (EJB3.x) wizard
3. Fill, package name, class name, check JMS, select 'Queue' and enter 'queue' to be destination name
4. Finish

Current result:
@MessageDriven(
		activationConfig = { @ActivationConfigProperty(
				propertyName = "destinationType", propertyValue = "javax.jms.Queue"
		) }, 
		mappedName = "queue")
public class MyMdb implements MessageListener {

This will fail to deploy on JBoss (and possibly others too) since the mappedName is *undefined* in the spec it is ignored.

A better and more portable result would be:

@MessageDriven(
		activationConfig = { @ActivationConfigProperty(
				propertyName = "destinationType", propertyValue = "javax.jms.Queue"
		),@ActivationConfigProperty(
				propertyName = "destination", propertyValue = "queue"
		)  })
public class MyMdb implements MessageListener {

This should work across most app servers since the destination and destionType attribute is *defined* which is not the case for mappedName.
Comment 1 Max Rydahl Andersen CLA 2011-05-30 09:55:29 EDT
Related JBoss jira issues: https://issues.jboss.org/browse/JBIDE-8530
Comment 2 Max Rydahl Andersen CLA 2011-05-30 10:20:29 EDT
Just to document this is what the javadoc spec actually says:

http://download.oracle.com/javaee/5/api/javax/ejb/MessageDriven.html

"A product specific name(e.g. global JNDI name of a queue) that this message-driven bean should be mapped to. Application servers are not required to support any particular form or type of mapped name, nor the ability to use mapped names. The mapped name is product-dependent and often installation-dependent. No use of a mapped name is portable. "

notice the "No use of a mapped name is portable" phrase.
Comment 3 Rob Stryker CLA 2011-08-16 13:57:28 EDT
Created attachment 201597 [details]
Ensuring a new property is added

Could you all please point out where in the spec "destination" and "destinationType" are defined?   

The attached patch adds the destination to the config without removing the mapped name. It could be argued my impl is shit, but it's the best I could do without understanding more about the surrounding infrastructure of the tools.
Comment 4 Rob Stryker CLA 2011-08-18 04:12:11 EDT
Pinging the QA lead
Comment 5 Rob Stryker CLA 2011-08-18 04:13:25 EDT
To be clear, my patch performs the following:

@MessageDriven(
        activationConfig = { @ActivationConfigProperty(
                propertyName = "destinationType", propertyValue =
"javax.jms.Queue"
        ),@ActivationConfigProperty(
                propertyName = "destination", propertyValue = "queue"
        )  }, 
        mappedName = "queue")
public class MyMdb implements MessageListener {


The reason my patch does this is in case other tools depend on the mappedName = "queue" attribute that has been there forever.
Comment 6 Kaloyan Raev CLA 2011-08-18 04:22:11 EDT
Rob, I am reviewing it right now.
Comment 7 Kaloyan Raev CLA 2011-08-18 10:39:44 EDT
Created attachment 201722 [details]
Reworked patch - fix done in the JET template and model

The original patch of Rob fixes the problem in the code generated by the JET engine. This patch fixes the problem also in the JET template and model.
Comment 8 Kaloyan Raev CLA 2011-08-18 10:43:07 EDT
Rob, could you confirm that the patch I've attached does the same as you original patch?

BTW, I've also searched in the EJB spec, but could not find the "destination" property specified. It would be good to have a reference to the relevant chapter in the spec.
Comment 9 Kaloyan Raev CLA 2011-08-24 06:54:26 EDT
Rob, have you got time to review the re-worked patch?
Comment 10 Rob Stryker CLA 2011-08-29 03:19:14 EDT
I will have time this week.  I needed to wait get Max's approval and spec reference, and he's been on vacation.
Comment 11 Kaloyan Raev CLA 2011-10-02 09:24:31 EDT
The Indigo SR1 train passed away. Moving for SR2.
Comment 12 Kaloyan Raev CLA 2012-01-26 03:52:37 EST
Rob, Max, do you still need this for the Indigo stream?
If yes, then please review the last patch.
Comment 13 Max Rydahl Andersen CLA 2012-05-23 13:50:24 EDT
The train has passed for Indigo - how about Juno ?
Comment 14 Rob Stryker CLA 2012-05-24 04:48:49 EDT
> It would be good to have a reference to the relevant chapter in the spec.


You'll want to lookat b.2.1.1 of the j2ee connector specification, which reads as follows:

destination

In general, a destination is a logical link between a message producer and a
consumer. A message producer produces messages addressed to a destination, and a
message consumer consumes messages from a chosen destination. 

A destination could be represented by a JMS provider in different ways. For example, it could be encapsulated as textual data (this may be specified by endpoint developer or assembler in the endpoint deployment descriptor) or as a private object available only at deployment time. Hence, it may not always be specified in an endpoint deployment descriptor (since deployment descriptor entries contain textual data only). 

However, during endpoint deployment JMS ActivationSpec JavaBean requires a value for the destination property. While configuring the JMS ActivationSpec JavaBean, the endpoint deployer must provide a value for this property (if it is not already present in the endpoint deployment descriptor). 

It is recommended that destination be specified by a JMS resource adapter provider as a property on the ActivationSpec JavaBean that requires a value. This can be specified in the JMS resource adapter deployment descriptor.

The destination property value may also be an object that implements the javax.jms.Destination interface. In such a case, the resource adapter should provide an administered object that implements the javax.jms.Destination interface.
Comment 15 Max Rydahl Andersen CLA 2012-05-25 17:34:51 EDT
And B 2.1.2 that talks about Destinationtype property.
Comment 16 Kaloyan Raev CLA 2012-05-28 04:04:10 EDT
Rob, Max, thank you for the references. 

Assuming you have reviewed the reworked patch I attached some time ago, I will apply it for Juno SR1.
Comment 17 Chuck Bridgham CLA 2012-09-06 14:25:54 EDT
Did we apply this patch?
Comment 18 Kaloyan Raev CLA 2012-09-10 10:56:50 EDT
Thanks for the reminder Chuck! Unfortunately, I did not. I waited for the Git migration to complete and then simply forgot. I will make sure to commit this change early for Juno SR2.
Comment 19 Rob Stryker CLA 2012-10-03 12:24:16 EDT
Hey Kaloyan:

Just a ping reminder to push this in to master and sr2 if possible ;)
Comment 20 Kaloyan Raev CLA 2012-10-04 04:49:22 EDT
Patch pushed to master: http://git.eclipse.org/c/ejb/webtools.ejb.git/commit/?id=d01e8201d9bb0b67c10353edba72d87b323bf97c
and to R3_4_maintenance: http://git.eclipse.org/c/ejb/webtools.ejb.git/commit/?h=R3_4_maintenance&id=a7795dbcf6f80c31e9a33a4a98523b1d11edb4d4

Hopefully I updated the map files correctly and the patch will be included in the next build.
Comment 21 Kaloyan Raev CLA 2012-10-05 04:35:14 EDT
The changes should be included in this build: http://build.eclipse.org/webtools/committers/wtp4x-R3.4.2-M/20121004182514/M-3.4.2-20121004182514/