1 2 Previous Next 19 Replies Latest reply on Apr 13, 2011 3:11 AM by lvdberg

    RestEasy Put method - Unable to mark for rollback on PersistenceException:

    olasamuel
      Hi All,

      Can someone please point me to what I am doing wrong as I am begining to be skeptical about seam at this moment.

      OK again I am using seam RestEasy and I am using the @PUT.


      This is my code

      @Path("/UpdateBalance/{msisdn}/{newBal}")
           @Produces(MediaType.TEXT_HTML)
           @POST
           public String updateBalance(@PathParam("msisdn") String msisdn, @PathParam("newBal")long newBal) {
                
                System.out.println("updateBalance( msisdn: "+msisdn+" , newBalance: "+newBal+" )");
                entityManager.clear();
                Query balInquiryQuery = entityManager.createQuery("UPDATE SubscriberTopUp sup SET    sup.balance=(sup.balance+1200) WHERE sup.msisdn='234165'");
                balInquiryQuery.executeUpdate();
                
                
                return  "Returning: String updateBalance( msisdn: "+msisdn+" , newBalance: "+newBal+" )";
           }


      If I remove the four lines of query just to test and see if PUT work without using any database it works very fine. However, if I put these four lines of query as it is above I got this error and the page display a forbidden error with error code 403 for me.

      Is there any security that I need to set somewhere that I am mistakenly ignoring. Can someone please tell me what I am doing wrong.


      This is my complete log file below:


      2011-03-30 15:21:15,049 INFO  [STDOUT] updateBalance( msisdn: 234165 , newBalance: 70000 )
      2011-03-30 15:21:15,060 ERROR [org.hibernate.ejb.AbstractEntityManagerImpl] Unable to mark for rollback on PersistenceException:
      java.lang.IllegalStateException: [com.arjuna.ats.internal.jta.transaction.arjunacore.nosuchtx] [com.arjuna.ats.internal.jta.transaction.arjunacore.nosuchtx] No such transaction!
           at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.setRollbackOnly(BaseTransaction.java:191)
           at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.setRollbackOnly(BaseTransactionManagerDelegate.java:123)
           at org.hibernate.ejb.AbstractEntityManagerImpl.markAsRollback(AbstractEntityManagerImpl.java:421)
           at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:576)
           at org.hibernate.ejb.QueryImpl.executeUpdate(QueryImpl.java:48)
           at za.co.csir.meraka.mobi4d.console.admin.resource.SubscriberTopUpResourceImpl.updateBalance(SubscriberTopUpResourceImpl.java:136)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
           at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
           at org.jboss.seam.resteasy.ResteasyContextInjectionInterceptor.aroundInvoke(ResteasyContextInjectionInterceptor.java:59)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
           at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
           at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
           at za.co.csir.meraka.mobi4d.console.admin.resource.SubscriberTopUpResourceImpl_$$_javassist_seam_6.updateBalance(SubscriberTopUpResourceImpl_$$_javassist_seam_6.java)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
           at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:246)
           at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:214)
           at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:204)
           at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:486)
           at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:463)
           at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:117)
           at org.jboss.seam.resteasy.ResteasyResourceAdapter$1.process(ResteasyResourceAdapter.java:146)
           at org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:65)
           at org.jboss.seam.resteasy.ResteasyResourceAdapter.getResource(ResteasyResourceAdapter.java:122)
           at org.jboss.seam.servlet.SeamResourceServlet.service(SeamResourceServlet.java:80)
           at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
           at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
           at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
           at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
           at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)
           at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
           at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
           at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
           at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
           at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
           at java.lang.Thread.run(Thread.java:619)

      I will greatfully appreciate an urgent explanantion of what is going on here. I am using Firefox restclient to test my code.
        • 1. Re: RestEasy Put method - Unable to mark for rollback on PersistenceException:
          olasamuel

          Hi,


          Can I assume that no one can provide answer(s) or lead to this question. I have posted this question on Put usage to this forum more than two times without getting any response that can help. I have also looked at the examples that was exposed by seam on RestEasy and there seems to be no implementation of PUT that one can use to as a lead as well. In fact I also have the privileged to look at the thesis that Josef Hartinger wrote on this and there also seem to be no mention of PUT as well as to how one can implement this.


          I will therefore like to ask to what conviction does one have in using seam RestEasy as it seems like its implementation is not complete for now and its causing frustration especially when you post question and no one seem to respond. This I ask with humility.


          Thank you

          • 2. Re: RestEasy Put method - Unable to mark for rollback on PersistenceException:
            lvdberg

            Hi,


            To begin with: On behalf of all unpaid forum members I ask humble forgiveness for the fact  that we are not able to answer your - only partially to Seam related - question within 24 hours.


            First things first:


            . you mention a PUT but I only see a POST annotation.
            - I don't see a Transactional annotation
            - You didn't send in any additional code, so I assume that you configured the @In's correctly
            - have you tried to create a standard (seam enabled) bean which is called from your REST and provides the DB-functionality.


            Leo


            P.S: Maybe you should read Restful java from Bill Burke 2010. which describes how to use all the HTTP-methods with Rest an especially with RestEasy?







            • 3. Re: RestEasy Put method - Unable to mark for rollback on PersistenceException:
              jharting

              It seems that you are using a POJO as a JAX-RS resource. POJOs do not support transactional processing. Therefore, you should either use @Transactional annotation to enable the TransactionInterceptor on your resource (like Leo said) or use a Session Bean.


              P.S. You should probably read the thesis once more, since I definitely used PUT in the Seam Application Framework extension as well as demostrated its use in the seam-tasks sample application.

              • 4. Re: RestEasy Put method - Unable to mark for rollback on PersistenceException:
                olasamuel
                Thank you very much Leo and also Jozef for your response. After I saw your message, I decided to do a lot of research and now I tried it out again and this time This is what I got as the error "org.jboss.resteasy.plugins.providers.jaxb.JAXBUnmarshalException: Could not find JAXBContextFinder for media type: text/plain;charset="UTF-8"". I am posting my complete source code and the error log that I got below. Can you please tell me what I am doing wrong and where I am doing it wrongly. I would really appreciate that. I have used at transaction and may be I do not know where to put it. Please see below the code and the error messages.


                The Error Log

                2011-04-07 01:02:26,294 ERROR [org.jboss.resteasy.core.SynchronousDispatcher] Failed executing PUT /subscriberTopUpResource/updateBalance/234165/70000
                org.jboss.resteasy.plugins.providers.jaxb.JAXBUnmarshalException: Could not find JAXBContextFinder for media type: text/plain;charset="UTF-8"
                     at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.findJAXBContext(AbstractJAXBProvider.java:49)
                     at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.readFrom(AbstractJAXBProvider.java:79)
                     at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:105)
                     at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.read(GZIPDecodingInterceptor.java:46)
                     at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:108)
                     at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(ReaderUtility.java:111)
                     at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(ReaderUtility.java:93)
                     at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:146)
                     at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:114)
                     at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137)
                     at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:246)
                     at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:214)
                     at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:204)
                     at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:486)
                     at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:463)
                     at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:117)
                     at org.jboss.seam.resteasy.ResteasyResourceAdapter$1.process(ResteasyResourceAdapter.java:146)
                     at org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:65)
                     at org.jboss.seam.resteasy.ResteasyResourceAdapter.getResource(ResteasyResourceAdapter.java:122)
                     at org.jboss.seam.servlet.SeamResourceServlet.service(SeamResourceServlet.java:80)
                     at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                     at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                     at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                     at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                     at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                     at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
                     at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                     at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
                     at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
                     at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                     at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                     at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)
                     at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                     at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
                     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                     at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
                     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
                     at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
                     at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
                     at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
                     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                     at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
                     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
                     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
                     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
                     at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
                     at java.lang.Thread.run(Thread.java:619)



                Complete Source Code

                The Interface


                package za.co.csir.meraka.mobi4d.console.admin.resource;

                import javax.ws.rs.GET;
                import javax.ws.rs.POST;
                import javax.ws.rs.PUT;
                import javax.ws.rs.Path;
                import javax.ws.rs.PathParam;
                import javax.ws.rs.Produces;
                import javax.ws.rs.QueryParam;
                import javax.ws.rs.core.MediaType;

                import org.jboss.seam.annotations.Transactional;

                import admin.entity.SubscriberTopUp;




                public interface SubscriberTopUpResource {
                     
                     
                     @GET
                     @Path("/{msisdn}")
                     public SubscriberTopUp getSubscriberTopUp(@PathParam("msisdn") String msisdn);
                     
                     
                     @POST
                     @Path("/create")
                     @Produces(MediaType.TEXT_PLAIN)
                     public SubscriberTopUp createSubscriberTopUp(SubscriberTopUp subscriberTopUp);
                     
                     
                     @PUT
                     @Path("/updateBalance/{msisdn}/{newBal}")
                     @Produces(MediaType.TEXT_HTML)
                     @Transactional
                     public   SubscriberTopUp updateSubscriberTopUp(SubscriberTopUp subscriberTopUp, @QueryParam("msisdn") String msisdn, @QueryParam("newBal") long newBal);
                     
                     @GET
                     @Path("/reserveUnits")
                     @Produces(MediaType.TEXT_PLAIN)
                     public String reserveUnits(@QueryParam("msisdn") String msisdn, @QueryParam("requestedUnits") long requestedUnits,@QueryParam("requestedAction") int requestedAction);
                     
                     @GET
                     @Path("/results")
                     @Produces(MediaType.TEXT_PLAIN)
                     public String getResults(@QueryParam("msisdn") long msisdn);
                     

                }






                And the Implementation


                package za.co.csir.meraka.mobi4d.console.admin.resource;

                import java.util.List;


                import org.jboss.seam.Component;
                import org.jboss.seam.annotations.In;
                import org.jboss.seam.annotations.Name;
                import org.jboss.seam.faces.FacesMessages;

                import javax.faces.application.FacesMessage;
                import javax.persistence.EntityManager;
                import javax.persistence.Query;
                import javax.ws.rs.Path;
                import javax.ws.rs.PathParam;
                import javax.ws.rs.Produces;
                import javax.ws.rs.QueryParam;
                import javax.ws.rs.core.MediaType;
                import javax.ws.rs.core.Response.Status;
                import javax.ws.rs.WebApplicationException;
                import javax.ws.rs.core.Response;

                admin.entity.SubscriberTopUp;
                admin.session.SubscriberTopUpHome;




                @Name("subscriberTopUpResource")
                @Path("/subscriberTopUpResource")
                @Produces({MediaType.TEXT_PLAIN})
                public class SubscriberTopUpResourceImpl implements SubscriberTopUpResource{
                     
                     @In(create=true)
                     private EntityManager entityManager;
                     
                     SubscriberTopUp subscriberTopUp = new SubscriberTopUp();
                     
                     //@In
                     //It seems like injection does not work here
                     SubscriberTopUpHome subscriberTopUpHome = (SubscriberTopUpHome) Component.getInstance(SubscriberTopUpHome.class);
                     
                     
                     
                     
                     
                     
                     public SubscriberTopUp createSubscriberTopUp(SubscriberTopUp subscriberTopUp) {
                          subscriberTopUpHome.setInstance(subscriberTopUp);
                          
                          if (!subscriberTopUpHome.persist().equals("persisted"))
                               throw new WebApplicationException(Status.NOT_ACCEPTABLE);
                               return subscriberTopUpHome.getInstance();
                     }
                     
                     
                     
                     

                     public String reserveUnits(@QueryParam("msisdn") String msisdn, @QueryParam("requestedUnits") long requestedUnits,@QueryParam("requestedAction") int requestedAction){     
                          
                          switch(requestedAction){
                               case 1:
                                    System.out.println("This is the GET action");
                                    break;
                               case 2:
                                    System.out.println("This is the UPDATE action");
                                    break;
                               case 3:
                                    System.out.println("This is the POST action");
                                    break;
                               case 4:
                                    System.out.println("This is the DELETEE action");
                                    break;
                               default:
                                    System.out.println("This is the UNKNOWN action");
                                         break;
                          }
                                    
                          
                          String balInquiry = "select balance from SubscriberTopUp where msisdn= :msisdn";
                          System.out.println("I was able to get here");
                          Query balInquiryQuery = entityManager.createQuery(balInquiry);
                          System.out.println("Something happened here");
                          long allocatedUnits = 0;
                          System.out.println("Another thing happened here");
                          @SuppressWarnings("unchecked")
                          List<Long> bals = (List<Long>)balInquiryQuery.setParameter("msisdn", Long.valueOf(msisdn)).getResultList();
                          System.out.println("OK Lets see if another thing happened here again");
                          //BigInteger newbal = new BigInteger(String.valueOf(requestedUnits));
                          
                          if (bals.size() > 0)          
                          {
                               allocatedUnits = Math.min(requestedUnits, bals.get(0));
                               if (bals.get(0) > requestedUnits)
                               FacesMessages.createFacesMessage(FacesMessage.SEVERITY_WARN, "Insufficient Fund.", "The System could only allocated " + allocatedUnits + "units");
                               System.out.println("You Reuested " + requestedUnits + " The current units in your account is " + bals + "units");
                          
                               
                               //From line 98 to line 102 was just added. This will be removed later and remove the comment from line 105
                          } else {
                               System.out.println("Null Record Returned" + bals.toString());
                               }
                          
                          System.out.println("The System Returned" + bals.toString());
                          
                          return String.valueOf(bals);     
                                    
                     }

                     
                     public String getResults(@QueryParam("msisdn") long msisdn) {return String.valueOf(msisdn); }



                     
                     private boolean checkExists(Long msisdn, EntityManager entityManager){
                        if (entityManager.find(SubscriberTopUp.class, msisdn) == null) {
                             System.out.println("The MSISDN you supplied could not be found. Please supply a correct msisdn");
                            return false;
                           
                        }
                        else{
                             
                             System.out.println("The MSISDN you supplied could be found. Thank you");
                            return true;
                        }
                    }

                     public SubscriberTopUp getSubscriberTopUp(@PathParam("msisdn") String msisdn) {
                          SubscriberTopUp subscriberTopUp = subscriberTopUpHome.findByMsisdn(msisdn.toUpperCase());
                          if (subscriberTopUp == null)
                               throw new WebApplicationException(Response.Status.NOT_FOUND);
                          return subscriberTopUp;
                     }

                     public SubscriberTopUp updateSubscriberTopUp(SubscriberTopUp subscriberTopUp, @QueryParam("msisdn") String msisdn, @QueryParam("newBal") long newBal) {
                          entityManager = subscriberTopUpHome.getEntityManager();
                          subscriberTopUpHome.clearInstance();
                          if (!checkExists(subscriberTopUp.getMsisdn(), entityManager))
                               throw new WebApplicationException(Response.Status.NOT_FOUND);
                          System.out.println("I WAS ABLE TO GET THE MSISDN HERE");
                          
                          newBal = 12000;
                          subscriberTopUp.setBalance(newBal);
                          entityManager.merge(subscriberTopUp);
                        subscriberTopUpHome.setInstance(subscriberTopUp);
                        subscriberTopUpHome.update();
                        System.out.println("UPDATING...... PLEASE WAIT");
                          return subscriberTopUpHome.getInstance();
                     }





                     

                }


                The problem I have been having all these while is with PUT. With get I did it once and it worked out of the box. Please I need direction on this. Thank you for your help.

                • 5. Re: RestEasy Put method - Unable to mark for rollback on PersistenceException:
                  lvdberg

                  Hi,




                  
                  From your interface:
                  
                  @PUT
                  @Path("/updateBalance/{msisdn}/{newBal}")
                  @Produces(MediaType.TEXT_HTML)
                  @Transactional
                  public SubscriberTopUp updateSubscriberTopUp(SubscriberTopUp subscriberTopUp, @QueryParam("msisdn") String msisdn, @QueryParam("newBal") long newBal);
                  
                  From your implementation:
                  
                  @Path("/updateBalance/{msisdn}/{newBal}")
                  @Produces(MediaType.TEXT_HTML)
                  @Transactional
                  public SubscriberTopUp updateSubscriberTopUp(SubscriberTopUp subscriberTopUp, @QueryParam("msisdn") String msisdn, @QueryParam("newBal") long newBal);




                  To start with the definition is not ok, because you put the annotations on the interface AND on your implementation, annotating the interface is sufficient. Besides that, you define path paramaters, while you annotate them as Query parameters in your methode signature.


                  Besides that, how do you supply the value for SubscriberTopUp in the method? because it is a local not initialized var, it should always be null..


                  Can you send us a sample of a URL you use to call this method, because I am curious how it can reach  the statement:



                  System.out.println("I WAS ABLE TO GET THE MSISDN HERE");





                  Leo

                  • 6. Re: RestEasy Put method - Unable to mark for rollback on PersistenceException:
                    olasamuel

                    Leo van den Berg wrote on Apr 07, 2011 03:33:


                    Hi,



                    
                    From your interface:
                    
                    @PUT
                    @Path("/updateBalance/{msisdn}/{newBal}")
                    @Produces(MediaType.TEXT_HTML)
                    @Transactional
                    public SubscriberTopUp updateSubscriberTopUp(SubscriberTopUp subscriberTopUp, @QueryParam("msisdn") String msisdn, @QueryParam("newBal") long newBal);
                    
                    From your implementation:
                    
                    @Path("/updateBalance/{msisdn}/{newBal}")
                    @Produces(MediaType.TEXT_HTML)
                    @Transactional
                    public SubscriberTopUp updateSubscriberTopUp(SubscriberTopUp subscriberTopUp, @QueryParam("msisdn") String msisdn, @QueryParam("newBal") long newBal);




                    To start with the definition is not ok, because you put the annotations on the interface AND on your implementation, annotating the interface is sufficient. Besides that, you define path paramaters, while you annotate them as Query parameters in your methode signature.

                    Besides that, how do you supply the value for SubscriberTopUp in the method? because it is a local not initialized var, it should always be null..

                    Can you send us a sample of a URL you use to call this method, because I am curious how it can reach  the statement:


                    System.out.println("I WAS ABLE TO GET THE MSISDN HERE");





                    Leo


                    Thanks once again Leo, But I think I only annotate this method in the interface. except the annotation that I did at the begining of the implementation method. Yeah the value for subscriberTopUp is always Local. Please see below the sample URL that I am using to call this method.



                    http://localhost:8080/admin/seam/resource/rest/subscriberTopUpResource/updateBalance/234165/70000/




                    and this is how it works and what I am trying to do. I have a value for msisdn in the database and what I am trying to do is that the balance should be updated to newBal where it encounters the msisdn. I do not even think it reached the statement


                    System.out.println("I WAS ABLE TO GET THE MSISDN HERE");



                    at all. This is just what I am using to check where the error is which I still do not get. Thank you

                    • 7. Re: RestEasy Put method - Unable to mark for rollback on PersistenceException:
                      lvdberg

                      Hi,


                      It doesn't call the method at all, because the signature you define is not correct.



                      The URL should match the defined paths:





                      @Path("/subscriberTopUpResource") + @Path("/updateBalance/{msisdn}/{newBal}")
                      



                      The last part of the URL matters:




                      .../subscriberTopUpResource/updateBalance/234165/70000/
                      



                      Where 234165 is your PATH PARAMETER msisdn and 70000 is your PATH PARAMETER newBal



                      So to reach the method, you should have:




                      public SubscriberTopUp updateSubscriberTopUp(@PathParam("msisdn") String msisdn, @PathParam("newBal") 



                      If you want to use QueryParam, the URL would be different and use the query with the


                       ?msidsn=234165



                      etc format



                      Try this fist with a simple GET, so you can check it in your browser. After you see it works, change it to a PUT



                      Leo

                      • 8. Re: RestEasy Put method - Unable to mark for rollback on PersistenceException:
                        olasamuel

                        Leo van den Berg wrote on Apr 07, 2011 04:01:


                        Hi,

                        It doesn't call the method at all, because the signature you define is not correct.


                        The URL should match the defined paths:




                        @Path("/subscriberTopUpResource") + @Path("/updateBalance/{msisdn}/{newBal}")
                        



                        The last part of the URL matters:



                        .../subscriberTopUpResource/updateBalance/234165/70000/
                        



                        Where 234165 is your PATH PARAMETER msisdn and 70000 is your PATH PARAMETER newBal


                        So to reach the method, you should have:



                        public SubscriberTopUp updateSubscriberTopUp(@PathParam("msisdn") String msisdn, @PathParam("newBal") 



                        If you want to use QueryParam, the URL would be different and use the query with the

                         ?msidsn=234165



                        etc format


                        Try this fist with a simple GET, so you can check it in your browser. After you see it works, change it to a PUT


                        Leo



                        Thanks again Leo. Just a quick update. Doing it the way you advised with GET work. I am yet to try it out with PUT. I will also update you when I do which will very soon. Just to keep you posted. Your help is highly appreciated. Thanks once again.

                        • 9. Re: RestEasy Put method - Unable to mark for rollback on PersistenceException:
                          olasamuel
                          Hi,

                          After I made all the necessary adjustment and even tried to rewrite the code I finally get the same error. This only happens when I use the PUT (and also POST) annotation which I suppose is the only annotation that I can use to update. Please see my code below and the error that I am geting which is the same error that I have been getting before.


                          The Interface
                          @PUT
                               @Path("/updateBalance/{msisdn}")
                               @Produces(MediaType.TEXT_HTML)
                               @Transactional
                               public SubscriberTopUp updateSubscriberTopUp(SubscriberTopUp subscriberTopUp, @PathParam("msisdn") String msisdn);


                          The Implementation

                          public SubscriberTopUp updateSubscriberTopUp(SubscriberTopUp subscriberTopUp, @PathParam("msisdn") String msisdn) {
                                    entityManager = subscriberTopUpHome.getEntityManager();
                                    subscriberTopUpHome.clearInstance();
                                    if (!checkExists(subscriberTopUp.getMsisdn(), entityManager)){
                                         throw new WebApplicationException(Response.Status.NOT_FOUND);
                                    } else {
                                         String balInquiry = "UPDATE SubscriberTopUp SET balance = 12000 where msisdn= :msisdn";
                                         System.out.println("I was able to get here");
                                         Query balInquiryQuery = entityManager.createQuery(balInquiry);
                                         System.out.println("Something happened here");
                                         System.out.println("Another thing happened here");
                                         @SuppressWarnings("unchecked")
                                         List<Long> bals = (List<Long>)balInquiryQuery.setParameter("msisdn", Long.valueOf(msisdn)).getResultList();
                                         System.out.println("OK Lets see if another thing happened here again");
                                         System.out.println("The System Returned" + bals.toString());
                                         entityManager.merge(subscriberTopUp);
                                         subscriberTopUpHome.setInstance(subscriberTopUp);
                                         subscriberTopUpHome.update();
                                         return subscriberTopUpHome.getInstance();

                                    }



                          The Error Log

                          2011-04-08 01:20:23,423 ERROR [org.jboss.resteasy.core.SynchronousDispatcher] Failed executing PUT /subscriberTopUpResource/updateBalance/234165
                          org.jboss.resteasy.plugins.providers.jaxb.JAXBUnmarshalException: Could not find JAXBContextFinder for media type: text/plain;charset="UTF-8"
                               at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.findJAXBContext(AbstractJAXBProvider.java:49)
                               at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.readFrom(AbstractJAXBProvider.java:79)
                               at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:105)
                               at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.read(GZIPDecodingInterceptor.java:46)
                               at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:108)
                               at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(ReaderUtility.java:111)
                               at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(ReaderUtility.java:93)
                               at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:146)
                               at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:114)
                               at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137)
                               at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:246)
                               at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:214)
                               at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:204)
                               at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:486)
                               at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:463)
                               at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:117)
                               at org.jboss.seam.resteasy.ResteasyResourceAdapter$1.process(ResteasyResourceAdapter.java:146)
                               at org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:65)
                               at org.jboss.seam.resteasy.ResteasyResourceAdapter.getResource(ResteasyResourceAdapter.java:122)
                               at org.jboss.seam.servlet.SeamResourceServlet.service(SeamResourceServlet.java:80)
                               at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                               at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
                               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                               at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                               at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                               at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                               at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
                               at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                               at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
                               at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
                               at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
                               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                               at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
                               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)
                               at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                               at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                               at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
                               at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                               at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
                               at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
                               at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
                               at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
                               at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
                               at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                               at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                               at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
                               at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                               at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
                               at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
                               at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
                               at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
                               at java.lang.Thread.run(Thread.java:619)



                          Now, when I tried to use GET, I get the following error and I guess this is because GET is only used for readOnly (I am not sure though).

                          2011-04-08 02:40:02,746 ERROR [org.jboss.resteasy.core.SynchronousDispatcher] Failed executing GET /subscriberTopUpResource/updateBalance/234165
                          org.jboss.resteasy.spi.BadRequestException: content-type was null and expecting to extract a body
                               at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:131)
                               at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:114)
                               at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137)
                               at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:246)
                               at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:214)
                               at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:204)
                               at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:486)
                               at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:463)
                               at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:117)
                               at org.jboss.seam.resteasy.ResteasyResourceAdapter$1.process(ResteasyResourceAdapter.java:146)
                               at org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:65)
                               at org.jboss.seam.resteasy.ResteasyResourceAdapter.getResource(ResteasyResourceAdapter.java:122)
                               at org.jboss.seam.servlet.SeamResourceServlet.service(SeamResourceServlet.java:80)
                               at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                               at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
                               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                               at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                               at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                               at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                               at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
                               at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                               at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
                               at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
                               at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
                               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                               at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
                               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)
                               at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                               at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                               at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
                               at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                               at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
                               at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
                               at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
                               at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
                               at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
                               at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                               at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                               at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
                               at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                               at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
                               at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
                               at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
                               at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
                               at java.lang.Thread.run(Thread.java:619)

                          Please, can you tell me what I am doing wrong
                          • 10. Re: RestEasy Put method - Unable to mark for rollback on PersistenceException:
                            lvdberg

                            Hi,


                            re-read my previous answer, you're still using:




                            public SubscriberTopUp updateSubscriberTopUp(SubscriberTopUp subscriberTopUp, @PathParam("msisdn") String msisdn) 



                            You're still including something in the method signature which will not be solved by Rest:



                            Try to visualise the flow firstm, so the webservice will be called by you and Rest will take care of injuecting the msidsn parameter, for you, But what about subscriberTopUp ? Where does that come from, When you do the test WITHOUT subscriberTopUp and with a GET and with both Pataparameters, you will see that it works, If you change that to a PUT, there is really NO difference. The error occurs, when you try to call something RestEasy is not able to solve.


                            If subscriberTopUp is valid when you call the method inject it with Seam with the normal IN-annotation.


                            Leo


                            • 11. Re: RestEasy Put method - Unable to mark for rollback on PersistenceException:
                              olasamuel
                              Thank you for your response so far Leo. But find below the code again this time. After I have implemented all your advice, all I see happening is that I am making circle within the sameHTTP Status 403 - Access to the requested resource has been denied errors. This time below is the error that I am getting:

                              type Status report

                              message Access to the requested resource has been denied

                              description Access to the specified resource (Access to the requested resource has been denied) has been forbidden.
                              JBoss Web/2.1.3.GA


                              The Interface as usual is as below


                              @PUT
                                      @Path("/updateBalance/{msisdn}")
                                      @Produces(MediaType.TEXT_HTML)
                                      @Transactional
                                      public String updateSubscriberTopUp(@PathParam("msisdn") String msisdn);



                              The Implementation
                              public String updateSubscriberTopUp(@PathParam("msisdn") String msisdn) {

                              String balInquiry = "UPDATE SubscriberTopUp SET balance = 12000 where msisdn= :msisdn";
                                              System.out.println("I was able to get here");
                                              Query balInquiryQuery = entityManager.createQuery(balInquiry);
                                              System.out.println("Something happened here");
                                              long allocatedUnits = 0;
                                              System.out.println("Another thing happened here");
                                              @SuppressWarnings("unchecked")
                                              List<Long> bals = (List<Long>)balInquiryQuery.setParameter("msisdn", Long.valueOf(msisdn)).getResultList();
                                              System.out.println("OK Lets see if another thing happened here again");
                                             
                                              System.out.println("The System Returned" + bals.toString());
                                             
                                              return String.valueOf(bals);
                                             
                                             
                                      }



                              Now take note of these two statements

                              String balInquiry = "select balance from SubscriberTopUp where msisdn= :msisdn";
                              String balInquiry = "UPDATE SubscriberTopUp SET balance = 12000 where msisdn= :msisdn";


                              When I use the first one irrespective of whether I use GET or PUT, I get a "status OK response but when I used the second one I get the error. So before I proceed, I will like to ask if there is anything that is wrong with my SQL statement? I have also used the @Transaction annotation as advised by Jozef.

                              Now I can see that the problem is basically at that point and all I have been trying to do with this thing for more than 1 month is to use PUT to update the data in the database.

                              I am sorry but the fact is that I am beginning to think that seam RESTFul implementation cannot handle PUT as claimed. The example that was produced in the seam Tasks as claimed by Jozef is in no way applicable (as it is to many examples inside the examples folders - A discussion for another though).

                              I will like to ask if you have had hands-on on any PUT use case? Can you show me an example of PUT use case that works? I think this will put me either wrong or right and I will know if it is worth while or to Stop wasting my time on this and look for another framework that can work. I suppose this is suppose to be simple as ABC - at least as claimed.

                              Thank you
                              • 12. Re: RestEasy Put method - Unable to mark for rollback on PersistenceException:
                                lvdberg

                                Hi,


                                There is really NO difference beteen a PUT, a GET or a POST, it's just another method of the HTTP-methods,
                                I't all a matter of understanding what happens exactly under the hood.


                                Let's get back to Jozef's remarks:



                                It seems that you are using a POJO as a JAX-RS resource. POJOs do not support transactional processing. Therefore, you should either use @Transactional annotation to enable the TransactionInterceptor on your resource (like Leo said) or use a Session Bean.




                                Picking up his advice: You can do one of the two thing (event using both works):


                                On your class:





                                @Scope(ScopeType.SESSION) <<-- Add this annotation to the existing ones
                                public class SubscriberTopUpResourceImpl implements SubscriberTopUpResource {
                                ...
                                
                                @Transactional <<-- Add this annotation to the Implementation !!
                                public String updateSubscriberTopUp(@PathParam("msisdn") String msisdn) {
                                
                                
                                
                                } 



                                From the documentation:







                                @Transactional


                                Specifies that a JavaBean component should have a similar transactional behavior to the default behavior of a session bean component. ie. method invocations should take place in a transaction, and if no transaction exists when the method is called, a transaction will be started just for that method. This annotation may be applied at either class or method level.



                                You can see i've moved the Transactional annotation to the method of the component.


                                Now test the method with a simple PUT for the SELECT statement first, if that works, you have your prove that there's nothing wrong with the Restfull service,


                                Now add the Update and see if it works, with the added annotations, it should work without a problem.


                                What you're doing is trying to solve different problems at the same time. First get Rest working and than the DB-access. The Seam rest integration is quite impressive and you basically have access to stateful web-services with a few annotations. I've used ALL methods and they ALL work.



                                Keep me informed !


                                Leo





                                • 13. Re: RestEasy Put method - Unable to mark for rollback on PersistenceException:
                                  olasamuel
                                  <blockquote>
                                  _Leo van den Berg wrote on Apr 08, 2011 10:14:_<br/>

                                  Hi,

                                  There is really NO difference beteen a PUT, a GET or a POST, it's just another method of the HTTP-methods,
                                  I't all a matter of understanding what happens exactly "under the hood".

                                  Let's get back to Jozef's remarks:

                                  "It seems that you are using a POJO as a JAX-RS resource. POJOs do not support transactional processing. Therefore, you should either use @Transactional annotation to enable the TransactionInterceptor on your resource (like Leo said) or use a Session Bean.

                                  "


                                  Picking up his advice: You can do one of the two thing (event using both works):

                                  On your class:




                                  `@Scope(ScopeType.SESSION) <<-- Add this annotation to the existing ones
                                  public class SubscriberTopUpResourceImpl implements SubscriberTopUpResource {
                                  ...

                                  @Transactional <<-- Add this annotation to the Implementation !!
                                  public String updateSubscriberTopUp(@PathParam("msisdn") String msisdn) {



                                  } `

                                  From the documentation:





                                  "@Transactional


                                  Specifies that a JavaBean component should have a similar transactional behavior to the default behavior of a session bean component. ie. method invocations should take place in a transaction, and if no transaction exists when the method is called, a transaction will be started just for that method. *This annotation may be applied at either class or method level*.

                                  "

                                  You can see i've moved the Transactional annotation to the method of the component.

                                  Now test the method with a simple PUT for the SELECT statement first, if that works, you have your prove that there's nothing wrong with the Restfull service,

                                  Now add the Update and see if it works, with the added annotations, it should work without a problem.

                                  What you're doing is trying to solve different problems at the same time. First get Rest working and than the DB-access. The Seam rest integration is quite impressive and you basically have access to stateful web-services with a few annotations. I've used ALL methods and they ALL work.


                                  Keep me informed !

                                  Leo





                                  </blockquote>

                                  Once again Leo, Thanks for your usual positive and helpful response. I am afraid but the fact is that with the simple SELECT statement, this works. However, with the UPDATE statement the same error I keep on getting which is:


                                  HTTP Status 403 - Access to the requested resource has been denied

                                  type Status report

                                  message Access to the requested resource has been denied

                                  description Access to the specified resource (Access to the requested resource has been denied) has been forbidden.
                                  JBoss Web/2.1.3.GA.


                                  I have modified the code as you and Jozef asked me to. I am not giving up on this but the fact is that if SELECT should work, I still fail to understand why UPDATE is not working. Remember, I am using entity class, which is the SubscriberTopUp, the SubscriberTopUpHome, the SubscriberTopUpList and the two resources classes (the interface and the implementation). Why is it that it is giving me error only when I use Update class?

                                  Find below my code and if you need all the code that I mentioned above for your testing and verification let me know.


                                  The Interface

                                  @PUT
                                       @Path("/updateBalance/{msisdn}")
                                       @Produces(MediaType.TEXT_HTML)
                                       @Transactional
                                       public String updateSubscriberTopUp(@PathParam("msisdn") String msisdn);




                                  The Implementation


                                  @Transactional
                                       public String updateSubscriberTopUp(@PathParam("msisdn") String msisdn) {
                                            /*entityManager = subscriberTopUpHome.getEntityManager();
                                            subscriberTopUpHome.clearInstance();
                                            if (!checkExists(subscriberTopUp.getMsisdn(), entityManager))
                                                 throw new WebApplicationException(Response.Status.NOT_FOUND);
                                            System.out.println("I WAS ABLE TO GET THE MSISDN HERE");
                                            
                                            newBal = 12000;
                                            subscriberTopUp.setBalance(newBal);
                                            entityManager.merge(subscriberTopUp);
                                          subscriberTopUpHome.setInstance(subscriberTopUp);
                                          subscriberTopUpHome.update();
                                          System.out.println("UPDATING...... PLEASE WAIT");
                                            return subscriberTopUpHome.getInstance();*/
                                            
                                            
                                            //String balInquiry = "select balance from SubscriberTopUp where msisdn= :msisdn";
                                            String balInquiry = "UPDATE SubscriberTopUp SET balance = 12000 where msisdn= :msisdn";
                                            System.out.println("I was able to get here");
                                            Query balInquiryQuery = entityManager.createQuery(balInquiry);
                                            System.out.println("Something happened here");
                                            long allocatedUnits = 0;
                                            System.out.println("Another thing happened here");
                                            @SuppressWarnings("unchecked")
                                            List<Long> bals = (List<Long>)balInquiryQuery.setParameter("msisdn", Long.valueOf(msisdn)).getResultList();
                                            System.out.println("OK Lets see if another thing happened here again");
                                            
                                            System.out.println("The System Returned" + bals.toString());
                                            
                                            return String.valueOf(bals);
                                            
                                            
                                       }


                                  I have also tried the one I totally commented within the code body but I keep on getting the same error.

                                  please, note I also put this annotation @Scope(ScopeType.SESSION) at the beginning on the implementation class. Can you please tell me what I am doing wrong this time?

                                  Thank you
                                  • 14. Re: RestEasy Put method - Unable to mark for rollback on PersistenceException:
                                    lvdberg

                                    Hi,


                                    it's getting interesting now.


                                    I walked through your original code and see some constructs (the Home stuff), which cause other problems.


                                    I once had such error messages, but that had to do with configurations (some faulty libs).


                                    Again, get back to the basics.


                                    With the present version you can check that it doesn't matter if you put a GET, POST, PUT or whatever method annotation on the method, They all will trigger the correct method. You have checked that, so can be sure that it is NOT the Rest code causing the problem. It is just that you're probably not able to change (UPDATE) something in the database. You could check this by using a simple INSERT an see if you have the same behaviour (probably yes).


                                    You now need to strip off everything until you get to the bare basics.
                                    Comment everything out from the method body, until you get something very simple like this:




                                    // Create whatever new object newBal, or something else
                                    //
                                    entityManager.persist(newBal);
                                    entityManager.flush();
                                    




                                    You more or less, create a new object when you call the method. Never mind its content, just see if it get created, without the error-message and if you can find a row in the DB.



                                    Next step is doing this with the PathParam values.
                                    Create the object directly with the data coming from the call. Something liek:




                                    Your yours = entityManager.find(Your.class, <<pathParamID>>); // This retrieves the managed object
                                    yours.setWhatever(<<Value from the Pathparam>>);
                                    entityManager.merge(yours);
                                    entityManager.flush();





                                    Of course you need to replace everything with your own names, but basically you're working directly with the entityManager directly and you're NOT using the Home-version anymore.


                                    If you get here, it means the REST service works correct AND the Transaction works correct.


                                    This latter means you have a problem in your code.


                                    My suggestion is NOT to assume all the time that it is a Rest problem, but that you should have some doubts about the rest of your code. I myself, stopped using the EntityHome, because it gave me a lot of headache. I normally call a Stateful bean (EJB) or a normal POJO, and I have NEVER found any problem. It really works like a charm.



                                    Keep me informed (this makes IT so fascinating...)


                                    Leo












                                    1 2 Previous Next