Hi,

 

I found one possible solution for the start up problem. There is now a
german :-( book about Axis2 on the market. It's called

 

Java Web Services mit Apache Axis2 ISBN 978-3-935042-81-9

 

Which explains on p. 212 the Axis2 ServiceLifeCycle interface. Based on
this interface I have written the following code (copied some code from
Muse ;-):

 

package com.ascom.ossj.wsn.producer.axis2;

 

import java.io.ByteArrayInputStream;

import java.io.File;

import java.io.IOException;

import java.net.MalformedURLException;

import java.net.URL;

 

import javax.xml.stream.XMLStreamException;

 

import org.apache.axiom.om.OMAbstractFactory;

import org.apache.axiom.om.OMElement;

import org.apache.axiom.om.impl.builder.StAXOMBuilder;

import org.apache.axiom.soap.SOAPEnvelope;

import org.apache.axiom.soap.SOAPFactory;

import org.apache.axiom.soap.SOAPHeader;

import org.apache.axis2.AxisFault;

import org.apache.axis2.addressing.EndpointReference;

import org.apache.axis2.context.ConfigurationContext;

import org.apache.axis2.context.MessageContext;

import org.apache.axis2.description.AxisService;

import org.apache.axis2.engine.ServiceLifeCycle;

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;

import org.apache.muse.core.platform.axis2.AxisIsolationLayer;

import org.apache.muse.util.xml.XmlUtils;

import org.w3c.dom.Document;

import org.w3c.dom.Element;

import org.xml.sax.SAXException;

 

/**

 * Implements the [EMAIL PROTECTED] ServiceLifeCycle} interface for Axis2.

 *

 * @author Dipl.-Ing. Matthias Beil (bel)

 */

public class WsnOssjProducerServiceLifeCycle implements ServiceLifeCycle
{

 

   // ~ Static fields/initializers
---------------------------------------------

 

   private static final Log LOGGER =
LogFactory.getFactory().getInstance(WsnOssjProducerServiceLifeCycle.clas
s);

 

   // ~ Methods
----------------------------------------------------------------

 

   /**

    * Method startUp.

    *

    * @param configCtx

    * @param axisService

    */

   public void startUp(final ConfigurationContext configCtx, final
AxisService axisService) {

 

      final AxisIsolationLayer layer = new AxisIsolationLayer();

      if (!layer.hasBeenInitialized()) {

 

         if (LOGGER.isDebugEnabled()) {

            LOGGER.info("Axis2 startup called for " +
axisService.getName());

         }

 

         // get service path

         final URL tmpURL =
axisService.getClassLoader().getResource("META-INF/services.xml");

         final File serviceFile = new File(tmpURL.getFile());

         final File museDir =
serviceFile.getParentFile().getParentFile();

         URL url = null;

         try {

            url = museDir.toURL();

         }

         catch (final MalformedURLException muex) {

 

 
WsnOssjProducerServiceLifeCycle.LOGGER.error("MalformedURLException
caught for " + museDir, muex);

         }

 

         // set url to axis service

         axisService.setFileName(url);

 

         final String wsaTo = "<wsa:To
xmlns:wsa=\"http://www.w3.org/2005/08/addressing\";>"

            + "http://localhost/wsn-ossj-producer/services/WsnOssjPort";
+ "</wsa:To>";

 

         final String wsaAction = "<wsa:Action
xmlns:wsa=\"http://www.w3.org/2005/08/addressing\";>"

            +
"http://docs.oasis-open.org/wsn/bw-2/NotificationProducer/GetCurrentMess
ageRequest" + "</wsa:Action>";

 

         final EndpointReference epr = new
EndpointReference("http://localhost/wsn-ossj-producer/services/WsnOssjPo
rt");

 

         final MessageContext ctx = new MessageContext();

         ctx.setConfigurationContext(configCtx);

         ctx.setAxisService(axisService);

         ctx.setTo(epr);

 

         final SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();

         final SOAPEnvelope envelope = fac.getDefaultEnvelope();

         final SOAPHeader header = envelope.getHeader();

 

         header.addChild(this.convertToAxiom(this.getElement(wsaTo)));

 
header.addChild(this.convertToAxiom(this.getElement(wsaAction)));

 

         try {

            ctx.setEnvelope(envelope);

         }

         catch (final AxisFault fault) {

 

            LOGGER.error("AxisFault caught while setting the
envelope!");

         }

 

         MessageContext.setCurrentMessageContext(ctx);

         layer.initialize();

      }

   }

 

   /**

    * Method shutDown.

    *

    * @param configCtx

    * @param axisService

    */

   public void shutDown(final ConfigurationContext configCtx, final
AxisService axisService) {

 

      if (LOGGER.isDebugEnabled()) {

         LOGGER.info("Axis2 shutdown called for " +
axisService.getName());

      }

   }

 

   /**

    * Convert DOM to Axiom. Muse uses the DOM API in the JDK, Axis2 uses
the

    * Axiom API, which is similar but... different.

    *

    * @param xml

    * @return OMElement

    * @throws RuntimeException

    */

   private OMElement convertToAxiom(final Element xml) {

 

      final String xmlString = XmlUtils.toString(xml, false);

      final byte [] xmlBytes = xmlString.getBytes();

      StAXOMBuilder builder = null;

 

      try {

         builder = new StAXOMBuilder(new
ByteArrayInputStream(xmlBytes));

      }

      catch (final XMLStreamException error) {

         throw new RuntimeException(error.getMessage(), error);

      }

 

      return builder.getDocumentElement();

   }

 

   /**

    * Getter method for <code>element</code>.

    *

    * @param txt

    *

    * @return Element

    */

   private Element getElement(final String txt) {

 

      Element elem = null;

 

      if ((txt != null) && (txt.length() > 0)) {

 

         try {

 

            final Document doc = XmlUtils.createDocument(txt);

            elem = doc.getDocumentElement();

         }

         catch (final IOException ioex) {

 

            LOGGER.error("IOException caught while getting Element for "
+ txt, ioex);

         }

         catch (final SAXException saxex) {

 

            LOGGER.error("SAXException caught while getting Element for
" + txt, saxex);

         }

      }

 

      return elem;

   }

 

}

 

 

The service.xml file looks partially like this

 

            <service name="WsnOssjPort"
class="com.ascom.ossj.wsn.producer.axis2.WsnOssjProducerServiceLifeCycle
">

 

                        <parameter locked="false"
name="ServiceClass">org.apache.muse.core.platform.axis2.AxisIsolationLay
er</parameter>

                        <operation name="handleRequest">

                                    <messageReceiver
class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver" />

                                   <actionMapping>

 
http://docs.oasis-open.org/wsrf/rpw-2/GetResourceProperty/GetResourcePro
pertyRequest

                                   </actionMapping>

                                   <actionMapping>

 
http://docs.oasis-open.org/wsn/bw-2/NotificationProducer/GetCurrentMessa
geRequest

                                   </actionMapping>

 
<actionMapping>http://docs.oasis-open.org/wsn/bw-2/NotificationProducer/
SubscribeRequest</actionMapping>

                        </operation>

 

                        <module ref="rampart" />

 

                        <parameter name="InflowSecurity">

                                   <action>

 
<items>UsernameToken</items>

 
<passwordCallbackClass>com.ascom.ossj.wsn.producer.security.PWCBHandler<
/passwordCallbackClass>

                                   </action>

                        </parameter>

 

            </service>

 

With this configuration I have my resource started and can now put a
message in a JMS topic which then activates the publisher and the
message is directly send to the NotifcationConsumer. I don't need to
call a getCurrentMessage method anymore to initiate Muse.

 

I would like to know if this is a way to go or are there some
considerations which I have not thought about?

 

Mit freundlichen Gruessen / With kind regards

Matthias Beil

Reply via email to