7 Replies Latest reply on Jan 9, 2009 11:11 AM by Klearchos Klearchou

    Web Services

    Klearchos Klearchou Newbie
      Hello to all,

      I am trying to make a simple web service call based on the seambay example.
      So I did the following:

      1. Created a project with seam-gen that supports EJB's (jar option).
      2. Created some simple model and action classes that through the web browser works fine.
      3. Created the services class according to the seambay.
      4. Created a standalone client that calls this web service.

      Everything ok up to now.

      My problem starts when I want to do something useful inside the web service method.
      For example I am trying to access a class like this:
      DocumentAction da = (DocumentAction) Component.getInstance(DocumentAction.class);

      I receive an error from the application server like the following:
      java.lang.IllegalStateException: No application context active

      Could you please point me what I miss here.
      The class from which I call the Component.getInstance( is something like this:

      @Stateless
      @WebService(name = "DocumentServices", serviceName = "DocumentServices")
      public class DocumentServices implements DocumentServicesRemote
      {
      ...
      and inside the web method

          @WebMethod
          public String registerDocument()
          {
      ...

      I try to get the instance from where I receive the error.

      Thank you in advance for your help.

        • 1. Re: Web Services
          John Ament Master

          what happens if you make it a seam object, annotate with @Name ?

          • 2. Re: Web Services
            Shane Bryzak Master

            Do you have a correctly configured standard-jaxws-endpoint-config.xml in your META-INF dir?

            • 3. Re: Web Services
              Klearchos Klearchou Newbie
              Hello to all,

              sorry for my late answer but yesterday I was not available.

              I have included the xml that the seam reference states.
              The object already contains the @Name.
              More specifically
              @Name("documentAction")
              @Scope(ScopeType.CONVERSATION)

              The object is an action that I already use for Seam.
              The first line in the web service method is the following:
                      System.out.println("Application context " + Contexts.isApplicationContextActive() );
                      System.out.println("Application Context is " + Contexts.getApplicationContext() );

              that returns false and null respectively.

              What else do you think it could be wrong?

              Thank you for your help.
              • 4. Re: Web Services
                Klearchos Klearchou Newbie

                Hello I have just now tried to place the @Name at the services object basically and not to the object that I want to receive using the getInstance and it worked!


                But why at the Seambay example there is no such an annotation (@Name) and it works?


                Tank you again.

                • 5. Re: Web Services
                  Klearchos Klearchou Newbie
                  Hello,

                  I have changed the generated task of the build.xml (seam-gen)
                  and I have simply inserted this extra line:
                  <include name="standard-jaxws-endpoint-config.xml" />
                  after the ejb-jar.xml

                          <target name="jar" depends="compile,copyclasses"
                                          description="Build the distribution .jar file">
                                  <copy todir="${jar.dir}">
                                          <fileset dir="${basedir}/resources">
                                                  <include name="seam.properties" />
                                                  <include name="*.drl" />
                                          </fileset>
                                  </copy>
                                  <copy todir="${jar.dir}/META-INF">
                                          <fileset dir="${basedir}/resources/META-INF">
                                                  <include name="ejb-jar.xml" />
                                                  <include name="standard-jaxws-endpoint-config.xml" />
                                          </fileset>
                                  </copy>
                                  <copy tofile="${jar.dir}/META-INF/persistence.xml"
                                              file="${basedir}/resources/META-INF/persistence-${profile}.xml"
                                     overwrite="true"/>
                                  <copy tofile="${jar.dir}/import.sql"
                                              file="${basedir}/resources/import-${profile}.sql"
                                     overwrite="true"/>
                          </target>

                  Is this enough?

                  Thank you,
                  • 6. Re: Web Services
                    Klearchos Klearchou Newbie
                    Hello to all,

                    in order to summarize up to now what I have done.
                    1. I have included the standard-jaxws-endpoint-config.xml file that in the past I have wrongly just placed it in the correct folder without changing the build.xml file.

                    2. I removed the @Name("services") from the DocumentServices class because it was not needed anymore (as in seambay example).

                    3. I have one action called RegisterDocumentAction that contains a register method.
                    I have inserted a @Begin like this
                            @Begin(join = true)
                         public String register()
                            {

                    4. When I run the web service I receive an error like this:

                    14:34:07 ERROR [STDERR] java.lang.IllegalStateException: Transaction begin not d
                    etected, try installing transaction:ejb-transaction in components.xml
                    14:34:07 ERROR [STDERR]         at org.jboss.seam.transaction.SeSynchronizations
                    .registerSynchronization(SeSynchronizations.java:57)

                    5. So I tried to follow the error message and I have inserted the <transaction:ejb-transaction/> at the components.xml
                    Unfortunately here the Jboss could not start with the following message:

                    15:04:39 ERROR [core.ContainerBase.[jboss.web].[localhost].[/documnetReader]] Ex
                    ception sending context initialized event to listener instance of class org.jbos
                    s.seam.servlet.SeamListener
                    java.lang.RuntimeException: error while reading /WEB-INF/components.xml
                            at org.jboss.seam.init.Initialization.initComponentsFromXmlDocument(Init
                    ialization.java:154)
                            at org.jboss.seam.init.Initialization.create(Initialization.java:104)
                            at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.j
                    ava:34)
                            at org.apache.catalina.core.StandardContext.listenerStart(StandardContex
                    t.java:3856)
                            at org.apache.catalina.core.StandardContext.start(StandardContext.java:4
                    361)
                            at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase
                    .java:790)
                            at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:77
                    0)
                            at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:553)

                            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.


                    Do you have please any ideas regarding the source of the problem ?


                    Best regards,
                    • 7. Re: Web Services
                      Klearchos Klearchou Newbie
                      Finally I found the problem.

                      The namespace must be declared at the beginning of the XML.
                      The name space is
                      xmlns:transaction="http://jboss.com/products/seam/transaction"

                      Thus the complete XML when we add the <transaction:ejb-transaction />
                      at the components.xml is
                      <?xml version="1.0" encoding="UTF-8"?>
                      <components
                                  xmlns="http://jboss.com/products/seam/components"
                                  xmlns:transaction="http://jboss.com/products/seam/transaction"
                                  xmlns:core="http://jboss.com/products/seam/core"
                                  xmlns:persistence="http://jboss.com/products/seam/persistence"
                                  xmlns:drools="http://jboss.com/products/seam/drools"
                                  xmlns:bpm="http://jboss.com/products/seam/bpm"
                                  xmlns:security="http://jboss.com/products/seam/security"
                                  xmlns:mail="http://jboss.com/products/seam/mail"
                                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                  xsi:schemaLocation=
                                      "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd
                                       http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd
                                       http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.0.xsd
                                       http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.0.xsd
                                       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                                       http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.0.xsd
                                       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd">

                      ....