4 Replies Latest reply on Apr 19, 2009 2:18 AM by jaikiran

    Specifying default values to @Service attributes (JBoss 5.0.

      Hi,

      I have a service ejb annotated with @Service. It has an attribute I'd like to assign different default values in different environments.

      For example:

      @Service
      public class MyService {
       private int simpleAttribute;
      
       public int getSimpleAttribute() {...}
      
       public void setSimpleAttribute(int value) {...}
      }


      I have a build script that generates two different EARs. One for test environment and one for production environment. I'm looking for a way to specify different default values to attributes for test and production environments. My idea was to use injection and env-refs in ejb-jar.xml or jboss.xml to inject different values. According to jboss' official ejb3 tutorial I should be able to reference the service using the tag within either ejb-jar.xml or jboss.xml. But whenever I specify the tag I get an exception when deploying the ejb, telling me that "service" is not a valid child of enterprise-beans tag. I also tried to reference the service as a regular ejb using tag, but than I get an exception while deploying the bean: java.lang.UnsupportedOperationException: Instead use JBossServicePolicyDecorator

      What is the standard way to assign default values to service EJB's attributes without hardcoding them into source code?

        • 1. Re: Specifying default values to @Service attributes (JBoss
          jaikiran

           

          According to jboss' official ejb3 tutorial I should be able to reference the service using the tag within either ejb-jar.xml or jboss.xml


          The service element in not available in ejb-jar.xml. Its available only in jboss.xml. Could you point us to the doc which says that its available in ejb-jar.xml? We'll fix it. The new tutorials for AS-5 are here http://www.jboss.org/jbossejb3/docs/

          Specifically, the @Service using deployment descriptors http://www.jboss.org/file-access/default/members/jbossejb3/freezone/docs/tutorial/1.0.4/html/Service_POJOs_through_deployment_descriptors.html

          The env-entry can be specified for the services in the jboss.xml. If that doesn't work then please post the contents of your jboss.xml and the entire exception stacktrace.

          While posting logs or xml content or code, please remember to wrap it in a code block by using the Code button in the message editor window. Please use the Preview button to ensure that your post is correctly formatted.

          • 2. Re: Specifying default values to @Service attributes (JBoss

             

            "jaikiran" wrote:

            The service element in not available in ejb-jar.xml. Its available only in jboss.xml.


            I tried both ejb-jar.xml and jboss.xml. None of them worked. I know the tutorial mentions only jboss.xml. The problem is that there is only a partial deployment descriptor in the tutorial that does not mention where I should put the service tag. Unfortunately I couldn't even find any references to the deployment descriptor XSD or DTD, so I couldn't figure out myself. No matter where I put the service tag I get the following exception after deploying the service:

            org.jboss.xb.binding.JBossXBRuntimeException: service not found as a child of enterprise-beans
            
             at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:863)
             at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:806)
             at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:293)
             at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:221)
             at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
             at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
             at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
             at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
             at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
             at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
             at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
             at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
             at java.lang.Thread.run(Thread.java:619)
            


            "jaikiran" wrote:

            The env-entry can be specified for the services in the jboss.xml. If that doesn't work then please post the contents of your jboss.xml and the entire exception stacktrace.


            That's exactly what I'm trying to do. Here are the DD and the class.

            <?xml version="1.0"?>
            <jboss>
             <enterprise-beans>
             <service>
             <ejb-name>TestService</ejb-name>
             <env-entry>
             <env-entry-name>defaultAttributeValue</env-entry-name>
             <env-entry-type>java.lang.Integer</env-entry-type>
             <env-entry-value>10</env-entry-value>
             <injection-target>
             <injection-target-class>test.TestService</injection-target-class>
             <injection-target-name>attribute</injection-target-name>
             </injection-target>
             </env-entry>
             </service>
             </enterprise-beans>
            </jboss>
            


            The service:
            package test;
            
            import javax.ejb.Remote;
            
            import org.jboss.ejb3.annotation.Management;
            import org.jboss.ejb3.annotation.Service;
            
            @Service(name = "TestService", objectName = "test:service=TestService")
            @Remote(TestInterface.class)
            @Management(TestInterface.class)
            public class TestService implements TestInterface {
            
             private int attribute;
            
             @Override
             public int getAttribute() {
             return attribute;
             }
            
             public void setAttribute(int attribute) {
             this.attribute = attribute;
             }
            
            }
            


            If I change the @Service attribute to @Stateless and the service tag to session, so that it's a regular SB, then it works fine and the container injects the value specified in the env-entry-value tag. I just cannot figure out how to do it with a @Service.



            • 3. Re: Specifying default values to @Service attributes (JBoss

               

              "csorbag" wrote:

              I tried both ejb-jar.xml and jboss.xml. None of them worked. I know the tutorial mentions only jboss.xml. The problem is that there is only a partial deployment descriptor in the tutorial that does not mention where I should put the service tag. Unfortunately I couldn't even find any references to the deployment descriptor XSD or DTD, so I couldn't figure out myself. No matter where I put the service tag I get the following exception after deploying the service:


              I finally found the DTD of jboss.xml (jboss_5_0.dtd under docs/dtd). I simply cannot find any trace of the service tag in that. I'm totally confused :(
              Is it a deprecated feature in the new release? Do I misunderstand something?

              • 4. Re: Specifying default values to @Service attributes (JBoss
                jaikiran

                 

                I know the tutorial mentions only jboss.xml. The problem is that there is only a partial deployment descriptor in the tutorial that does not mention where I should put the service tag. Unfortunately I couldn't even find any references to the deployment descriptor XSD or DTD, so I couldn't figure out myself.


                The tutorials that i pointed to also have the downloadable source code. Here's the jboss.xml with the xsd declaration http://anonsvn.jboss.org/repos/jbossas/projects/ejb3/trunk/docs/tutorial/service_deployment_descriptor/META-INF/jboss.xml

                I finally found the DTD of jboss.xml (jboss_5_0.dtd under docs/dtd). I simply cannot find any trace of the service tag in that. I'm totally confused :(
                Is it a deprecated feature in the new release? Do I misunderstand something?


                For EJB3 on JBoss, the DTD for jboss.xml cannot be used. You will have to the xsd as shown in the above SVN file.