4 Replies Latest reply on Sep 10, 2007 10:49 AM by Michael Schwartz

    How to Handle POST Callbacks from a third party appliation

    Michael Schwartz Newbie

      Jbilling uses HTTP POST to send information about billing events to the application (i.e. the subscription renewal payment was declined, and the account should be de-activated). I could setup a Servlet to process this POST, but it would be nice if I could route it through SEAM. If it were a GET, I'd know how to deal with it. But what do you do with a POST, because there is no conversation id.

      thx,

      Mike

        • 1. Re: How to Handle POST Callbacks from a third party appliati
          fhh Expert

          Use page parameters and a page action.

          Regards

          Felix

          • 2. Re: How to Handle POST Callbacks from a third party appliati
            Michael Schwartz Newbie

            I am getting a NPE... I must be doing something wrong! But what...

            pages.xml

             <page view-id="/jbillingCallbackHandler.xhtml"
             action="#{jBillingCallbackHandlerAction.processPost}">
             <param name="cmd" value="#{jbillingCallback.cmd}"/>
             <param name="user_id" value="#{jbillingCallback.user_id}"/>
             <param name="login_name" value="#{jbillingCallback.login_name}"/>
             <param name="from_status" value="#{jbillingCallback.from_status}"/>
             <param name="to_status" value="#{jbillingCallback.to_status}"/>
             </page>
            


            Error
             ... 51 more
            Caused by: java.lang.NullPointerException
             at us.ziacom.vm.action.JbillingCallbackHandlerAction.processPost(Jbillin
            gCallbackHandlerAction.java:21)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
            java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
            sorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:597)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
            java:112)
             at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationCo
            ntextImpl.java:166)
             at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationCo
            ntext.java:44)
             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocation
            Context.java:56)
             at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackI
            nterceptor.java:31)
             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocation
            Context.java:68)
             at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterc
            eptor.java:46)
             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocation
            Context.java:68)
             at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodConte
            xtInterceptor.java:42)
             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocation
            Context.java:68)
             at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke
            (EntityManagerProxyInterceptor.java:26)
             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocation
            Context.java:68)
             at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInv
            oke(HibernateSessionProxyInterceptor.java:27)
             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocation
            Context.java:68)
             at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:
            106)
             at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionB
            eanInterceptor.java:50)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
            java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
            sorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:597)
             at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationCo
            ntextImpl.java:118)
             at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3Int
            erceptorsInterceptor.java:63)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
            java:101)
             at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invok
            e(TransactionScopedEntityManagerInterceptor.java:54)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
            java:101)
             at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsI
            nterceptor.java:47)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
            java:101)
             at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
             ... 84 more
            


            Action
            @Stateless
            @Scope(ScopeType.STATELESS)
            @Name("jBillingCallbackHandlerAction")
            public class JbillingCallbackHandlerAction implements
             IJbillingCallbackHandlerAction {
            
             @In(required=false)
             JbillingCallback callback;
            
             @Override
             public String processPost() {
             System.out.println("**********" + callback.getCmd());
             System.out.println("**********" + callback.getUser_id());
             System.out.println("**********" + callback.getLogin_name());
             System.out.println("**********" + callback.getFrom_status());
             System.out.println("**********" + callback.getTo_status());
             return "home";
             }
            


            HTML Test Page that Posts Request
            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
            <html>
             <head>
             <title>MyHtml.html</title>
            
             <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
             <meta http-equiv="description" content="this is my page">
             <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
            
             <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
            
             </head>
            
             <body>
             This is my HTML page.
             <br>
             <form method="post" action="http://jboss.ziacom.us:8080/voicemail/jbillingCallbackHandler.seam" name="jbillingTest">
             <input type="hidden" value="foo" name="cmd">
             <input type="hidden" value="bar" name="user_id">
             <input type="hidden" value="spam" name="login_name">
             <input type="hidden" value="eggs" name="from_status">
             <select size="4" name="to_status">
             <option selected value="spam">foo</option>
             <option value="eggs">bar</option>
             </select>
             <BR />
             <input type="submit" value="Submit" name="submit">
             </form>
             </body>
            </html>
            


            Model
            import org.jboss.seam.annotations.Name;
            
            @Name("jbillingCallback")
            public class JbillingCallback {
             private String cmd;
             private String user_id;
             private String login_name;
             private String from_status;
             private String to_status;
            
             /**
             * A string that identifies jbilling's call. It is always set to ?ageing_update? by
             * jbilling,and allows you to uniquely identify a jbilling call (in case the callback's
             * url is used for other purposes).
             */
             public String getCmd() {
             return cmd;
             }
             public void setCmd(String cmd) {
             this.cmd = cmd;
             }
            
             /**
             * The User ID of the user that is undergoing a status change in jbilling. You can
             * use this ID to identify the user directly, or otherwise query jbilling via the API to
             * obtain the data for the user, should you need further information.
             */
             public String getUser_id() {
             return user_id;
             }
             public void setUser_id(String user_id) {
             this.user_id = user_id;
             }
            
             /**
             * The user name of the user that is undergoing a status change.
             */
             public String getLogin_name() {
             return login_name;
             }
             public void setLogin_name(String login_name) {
             this.login_name = login_name;
             }
            
             /**
             * The status the user is transitioning from. This is the status the user had
             * before the transition took place.
             */
             public String getFrom_status() {
             return from_status;
             }
             public void setFrom_status(String from_status) {
             this.from_status = from_status;
             }
            
             /**
             * The status the user is transitioning to. This is the status the user has once
             * the transition took place. Subsequent calls to getUser() in the API will return this
             * status code.
             */
             public String getTo_status() {
             return to_status;
             }
             public void setTo_status(String to_status) {
             this.to_status = to_status;
             }
            }
            
            



            • 3. Re: How to Handle POST Callbacks from a third party appliati
              fhh Expert

              Start JBoss in debug mode and set a beakpoint in us.ziacom.vm.action.JbillingCallbackHandlerAction.processPost().

              Regards

              Felix

              • 4. Re: How to Handle POST Callbacks from a third party appliati
                Michael Schwartz Newbie

                Actually, the solution was quite simple:

                pages.xml

                 <page view-id="/jbillingCallbackHandler.xhtml"
                 action="#{jBillingCallbackHandlerAction.processPost}">
                 </page>
                


                Action
                @Stateless
                @Scope(ScopeType.STATELESS)
                @Name("jBillingCallbackHandlerAction")
                public class JbillingCallbackHandlerAction implements
                 IJbillingCallbackHandlerAction {
                
                // @In(required=false)
                // JbillingCallbackEntity callback;
                
                 @RequestParameter("cmd")
                 private String cmd;
                
                 @RequestParameter("user_id")
                 private String user_id;
                
                 @RequestParameter("login_name")
                 private String login_name;
                
                 @RequestParameter("from_status")
                 private String from_status;
                
                 @RequestParameter("to_status")
                 private String to_status;
                
                 @Override
                 public String processPost() {
                 System.out.println("**********" + cmd);
                 System.out.println("**********" + user_id);
                 System.out.println("**********" + login_name);
                 System.out.println("**********" + from_status);
                 System.out.println("**********" + to_status);
                 return "home";
                 }
                
                }