Bug 180952 - Sample JSP generator chokes on interfaces and abstract classes
Summary: Sample JSP generator chokes on interfaces and abstract classes
Status: CLOSED FIXED
Alias: None
Product: WTP Webservices
Classification: WebTools
Component: wst.ws (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P2 major (vote)
Target Milestone: 1.5.4 M154   Edit
Assignee: Andrew Mak CLA
QA Contact: Chris Brealey CLA
URL:
Whiteboard: PMC_approved
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-04 10:20 EDT by Chris Brealey CLA
Modified: 2007-04-20 16:44 EDT (History)
2 users (show)

See Also:


Attachments
Example of Java service using abstract classes and interfaces (1.33 KB, application/x-zip-compressed)
2007-04-04 10:25 EDT, Chris Brealey CLA
no flags Details
Patch for jst.ws.consumption plugin (13.22 KB, patch)
2007-04-10 22:08 EDT, Andrew Mak CLA
no flags Details | Diff
updated patch (13.15 KB, patch)
2007-04-12 12:42 EDT, Andrew Mak CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Brealey CLA 2007-04-04 10:20:16 EDT
The Sample Web application JSPs emitted for a Java service class by the Web Service (JAX-RPC) Sample JSP generator will fail to compile and run if the Java service class' methods use, directly or indirectly, abstract beans or bean interfaces. The symptom appears as an HTTP 500 in the Results frame of the Sample Web app with this root cause:

org.apache.jasper.JasperException: /sampleService/Result.jsp(27,8) The value for the useBean class attribute example.ThingInterface is invalid.

The reason this occurs is that the Sample JSP generator does not verify that each bean it encounters while analyzing the service class is concrete and has a public default constructor.

Ideally, the Sample JSP generator should search for viable concrete subclasses of any interfaces or abstract classes and emit JSPs that provide the user with a way to choose from possibly many such concrete classes and fill in their fields, however, this degree of dynamism is beyond the scope of the Sample JSP facility.

Therefore, the generator should at minimum detect method parameters or bean properties whose types are abstract classes, interfaces or not in possession of a public default CTOR. In such cases, the generator should not emit an input form fragment for the type. Furthermore, if the unsupported type is used by a method parameter, the generator should emit a 'null' value for the parameter where the method is invoked.
Comment 1 Chris Brealey CLA 2007-04-04 10:25:21 EDT
Created attachment 62926 [details]
Example of Java service using abstract classes and interfaces

To reproduce the problem, insure you have Sample JSP friendly Web application server installed such as Apache Tomcat, import the attached jar into a Java project, right click on Service.java, and choose to Generate Sample JSPs.
Comment 2 Chris Brealey CLA 2007-04-04 10:28:15 EDT
Raised priority to P2. Targetted to 1.5.4.
Comment 3 Chris Brealey CLA 2007-04-10 15:30:01 EDT
Andrew, reassigned to you. Thanks for investigating.
Comment 4 Andrew Mak CLA 2007-04-10 22:08:36 EDT
Created attachment 63456 [details]
Patch for jst.ws.consumption plugin

This patch will detect types which cannot be instanstiated via the useBean jsp action and does not emit code fragments for them.
Comment 5 Andrew Mak CLA 2007-04-10 22:12:04 EDT
This patch is ready for review, thanks!
Comment 6 Chris Brealey CLA 2007-04-12 09:09:57 EDT
Andrew, thanks for the patch. Two observations:

1. JavaMofTypeVisitorAction.hasDefaultConstructor() is searching methods returned by JavaClass.getPublicMethods(). If I have a class with at least one non-public CTOR and zero public CTORs, then it looks like this method will incorrectly return 'true'. Shouldn't we be searching all methods for a class that either (A) has no CTORs of any access level or (B) has a public default CTOR?

2. The generator should produce a warning to the user that interfaces, abstracts, and otherwise non-public-default-constructable classes have been encountered, similar to what it does for other unsupported types. In part because of the impact to translatable properties, I consider this beyond the scope of a service release and the central issue of this bug (JSPs that don't compile). Would you please open a separate bug for the JSP generator to notify the user that non-constructable stuff was found? Either we can use the generator's existing mechanism for queueing up warning conditions and presenting them in a dialog, or we can generate a placeholder into the input form to tell the user their method or property was not forgotten, but has been wired to null and can only be changed by hand-customizing the JSPs.
Comment 7 Andrew Mak CLA 2007-04-12 12:42:21 EDT
Created attachment 63631 [details]
updated patch

Chris, you are quite right, we need to check for non-public default constructors as well.  Here is an updated patch to do this.

bug 182167 is opened re your second comment.
Comment 8 Chris Brealey CLA 2007-04-13 09:34:26 EDT
Thanks Andrew, the new patch looks good.

PMC, please approve for WTP 1.5.4. This fix does the minimum to keep the JSP generator from spewing forth JSPs with unhealthy useBean tags.
Comment 9 David Williams CLA 2007-04-17 01:36:19 EDT
+1 
spewing unhealthy JSP's must be avoided. :) 
Comment 10 Tim deBoer CLA 2007-04-17 17:48:17 EDT
+1
Comment 11 Peter Moogk CLA 2007-04-18 16:30:37 EDT
The fix for this defect has been committed and released to the 1.5.4 stream under v200704182024.
Comment 12 Chris Brealey CLA 2007-04-20 16:43:50 EDT
Verified on 1.5.4 RC1.
Comment 13 Chris Brealey CLA 2007-04-20 16:44:10 EDT
Thanks for the fix, Andrew. Closed.