6 Replies Latest reply on Jul 21, 2011 9:32 PM by njiang

    Java First SOAP\JMS Service With CXF

    mtarullo463

      I am working on an R&D service that will be using SOAP over JMS.  The following are the interface for the service and and the implementation:

       

      package gov.faa.swim.nsrr.soapoverjms;

       

      public interface ISoapJmsWeather

      {

        public String GetForecast(String locationCityName);

        public float  GetTemperature(int locationCityZipCode);

        public void   SetTemperature(int locationCityZipCode, float locationTemperature);

      }

       

      package gov.faa.swim.nsrr.soapoverjms;

       

      public class SoapJmsWeatherImpl implements ISoapJmsWeather

      {

          private String cityForecasts[][] = {{"New York", "Philadelphia", "Baltimore"},

                                                         {"10036",    "19107",        "21225"    },

                                                         {"Cloudy",   "Sunny",        "Rain"     },

                                                         {"75.0",     "90.5",         "80.0"     }};

       

       

          public String GetForecast(String locationCityName)

          {

            .....

          }

       

          public float  GetTemperature(int locationCityZipCode)

          {

            .....

          }

       

          public void   SetTemperature(int locationCityZipCode, float locationTemperature)

          {

            .....

          }

      }

       

      The Fuse Services Framework Developing Applications Using JAX-WS

      Version 2.4 June 2011 - Section 17 Using SOAP over JMS provides the following code for "publishing" the service (modified slightly for my interface and implementation):

       

      package gov.faa.swim.nsrr.soapoverjms;

       

      import org.apache.cxf.jaxws.JaxWsServerFactoryBean;

      import org.apache.cxf.transport.jms.spec.JMSSpecConstants;

       

      public class SoapJmsWeatherPublisherForCXF

      {

        public void Publish()

        {

          String address = "jms:jndi:dynamicQueues/test.cxf.jmstransport.queue3" +

                                 "?jndiInitialContextFactory" +

                                 "=org.apache.activemq.jndi.ActiveMQInitialContextFactory" +

                                 "&jndiConnectionFactoryName=ConnectionFactory" +

                                 "&jndiURL=tcp://localhost:61500";

          SoapJmsWeatherImpl implementor = new SoapJmsWeatherImpl();

          JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();

          svrFactory.setServiceClass(ISoapJmsWeather.class);

          svrFactory.setAddress(address);

          svrFactory.setTransportId

                            (JMSSpecConstants.SOAP_JMS_SPECIFICATION_TRANSPORTID);

          svrFactory.setServiceBean(implementor);

          svrFactory.create();

        }

      }

       

      My questions are:

      1) Where does this belong (as you can see I created a class for it)?

      2) How does it get called?

       

      I am using JBoss 6.0 AS for this R&D project which now comes with the CXF Web Services Stack.  We have also replaced the JBoss messaging with ActiveMQ and will be using this for JMS.

       

      Thank you.

        • 1. Re: Java First SOAP\JMS Service With CXF
          njiang

          JMS URI is used as same as the http address.

          When your server is published with that URI, your client can use that to consume the service.

           

          You can find some examples of SOAP/JMS here

           

          Willem

          • 2. Re: Java First SOAP\JMS Service With CXF
            mtarullo463

            Thank you for the reply.

             

            I'm sorry but I don't understand your answer.

             

            What I want to know is given that I have an interface and a class that implements that interface (i.e. my implementation), where does the code that I found in the FUSE Services Framework documentation and have provided here in a third class in a method called publish belong?

             

            Does the code from the documentation belong in my implementation class or a separate class as I've provided here?

             

            Does this code need to be executed every time my service is called?

             

            Since it appears to me that it should not, since it is publishing the service through the API, how then would it get called?

            • 3. Re: Java First SOAP\JMS Service With CXF
              njiang
              mtarullo463 wrote:

              Thank you for the reply.

               

              I'm sorry but I don't understand your answer.

               

              What I want to know is given that I have an interface and a class that implements that interface (i.e. my implementation), where does the code that I found in the FUSE Services Framework documentation and have provided here in a third class in a method called publish belong?

               

              Does the code from the documentation belong in my implementation class or a separate class as I've provided here?

              You can put the method into your implementation class or a separated class.

               

               

              Does this code need to be executed every time my service is called?

               

              No, once you call the publish method,  the server is started.

              You don't need to any addition work.

               

               

              Since it appears to me that it should not, since it is publishing the service through the API, how then would it get called?

               

              The publishing code will start a CXF server which will listen to the JMS address that you configured.

              You can do the same thing by using the JAXWS API Endpoint.publish().

              You can get the server instance when the svrFactory.create() is called.

              Server server = svrFactory.create();

              You can call the stop() method  if you want to stop the server.

              • 4. Re: Java First SOAP\JMS Service With CXF
                mtarullo463

                Thanks!  That's what I wanted to know.

                 

                I may have more questions about this as I continue to work on my SOAP\JMS service.

                 

                I'll post threads to this message.

                 

                Thanks again.

                • 5. Re: Java First SOAP\JMS Service With CXF
                  mtarullo463

                  The following code is what I have done based on the last reply.

                   

                  I've copied the code provided in the FUSE Services Framework documentation to my service implementation class.  Does this look correct?

                   

                  package gov.faa.swim.nsrr.soapoverjms;

                   

                  import org.apache.cxf.jaxws.JaxWsServerFactoryBean;

                  import org.apache.cxf.transport.jms.spec.JMSSpecConstants;

                   

                  public class SoapJmsWeatherImpl implements ISoapJmsWeather

                  {

                      private boolean startCXFJMSListener = true;

                       

                      private String cityForecasts[][] = {{"New York", "Philadelphia", "Baltimore"},

                                                          {"10036",    "19107",        "21225"    },

                                                          {"Cloudy",   "Sunny",        "Rain"     },

                                                          {"75.0",     "90.5",         "80.0"     }};

                   

                   

                      public String GetForecast(String locationCityName)

                      {

                        int cityIdx = -1;

                   

                        if(startCXFJMSListener)

                        {

                          StartCXFJMSListener();

                        }

                   

                        ..... code to get forecast would be here

                   

                      }

                   

                      public float  GetTemperature(int locationCityZipCode)

                      {

                        int cityIdx = -1;

                   

                        if(startCXFJMSListener)

                        {

                          StartCXFJMSListener();

                        }

                         

                        ..... code to get temperature would be here

                   

                      }

                   

                      public void   SetTemperature(int locationCityZipCode, float locationTemperature)

                      {

                        // There's really nothing to do here but return

                        if(startCXFJMSListener)

                        {

                          StartCXFJMSListener();

                        }

                         

                        ..... code to set temperature would be here

                   

                        return;

                      }

                       

                      private void StartCXFJMSListener()

                      {

                        String address = "jms:jndi:dynamicQueues/test.cxf.jmstransport.queue3" +

                                         "?jndiInitialContextFactory" +

                                         "=org.apache.activemq.jndi.ActiveMQInitialContextFactory" +

                                         "&jndiConnectionFactoryName=ConnectionFactory" +

                                         "&jndiURL=tcp://localhost:61500";

                        SoapJmsWeatherImpl implementor = new SoapJmsWeatherImpl();

                        JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();

                        svrFactory.setServiceClass(ISoapJmsWeather.class);

                        svrFactory.setAddress(address);

                        svrFactory.setTransportId(JMSSpecConstants.SOAP_JMS_SPECIFICATION_TRANSPORTID);

                        svrFactory.setServiceBean(implementor);

                        svrFactory.create();

                   

                        startCXFJMSListener = false;

                      }

                  }

                  • 6. Re: Java First SOAP\JMS Service With CXF
                    njiang

                    No, your services implementor method should have nothing to do with the Service publishing.

                     

                    Once you publish the service, CXF will delegate the client request to the implementor method according to the request message.