9 Replies Latest reply on Aug 31, 2011 10:53 AM by simon shen

    How to load web.xml

    simon shen Newbie

      As a usual web application, we put web.xml under [WEB-INF], when tomcat or jbossAS starts up, it will be loaded.

      And meanwhile, if you define [org.springframework.web.context.ContextLoaderListener], spring-context.xml will also be loaded.

       

      Now, I did a POC of esb, in an esb action, I used spring anotation to inject service bean, but I failed.

      Because ESB server didnot load web.xml.

       

      How can I fix it?

      Do you ever combine esb with spring?

       

      Thanks

        • 1. Re: How to load web.xml
          everson . Newbie

          you can create a web project and packing it  as .war into you esb project. Maybe it works....

           

          myEsbproject.esb

               - META-INF/jboss-esb.xml, deployment.xml

               - myWebproject.war

                          -WEB-INF/web.xml

          • 2. Re: How to load web.xml
            simon shen Newbie

            If I difine the action class in war, and the other classes are also in war, when executing jboss-esb.xml action flow, does it work?

            I will try it, thanks.

            • 3. Re: How to load web.xml
              everson . Newbie

              I used spring anotation to inject service bean, but I failed. Because ESB server didnot load web.xml.

               

              what i said is that you can use a .war into your .esb, and then load your web.xml.  Your  esb action class still are into .esb project

               

              is not a solution, just a suggestion 

              • 4. Re: How to load web.xml
                simon shen Newbie

                yes, action classes are in esb project, service and other classes are in war, that doesn't work.

                anyway, thanks a lot.

                anybody can help me?

                • 5. Re: How to load web.xml
                  Hans Wolffenbuttel Expert

                  Simon,

                   

                  Everson means you can build your .esb file with the .war in it. If you do that, you will have to define your war in your deployment.xml of your .esb. something like

                   

                  <esb-depends>YourName.war</esb-depends>

                  also you will need a dependancy to spring, otherwise your .esb will be loaded before spring is loaded, like so:

                  <depends>jboss.esb:deployment=spring.esb</depends>

                   

                   

                  An alternative is adding a Hibernate.cfg.xml configuration to your esbcontent dir and to create a HibernateSessionFactory instance with that configuration. If you want to use annotations i.e. for hibernate, then you need to create your own HibernateSessionFactory and replace all references to the standard configuration with the AnnotationConfiguration. At least, there wasn't an implementatione when I searched for it.

                  Regards,


                  Hans

                   

                   

                  • 6. Re: How to load web.xml
                    simon shen Newbie

                    Hi, Hans & Everson

                     

                    The following is my source coding.

                    1. jboss-esb.xml

                    <action name="transform" class="org.jboss.soa.esb.smooks.SmooksAction">

                      <property name="smooksConfig" value="/smooks-res.xml" />

                      <property name="resultType" value="JAVA" />

                    </action>

                     

                    <action name="receiveAction" class="esb.server.action.ReceiveAction" />

                     

                    <action name="soapClientAction" class="org.jboss.soa.esb.actions.soap.SOAPClient">

                      <property name="wsdl" value="http://127.0.0.1:8080/alice/ReimburseService?wsdl" />

                      <property name="responseAsOgnlMap" value="true" />

                      <property name="SOAPAction" value="processOrder"/>

                    </action>

                     

                    2.ReceiveAction

                    public class ReceiveAction extends AbstractActionPipelineProcessor {

                       

                        protected final Log logger = LogFactory.getLog(getClass());

                       

                        protected ConfigTree _config;

                       

                        @Resource

                        private ReceiveService receiveService;

                       

                        public ReceiveAction(ConfigTree config) {

                              _config = config;

                        }

                       

                        public Message process(Message message) throws ActionProcessingException {

                            Map javaRequestMap = (Map) message.getBody().get();

                            ReimburseRequestBO reimburseRequest = (ReimburseRequestBO) javaRequestMap.get("reimburseRequest");

                            List<ReimburseFile> reimburseFileList = (List<ReimburseFile>) javaRequestMap.get("reimburseFileList");

                            System.out.println(reimburseRequest.getTitle());

                            System.out.println(reimburseRequest.getTotalAmount());

                            System.out.println(reimburseRequest.getRequestDate());

                            System.out.println(reimburseRequest.getUserId());

                            System.out.println(reimburseRequest.getRemark());

                            try {

                                receiveService.saveReceivedMessage(reimburseRequest, reimburseFileList);

                            } catch (Exception e) {

                                e.printStackTrace();

                                throw new ActionProcessingException(e.getMessage(), e);

                            }

                           

                            return message;

                        }

                       

                        public void exceptionHandler(Message message, Throwable exception) {

                            exception.printStackTrace();

                        }

                    }

                     

                    3.ReceiveServiceImpl.java

                    @Service

                    public class ReceiveServiceImpl implements ReceiveService {

                    ......

                    }

                     

                    If this is a web application project, I can define web.xml to load the spring configuration. ReceiveAction can be injected with ReceiveServiceImpl bean.

                    At the beginning, I try to figure out whether esb server can recognize the web.xml, but it doesn't work.

                     

                    In esb project, as the esb samples, we can load spring configuration like this:

                    <action name="sayHello" class="org.jboss.soa.esb.samples.quickstart.spring_helloworld.MySpringEnabledAction" process="sayHelloSpring,displayMessage">

                      <property name="springContextXml" value="spring-context-hello.xml"/>

                    </action>

                     

                    if there are several actions, should we have to define springContextXml property under every action?

                    if so, the springContextXml will be loaded several times?

                    all the actions use the same spring container? under the same transaction? use the same datasource?

                    • 7. Re: How to load web.xml
                      simon shen Newbie

                      By now, I just use spring + ibatis + esb.

                      I defined three actions in jboss-esb.xml,

                      one is used to transform xml to java bean by using smooks,

                      the second is used to perform message store(in this action, I defined sprint-context property),

                      the last is used to transfer message to another web service.

                      • 8. Re: How to load web.xml
                        Tom Cunningham Master

                        Simon, did you follow Hans and everson's suggestions though?    They are suggesting you package a WAR inside of your deployment.xml to your ESB archive (check how the quickstarts do it) with dependencies on your WAR and on spring.esb.   

                         

                        In answer to your question - check out the spring_helloworld quickstart.    You do have to list the springContextXml in each one of your Spring-enabled actions.

                        • 9. Re: How to load web.xml
                          simon shen Newbie

                          id you follow Hans and everson's suggestions though?

                          ->

                          I followed the quickstart sample of spring_helloworld.

                           

                          You do have to list the springContextXml in each one of your Spring-enabled actions.

                          ->

                          So, the bean configured in the different context will in the different container, right?