This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 209127 - REST: Customer Database Example (Java EE 5) Sample Does Not Work
Summary: REST: Customer Database Example (Java EE 5) Sample Does Not Work
Status: RESOLVED FIXED
Alias: None
Product: webservices
Classification: Unclassified
Component: REST (show other bugs)
Version: 7.1.1
Hardware: All All
: P3 normal (vote)
Assignee: Denis Anisimov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-03 17:11 UTC by jyeary
Modified: 2012-04-06 10:06 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jyeary 2012-03-03 17:11:25 UTC
The sample REST: Customer Database Example (Java EE 5) application does not run when created from scratch and executed. Verified on GlassFish 3.1.2 and 2.1.1. The code needs to be updated. 

In addition, not all libraries (EclipseLink) are included in the project.
Comment 1 Denis Anisimov 2012-03-29 10:38:10 UTC
The issue is caused by: javax.naming.NamingException: Lookup failed for 'java:comp/env/persistence-factory' in SerialContext  [Root exception is javax.naming.NameNotFoundException: No object bound to name java:comp/env/persistence-factory]
	at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
	at javax.naming.InitialContext.lookup(InitialContext.java:392)
	at javax.naming.InitialContext.lookup(InitialContext.java:392)
	at customerdb.service.CustomerRESTFacade.getEntityManagerFactory(CustomerRESTFacade.java:68)
	at customerdb.service.CustomerRESTFacade.getJpaController(CustomerRESTFacade.java:74)
	... 42 more
Caused by: javax.naming.NameNotFoundException: No object bound to name java:comp/env/persistence-factory
	at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:684)
	at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:657)
	at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:148)
	at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:428)
	... 46 more
Comment 2 Denis Anisimov 2012-03-29 12:06:47 UTC
Still problems are discovered after fixing persistence factory issue. Got the exception trying to access some REST method :
com.sun.jersey.api.MessageException: A message body writer for Java class java.util.Vector, and Java type java.util.List<customerdb.DiscountCode>, and MIME media type application/xml was not found
The same is valid for JSON mime type.
It seems this is caused by absence Jersey jars in the project's classpath.
That's consequence of fix for issue #208706.

I'm able to fix the problem with JSON mime-type after adding some 
Jersey related jars from server bundle to project's classpath.
But still have a problem with XML mime type.
This is some runtime problem: message writer providers present at the server 
classpath but they are not used if application package doesn't contain them.

It seems this is related to the issue #209515.
But I didn't find a way to complete fix for current issue from 209515 issue's 
comments. This is JEE5 case and web.xml modification doesn't help.
I need help from GF runtime guys for workaround.

web-main#687df0e2b92e
Comment 3 japod 2012-03-29 13:33:34 UTC
(In reply to comment #2)
> Still problems are discovered after fixing persistence factory issue. Got the
> exception trying to access some REST method :
> com.sun.jersey.api.MessageException: A message body writer for Java class
> java.util.Vector, and Java type java.util.List<customerdb.DiscountCode>, and
> MIME media type application/xml was not found

What URI(s) you tried to access when the above messages were seen? 
I.e. how to reproduce?

Also when it comes to collection serialization, that scenario is not covered
by the JAX-RS spec. I.e. an application willing to serialize a JAXB bean list
is not JAX-RS compliant, unless it provides its own msg body writer
for the above. Then Jersey libs should probably be bundled
to make ensure portability. 

> The same is valid for JSON mime type.
> It seems this is caused by absence Jersey jars in the project's classpath.
> That's consequence of fix for issue #208706.

That is really strange, i need to reproduce locally to see what happens there.
> 
> I'm able to fix the problem with JSON mime-type after adding some 
> Jersey related jars from server bundle to project's classpath.
> But still have a problem with XML mime type.
> This is some runtime problem: message writer providers present at the server 
> classpath but they are not used if application package doesn't contain them.

In Jersey we have some workers for lists and arrays, but i am not sure about Vectors,
maybe that is the cause. As written above, i need to reproduce by myself.

> 
> It seems this is related to the issue #209515.
> But I didn't find a way to complete fix for current issue from 209515 issue's 
> comments. This is JEE5 case and web.xml modification doesn't help.
> I need help from GF runtime guys for workaround.
> 
> web-main#687df0e2b92e
Comment 4 Denis Anisimov 2012-03-30 07:04:58 UTC
(In reply to comment #3)
> (In reply to comment #2)
> > Still problems are discovered after fixing persistence factory issue. Got the
> > exception trying to access some REST method :
> > com.sun.jersey.api.MessageException: A message body writer for Java class
> > java.util.Vector, and Java type java.util.List<customerdb.DiscountCode>, and
> > MIME media type application/xml was not found
> 
> What URI(s) you tried to access when the above messages were seen? 
> I.e. how to reproduce?
NB Web project has "RESTful WSs" node. It has "Test RESTful WS" action item.
The result of this action is generated test client. It will be opened in the 
browser. It allows to send various requests to the RESTful WS with various 
HTTP methods and mime-types.
The exception is thrown on 
@GET
    @Produces({"application/xml", "application/json"})
    public List<DiscountCode> findAll() {
        return getJpaController().findDiscountCodeEntities();
    }
method , "rest.discountcode" URI is used.
> 
> Also when it comes to collection serialization, that scenario is not covered
> by the JAX-RS spec. I.e. an application willing to serialize a JAXB bean list
> is not JAX-RS compliant, unless it provides its own msg body writer
> for the above. Then Jersey libs should probably be bundled
> to make ensure portability. 
Yes, but different versions of Jersey are not compatible so there is no portability ( see ##208706 ).
> 
> > The same is valid for JSON mime type.
> > It seems this is caused by absence Jersey jars in the project's classpath.
> > That's consequence of fix for issue #208706.
> 
> That is really strange, i need to reproduce locally to see what happens there.
> > 
> > I'm able to fix the problem with JSON mime-type after adding some 
> > Jersey related jars from server bundle to project's classpath.
> > But still have a problem with XML mime type.
> > This is some runtime problem: message writer providers present at the server 
> > classpath but they are not used if application package doesn't contain them.
> 
> In Jersey we have some workers for lists and arrays, but i am not sure about
> Vectors,
> maybe that is the cause. As written above, i need to reproduce by myself.
Vector implements List. I don't know the real type of the result ( it is 
produced by JPA ) but REST interface doesn't declare Vector. Methods declares 
interfaces as return types: either List or Collection ( JPA entities ).
> 
> > 
> > It seems this is related to the issue #209515.
> > But I didn't find a way to complete fix for current issue from 209515 issue's 
> > comments. This is JEE5 case and web.xml modification doesn't help.
> > I need help from GF runtime guys for workaround.
> > 
> > web-main#687df0e2b92e
Comment 5 japod 2012-04-05 08:04:00 UTC
customerdb.DiscountCode is missing the @javax.xml.bind.annotation.XmlRootElement
annotation, try to add this annotation, and things should work fine:

--8<--
curl -Haccept:application/xml http://localhost:8080/CustomerDB/resources/customerdb.discountcode
                                       
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><discountCodes><discountCode><discountCode>72</discountCode><rate>16.00</rate></discountCode><discountCode><discountCode>77</discountCode><rate>11.00</rate></discountCode><discountCode><discountCode>76</discountCode><rate>7.00</rate></discountCode><discountCode><discountCode>78</discountCode><rate>0.00</rate></discountCode></discountCodes>
-->8--

Without the annotation, Jersey runtime can not tell the returned collection could be serialized into XML

The same most likely applies (not tested though) to the customerdb.Customer class.

Notice: the test client only shows a link to the application.wadl file, no left hand side pane
including root resource list is populated. Tested with Firefox/Chrome on my MacBook.
Comment 6 Denis Anisimov 2012-04-05 08:32:34 UTC
(In reply to comment #5)
> customerdb.DiscountCode is missing the
> @javax.xml.bind.annotation.XmlRootElement
> annotation, try to add this annotation, and things should work fine:
> 
> --8<--
> curl -Haccept:application/xml
> http://localhost:8080/CustomerDB/resources/customerdb.discountcode
> 
> <?xml version="1.0" encoding="UTF-8"
> standalone="yes"?><discountCodes><discountCode><discountCode>72</discountCode><rate>16.00</rate></discountCode><discountCode><discountCode>77</discountCode><rate>11.00</rate></discountCode><discountCode><discountCode>76</discountCode><rate>7.00</rate></discountCode><discountCode><discountCode>78</discountCode><rate>0.00</rate></discountCode></discountCodes>
> -->8--
> 
> Without the annotation, Jersey runtime can not tell the returned collection
> could be serialized into XML
> 
> The same most likely applies (not tested though) to the customerdb.Customer
> class.
That's right.
It's my fault. I completely missed that. I've been pretty sure that it worked 
before. Both entities has no JAXB annotation.
> 
> Notice: the test client only shows a link to the application.wadl file, no left
> hand side pane
> including root resource list is populated. Tested with Firefox/Chrome on my
> MacBook.
That's the consequence of default option in the 
"Test client configuration"  dialog. The default value is "locally generated client". It doesn't work in most of modern browsers. That's the security restrictions ( browsers don't allow to send HTTP requests to external domains ).
Comment 7 Denis Anisimov 2012-04-05 09:46:06 UTC
web-main#681433939ad3
Comment 8 Quality Engineering 2012-04-06 10:06:58 UTC
Integrated into 'main-golden', will be available in build *201204060400* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/681433939ad3
User: Denis Anisimov <ads@netbeans.org>
Log: Fix for BZ#209127 - REST: Customer Database Example (Java EE 5) Sample Does Not Work