5 Replies Latest reply on Mar 27, 2008 6:20 PM by srini.ragu

    Variable injection issue with web service

    newbie000

      I have a problem that i've been stuck on for a long time.


      I am using JBoss Developer Studio, and have used the SeamBay example to guide me.


      I am trying to implement a basic web app that allows me to register, login, and perform some actions, along with a web service that exposes some of these actions.


      In terms of the website i have that working fine. However, the web service fails to work once I have logged in.


      For some reason, it does not seem to persist the user variable once logged in (i.e. in the authenticator class). So when I create a certain action that should inject the user variable, it does not seem to do this, and I get a NPE.


      Can anyone explain why it is not injecting correctly when using a web service call, but it works fine in the web site?


      Ive tried to get the SeamBay example working and this seems to fail for me as well


      Any help would be greatly appreciated. Or if you can point me to an example that actually works.


      Cheers

        • 1. Re: Variable injection issue with web service
          srini.ragu

          Since webservice calls are stateless, your login wont persist across separate webservice request.


          You should either implement a custom JAX-WS handler which does the login for you every time.


          Or to get the stateful service, send the cid parameter from the webservice client when you make subsequent request after login call.


          Seam sends you the cid parameter in the SOAP header after the first login, then by sending back the cid parameter in the header you should be able to join the same session. So you will have the identity information.

          • 2. Re: Variable injection issue with web service
            newbie000

            Ok cool that makes sense.


            How exactly would I join the same session from the CID, and would i rejoin this session within the web service method?


            Thanks

            • 3. Re: Variable injection issue with web service
              srini.ragu

              if you sent the cid in the soap header as described in the doc, seam will pick that up and join you to the same conversation if a conversation with same cid exists.


              http://docs.jboss.com/seam/2.1.0.A1/reference/en/html/webservices.html#d0e13315


              Its like using conversation-id as key for state management.


              If you are using a JAX-WS based client, you may need to write additional custom handlers to the add cid information to the soap header. And configure them to be apply on outgoing and incoming messages.


              If you are constructing the whole request message manually then its easy to insert the cid to the SOAP header.


              • 4. Re: Variable injection issue with web service
                newbie000

                So are you saying that the action class must be conversational for it to work (i.e. @Scope(CONVERSATION))?

                • 5. Re: Variable injection issue with web service
                  srini.ragu

                  To implement a stateful webservice requires a extra coding in webservice client normally in any framework. Easiest is to use them as stateless services.


                  If all you need is authorization and restrictions to access the webservice. Then you should perform authorization at container level, or by custom SOAP handler code.


                  Or inject the webservice context through @WebServiceContext annotation, so you can access request and response objects within your webservice.


                  There are several ways to implement security in webservices.