Hi Deepal
I have just created an AxisObserver for Synapse, but it has not yet
been committed, nor does it change the existing behavior of Synapse
initialization (- i.e. if for some reason the Observer was left out
from the axis2.xml.)
One reason that I picked the Observer against the mediator is that at
the time of initialization/startup, an Observer gets access to the
AxisConfiguration (from which we could get the necessary references to
the classloaders when needed). But maybe a module is the better way to
do this.. but at its init() method it gets only a reference to a
HandlerDescription
The Axis Observer which will initialize synapse at Axis startup will
work only when Axis2 is on top.. and I guess we could have such
different methods for initialization of Synapse, and pick and choose
the most suitable one for the environment at hand.
thanks
asankha
Deepal jayasinghe wrote:
Hi Saminda and all;
I am very sorry that I was not up to date with Synapse status , and I
did not know that Synapse is independent of Axis2 (Thx Saminda for
explaining everything).
So what Asankha trying to do is to embed Synapse into Axis2 (am I
correct ?). So As I can see you have many ways of doing this,
- Adding an observer
- Introducing transports
- Adding module etc...
What you are trying to achieve is , just to create a SynapseEnv some how
and initialize synapse. So uing either of above procedure you can create
SynpaseEnv and inti the synapse. There you can add components required
to integrate synapse into Axis2 at that point (Message receivers ,
Dispatcher etc..) .
If someone else want to embed synapse into his app server or what ever ,
then he has to setup Synapse and then need to hand over the messages
when it received.
Saminda Abeyruwan wrote:
Hi All,
Using AxisObserver (SynapseAxis2Interceptor) is a good way of using
to initialize the SynapseEnv but it exposes update methods that may
not be useful with Synapse. according to the init code in
SynapseAxis2Interceptor, we create the SynpaseEnv and set it in the
ConfigurationContext.
IMHO we are going to work with axis2's SimpleHTTPServer for the
Synapse M2 release. Wouldn't it be nicer if we can have the
following to initialize the SynpeEnv
public class SynaspeServer {
private SimpleHTTPServer receiver;
private ConfigurationContext context;
public SynaspeServer(int port, String dir,String file) {
// create the ConfigurationContext using dir and file
// initialize the receiver using port
// initialize the synapse builders
// initialize the SynapseEnvironment impl
// set the SynpaseEnvironment impl to ConfigurationContext
}
// other SynapseServer constructors we think of useful
public void start(){
// start the synapse server
}
public void stop(){}
public static void main(String[] args) {
}
}
So with a simple check in SynpaseMessageReceiver we can determine the
existence of SynapseEnvironment impl.
Classloader issue can be done with the way of M1
IMHO AxisObserver should be taken into action, if Synapse need to do
some even handling wrt changes of Axis2.
Thank you
Saminda
On 5/11/06, *Asankha C. Perera* <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>> wrote:
This patch will initialize Synapse along with Axis2 through an
AxisObserver. As the Axis2 classloaders are not properly
initialized at the time the interceptor gets invokes, a reference
to the AxisConfiguration is held in the Axis2SynapseEnvironment.
Hence at runtime (i.e. once Axis2 has properly initialized the
classloaders) we have access to all of Axis2's classloaders.
This patch also introduces a simple optional way to specify the
synapse.xml through a system property. This will allow us to write
a set of very simple "sample synapse.xml"s and use them for
initialization through the synapse start script. I will commit a
few such samples soon, and the initial sample is what we had
earlier (i.e. the Stock Quote sample)
asankha
Sanjiva Weerawarana wrote:
On Wed, 2006-05-10 at 14:41 +0100, Paul Fremantle wrote:
Asankha
The classloader is used by the Spring extension.
Hmmm then it doesn't belong in the SynapseEnvironment .. let's move it
to inside the Spring dependent code.
I think it would be good to load Synapse on Axis2 start.
+1.
Sanjiva.
---------------------------------------------------------------------
To unsubscribe, e-mail:
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
Index: bin/synapse.bat
===================================================================
--- bin/synapse.bat (revision 405612)
+++ bin/synapse.bat (working copy)
@@ -24,12 +24,16 @@
set DEFAULT_SYNAPSE_HOME=
set _USE_CLASSPATH=yes
+set _SYNAPSE_XML=
rem Slurp the command line arguments. This loop allows for an
unlimited number
rem of arguments (up to the command line limit, anyway).
+if ""%1""==""-sample"" goto synapseSample
+
set SYNAPSE_CMD_LINE_ARGS=%1
if ""%1""=="""" goto doneStart
shift
+
:setupArgs
if ""%1""=="""" goto doneStart
if ""%1""==""-noclasspath"" goto clearclasspath
@@ -46,6 +50,12 @@
rem This label provides a place for the argument list loop to
break out
rem and for NT handling to skip to.
+:synapseSample
+shift
+set
_SYNAPSE_XML=-Dsynapse.xml=%SYNAPSE_HOME%\synapse_repository\conf\sample\synapse_sample_%1.xml
+shift
+goto setupArgs
+
:doneStart
rem find SYNAPSE_HOME if it does not exist due to either an
invalid value passed
rem by the user or the %0 problem on Windows 9x
@@ -74,7 +84,7 @@
:runSynapse
@echo on
-"%_JAVACMD%"
-Daxis2.xml=%SYNAPSE_HOME%\synapse_repository\conf\axis2.xml
-Djava.ext.dirs=%SYNAPSE_HOME%\lib ;%EXT_DIRS%;%SYNAPSE_HOME% -cp
%SYNAPSE_HOME%\lib
org.apache.axis2.transport.http.SimpleHTTPServer
%SYNAPSE_CMD_LINE_ARGS%
+"%_JAVACMD%" %_SYNAPSE_XML%
-Daxis2.xml=%SYNAPSE_HOME%\synapse_repository\conf\axis2.xml
-Djava.ext.dirs=%SYNAPSE_HOME%\lib;%EXT_DIRS%;%SYNAPSE_HOME% -cp
%SYNAPSE_HOME%\lib
org.apache.axis2.transport.http.SimpleHTTPServer
%SYNAPSE_CMD_LINE_ARGS%
goto end
:end
Index: modules/core/maven.xml
===================================================================
--- modules/core/maven.xml (revision 405612)
+++ modules/core/maven.xml (working copy)
@@ -50,10 +50,17 @@
<mkdir dir="target/synapse-repository/modules"/>
<copy file="../../repository/modules/addressing-${
addressing.version}.mar"
tofile="target/synapse-repository/modules/addressing-${addressing.version}.mar"/>
+ <!--
<copy file="../../repository/conf/axis2.xml"
tofile="target/synapse-repository/conf/axis2.xml"/>
<copy file="../../repository/conf/synapse.xml"
tofile="target/synapse-repository/conf/synapse.xml"/>
+ -->
+ <copy todir="target/synapse-repository/conf">
+ <fileset dir="../../repository/conf">
+ <include name="**"/>
+ </fileset>
+ </copy>
<echo message="-----------Creating Testing Repository -
Fault Handling ----------"/>
<mkdir dir="target/synapse-repository-fault"/>
Index: modules/core/src/org/apache/synapse/config/Endpoint.java
===================================================================
--- modules/core/src/org/apache/synapse/config/Endpoint.java
(revision 405630)
+++ modules/core/src/org/apache/synapse/config/Endpoint.java
(working copy)
@@ -26,8 +26,12 @@
*/
public class Endpoint {
+ /** The name of this endpoint instance */
private String name = null;
+ /** The simple address this endpoint resolves to - if
explicitly specified */
private URL address = null;
+ /** The name of the actual endpoint to which this instance
refers to */
+ private String ref = null;
/**
* Return the name of the endpoint
@@ -60,4 +64,20 @@
public void setAddress(URL address) {
this.address = address;
}
+
+ /**
+ * Get the name of the Endpoint to which this instance refers to
+ * @return the name of the referenced endpoint
+ */
+ public String getRef() {
+ return ref;
+ }
+
+ /**
+ * Set the name of an Endpoint as the referenced endpoint of
this instance
+ * @param ref the name of the Endpoint referenced
+ */
+ public void setRef(String ref) {
+ this.ref = ref;
+ }
}
Index:
modules/core/src/org/apache/synapse/config/xml/FaultMediatorFactory.java
===================================================================
---
modules/core/src/org/apache/synapse/config/xml/FaultMediatorFactory.java
(revision 405673)
+++
modules/core/src/org/apache/synapse/config/xml/FaultMediatorFactory.java
(working copy)
@@ -21,6 +21,7 @@
import org.apache.synapse.api.Mediator;
import org.apache.synapse.mediators.transform.FaultMediator;
import org.apache.synapse.SynapseException;
+import org.apache.synapse.Util;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.xpath.AXIOMXPath;
@@ -80,7 +81,19 @@
OMAttribute _expression_ = code.getAttribute(ATT_EXPR_Q);
if (value != null) {
-
faultMediator.setFaultCodeValue(QName.valueOf(value.getAttributeValue()));
+ String strValue = value.getAttributeValue();
+ String prefix, name;
+ if (strValue.indexOf(":") != -1) {
+ prefix = strValue.substring(0,
strValue.indexOf(":"));
+ name = strValue.substring(strValue.indexOf
(":")+1);
+ } else {
+ String msg = "A QName is expected for fault
code as prefix:name";
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+ faultMediator.setFaultCodeValue (
+ new QName(Util.getNameSpaceWithPrefix(prefix,
code), name));
+
} else if (_expression_ != null) {
try {
faultMediator.setFaultCodeExpr(new
AXIOMXPath(_expression_.getAttributeValue()));
Index:
modules/core/src/org/apache/synapse/config/xml/LogMediatorFactory.java
===================================================================
---
modules/core/src/org/apache/synapse/config/xml/LogMediatorFactory.java
(revision 405612)
+++
modules/core/src/org/apache/synapse/config/xml/LogMediatorFactory.java
(working copy)
@@ -60,13 +60,14 @@
// Set the high level set of properties to be logged (i.e.
log level)
OMAttribute level = elem.getAttribute(new
QName(Constants.NULL_NAMESPACE, "level"));
if (level != null) {
- if (SIMPLE.equals(level)) {
+ String levelstr = level.getAttributeValue();
+ if ( SIMPLE.equals(levelstr)) {
logMediator.setLogLevel(LogMediator.SIMPLE);
- } else if (HEADERS.equals(level)) {
+ } else if (HEADERS.equals(levelstr)) {
logMediator.setLogLevel (LogMediator.HEADERS);
- } else if (FULL.equals(level)) {
+ } else if (FULL.equals(levelstr)) {
logMediator.setLogLevel(LogMediator.FULL);
- } else if (CUSTOM.equals (level)) {
+ } else if (CUSTOM.equals(levelstr)) {
logMediator.setLogLevel(LogMediator.CUSTOM);
}
}
Index:
modules/core/src/org/apache/synapse/config/xml/SendMediatorFactory.java
===================================================================
---
modules/core/src/org/apache/synapse/config/xml/SendMediatorFactory.java
(revision 405612)
+++
modules/core/src/org/apache/synapse/config/xml/SendMediatorFactory.java
(working copy)
@@ -21,8 +21,17 @@
import org.apache.synapse.api.Mediator;
import org.apache.synapse.mediators.builtin.SendMediator;
+import org.apache.synapse.config.Endpoint;
+import org.apache.synapse.SynapseException ;
import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import java.util.Iterator;
+import java.net.URL;
+import java.net.MalformedURLException;
+
/**
* The Send mediator factory parses a Send element and creates an
instance of the mediator
*
@@ -57,10 +66,45 @@
*/
public class SendMediatorFactory extends AbstractMediatorFactory {
+ private static final Log log =
LogFactory.getLog(SendMediatorFactory.class);
+
private static final QName SEND_Q = new
QName(Constants.SYNAPSE_NAMESPACE, "send");
- public Mediator createMediator(OMElement el) {
+ private static final QName ATT_REF_Q = new
QName(Constants.NULL_NAMESPACE, "ref");
+ private static final QName ATT_ADDRESS_Q = new
QName(Constants.NULL_NAMESPACE, "address");
+
+ public Mediator createMediator(OMElement elem) {
+
SendMediator sm = new SendMediator();
+
+ Iterator iter = elem.getChildrenWithName(new
QName(Constants.SYNAPSE_NAMESPACE, "endpoint"));
+ while (iter.hasNext()) {
+
+ OMElement endptElem = (OMElement) iter.next();
+ OMAttribute ref = endptElem.getAttribute(ATT_REF_Q);
+ OMAttribute address =
endptElem.getAttribute(ATT_ADDRESS_Q);
+
+ Endpoint endpt = new Endpoint();
+ if (ref != null) {
+ endpt.setRef(ref.getAttributeValue());
+ } else if (address != null) {
+ try {
+ endpt.setAddress(new
URL(address.getAttributeValue ()));
+ } catch (MalformedURLException e) {
+ String msg = "Invalid endpoint address : " +
address.getAttributeValue();
+ log.error(msg, e);
+ throw new SynapseException(msg, e);
+ }
+ } else {
+ String msg = "An endpoint used within a send
mediator definition must contain a " +
+ "'ref' (reference) or 'address' (absolute
URL) attribute";
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+ sm.addEndpoint(endpt);
+ }
+
return sm;
}
Index: modules/core/src/org/apache/synapse/Constants.java
===================================================================
--- modules/core/src/org/apache/synapse/Constants.java (revision
405612)
+++ modules/core/src/org/apache/synapse/Constants.java (working copy)
@@ -43,6 +43,8 @@
String SYNAPSE_ENV = "synapse.env";
+ String SYNAPSE_XML = "synapse.xml";
+
String ADD_ADDRESSING = " synapse.send.useaddressing";
// for security supporting
Index:
modules/core/src/org/apache/synapse/core/axis2/Axis2MessageContextFinder.java
===================================================================
---
modules/core/src/org/apache/synapse/core/axis2/Axis2MessageContextFinder.java
(revision 405673)
+++
modules/core/src/org/apache/synapse/core/axis2/Axis2MessageContextFinder.java
(working copy)
@@ -74,12 +74,21 @@
log.debug("Synapse Config not available. Creating...");
AxisConfiguration ac =
mc.getConfigurationContext().getAxisConfiguration();
- Parameter param = ac.getParameter(SYNAPSE_CONFIGURATION);
- if (param == null) {
- throw new SynapseException(
- "Axis2 configuration does not specify a '" +
SYNAPSE_CONFIGURATION + "' parameter");
+
+ InputStream is = null;
+ // Has a system property synapse.xml overwritten the
synapse config location?
+ if (System.getProperty(SYNAPSE_XML) == null) {
+ Parameter param = ac.getParameter(SYNAPSE_CONFIGURATION);
+ if (param == null) {
+ throw new SynapseException(
+ "Axis2 configuration does not specify a '" +
SYNAPSE_CONFIGURATION + "' parameter");
+ }
+ log.debug("Loading configuration from : " + ((String)
param.getValue()));
+ is =
mc.getAxisService().getClassLoader().getResourceAsStream(((String)
param.getValue()).trim());
+ } else {
+ log.debug("Loading configuration from : " +
System.getProperty(SYNAPSE_XML));
+ is =
mc.getAxisService().getClassLoader().getResourceAsStream(
System.getProperty(SYNAPSE_XML));
}
- InputStream is =
mc.getAxisService().getClassLoader().getResourceAsStream(((String)
param.getValue()).trim());
SynapseConfigurationBuilder cfgBuilder = new
SynapseConfigurationBuilder();
cfgBuilder.setConfiguration(is);
Index:
modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
===================================================================
---
modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
(revision 405673)
+++
modules/core/src/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
(working copy)
@@ -20,6 +20,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.MessageContext;
import org.apache.synapse.core.SynapseEnvironment;
+import org.apache.axis2.engine.AxisConfiguration;
/**
* <p> This is the Axis2 implementation of the MessageContext
@@ -27,13 +28,30 @@
public class Axis2SynapseEnvironment implements SynapseEnvironment {
private ClassLoader cl = null;
+ /** If synapse is initialized by the SynapseAxis2Interceptor,
the Axis2
+ * class loaders were not initialized properly at init time.
Hence in such
+ * a case, the axisCfg would be set to refer to the Axis
configuration
+ * from which the correct and properly initialized
classloader could be picked
+ * up at runtime. This would be used only if the explicit
classloader referrenced
+ * by "cl" is null (i.e. has not been set) and the axisCfg is
available.
+ */
+ private AxisConfiguration axisCfg = null;
private static final Log log =
LogFactory.getLog(Axis2SynapseEnvironment.class);
+ public Axis2SynapseEnvironment() {
+ super();
+ }
+
public Axis2SynapseEnvironment(ClassLoader cl) {
super();
this.cl <http://this.cl> = cl;
}
+ public Axis2SynapseEnvironment(AxisConfiguration axisCfg) {
+ super();
+ this.axisCfg = axisCfg;
+ }
+
public void injectMessage(MessageContext synCtx) {
synCtx.setEnvironment (this);
synCtx.getConfiguration().getMainMediator().mediate(synCtx);
@@ -47,7 +65,12 @@
}
public ClassLoader getClassLoader() {
- return cl;
+ if (cl != null) {
+ return cl;
+ } else if (axisCfg != null) {
+ axisCfg.getServiceClassLoader();
+ }
+ return null;
}
public void setClassLoader(ClassLoader cl) {
Index:
modules/core/src/org/apache/synapse/core/axis2/SynapseAxis2Interceptor.java
===================================================================
---
modules/core/src/org/apache/synapse/core/axis2/SynapseAxis2Interceptor.java
(revision 0)
+++
modules/core/src/org/apache/synapse/core/axis2/SynapseAxis2Interceptor.java
(revision 0)
@@ -0,0 +1,142 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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
<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.core.axis2;
+
+import org.apache.axis2.engine.AxisObserver;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.engine.AxisEvent;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.AxisModule;
+import org.apache.axis2.description.Parameter ;
+import org.apache.axis2.AxisFault;
+import org.apache.axiom.om.OMElement;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.Constants;
+import org.apache.synapse.config.xml.SynapseConfigurationBuilder ;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.ArrayList;
+import java.io.InputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException ;
+
+/**
+ * The Synapse Axis2 interceptor will be invoked by Axis2 upon
Axis initialization.
+ * This allows the Synapse engine to be initialized at Axis2
startup, and store the
+ * initial Synapse configuration into the AxisConfiguration for
subsequent lookup.
+ */
+public class SynapseAxis2Interceptor implements AxisObserver,
Constants {
+
+ private static final Log log =
LogFactory.getLog(SynapseAxis2Interceptor.class);
+
+ /**
+ * This is where Synapse is initialized at Axis2 startup
+ * @param axisCfg the Axis2 Configuration
+ */
+ public void init(AxisConfiguration axisCfg) {
+
+ log.info("Initializing Synapse...");
+
+ String synapseXmlLocation = null;
+ // Has a system property synapse.xml overwritten the
synapse config location?
+ if (System.getProperty(SYNAPSE_XML) != null) {
+ log.info("Loading configuration from XML file
specified by the system property '" + SYNAPSE_XML +"'");
+ synapseXmlLocation = System.getProperty(SYNAPSE_XML);
+
+ } else {
+ // get the synapse configuration XML file parameter
+ Parameter param =
axisCfg.getParameter(SYNAPSE_CONFIGURATION);
+ if (param == null) {
+ handleException("Axis2 configuration does not
specify the '" + SYNAPSE_CONFIGURATION + "' parameter");
+ } else {
+ synapseXmlLocation = ((String)
param.getValue()).trim();
+ }
+ }
+
+ // The axis classloaders such as
axisCfg.getServiceClassLoader(), axisCfg.getModuleClassLoader(),
+ // axisCfg.getSystemClassLoader() are not yet initialized
at this point, hence load the synapse.xml
+ // from a FileInputStream as does Axis!
+ InputStream is = null;
+ try {
+ is = new FileInputStream(synapseXmlLocation);
+ } catch (FileNotFoundException fnf) {
+ handleException("Cannot load Synapse configuration
from : " + synapseXmlLocation, fnf);
+ }
+
+ // build the Synapse configuration parsing the XMl config
file
+ SynapseConfigurationBuilder cfgBuilder = new
SynapseConfigurationBuilder();
+ cfgBuilder.setConfiguration(is);
+ log.info("Loaded Synapse configuration from : " +
synapseXmlLocation);
+
+ Parameter synapseCtxParam = new Parameter(SYNAPSE_CONFIG,
null);
+ synapseCtxParam.setValue(cfgBuilder.getConfig());
+
+ Parameter synapseEnvParam = new Parameter(SYNAPSE_ENV, null);
+ // Note.. will the classloader mentioned below be
overwritten subsequently by Axis?
+ synapseEnvParam.setValue(new
Axis2SynapseEnvironment(axisCfg));
+
+ try {
+ axisCfg.addParameter(synapseCtxParam);
+ axisCfg.addParameter(synapseEnvParam);
+
+ } catch (AxisFault e) {
+ handleException(
+ "Could not set parameters '" + SYNAPSE_CONFIG +
"' and/or '" + SYNAPSE_ENV +
+ "'to the Axis2 configuration : " +
e.getMessage(), e);
+ }
+
+ log.info("Synapse initialized...");
+ }
+
+ private void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+ private void handleException(String msg, Exception e) {
+ log.error(msg, e);
+ throw new SynapseException(msg, e);
+ }
+
+
//---------------------------------------------------------------------------------------
+ public void serviceUpdate(AxisEvent axisEvent, AxisService
axisService) {
+ }
+
+ public void moduleUpdate(AxisEvent axisEvent, AxisModule
axisModule) {
+ }
+
+ public void addParameter(Parameter parameter) throws AxisFault {
+ }
+
+ public void removeParameter(Parameter parameter) throws
AxisFault {
+ }
+
+ public void deserializeParameters(OMElement elem) throws
AxisFault {
+ }
+
+ public Parameter getParameter(String string) {
+ return null;
+ }
+
+ public ArrayList getParameters() {
+ return null;
+ }
+
+ public boolean isParameterLocked(String string) {
+ return false;
+ }
+}
Index:
modules/core/src/org/apache/synapse/core/axis2/SynapseDispatcher.java
===================================================================
---
modules/core/src/org/apache/synapse/core/axis2/SynapseDispatcher.java
(revision 405612)
+++
modules/core/src/org/apache/synapse/core/axis2/SynapseDispatcher.java
(working copy)
@@ -22,15 +22,19 @@
import org.apache.axis2.description.HandlerDescription;
import org.apache.axis2.engine.AbstractDispatcher;
import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.commons.logging.Log ;
+import org.apache.commons.logging.LogFactory;
import javax.xml.namespace.QName;
/**
- * This sends every message to the SynapseMessageReceiver so that
it can pass them to Synapse
+ * This is the Axis2 Dispatcher which is registered with the
Axis2 engine. It dispatches
+ * each and every message received to the SynapseMessageReceiver
for processing.
*/
public class SynapseDispatcher extends AbstractDispatcher {
- // FOR EVERY REQUEST - ALWAYS DISPATH TO THE SYNAPSE SERVICE
+ private static final Log log =
LogFactory.getLog(SynapseDispatcher.class);
+
private static final long serialVersionUID =
-6970206989111592645L;
private static final String SYNAPSE_SERVICE_NAME = "synapse";
@@ -41,7 +45,6 @@
QName qn = new QName("http://synapse.apache.org",
"SynapseDispatcher");
HandlerDescription hd = new HandlerDescription(qn);
super.init(hd);
-
}
public AxisService findService(MessageContext mc) throws
AxisFault {
@@ -50,11 +53,8 @@
return as;
}
- public AxisOperation findOperation(AxisService svc,
MessageContext mc)
- throws AxisFault {
-
+ public AxisOperation findOperation(AxisService svc,
MessageContext mc) throws AxisFault {
AxisOperation ao = svc.getOperation(MEDIATE_OPERATION_NAME);
return ao;
}
-
}
Index:
modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java
===================================================================
---
modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java
(revision 405673)
+++
modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java
(working copy)
@@ -84,6 +84,8 @@
StringBuffer sb = new StringBuffer();
if (synCtx.getTo() != null)
sb.append("To: " + synCtx.getTo().getAddress());
+ else
+ sb.append("To: ");
if (synCtx.getFrom() != null)
sb.append(SEP + "From: " + synCtx.getFrom().getAddress());
if (synCtx.getWSAAction() != null)
Index:
modules/core/src/org/apache/synapse/mediators/builtin/SendMediator.java
===================================================================
---
modules/core/src/org/apache/synapse/mediators/builtin/SendMediator.java
(revision 405673)
+++
modules/core/src/org/apache/synapse/mediators/builtin/SendMediator.java
(working copy)
@@ -17,20 +17,31 @@
package org.apache.synapse.mediators.builtin;
import org.apache.synapse.MessageContext;
+import org.apache.synapse.config.Endpoint;
import org.apache.synapse.mediators.AbstractMediator ;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.axis2.addressing.EndpointReference;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* The Send mediator sends the message using the following semantics.
* <p/>
* This is a leaf mediator (i.e. further processing halts after
this mediator completes)
* <p/>
- * TODO support endpoints, loadbalancing and failover
+ * TODO support loadbalancing and failover
*/
public class SendMediator extends AbstractMediator {
private static final Log log =
LogFactory.getLog(SendMediator.class);
+
+ /** The list of endpoints to which the message should be sent
to. If none
+ * are specified, the message is sent where its implicitly
stated in the
+ * current message */
+ private List endpoints = new ArrayList();
+
/**
* This is a leaf mediator. i.e. processing stops once send is
invoked,
* as it always returns false
@@ -40,10 +51,34 @@
*/
public boolean mediate(MessageContext synCtx) {
log.debug(getType() + " mediate()");
- log.debug("Sending To: " + ( synCtx.getTo() != null ?
+ /*log.debug("Sending To: " + (synCtx.getTo() != null ?
synCtx.getTo().getAddress() : "null"));
- log.debug("Body : \n" + synCtx.getEnvelope ());
- synCtx.getEnvironment().send(synCtx);
+ log.debug("SOAPAction: " + (synCtx.getWSAAction() != null ?
+ synCtx.getWSAAction() : "null"));
+ log.debug("Body : \n" + synCtx.getEnvelope());*/
+
+ // if no endpoints are defined, send where implicitly stated
+ if (endpoints.isEmpty()) {
+ synCtx.getEnvironment().send(synCtx);
+
+ } else if ( endpoints.size() == 1) {
+ Endpoint singleEndpoint = (Endpoint) endpoints.get(0);
+ synCtx.setTo(new
EndpointReference(singleEndpoint.getAddress().toString()));
+
+ } else {
+ String msg = "The send mediator currently supports
only one endpoint";
+ log.error(msg);
+ throw new UnsupportedOperationException(msg);
+ }
return false;
}
+
+ /**
+ * Add the given Endpoint as an endpoint for this Send
mediator instance
+ * @param e the Endpoint to be added
+ * @return true if the endpoint list was updated
+ */
+ public boolean addEndpoint(Endpoint e) {
+ return endpoints.add(e);
+ }
}
Index:
modules/core/src/org/apache/synapse/mediators/GetPropertyFunction.java
===================================================================
---
modules/core/src/org/apache/synapse/mediators/GetPropertyFunction.java
(revision 405673)
+++
modules/core/src/org/apache/synapse/mediators/GetPropertyFunction.java
(working copy)
@@ -21,6 +21,7 @@
import org.jaxen.Navigator;
import org.jaxen.function.StringFunction;
import org.apache.synapse.MessageContext;
+import org.apache.synapse.HeaderType;
import org.apache.commons.logging.Log ;
import org.apache.commons.logging.LogFactory;
@@ -59,7 +60,25 @@
while (iter.hasNext()) {
String key = StringFunction.evaluate(iter.next(),
navigator);
// ignore if more than one argument has been
specified
- return synCtx.getProperty(key);
+ Object result = synCtx.getProperty(key);
+
+ if (result != null) {
+ return result;
+ } else {
+ if (HeaderType.STR_TO.equals(key) &&
synCtx.getTo() != null) {
+ return synCtx.getTo().getAddress();
+ } else if (HeaderType.STR_FROM.equals(key) &&
synCtx.getFrom() != null) {
+ return synCtx.getFrom().getAddress();
+ } else if (HeaderType.STR_ACTION.equals(key)
&& synCtx.getWSAAction() != null) {
+ return synCtx.getWSAAction();
+ } else if (HeaderType.STR_FAULT.equals(key)
&& synCtx.getFaultTo() != null) {
+ return synCtx.getFaultTo().getAddress();
+ } else if
(HeaderType.STR_REPLY_TO.equals(key) && synCtx.getReplyTo() != null) {
+ return synCtx.getReplyTo().getAddress();
+ } else {
+ return null;
+ }
+ }
}
}
return null;
Index:
modules/core/src/org/apache/synapse/mediators/transform/FaultMediator.java
===================================================================
---
modules/core/src/org/apache/synapse/mediators/transform/FaultMediator.java
(revision 405673)
+++
modules/core/src/org/apache/synapse/mediators/transform/FaultMediator.java
(working copy)
@@ -226,7 +226,7 @@
} else {
if (
-
SOAP12Constants.SOAP_DEFAULT_NAMESPACE_PREFIX.equals
(faultCodeValue.getNamespaceURI()) &&
+
SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(faultCodeValue.getNamespaceURI())
&&
(SOAP12Constants.FAULT_CODE_DATA_ENCODING_UNKNOWN.equals
(faultCodeValue.getLocalPart()) ||
SOAP12Constants.FAULT_CODE_MUST_UNDERSTAND.equals(faultCodeValue.getLocalPart())
||
Index: modules/core/src/org/apache/synapse/Util.java
===================================================================
--- modules/core/src/org/apache/synapse/Util.java (revision
405673)
+++ modules/core/src/org/apache/synapse/Util.java (working copy)
@@ -18,6 +18,8 @@
import org.apache.axiom.om.xpath.AXIOMXPath;
import org.apache.axiom.om.impl.llom.OMElementImpl;
import org.apache.axiom.om.impl.llom.OMTextImpl;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
import org.apache.commons.logging.LogFactory ;
import org.apache.commons.logging.Log;
import org.apache.synapse.mediators.GetPropertyFunction;
@@ -91,4 +93,26 @@
}
}
+ /**
+ * Return the namespace with the given prefix, using the
given element
+ * @param prefix the prefix looked up
+ * @param elem the source element to use
+ * @return the namespace which maps to the prefix or null
+ */
+ public static String getNameSpaceWithPrefix(String prefix,
OMElement elem) {
+ if (prefix == null || elem == null) {
+ log.warn("Searching for null NS prefix and/or using
null OMElement");
+ return null;
+ }
+
+ Iterator iter = elem.getAllDeclaredNamespaces();
+ while (iter.hasNext()) {
+ OMNamespace ns = (OMNamespace) iter.next();
+ if (prefix.equals(ns.getPrefix())) {
+ return ns.getName();
+ }
+ }
+ return null;
+ }
+
}
Index: repository/conf/axis2.xml
===================================================================
--- repository/conf/axis2.xml (revision 405612)
+++ repository/conf/axis2.xml (working copy)
@@ -12,13 +12,17 @@
<!-- Location of the SynapseRepository -->
- <parameter name="SynapseConfiguration"
locked="false">conf/synapse.xml</parameter>
+ <parameter name="SynapseConfiguration"
locked="false">./../synapse_repository/conf/synapse.xml</parameter>
<parameter name="userName" locked="false">admin</parameter>
<parameter name="password" locked="false">axis2</parameter>
+ <!-- Always engage addressing for Synapse -->
<module ref="addressing"/>
+ <!-- This interceptor initializes Synapse on Axis2 startup -->
+ <listener
class="org.apache.synapse.core.axis2.SynapseAxis2Interceptor"/>
+
<!-- ================================================= -->
<!-- Message Receivers -->
<!-- ================================================= -->
Index: repository/conf/sample/synapse_sample_0.xml
===================================================================
--- repository/conf/sample/synapse_sample_0.xml (revision 0)
+++ repository/conf/sample/synapse_sample_0.xml (revision 0)
@@ -0,0 +1,39 @@
+<synapse xmlns=" http://ws.apache.org/ns/synapse">
+
+ <definitions>
+
+ <sequence name="stockquote">
+ <!-- set the To address to the real endpoint -->
+ <header name="To" value="
http://www.webservicex.net/stockquote.asmx"/>
+
+ <!-- check if the symbol is MSFT -->
+ <filter xpath="//*[wsx:symbol='MSFT']"
xmlns:wsx="http://www.webserviceX.NET/">
+ <!-- if it is throw a fault -->
+ <makefault>
+ <code value="tns:Receiver" xmlns:tns="
http://www.w3.org/2003/05/soap-envelope"/>
+ <reason value="Isn't there a Windows API for that?"/>
+ </makefault>
+ </filter>
+ </sequence>
+
+ </definitions>
+
+ <rules>
+ <!-- now log the message using log4j -->
+ <log level="full"/>
+
+ <!-- Check if the URL matches the stockquote gateway/dumb
case -->
+ <filter source="get-property('To')" regex=".*/StockQuote.*">
+ <sequence ref="stockquote"/>
+ </filter>
+
+ <!-- check if the URL matches the virtual url - either the
proxy or ws-add case -->
+ <filter source="get-property('To')"
regex="http://stockquote.*">
+ <sequence ref="stockquote"/>
+ </filter>
+
+ <!-- send the message on -->
+ <send/>
+ </rules>
+
+</synapse>
\ No newline at end of file
Index: repository/conf/sample/synapse_sample_0.xml
===================================================================
--- repository/conf/sample/synapse_sample_0.xml (revision 0)
+++ repository/conf/sample/synapse_sample_0.xml (revision 0)
@@ -0,0 +1,39 @@
+<synapse xmlns="http://ws.apache.org/ns/synapse">
+
+ <definitions>
+
+ <sequence name="stockquote">
+ <!-- set the To address to the real endpoint -->
+ <header name="To" value="
http://www.webservicex.net/stockquote.asmx"/>
+
+ <!-- check if the symbol is MSFT -->
+ <filter xpath="//*[wsx:symbol='MSFT']" xmlns:wsx="
http://www.webserviceX.NET/">
+ <!-- if it is throw a fault -->
+ <makefault>
+ <code value="tns:Receiver" xmlns:tns="
http://www.w3.org/2003/05/soap-envelope"/>
+ <reason value="Isn't there a Windows API for that?"/>
+ </makefault>
+ </filter>
+ </sequence>
+
+ </definitions>
+
+ <rules>
+ <!-- now log the message using log4j -->
+ <log level="full"/>
+
+ <!-- Check if the URL matches the stockquote gateway/dumb
case -->
+ <filter source="get-property('To')" regex=".*/StockQuote.*">
+ <sequence ref="stockquote"/>
+ </filter>
+
+ <!-- check if the URL matches the virtual url - either the
proxy or ws-add case -->
+ <filter source="get-property('To')"
regex="http://stockquote.*">
+ <sequence ref="stockquote"/>
+ </filter>
+
+ <!-- send the message on -->
+ <send/>
+ </rules>
+
+</synapse>
\ No newline at end of file
Index: repository/conf/synapse.xml
===================================================================
--- repository/conf/synapse.xml (revision 405612)
+++ repository/conf/synapse.xml (working copy)
@@ -1,41 +1,39 @@
- <synapse xmlns=" http://ws.apache.org/ns/synapse">
- <definitions>
- <sequence name="registration_flow">
- <filter xpath="//[EMAIL PROTECTED]'GOLD']">
- <log level="full">
- <property name="category" value="GOLD"/>
- </log>
- <drop/>
- </filter>
- <sequence ref="fault_flow"/>
- </sequence>
+<synapse xmlns=" http://ws.apache.org/ns/synapse">
- <sequence name="fault_flow">
- <log level="full">
- <property name="application" value="Hello World"/>
- </log>
- <drop/>
- </sequence>
-
- <sequence name="stockquote">
- <log level="full">
- <property name="application" value="StockQuote"/>
- </log>
- <filter xpath="//*[wsx:symbol='MSFT']"
xmlns:wsx="http://www.webserviceX.NET/ <http://www.webserviceX.NET/>">
- <makefault>
- <reason>Sorry the requested stock is no
longer available</reason>
- </makefault>
- </filter>
- <header name="to" value="
http://www.webservicex.net/stockquote.asmx"/>
- </sequence>
-
- </definitions>
-
- <rules>
- <filter source="//wsa:To" regex=".*/StockQuote.*"
xmlns:wsa=" http://schemas.xmlsoap.org/ws/2004/08/addressing">
- <sequence ref="stockquote"/>
- </filter>
- <send/>
- </rules>
-
- </synapse>
\ No newline at end of file
+ <definitions>
+
+ <sequence name="stockquote">
+ <!-- set the To address to the real endpoint -->
+ <header name="To" value="
http://www.webservicex.net/stockquote.asmx"/>
+
+ <!-- check if the symbol is MSFT -->
+ <filter xpath="//*[wsx:symbol='MSFT']" xmlns:wsx="
http://www.webserviceX.NET/">
+ <!-- if it is throw a fault -->
+ <makefault>
+ <code value="tns:Receiver" xmlns:tns="
http://www.w3.org/2003/05/soap-envelope"/>
+ <reason value="Isn't there a Windows API for that?"/>
+ </makefault>
+ </filter>
+ </sequence>
+
+ </definitions>
+
+ <rules>
+ <!-- now log the message using log4j -->
+ <log level="full"/>
+
+ <!-- Check if the URL matches the stockquote gateway/dumb
case -->
+ <filter source="get-property('To')" regex=".*/StockQuote.*">
+ <sequence ref="stockquote"/>
+ </filter>
+
+ <!-- check if the URL matches the virtual url - either the
proxy or ws-add case -->
+ <filter source="get-property('To')"
regex="http://stockquote.*">
+ <sequence ref="stockquote"/>
+ </filter>
+
+ <!-- send the message on -->
+ <send/>
+ </rules>
+
+</synapse>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
|