You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by ru...@apache.org on 2007/09/03 15:02:35 UTC

svn commit: r572304 - in /webservices/synapse/trunk/java: ./ modules/core/src/main/java/org/apache/synapse/core/ modules/core/src/main/java/org/apache/synapse/core/axis2/ modules/core/src/main/java/org/apache/synapse/mediators/transform/ modules/handle...

Author: ruwan
Date: Mon Sep  3 06:02:33 2007
New Revision: 572304

URL: http://svn.apache.org/viewvc?rev=572304&view=rev
Log:
Adding new handler module. This will enable Synapse to be engaged in to an axis2 service and do mediation either on the client side or else server side itself. This needs the API change of SynEnv.injectMessage which goes with this commit.

Added:
    webservices/synapse/trunk/java/modules/handler/
    webservices/synapse/trunk/java/modules/handler/pom.xml
    webservices/synapse/trunk/java/modules/handler/src/
    webservices/synapse/trunk/java/modules/handler/src/main/
    webservices/synapse/trunk/java/modules/handler/src/main/java/
    webservices/synapse/trunk/java/modules/handler/src/main/java/org/
    webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/
    webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/
    webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/handler/
    webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/handler/SynapseInHandler.java
    webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/handler/SynapseModule.java
    webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/handler/SynapseOutHandler.java
    webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/util/
    webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/util/HandlerUtil.java
    webservices/synapse/trunk/java/modules/handler/src/main/resources/
    webservices/synapse/trunk/java/modules/handler/src/main/resources/META-INF/
    webservices/synapse/trunk/java/modules/handler/src/main/resources/META-INF/module.xml
    webservices/synapse/trunk/java/modules/handler/src/test/
    webservices/synapse/trunk/java/modules/handler/src/test/java/
    webservices/synapse/trunk/java/modules/handler/src/test/resources/
Modified:
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/SynapseEnvironment.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
    webservices/synapse/trunk/java/pom.xml

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/SynapseEnvironment.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/SynapseEnvironment.java?rev=572304&r1=572303&r2=572304&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/SynapseEnvironment.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/SynapseEnvironment.java Mon Sep  3 06:02:33 2007
@@ -34,8 +34,12 @@
      * This method injects a new message into the Synapse engine. This is used by
      * the underlying SOAP engine to inject messages into Synapse for mediation.
      * e.g. The SynapseMessageReceiver used by Axis2 invokes this to inject new messages
+     *
+     * @param smc - Synapse MessageContext to be injected
+     * @return boolean true if the message processing should be continued
+     *  and false if it should be aborted
      */
-    public void injectMessage(MessageContext smc);
+    public boolean injectMessage(MessageContext smc);
 
     /**
      * This method allows a message to be sent through the underlying SOAP engine.

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java?rev=572304&r1=572303&r2=572304&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java Mon Sep  3 06:02:33 2007
@@ -166,7 +166,8 @@
         properties.put(key, value);
 
         // do not commit response by default in the server process
-        if (Constants.RESPONSE.equals(key)) {
+        if (Constants.RESPONSE.equals(key) &&
+                getAxis2MessageContext().getOperationContext() != null) {
             getAxis2MessageContext().getOperationContext().setProperty(
                 org.apache.axis2.Constants.RESPONSE_WRITTEN, "SKIP");
         }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java?rev=572304&r1=572303&r2=572304&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java Mon Sep  3 06:02:33 2007
@@ -66,7 +66,7 @@
         this.synapseConfig = synapseConfig;
     }
 
-    public void injectMessage(final MessageContext synCtx) {
+    public boolean injectMessage(final MessageContext synCtx) {
         if (log.isDebugEnabled()) {
             log.debug("Injecting MessageContext");
         }
@@ -123,8 +123,9 @@
             if (log.isDebugEnabled()) {
                 log.debug("Using Main Sequence for injected message");
             }
-            synCtx.getMainSequence().mediate(synCtx);
+            return synCtx.getMainSequence().mediate(synCtx);
         }
+        return true;
     }
 
     public void send(EndpointDefinition endpoint, MessageContext synCtx) {

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java?rev=572304&r1=572303&r2=572304&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java Mon Sep  3 06:02:33 2007
@@ -121,8 +121,11 @@
      */
     private boolean isDOMRequired = true;
 
-    public static final String DEFAULT_XPATH = "//s11:Envelope/s11:Body/child::*[position()=1] | " +
-            "//s12:Envelope/s12:Body/child::*[position()=1]";
+    // todo - this is a hack to get the handler module case working - ruwan
+//    public static final String DEFAULT_XPATH = "//s11:Envelope/s11:Body/child::*[position()=1] | " +
+//            "//s12:Envelope/s12:Body/child::*[position()=1]";
+    public static final String DEFAULT_XPATH = "s11:Body/child::*[position()=1] | " +
+            "s12:Body/child::*[position()=1]";
 
     static {
         // Set the TransformerFactory system property to generate and use translets.

Added: webservices/synapse/trunk/java/modules/handler/pom.xml
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/handler/pom.xml?rev=572304&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/handler/pom.xml (added)
+++ webservices/synapse/trunk/java/modules/handler/pom.xml Mon Sep  3 06:02:33 2007
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~  Licensed to the Apache Software Foundation (ASF) under one
+  ~  or more contributor license agreements.  See the NOTICE file
+  ~  distributed with this work for additional information
+  ~  regarding copyright ownership.  The ASF licenses this file
+  ~  to you under the Apache License, Version 2.0 (the
+  ~  "License"); you may not use this file except in compliance
+  ~  with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~  Unless required by applicable law or agreed to in writing,
+  ~  software distributed under the License is distributed on an
+  ~   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~  KIND, either express or implied.  See the License for the
+  ~  specific language governing permissions and limitations
+  ~  under the License.
+  -->
+
+<project
+        xmlns="http://maven.apache.org/POM/4.0.0"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.synapse</groupId>
+        <artifactId>Apache-Synapse</artifactId>
+        <version>SNAPSHOT</version>
+    </parent>
+
+    <groupId>org.apache.synapse</groupId>
+    <artifactId>synapse-handler</artifactId>
+
+    <name>Apache Synapse - Handler Module</name>
+    <description>Apache Synapse - Handler Module</description>
+    <packaging>jar</packaging>
+
+    <build>
+
+        <plugins>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-antrun-plugin</artifactId>
+                <version>1.1</version>
+                <executions>
+                    <execution>
+                        <id>mar</id>
+                        <phase>package</phase>
+                        <configuration>
+                            <tasks>
+                                <copy file="target/synapse-handler-${synapse.version}.jar"
+                                      tofile="target/synapse-handler-${synapse.version}.mar"/>
+                            </tasks>
+                        </configuration>
+                        <goals>
+                            <goal>run</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <version>1.0</version>
+                <executions>
+                    <execution>
+                        <id>mar</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>attach-artifact</goal>
+                        </goals>
+                        <configuration>
+                            <artifacts>
+                                <artifact>
+                                    <file>target/synapse-handler-${synapse.version}.mar</file>
+                                    <type>mar</type>
+                                </artifact>
+                            </artifacts>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.synapse</groupId>
+            <artifactId>synapse-core</artifactId>
+        </dependency>
+    </dependencies>
+
+</project>

Added: webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/handler/SynapseInHandler.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/handler/SynapseInHandler.java?rev=572304&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/handler/SynapseInHandler.java (added)
+++ webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/handler/SynapseInHandler.java Mon Sep  3 06:02:33 2007
@@ -0,0 +1,92 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.synapse.handler;
+
+import org.apache.axis2.handlers.AbstractHandler;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.AxisFault;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.core.axis2.MessageContextCreatorForAxis2;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.FaultHandler;
+import org.apache.synapse.Constants;
+import org.apache.synapse.util.HandlerUtil;
+
+/**
+ * This is the InHandler which injects the Axis2MC in to Synapse after converting the message
+ * context to a SynapseMC
+ */
+public class SynapseInHandler extends AbstractHandler {
+
+    /**
+     * Log variable which will be used for logging
+     */
+    private static final Log log = LogFactory.getLog(SynapseInHandler.class);
+
+    /**
+     * This method will inject the message into Synapse after creating the SynapseMC from the
+     * Axis2MC and after the mediation if synapse lets the message to flow through this will let
+     * the message to flow and if not aborts the message
+     *
+     * @param messageContext - Axis2MC to be mediated using Synapse
+     * @return InvocationResponse.CONTINUE if Synapse lets the message to flow and
+     *  InvocationResponse.ABORT if not
+     * @throws AxisFault - incase of a failure in mediation of initiation of the mediation
+     */
+    public InvocationResponse invoke(MessageContext messageContext) throws AxisFault {
+
+        HandlerUtil.doHandlerLogging(log, messageContext);
+
+        org.apache.synapse.MessageContext synCtx
+                = MessageContextCreatorForAxis2.getSynapseMessageContext(messageContext);
+
+        // handles the incoming and outgoing behaviours in client and server sides
+        if (!messageContext.isServerSide()) {
+            synCtx.setProperty(Constants.RESPONSE, Boolean.TRUE);
+            synCtx.setResponse(true);
+        } else {
+            synCtx.setProperty(Constants.RESPONSE, Boolean.FALSE);
+            synCtx.setResponse(false);
+        }
+
+        try {
+            // if synapse says ok let the message to flow through
+            if (synCtx.getEnvironment().injectMessage(synCtx)) {
+                return InvocationResponse.CONTINUE;
+            } else {
+                // if not abort the further processings
+                log.debug("Synapse has decided to abort the message:\n" + synCtx.getEnvelope());
+                return InvocationResponse.ABORT;
+            }
+        } catch (SynapseException syne) {
+            if (!synCtx.getFaultStack().isEmpty()) {
+                ((FaultHandler) synCtx.getFaultStack().pop()).handleFault(synCtx, syne);
+            } else {
+                log.error("Synapse encountered an exception, " +
+                        "No error handlers found.\n" + syne.getMessage());
+                throw new AxisFault("Synapse encountered an error." + syne);
+            }
+        }
+
+        // general case should let the message flow
+        return InvocationResponse.CONTINUE;
+    }
+}

Added: webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/handler/SynapseModule.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/handler/SynapseModule.java?rev=572304&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/handler/SynapseModule.java (added)
+++ webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/handler/SynapseModule.java Mon Sep  3 06:02:33 2007
@@ -0,0 +1,139 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.synapse.handler;
+
+import org.apache.axis2.modules.Module;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.description.AxisModule;
+import org.apache.axis2.description.AxisDescription;
+import org.apache.axis2.AxisFault;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.Policy;
+import org.apache.synapse.Constants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.File;
+
+/**
+ * This will be the Module class for the Synapse handler based mediations inside axis2 server. This
+ * will just set the default system property of SYNAPSE_XML to the repository/conf/synapse.xml in
+ * the axis2 servers repository and call the normal SynapseModule.init()
+ *
+ * @see org.apache.synapse.core.axis2.SynapseModule
+ */
+public class SynapseModule implements Module {
+
+    /**
+     * Log variable to be used as the logging appender
+     */
+    private static final Log log = LogFactory.getLog(SynapseModule.class);
+
+    /**
+     * Normal SynapseModule which initiates the Synapse
+     */
+    private org.apache.synapse.core.axis2.SynapseModule module = null;
+
+    /**
+     * This method will call the normal initiation after setting the SYNAPSE_XML file to get from
+     * the axis2 respository/conf folder
+     * 
+     * @param configurationContext - ConfigurationContext of the Axis2 env
+     * @param axisModule - AxisModule describing handler module of Synapse
+     * @throws AxisFault - incase of a failure in initiation
+     */
+    public void init(ConfigurationContext configurationContext,
+                     AxisModule axisModule) throws AxisFault {
+        if (System.getProperty(Constants.SYNAPSE_XML) == null) {
+            System.setProperty(Constants.SYNAPSE_XML, configurationContext.
+                    getAxisConfiguration().getRepository().getPath() + "/conf/synapse.xml");
+        }
+        if (new File(System.getProperty(Constants.SYNAPSE_XML)).exists()) {
+            module = new org.apache.synapse.core.axis2.SynapseModule();
+            module.init(configurationContext, axisModule);
+        } else {
+            handleException("Unable to initialize the Synapse module. Couldn't " +
+                    "find the configuration file in the location "
+                    + System.getProperty(Constants.SYNAPSE_XML));
+        }
+    }
+
+    /**
+     * Just do what the main SynapseModule tells you to do
+     * 
+     * @param axisDescription
+     * @throws AxisFault
+     */
+    public void engageNotify(AxisDescription axisDescription) throws AxisFault {
+        if (module != null) {
+            module.engageNotify(axisDescription);
+        } else {
+            handleException("Couldn't find the module");
+        }
+    }
+
+    /**
+     * Just do what the main SynapseModule tells you to do
+     * 
+     * @param assertion
+     * @return
+     */
+    public boolean canSupportAssertion(Assertion assertion) {
+        if (module != null) {
+            return module.canSupportAssertion(assertion);
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Just do what the main SynapseModule tells you to do
+     * 
+     * @param policy
+     * @param axisDescription
+     * @throws AxisFault
+     */
+    public void applyPolicy(Policy policy, AxisDescription axisDescription) throws AxisFault {
+        if (module != null) {
+            module.applyPolicy(policy, axisDescription);
+        } else {
+            handleException("Couldn't find the module");
+        }
+    }
+
+    /**
+     * Just do what the main SynapseModule tells you to do
+     * 
+     * @param configurationContext
+     * @throws AxisFault
+     */
+    public void shutdown(ConfigurationContext configurationContext) throws AxisFault {
+        if (module != null) {
+            module.shutdown(configurationContext);
+        } else {
+            handleException("Couldn't find the module");
+        }
+    }
+
+    private void handleException(String message) throws AxisFault {
+        log.error(message);
+        throw new AxisFault(message);
+    }
+}

Added: webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/handler/SynapseOutHandler.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/handler/SynapseOutHandler.java?rev=572304&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/handler/SynapseOutHandler.java (added)
+++ webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/handler/SynapseOutHandler.java Mon Sep  3 06:02:33 2007
@@ -0,0 +1,93 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.synapse.handler;
+
+import org.apache.axis2.handlers.AbstractHandler;
+import org.apache.axis2.engine.Handler;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.AxisFault;
+import org.apache.synapse.util.HandlerUtil;
+import org.apache.synapse.core.axis2.MessageContextCreatorForAxis2;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.FaultHandler;
+import org.apache.synapse.Constants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * This is the OutHandler which injects the Axis2MC in to Synapse after converting the message
+ * context to a SynapseMC
+ */
+public class SynapseOutHandler extends AbstractHandler {
+
+    /**
+     * Log variable which will be used for logging
+     */
+    private static final Log log = LogFactory.getLog(SynapseOutHandler.class);
+
+    /**
+     * This method will inject the message into Synapse after creating the SynapseMC from the
+     * Axis2MC and after the mediation if synapse lets the message to flow through this will let
+     * the message to flow and if not aborts the message
+     *
+     * @param messageContext - Axis2MC to be mediated using Synapse
+     * @return InvocationResponse.CONTINUE if Synapse lets the message to flow and
+     *  InvocationResponse.ABORT if not
+     * @throws AxisFault - incase of a failure in mediation of initiation of the mediation
+     */
+    public InvocationResponse invoke(MessageContext messageContext) throws AxisFault {
+
+        HandlerUtil.doHandlerLogging(log, messageContext);
+
+        org.apache.synapse.MessageContext synCtx
+                = MessageContextCreatorForAxis2.getSynapseMessageContext(messageContext);
+
+        // handles the incoming and outgoing behaviours in client and server sides
+        if (messageContext.isServerSide()) {
+            synCtx.setProperty(Constants.RESPONSE, Boolean.TRUE);
+            synCtx.setResponse(true);
+        } else {
+            synCtx.setProperty(Constants.RESPONSE, Boolean.FALSE);
+            synCtx.setResponse(false);
+        }
+
+        try {
+            // if synapse says ok let the message to flow through
+            if (synCtx.getEnvironment().injectMessage(synCtx)) {
+                return InvocationResponse.CONTINUE;
+            } else {
+                // if not abort the further processings
+                log.debug("Synapse has decided to abort the message:\n" + synCtx.getEnvelope());                
+                return InvocationResponse.ABORT;
+            }
+        } catch (SynapseException syne) {
+            if (!synCtx.getFaultStack().isEmpty()) {
+                ((FaultHandler) synCtx.getFaultStack().pop()).handleFault(synCtx, syne);
+            } else {
+                log.error("Synapse encountered an exception, " +
+                        "No error handlers found.\n" + syne.getMessage());
+                throw new AxisFault("Synapse encountered an error." + syne);
+            }
+        }
+
+        // general case should let the message flow
+        return InvocationResponse.CONTINUE;
+    }
+}

Added: webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/util/HandlerUtil.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/util/HandlerUtil.java?rev=572304&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/util/HandlerUtil.java (added)
+++ webservices/synapse/trunk/java/modules/handler/src/main/java/org/apache/synapse/util/HandlerUtil.java Mon Sep  3 06:02:33 2007
@@ -0,0 +1,54 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.synapse.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.axis2.context.MessageContext;
+
+/**
+ * This is a helper class to get the loggin done in both in and out handlers
+ */
+public class HandlerUtil {
+
+    /**
+     * Helper util method to get the logging done whenever injecting the message into synapse
+     * 
+     * @param log - Log appender to be used to append logs
+     * @param messageContext - MessageContext which will be logged
+     */
+    public static void doHandlerLogging(Log log, MessageContext messageContext) {
+        if (log.isDebugEnabled()) {
+            log.debug("Synapse handler received a new message for message mediation...");
+            log.debug("Received To: " + (messageContext.getTo() != null ?
+                    messageContext.getTo().getAddress() : "null"));
+            log.debug("SOAPAction: " + (messageContext.getSoapAction() != null ?
+                    messageContext.getSoapAction() : "null"));
+            log.debug("WSA-Action: " + (messageContext.getWSAAction() != null ?
+                    messageContext.getWSAAction() : "null"));
+            String[] cids = messageContext.getAttachmentMap().getAllContentIDs();
+            if (cids != null && cids.length > 0) {
+                for (int i = 0; i < cids.length; i++) {
+                    log.debug("Attachment : " + cids[i]);
+                }
+            }
+            log.debug("Body : \n" + messageContext.getEnvelope());
+        }
+    }
+}

Added: webservices/synapse/trunk/java/modules/handler/src/main/resources/META-INF/module.xml
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/handler/src/main/resources/META-INF/module.xml?rev=572304&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/handler/src/main/resources/META-INF/module.xml (added)
+++ webservices/synapse/trunk/java/modules/handler/src/main/resources/META-INF/module.xml Mon Sep  3 06:02:33 2007
@@ -0,0 +1,40 @@
+<!--
+  ~  Licensed to the Apache Software Foundation (ASF) under one
+  ~  or more contributor license agreements.  See the NOTICE file
+  ~  distributed with this work for additional information
+  ~  regarding copyright ownership.  The ASF licenses this file
+  ~  to you under the Apache License, Version 2.0 (the
+  ~  "License"); you may not use this file except in compliance
+  ~  with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~  Unless required by applicable law or agreed to in writing,
+  ~  software distributed under the License is distributed on an
+  ~   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~  KIND, either express or implied.  See the License for the
+  ~  specific language governing permissions and limitations
+  ~  under the License.
+  -->
+
+<module name="synapse-handler" class="org.apache.synapse.handler.SynapseModule">
+
+    <Description>
+        This is a handler imnplementation of the Synapse mediation framework. This will engage to
+        an existing service as a module with a SynapseHandler which will do the Synapse mediation
+        in the handler chain but not dispatches the message to SynapseMessageReceiver
+    </Description>
+
+    <InFlow>
+        <handler name="SynapseIn" class="org.apache.synapse.handler.SynapseInHandler">
+            <order phase="PreDispatch"/>
+        </handler>
+    </InFlow>
+
+    <OutFlow>
+        <handler name="SynapseOut" class="org.apache.synapse.handler.SynapseOutHandler">
+            <order phase="MessageOut"/>
+        </handler>
+    </OutFlow>
+    
+</module>

Modified: webservices/synapse/trunk/java/pom.xml
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/pom.xml?rev=572304&r1=572303&r2=572304&view=diff
==============================================================================
--- webservices/synapse/trunk/java/pom.xml (original)
+++ webservices/synapse/trunk/java/pom.xml Mon Sep  3 06:02:33 2007
@@ -864,6 +864,7 @@
         <module>modules/samples</module>
         <module>modules/mar</module>
         <module>modules/war</module>
+        <module>modules/handler</module>
     </modules>
 
     <properties>



---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org